unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Morgan Smith <Morgan.J.Smith@outlook.com>
To: Tassilo Horn <tsdh@gnu.org>
Cc: Eli Zaretskii <eliz@gnu.org>, 64516@debbugs.gnu.org, jao@gnu.org
Subject: bug#64516: [PATCH] docview: Only enable imenu when supported
Date: Tue, 11 Jul 2023 13:49:25 -0400	[thread overview]
Message-ID: <DM5PR03MB3163B54C5C827DE6CE597480C531A@DM5PR03MB3163.namprd03.prod.outlook.com> (raw)
In-Reply-To: <878rbpxybj.fsf@gnu.org> (Tassilo Horn's message of "Sun, 09 Jul 2023 10:13:41 +0200")

[-- Attachment #1: Type: text/plain, Size: 688 bytes --]

Hello,

Tassilo Horn <tsdh@gnu.org> writes:

>
> 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.

I feel like my reviewers often can't reproduce my errors.  I'm running
Emacs from a very recent commit and I have mutool installed.  I really
feel like the error should be reproducible for anyone that meets those
two requirements.  Do I need to include more information in my bug
reports?  If so, what information?


Anyways I modified my patch with Tassilo's feedback.  However, I
realized that it partially reverts commit
b23e062d7463b76d25dfd9ba4a80c1848a448e42


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-docview-imenu-check-return-value-of-mutool.patch --]
[-- Type: text/x-patch, Size: 2425 bytes --]

From 5b24d23e3317491c31ae1392c29ac7cdf303f9d4 Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
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


[-- Attachment #3: Type: text/plain, Size: 202 bytes --]



I can't really seem to figure out why we call 'doc-view--pdf-outline' in
doc-view-imenu-setup even after reading the two bug reports that are
linked in the commit message.  For this reason I CC'd jao

  reply	other threads:[~2023-07-11 17:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07 15:24 bug#64516: [PATCH] docview: Only enable imenu when supported Morgan Smith
2023-07-07 15:40 ` Morgan Smith
2023-07-07 16:05   ` Morgan Smith
2023-07-08  9:14 ` Eli Zaretskii
2023-07-09  8:13   ` Tassilo Horn
2023-07-11 17:49     ` Morgan Smith [this message]
2023-07-11 18:22       ` Morgan Smith
2023-07-15  8:05         ` Eli Zaretskii
2023-07-15 18:39           ` Tassilo Horn
2023-07-15 23:50             ` Morgan Smith
2023-07-16  4:39               ` Tassilo Horn
2023-07-16 15:03                 ` Morgan Smith
2023-07-16 15:24                   ` Tassilo Horn
2023-07-18 18:40                     ` Morgan Smith
2023-07-18 19:14                       ` Tassilo Horn
2023-07-20 16:05                         ` Eli Zaretskii
2023-07-28 10:14                         ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-28 10:19                           ` Tassilo Horn
2023-07-28 11:22                             ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-11 18:28       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM5PR03MB3163B54C5C827DE6CE597480C531A@DM5PR03MB3163.namprd03.prod.outlook.com \
    --to=morgan.j.smith@outlook.com \
    --cc=64516@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=jao@gnu.org \
    --cc=tsdh@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).