branch: master commit 2bc07b78fff81da3eb705ab6bc93da35ddb4ba76 Author: Ikumi Keita <ik...@ikumi.que.jp> Commit: Ikumi Keita <ik...@ikumi.que.jp>
Fix `TeX-documentation-texdoc' for okular We used `start-process-shell-command' for these 4 years. However, it turned out that that invalidated okular. (See bug#40577 and <URL:https://lists.gnu.org/r/auctex/2023-01/msg00006.html>.) The reason that `TeX-documentation-texdoc' tried hard to collect and show the output from Texdoc is that the exit code wasn't meaningful once[1]. This was the only way to notify the user when Texdoc can't find any documentation for the given keyword. However, recent Texdoc is improved to return non-zero exit code when it can't find any documentation[2]. Now we use `call-process' instead of `start-process-shell-command'. This has a drawback that user who sticks to older TeX Live distribution isn't notified at all when the given keyword didn't match any documentation, but we hope that it doesn't cause major problem. [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28905#17 [2] https://tug.org/texdoc/doc/texdoc.man1.pdf * tex.el (TeX-documentation-texdoc): Use `call-process' to invoke Texdoc. Move `executable-find' test up in the function body so that it covers no prefix case as well. Add NO-PROPERTIES argument to `thing-at-point'. Remove unnecessary `save-excursion'. Refill. --- tex.el | 121 +++++++++++++++++++++++++---------------------------------------- 1 file changed, 47 insertions(+), 74 deletions(-) diff --git a/tex.el b/tex.el index 456c0310..628f0362 100644 --- a/tex.el +++ b/tex.el @@ -6390,81 +6390,54 @@ If called with a prefix argument ARG, after selecting the package, prompt for selection of the manual of that package to show." (interactive "P") - (let ((pkg (thing-at-point 'symbol)) - buffer list doc) - ;; 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: run "texdoc --list --nointeract <pkg>" - (progn - ;; Create the buffer, insert the result of the command, and - ;; accumulate the list of manuals. - (with-current-buffer (get-buffer-create - (setq buffer (format "*texdoc: %s*" pkg))) - (erase-buffer) - (insert (shell-command-to-string - (concat "texdoc --list --nointeract " pkg))) - (goto-char 1) ; No need to use `point-min' here. - (save-excursion + (if (not (executable-find "texdoc")) + (message "texdoc not found") + (let ((pkg (thing-at-point 'symbol t)) + buffer list doc) + (setq pkg (TeX-read-string "View documentation for: " pkg)) + (unless (zerop (length pkg)) + (if arg + ;; Called with prefix argument: + ;; run "texdoc --list --nointeract <pkg>" + (progn + ;; Create the buffer, insert the result of the command, + ;; and accumulate the list of manuals. + (with-current-buffer (get-buffer-create + (setq buffer (format "*texdoc: %s*" pkg))) + (erase-buffer) + (insert (shell-command-to-string + (concat "texdoc --list --nointeract " pkg))) + (goto-char 1) ; No need to use `point-min' here. (while (re-search-forward - ;; XXX: XEmacs doesn't support character classes in - ;; regexps, like "[:alnum:]". - "^ *\\([0-9]+\\) +\\([-~/a-zA-Z0-9_.${}#%,:\\ ()]+\\)" nil t) - (push (cons (match-string 1) (match-string 2)) list)))) - (unwind-protect - (cond - ((null (executable-find "texdoc")) - ;; Note: `shell-command-to-string' uses shell, only - ;; `call-process' looks at `exec-path', thus only here makes - ;; sense to use `executable-find' to test whether texdoc is - ;; available. - (message "texdoc not found")) - (list - ;; Go on if there are manuals listed: show the buffer, prompt - ;; for the number of the manual, then run - ;; texdoc --just-view <doc> - (TeX-pop-to-buffer (get-buffer buffer)) - (condition-case nil - (when (setq doc - (cdr (assoc (TeX-read-string "Please enter \ -the number of the file to view, anything else to skip: ") list))) - (call-process "texdoc" nil 0 nil "--just-view" doc)) - ;; Exit gently if a `quit' signal is thrown. - (quit nil))) - (t (message "No documentation found for %s" pkg))) - ;; In any case quit-and-kill the window. - (when (get-buffer-window buffer) - (quit-window t (get-buffer-window buffer))))) - ;; Called without prefix argument: just run "texdoc --view <pkg>" and - ;; show the output, so that the user is warned in case it doesn't find - ;; the documentation or "texdoc" is not available. - (message "%s" - ;; The folowing code to the end of `defun' used to be - ;; just - ;; (shell-command-to-string (concat "texdoc --view " pkg)) - ;; , but in some cases it blocks emacs until the user - ;; quits the viewer (bug#28905). - (with-output-to-string - (let* (;; Use pipe rather than pty because the - ;; latter causes atril (evince variant - ;; viewer) to exit before showing anything. - (process-connection-type nil) - (process (start-process-shell-command - "Doc view" standard-output - (concat "texdoc --view " pkg)))) - ;; Suppress the message "Process Doc view - ;; finished". - (set-process-sentinel process #'ignore) - ;; Kill temp buffer without query. This is - ;; necessary, at least for some environment, if - ;; the underlying shell can't find the texdoc - ;; executable. - (set-process-query-on-exit-flag process nil) - ;; Don't discard shell output. - (accept-process-output process)))))))) + "^ *\\([0-9]+\\) +\\([-~/a-zA-Z0-9_.${}#%,:\\ ()]+\\)" + nil t) + (push (cons (match-string 1) (match-string 2)) list))) + (unwind-protect + (cond + (list + ;; Go on if there are manuals listed: show the + ;; buffer, prompt for the number of the manual, + ;; then run + ;; texdoc --just-view <doc> + (TeX-pop-to-buffer (get-buffer buffer)) + (condition-case nil + (when (setq doc + (cdr (assoc (TeX-read-string "Please \ +enter the number of the file to view, anything else to skip: ") list))) + (call-process "texdoc" nil 0 nil "--just-view" doc)) + ;; Exit gently if a `quit' signal is thrown. + (quit nil))) + (t (message "No documentation found for %s" pkg))) + ;; In any case quit-and-kill the window. + (when (get-buffer-window buffer) + (quit-window t (get-buffer-window buffer))))) + ;; Called without prefix argument: + ;; just run "texdoc --view <pkg>". + ;; Recent Texdoc returns exit code 3 when it can't find the + ;; specified document, according to + ;; <URL:https://tug.org/texdoc/doc/texdoc.man1.pdf> + (if (= (call-process "texdoc" nil nil nil "--view" pkg) 3) + (message "No documentation found for %s" pkg))))))) (defun TeX-goto-info-page () "Read documentation for AUCTeX in the info system."