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

From: Tassilo Horn <[email-masked]>
Date: Sun, 09 Jul 2023 10:13:41 +0200

Eli Zaretskii <[email-masked]> writes:

Hi Morgan & Eli,

>> 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)
>
> Thanks.
>
> Tassilo, any comments to the problem and the proposed patch?

I couldn't test it because all epub files I found result in

  imenu unavailable: "No items suitable for an index found in this buffer"

and not the described error.  Anyhow, I've looked at the patch (V3)
which basically looks good to me.

However, I'm not sure if setting doc-view-imenu-enabled to nil if mutool
is there but the doc is not a PDF is the right thing.  I think the only
difference is the error you get when invoking imenu, i.e., if we'd skip
that hunk of the patch and cater for the possibility that "mutool show"
might eventually support epub files, you'd get

  "Unable to create imenu index using `mutool'"

right now.  With that hunk, you get

  "This buffer cannot use ‘imenu-default-create-index-function’"

which is not really better.

So I'd suggest leave the doc-view-imenu-enabled initialization as-is and
in the "mutool show exits non-zero case", we signal a
imenu-unavailable-error (rather than a plain error) with the message
that's already there in the patch.

Bye,
Tassilo