[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX-devel] Changing TeX-doc?

From: Mosè Giordano
Subject: Re: [AUCTeX-devel] Changing TeX-doc?
Date: Sun, 31 Jan 2016 20:52:51 +0100

Dear all,

2016-01-28 13:27 GMT+01:00 Mosè Giordano <address@hidden>:
> A possible improvement could be to offer the list of alternatives, as
> "texdoc --list" does, when calling the function with a prefix
> argument.  I tried to call "texdoc --list <string>" with `comint-exec'
> but it doesn't start the viewer, I suspect there is something wrong in
> `texdoc' (or in its interaction with `comint-exec') because other
> programs run with `comint-exec' are able to start external programs.
> Thus, I think we should parse "Data.tlpdb.lua" as suggested by
> Nicolas.  Anyway, I'd add this feature later.

Here is the improved version of `TeX-documentation-texdoc' with
parsing of Data.tlpdb.lua:

--8<---------------cut here---------------start------------->8---
(defun TeX-documentation-texdoc (&optional arg)
  "Run texdoc to read documentation.

Prompt for selection of the package of which to show the documentation.

If called with a prefix argument ARG, after selecting the
package, prompt for selection of the manual of that package to
  (interactive "*P")
  (let ((pkg (thing-at-point 'symbol))
    root docs)
    ;; Strip off properties.  XXX: XEmacs doesn't have
    ;; `substring-no-properties'.
    (set-text-properties 0 (length pkg) nil pkg)
    (setq pkg (TeX-read-string "View documentation for: " pkg))
    (unless (zerop (length pkg))
      (if arg
      ;; Called with prefix argument: search for all manuals of `pkg' listed
      ;; in `Data.tlpdb.lua'.
      (if (executable-find "texdoc")
        (setq root (car (TeX-tree-expand '("$TEXMFROOT") "latex")))
        (insert-file (replace-regexp-in-string
                  "[\n\r]*\\'" ""
                   "kpsewhich Data.tlpdb.lua")))
        ;; Look for aliases listed in "tlp_from_runfile".
        (re-search-forward "^local tlp_from_runfile =[^{]+")
        (narrow-to-region (point) (scan-sexps (point) 1))
        (when (re-search-forward
            "\\[\"" pkg "\"\\] = {\\[\"\\([-[:alnum:]]+\\)\"\\]")
               nil t)
          (setq pkg (match-string 1)))
        ;; Widen the buffer and go on searching for the list of manuals.
        (re-search-forward "^local tlp_doclist =[^{]+")
        (narrow-to-region (point) (scan-sexps (point) 1))
        (if (re-search-forward (concat "\\[\"" pkg "\"\\] =[^{]+")
                       nil t)
              (narrow-to-region (point) (scan-sexps (point) 1))
               nil t)
            (push (expand-file-name (match-string 1) root) docs))
              (call-process "texdoc" nil nil nil "--just-view"
                     (concat "Choose manual for " pkg ": ")
                     docs nil nil root)))
          (message "No documentation found for %s" pkg)))
        (message "texdoc not found"))
    ;; Called without prefix argument: just run "texdoc --view" and show the
    ;; output, so that the user is warned in case it doesn't find the
    ;; documentation or "texdoc" is not available.
    (message (shell-command-to-string (concat "texdoc --view " pkg)))))))
--8<---------------cut here---------------end--------------->8---

Thanks to Nicolas for the suggestion!  As usual, comments welcome.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]