Skip to content

Commit 6510899

Browse files
MorganJamesSmithEli-Zaretskii
authored andcommitted
docview: imenu: check return value of 'mutool'
While 'mutool' supports many filetypes, 'mutool show' only supports PDF files. This would lead to cryptic imenu errors when opening other file types (like EPUB) since we would parse the error output. During my testing this caused 'imenu--index-alist' to have a value of '(nil). * lisp/doc-view.el (doc-view--pdf-outline): Error when 'mutool' returns an error. Use 'call-process' to get the return value and remove the call to 'shell-quote-argument' as 'call-process' doesn't want any escapes. (doc-view-mode): Handle possible error from 'doc-view-imenu-setup'. (doc-view-imenu-enabled): Remove superfluous (and ... t). (doc-view-imenu-setup): Remove check for mutool already ensured by 'doc-view-imenu-enabled' being non-nil. (Bug#64516)
1 parent 3c041e3 commit 6510899

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lisp/doc-view.el

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@
147147
(require 'filenotify)
148148
(eval-when-compile (require 'subr-x))
149149

150+
(autoload 'imenu-unavailable-error "imenu")
151+
150152
;;;; Customization Options
151153

152154
(defgroup doc-view nil
@@ -214,7 +216,7 @@ are available (see Info node `(emacs)Document View')."
214216
:type 'boolean
215217
:version "30.1")
216218

217-
(defcustom doc-view-imenu-enabled (and (executable-find "mutool") t)
219+
(defcustom doc-view-imenu-enabled (executable-find "mutool")
218220
"Whether to generate an imenu outline when \"mutool\" is available."
219221
:type 'boolean
220222
:version "29.1")
@@ -1910,9 +1912,10 @@ structure is extracted by `doc-view--imenu-subtree'."
19101912
(let ((fn (or file-name (buffer-file-name))))
19111913
(when fn
19121914
(let ((outline nil)
1913-
(fn (shell-quote-argument (expand-file-name fn))))
1915+
(fn (expand-file-name fn)))
19141916
(with-temp-buffer
1915-
(insert (shell-command-to-string (format "mutool show %s outline" fn)))
1917+
(unless (= 0 (call-process "mutool" nil (current-buffer) nil "show" fn "outline"))
1918+
(imenu-unavailable-error "Unable to create imenu index using `mutool'"))
19161919
(goto-char (point-min))
19171920
(while (re-search-forward doc-view--outline-rx nil t)
19181921
(push `((level . ,(length (match-string 1)))
@@ -1961,7 +1964,7 @@ GOTO-PAGE-FN other than `doc-view-goto-page'."
19611964

19621965
(defun doc-view-imenu-setup ()
19631966
"Set up local state in the current buffer for imenu, if needed."
1964-
(when (and doc-view-imenu-enabled (executable-find "mutool"))
1967+
(when doc-view-imenu-enabled
19651968
(setq-local imenu-create-index-function #'doc-view-imenu-index
19661969
imenu-submenus-on-top nil
19671970
imenu-sort-function nil
@@ -2236,7 +2239,10 @@ toggle between displaying the document or editing it as text.
22362239
(setq mode-name "DocView"
22372240
buffer-read-only t
22382241
major-mode 'doc-view-mode)
2239-
(doc-view-imenu-setup)
2242+
(condition-case imenu-error
2243+
(doc-view-imenu-setup)
2244+
(imenu-unavailable (message "imenu support unavailable: %s"
2245+
(cadr imenu-error))))
22402246
(doc-view-initiate-display)
22412247
;; Switch off view-mode explicitly, because doc-view-mode is the
22422248
;; canonical view mode for PDF/PS/DVI files. This could be

0 commit comments

Comments
 (0)