From cd73281f324a5b21c304789ca7b828295e8718d9 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. (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. --- lisp/doc-view.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/doc-view.el b/lisp/doc-view.el index b14655fb274..d9c12fc49c0 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -1912,7 +1912,8 @@ doc-view--pdf-outline (let ((outline nil) (fn (shell-quote-argument (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