From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jose A Ortega Ruiz Newsgroups: gmane.emacs.bugs Subject: bug#58131: [PATCH] docview: new customization options for imenu Date: Wed, 28 Sep 2022 03:21:31 +0100 Message-ID: <87fsgcb5n8.fsf@mail.jao.io> 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="10560"; mail-complaints-to="usenet@ciao.gmane.io" To: 58131@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 28 04:22:13 2022 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 1odMiC-0002aG-LL for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 28 Sep 2022 04:22:12 +0200 Original-Received: from localhost ([::1]:51904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odMiB-0000NN-4q for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 27 Sep 2022 22:22:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odMi2-0000Kx-El for bug-gnu-emacs@gnu.org; Tue, 27 Sep 2022 22:22:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odMi2-0003aw-6Q for bug-gnu-emacs@gnu.org; Tue, 27 Sep 2022 22:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1odMi2-00008y-24 for bug-gnu-emacs@gnu.org; Tue, 27 Sep 2022 22:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jose A Ortega Ruiz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 Sep 2022 02:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58131 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.1664331700520 (code B ref -1); Wed, 28 Sep 2022 02:22:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Sep 2022 02:21:40 +0000 Original-Received: from localhost ([127.0.0.1]:57097 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odMhf-00008K-Rw for submit@debbugs.gnu.org; Tue, 27 Sep 2022 22:21:40 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:50422) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odMhd-000082-8x for submit@debbugs.gnu.org; Tue, 27 Sep 2022 22:21:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odMhd-0008Io-46 for bug-gnu-emacs@gnu.org; Tue, 27 Sep 2022 22:21:37 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:35656) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odMhc-0003Ti-7M; Tue, 27 Sep 2022 22:21:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=kkP+eRc81JLwcNV4jdf336qFvGrlnbF1RggPjvwqncM=; b=jQAbVSL8eNsXUk uxWTj6Mf/f+jyJ9BlP5ivzxTfnvup8kysfBHkhYbkXa8otOaXvQBHmF9cL0AkSuzFG2eUSmGHvBgr dcbH3qxBSFiycRwhXaWswHImtvkqWb8iFVUGr1oiHNCLWYPFjsdpNYMHTehxq9vkYMc/p7Zw7wBvr JJU9StlAU922Bq39fazZlP6xquoFseRiYV7IYenqbUXf3gV0lGDhLpgfgZYi9w45Y8EnO6SxmetZk EZu10H6xfbV4WIHxWGxwzGwEtWt/1CotMOzPlwlA3moGrnSCaCBHRUFPQzfzdWAw5ql9P8/KEHfg7 ETg1xgnlKVOZ/S8iBFfQ==; Original-Received: from cpc103048-sgyl39-2-0-cust502.18-2.cable.virginm.net ([92.233.85.247]:59948 helo=rivendell.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odMhb-0006lX-T0; Tue, 27 Sep 2022 22:21:36 -0400 Original-Received: from localhost (rivendell.localdomain [local]) by rivendell.localdomain (OpenSMTPD) with ESMTPA id 7acfdc48; Wed, 28 Sep 2022 02:21:31 +0000 (UTC) X-Attribution: jao X-Clacks-Overhead: GNU Terry Pratchett X-URL: 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" Xref: news.gmane.io gmane.emacs.bugs:243776 Archived-At: --=-=-= Content-Type: text/plain Tags: patch A follow up to bug#58103 with a little fix for section title extraction and a couple of easy to implement customizable options. I've tried to document them clearly enough in the docstrings and then just mention their existence in the manual: is that a good practice or do we prefer some duplication? Cheers, jao In GNU Emacs 29.0.50 (build 20, x86_64-pc-linux-gnu, cairo version 1.16.0) of 2022-09-27 built on rivendell Repository revision: 7368cdd359325cb6ed83688178ae4b4eaf22f4d5 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101004 System Description: Debian GNU/Linux bookworm/sid Configured using: 'configure --prefix=/usr/local/stow/emacs29 --with-x-toolkit=no --with-imagemagick -C' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-docview-new-customization-options-for-imenu.patch >From a434024c4e452b4f2495921832b00e801568939e Mon Sep 17 00:00:00 2001 From: Jose A Ortega Ruiz Date: Wed, 28 Sep 2022 03:02:57 +0100 Subject: [PATCH] docview: new customization options for imenu * doc/emacs/misc.texi (DocView Navigation): * lisp/doc-view.el (doc-view-imenu-title-format, doc-view-imenu-flatten): (doc-view--imenu-subtree): customizable format for imenu entry titles, and flag to disable nested submenus. * lisp/doc-view.el (doc-view--pdf-outline): clean up whitespace markers '\r' and '\t' in imenu item titles. --- doc/emacs/misc.texi | 9 +++++++-- lisp/doc-view.el | 29 +++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 04f7f2e921..cef2580f3b 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -585,11 +585,16 @@ DocView Navigation @code{doc-view-resolution}. @vindex doc-view-imenu-enabled +@vindex doc-view-imenu-flatten +@vindex doc-view-imenu-format When the @command{mutool} program is available, DocView will use it to generate entries for an outline menu, making it accessible via the @code{imenu} facility (@pxref{Imenu}). To disable this functionality -even when @command{mutool} can be found on your system, customize -the variable @code{doc-view-imenu-enabled} to the @code{nil} value. +even when @command{mutool} can be found on your system, customize the +variable @code{doc-view-imenu-enabled} to the @code{nil} value. You +can further customize how @code{imenu} items are formatted and +displayed using the variables @code{doc-view-imenu-format} and +@code{doc-view-flatten}. @node DocView Searching @subsection DocView Searching diff --git a/lisp/doc-view.el b/lisp/doc-view.el index fa583df12b..9e3bb6e46c 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -219,6 +219,23 @@ doc-view-imenu-enabled :type 'boolean :version "29.1") +(defcustom doc-view-imenu-title-format "%t (%p)" + "Format string for document section titles in imenu. + +The special markers '%t' and '%p' are replaced by the section +title and page number in this format string, which uses +`format-spec'. + +For instance, setting this variable to \"%t\" will produce items +showing only titles and no page number." + :type 'string + :version "29.1") + +(defcustom doc-view-imenu-flatten nil + "Whether to generate a flat list of sections instead of a nested tree." + :type 'boolean + :version "29.1") + (defcustom doc-view-svg-background "white" "Background color for svg images. See `doc-view-mupdf-use-svg'." @@ -1898,7 +1915,8 @@ doc-view--pdf-outline (goto-char (point-min)) (while (re-search-forward doc-view--outline-rx nil t) (push `((level . ,(length (match-string 1))) - (title . ,(match-string 2)) + (title . ,(replace-regexp-in-string "\\\\[rt]" " " + (match-string 2))) (page . ,(string-to-number (match-string 3)))) outline))) (nreverse outline))) @@ -1911,11 +1929,14 @@ doc-view--imenu-subtree level. Returns that imenu alist together with any other pending outline entries at an upper level." (let ((level (alist-get 'level (car outline))) + (nested (not doc-view-imenu-flatten)) (index nil)) - (while (and (car outline) (<= level (alist-get 'level (car outline)))) + (while (and (car outline) + (or nested (<= level (alist-get 'level (car outline))))) (let-alist (car outline) - (let ((title (format "%s (%s)" .title .page))) - (if (> .level level) + (let ((title (format-spec doc-view-imenu-title-format + `((?t . ,.title) (?p . ,.page))))) + (if (and nested (> .level level)) (let ((sub (doc-view--imenu-subtree outline act)) (fst (car index))) (setq index (cdr index)) -- 2.37.2 --=-=-= Content-Type: text/plain -- Too often we enjoy the comfort of opinion without the discomfort of thought. -John F. Kennedy, 35th US president (1917-1963) --=-=-=--