>From 5b24d23e3317491c31ae1392c29ac7cdf303f9d4 Mon Sep 17 00:00:00 2001 From: Morgan Smith Date: Tue, 11 Jul 2023 13:31:40 -0400 Subject: [PATCH] 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-imenu-setup): Do not preemptively run 'doc-view--pdf-outline' as an error here would inhibit display of the document. --- lisp/doc-view.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/doc-view.el b/lisp/doc-view.el index b14655fb274..d5ccfc19853 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -147,6 +147,8 @@ (require 'filenotify) (eval-when-compile (require 'subr-x)) +(autoload 'imenu-unavailable-error "imenu") + ;;;; Customization Options (defgroup doc-view nil @@ -1910,9 +1912,10 @@ doc-view--pdf-outline (let ((fn (or file-name (buffer-file-name)))) (when fn (let ((outline nil) - (fn (shell-quote-argument (expand-file-name fn)))) + (fn (expand-file-name fn))) (with-temp-buffer - (insert (shell-command-to-string (format "mutool show %s outline" fn))) + (unless (= 0 (call-process "mutool" nil (current-buffer) nil "show" fn "outline")) + (imenu-unavailable-error "Unable to create imenu index using `mutool'")) (goto-char (point-min)) (while (re-search-forward doc-view--outline-rx nil t) (push `((level . ,(length (match-string 1))) @@ -1964,8 +1967,7 @@ doc-view-imenu-setup (when (and doc-view-imenu-enabled (executable-find "mutool")) (setq-local imenu-create-index-function #'doc-view-imenu-index imenu-submenus-on-top nil - imenu-sort-function nil - doc-view--outline (doc-view--pdf-outline)) + imenu-sort-function nil) (when doc-view--outline (imenu-add-to-menubar "Outline")))) ;;;; User interface commands and the mode -- 2.40.1