Subject: bug#64516: closed (Re: bug#64516: [PATCH] docview: Only enable imenu when supported)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 20 Jul 2023 16:06:02 +0000

Your bug report

#64516: [PATCH] docview: Only enable imenu when supported

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
64516: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64516
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#64516: [PATCH] docview: Only enable imenu when supported
From: Eli Zaretskii <[email-masked]>
To: Tassilo Horn <[email-masked]>
Cc: [email-masked], [email-masked], [email-masked]
Date: Thu, 20 Jul 2023 19:05:38 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Tassilo Horn <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>, [email-masked], [email-masked]
> Date: Tue, 18 Jul 2023 21:14:35 +0200
> 
> Alright, I've amended your patch with my slight modifications.  Eli,
> feel free to "git am" it where you see fit.  It should apply both on
> master and on emacs-29.

Thanks to both of you.  I've now installed this on the master branch,
and I'm closing the bug.

Subject: [PATCH] docview: Only enable imenu when supported
From: Morgan Smith <[email-masked]>
To: [email-masked]
Date: Fri, 07 Jul 2023 11:24:01 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

More info is in the commit message.

To re-create the error open up an EPUB file (or possibly any non-PDF
file in doc-view) and press 'M-g i' to run 'imenu'.  Doing that I get
the following error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match("\\`PK\\'" nil)
  imenu-find-default("PK" (("*Rescan*" . -99) nil))
  imenu--completion-buffer((("*Rescan*" . -99) nil) nil)
  imenu-choose-buffer-index()
  byte-code("\300 C\207" [imenu-choose-buffer-index] 1)
  command-execute(imenu)

>From cd73281f324a5b21c304789ca7b828295e8718d9 Mon Sep 17 00:00:00 2001
From: Morgan Smith <[email-masked]>
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