From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.bugs Subject: bug#64516: [PATCH] docview: Only enable imenu when supported Date: Tue, 18 Jul 2023 21:14:35 +0200 Message-ID: <87jzuxrppg.fsf@gnu.org> References: <83lefqdatb.fsf@gnu.org> <878rbpxybj.fsf@gnu.org> <83ttu5d2h4.fsf@gnu.org> <87jzv1c8vg.fsf@gnu.org> <04eb26ce-b33f-4ebf-9d9d-f1846fead2ed@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40074"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.11.9; emacs 30.0.50 Cc: Eli Zaretskii , 64516@debbugs.gnu.org, jao@gnu.org To: Morgan Smith Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 18 21:22:26 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qLqHB-000ACN-RS for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 18 Jul 2023 21:22:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qLqGt-0003OZ-5c; Tue, 18 Jul 2023 15:22:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qLqGo-0003O2-RU for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2023 15:22:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qLqGo-0004Nz-Js for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2023 15:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qLqGo-00005f-FG for bug-gnu-emacs@gnu.org; Tue, 18 Jul 2023 15:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tassilo Horn Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 18 Jul 2023 19:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64516 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 64516-submit@debbugs.gnu.org id=B64516.168970807432747 (code B ref 64516); Tue, 18 Jul 2023 19:22:02 +0000 Original-Received: (at 64516) by debbugs.gnu.org; 18 Jul 2023 19:21:14 +0000 Original-Received: from localhost ([127.0.0.1]:54322 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qLqG2-0008W7-Cr for submit@debbugs.gnu.org; Tue, 18 Jul 2023 15:21:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41414) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qLqG0-0008Vu-6p for 64516@debbugs.gnu.org; Tue, 18 Jul 2023 15:21:13 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qLqFt-0003tr-CQ; Tue, 18 Jul 2023 15:21:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-reply-to:Date:Subject:To:From: References; bh=r7Dj9Ih0UUTq54S28p4OPCy9JDD/b44YqOgPLsMUTxY=; b=O8H0s10ZVySzbN RB1w1+vSoFxDzd1D/ya7r5ewX1guQF5ddCsF62fwPK3RIx34zIC5ZHWqV8QrOhWQyD3AEMNfKBcUz 3zOKBDavmVt/pDKnuPj0Es0LBf5Wdop1XlfsLmhg/I0yFuaxC+XEoDHsq6VL9fzzga0yGZSbvniff /pm58JozS9slIfwN9Gk/JcKL5tEj6+0rXtu2i3MsSi3SvsW42z91gUis0Aryz1we67gFVacpL/Rle f5lZUK6X6TMamQ7E5zM1Y7j2HSEAWx04ZKT7fA5i7G2ttZ3svHdgHhkk+kg31MZrpkPD+FD/cKx4S GKPswXxSw+6g8kbL2T1A==; Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qLqFt-0007ZV-4R; Tue, 18 Jul 2023 15:21:05 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id B205927C0054; Tue, 18 Jul 2023 15:21:04 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 18 Jul 2023 15:21:04 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrgeeggddufeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvvefuffgjkfggtgesmhdtreertdertdenucfhrhhomhepvfgrshhs ihhlohcujfhorhhnuceothhsughhsehgnhhurdhorhhgqeenucggtffrrghtthgvrhhnpe eihfetffeiledufeffffekveegffehgefhieettdejgefgveeiueduveehffffteenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhorhhnod hmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdekieejfeekjeekgedqieefhedv leekqdhtshguhheppehgnhhurdhorhhgsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 18 Jul 2023 15:21:03 -0400 (EDT) In-reply-to: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:265495 Archived-At: --=-=-= Content-Type: text/plain Morgan Smith writes: Hi Morgan, >> my reasoning was to have an explanation in the *Messages* buffer for >> people who ask themselves "where the heck is the Outline menu item"? > > I didn't think of users using the toolbar. I've heared there are three of them. But we are talking about the menu bar of which there are a good dozen users. :-) > I think you can go ahead and use the patch you sent a couple emails > back. I'm happy with that one. 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, Tassilo --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-docview-imenu-check-return-value-of-mutool.patch >From 2a297bc4c1de575f45fa7fdb9e2b9ea2f23294a2 Mon Sep 17 00:00:00 2001 From: Morgan Smith Date: Tue, 11 Jul 2023 14:08:24 -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-mode): Handle possible error from 'doc-view-imenu-setup'. (doc-view-imenu-enabled): Remove superfluous (and ... t). (doc-view-imenu-setup): Remove check for mutool already ensured by 'doc-view-imenu-enabled' being non-nil. --- lisp/doc-view.el | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lisp/doc-view.el b/lisp/doc-view.el index b14655fb274..847601872f5 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 @@ -214,7 +216,7 @@ doc-view-mupdf-use-svg :type 'boolean :version "30.1") -(defcustom doc-view-imenu-enabled (and (executable-find "mutool") t) +(defcustom doc-view-imenu-enabled (executable-find "mutool") "Whether to generate an imenu outline when \"mutool\" is available." :type 'boolean :version "29.1") @@ -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))) @@ -1961,7 +1964,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 doc-view-imenu-enabled (setq-local imenu-create-index-function #'doc-view-imenu-index imenu-submenus-on-top nil imenu-sort-function nil @@ -2236,7 +2239,10 @@ doc-view-mode (setq mode-name "DocView" buffer-read-only t major-mode 'doc-view-mode) - (doc-view-imenu-setup) + (condition-case imenu-error + (doc-view-imenu-setup) + (imenu-unavailable (message "imenu support unavailable: %s" + (cadr imenu-error)))) (doc-view-initiate-display) ;; Switch off view-mode explicitly, because doc-view-mode is the ;; canonical view mode for PDF/PS/DVI files. This could be -- 2.41.0 --=-=-=--