From 011beaccb3b2e004240ed80a4948d791fc4efbb9 Mon Sep 17 00:00:00 2001 From: Morgan Smith Date: Fri, 7 Jul 2023 11:17:15 -0400 Subject: [PATCH] docview: Only enable imenu when supported 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): Don't check for 'mutool' as that is already done by 'doc-view-imenu-enabled'. Only enable imenu for PDF documents. (bug#64516) --- lisp/doc-view.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lisp/doc-view.el b/lisp/doc-view.el index b14655fb274..101de04297f 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -1910,9 +1910,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")) + (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))) @@ -1961,7 +1962,7 @@ doc-view-imenu-index (defun doc-view-imenu-setup () "Set up local state in the current buffer for imenu, if needed." - (when (and doc-view-imenu-enabled (executable-find "mutool")) + (when (and doc-view-imenu-enabled (eq 'pdf doc-view-doc-type)) (setq-local imenu-create-index-function #'doc-view-imenu-index imenu-submenus-on-top nil imenu-sort-function nil -- 2.40.1