From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Visuwesh Newsgroups: gmane.emacs.bugs Subject: bug#73530: [PATCH] Add imenu index function for Djvu files in doc-view Date: Sat, 28 Sep 2024 20:40:54 +0530 Message-ID: <8734ljg6f5.fsf@gmail.com> 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="38552"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 73530@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 28 17:11:50 2024 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 1suZ6r-0009qu-Ik for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 28 Sep 2024 17:11:49 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suZ6d-0001UQ-2g; Sat, 28 Sep 2024 11:11:35 -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 1suZ6b-0001U8-DA for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 11:11:33 -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 1suZ6b-0006ed-4e for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 11:11:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=FJJu4ITbJHmlzA3c29BcOjRJRZGAXCGw2U6XcSVZ96A=; b=hkF/tuP7tbLuaqeoXHHggYNNAnZdlPaEgB2EImRkvLJovs4U0nWEEZIRAEp6UIYx+LeLotYxHutPruW/muGR9AaKYjfjcAQ6/cN+V4pFRfqHl868fV78okNrekLZQfpHvu5Ibjvty15wbrXat4QODfzJMCG6p+ZDyWGxQIA8K3fn82qTi+PclMlXZeMDB8/P4OhejrBSviYf5sCKyypUyWp0v9F9mg5+RZNanTaBGcJuRUS7+EJ8fJPp5/albt4URuRYXi/71jqexIegB+M2+7Vj1MoNH5Q/tUOczPBLsqo+NrCDjerwCC3uVosimhicF/118Trg3vON6TZDHQnk2A==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1suZ74-0006EC-JO for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 11:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Visuwesh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Sep 2024 15:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73530 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.172753629623847 (code B ref -1); Sat, 28 Sep 2024 15:12:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Sep 2024 15:11:36 +0000 Original-Received: from localhost ([127.0.0.1]:35587 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1suZ6e-0006CX-2Q for submit@debbugs.gnu.org; Sat, 28 Sep 2024 11:11:36 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:42280) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1suZ6b-0006CO-M7 for submit@debbugs.gnu.org; Sat, 28 Sep 2024 11:11:34 -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 1suZ67-0001Ss-9M for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 11:11:03 -0400 Original-Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suZ65-0006df-9A for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 11:11:02 -0400 Original-Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-20b64584fd4so2024465ad.1 for ; Sat, 28 Sep 2024 08:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727536259; x=1728141059; darn=gnu.org; h=mime-version:user-agent:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to; bh=FJJu4ITbJHmlzA3c29BcOjRJRZGAXCGw2U6XcSVZ96A=; b=c66XKLzIgASKUp8Qm7B5UyI3v6leHN8OP17ZQCRjhjfUMXHDWbiDVFUtFMRiDPjA9B j5f3fAqEhk31yQG/9GM++6ffoBeS7+Q5/hdK+HlZ8CDA6le2gUHlTchDfSXcenB5PpRJ yxGcsN4xaRf8lWTZ9LUaLXU1+8WtfxVgBYOQci9mJC9LCbD4D6nRhN0Cgkr+3vqiQ2uh G5Br8Ae4o5wsralJwNMlGaglKK3Sigw3T1j75WP66oC2831MuYaa14224F7wz3vWXGl+ 0utjIL5Xnl5C/5HRQoSjTUHepP8toY31VjxkS9nO7LyEY628oMfs9/76brRhXgxDLvyu QXSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727536259; x=1728141059; h=mime-version:user-agent:message-id:date:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FJJu4ITbJHmlzA3c29BcOjRJRZGAXCGw2U6XcSVZ96A=; b=HIMHIpTAWkXordPvyqd0Qeu/l//RuS7vgQwf/yHtuM6/HAfTtBLIymvEmnJrBSvUFN BnIFmo0XCAWZpn0ONn7kwOtRYzKbL64HwPY93I7Hc2qciGnMZEP90PW1G2rKB2hJ46Hp xChMInLqt09eK8sxFdCAtkzIttxhCwCeufiEKKQy9pyxJ764sBE2PvkWafoRFErteIMB jkgeNPMI0L3MRTbCVRI5tJZqoEjBY5fcp+G/gSSmGh5UjLB3PS8CVS7Ub7pMkBLX1rQQ QVf2JOB+SUWejN+IgGAp1wlgYOhR5fFgH6Sti9BGquaPL2a20aW9sW7eMr3eVxJ01VS4 fJvw== X-Gm-Message-State: AOJu0YwQJdIQ3kPA1dH0VyllX4Viv7lwRBdJvs+BtTkC8HEkALFRFdxm Ic86S5BIfAlng3RLfJ2cZLhAFudpK76sXcdJD5ywairz8Y+nESbeKZLfN5RX X-Google-Smtp-Source: AGHT+IHGmpsZh3g9k4wZb+KT+G4dlCP8401xGTT83th8OdCLb+GCx99Yp3e3LWBoeJ2mYcwfOxwS8Q== X-Received: by 2002:a17:902:ce12:b0:207:1708:734c with SMTP id d9443c01a7336-20b367d7b35mr88538345ad.11.1727536258953; Sat, 28 Sep 2024 08:10:58 -0700 (PDT) Original-Received: from localhost ([1.7.159.70]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e6d01esm27980355ad.308.2024.09.28.08.10.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Sep 2024 08:10:58 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=visuweshm@gmail.com; helo=mail-pl1-x644.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:292579 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Attached patch adds a function to create imenu index for Djvu files using djvused. If you do not have a Djvu file available, I can point to a file from libgen that can be used as a test file. In GNU Emacs 31.0.50 (build 7, x86_64-pc-linux-gnu, X toolkit, cairo version 1.18.0, Xaw scroll bars) of 2024-09-09 built on astatine Repository revision: 7d7aa65f63db78c5732f1580213fc3767b767a4a Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101011 System Description: Debian GNU/Linux trixie/sid Configured using: 'configure --with-sound=alsa --with-x-toolkit=lucid --without-xaw3d --without-gconf --without-libsystemd --with-cairo' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-imenu-index-function-for-Djvu-files-in-doc-view.patch >From 27174371d677f0e79f2291ce3f2849838a28ca0e Mon Sep 17 00:00:00 2001 From: Visuwesh Date: Sat, 28 Sep 2024 20:37:50 +0530 Subject: [PATCH] Add imenu index function for Djvu files in doc-view * lisp/doc-view.el (doc-view-imenu-enabled): Tweak the default value to check for 'djvused'. (doc-view--djvu-outline, doc-view--parse-djvu-outline): Add new functions to return imenu index for a Djvu file. (doc-view--outline): Add new function to create the imenu index depending on the file type. (doc-view-imenu-index, doc-view-imenu-setup): Use new function instead. * doc/emacs/misc.texi (DocView Navigation): Mention index creation using 'djvused' too. * etc/NEWS: Announce the change. --- doc/emacs/misc.texi | 16 ++++++------ etc/NEWS | 5 ++++ lisp/doc-view.el | 60 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index e19e554fb26..eee6f08ef3b 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -584,14 +584,14 @@ DocView Navigation @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. You -can further customize how @code{imenu} items are formatted and -displayed using the variables @code{doc-view-imenu-format} and -@code{doc-view-imenu-flatten}. + When the @command{mutool} or the @command{djvused} 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 the required program 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-imenu-flatten}. @findex doc-view-page-to-register @findex doc-view-jump-to-register diff --git a/etc/NEWS b/etc/NEWS index 607665a71bb..162af7b3e43 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -268,6 +268,11 @@ Docview can store current page to buffer local registers with the new command 'doc-view-page-to-register' (bound to 'm'), and later can be restored with 'doc-view-jump-to-register' (bound to '''). ++++ +*** Docview can generate imenu index for Djvu files. +When the 'djvused' program is available, Docview can now generate imenu +index for Djvu files from its outline. + ** Tramp +++ diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 395993e6263..d461b606ce6 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -216,10 +216,13 @@ doc-view-mupdf-use-svg :type 'boolean :version "30.1") -(defcustom doc-view-imenu-enabled (and (executable-find "mutool") t) - "Whether to generate an imenu outline when \"mutool\" is available." +(defcustom doc-view-imenu-enabled (and (or (executable-find "mutool") + (executable-find "djvused")) + t) + "Whether to generate an imenu outline when available. +This uses \"mutool\" for PDF files and \"djvused\" for Djvu files." :type 'boolean - :version "29.1") + :version "31.1") (defcustom doc-view-imenu-title-format "%t (%p)" "Format spec for imenu's display of section titles from docview documents. @@ -2004,6 +2007,41 @@ doc-view--imenu-subtree (setq outline (cdr outline)))))) (cons (nreverse index) outline))) +(defun doc-view--djvu-outline (&optional file-name) + "Return a list describing the outline of FILE-NAME. +If FILE-NAME is nil, use the current file. + +For the format, see `doc-view--pdf-outline'." + (unless file-name (setq file-name (buffer-file-name))) + (with-temp-buffer + (call-process "djvused" nil (current-buffer) nil + "-e" "print-outline" file-name) + (goto-char (point-min)) + (when (eobp) + (imenu-unavailable-error "Unable to create imenu index using `djvused'")) + (nreverse (doc-view--parse-djvu-outline (read (current-buffer)))))) + +(defun doc-view--parse-djvu-outline (bookmark &optional level) + "Return a list describing the djvu outline from BOOKMARK. +Optional argument LEVEL is the current heading level. If nil, then 1 is +used." + (unless level (setq level 1)) + (let ((res)) + (unless (eq (car bookmark) 'bookmarks) + (user-error "Unknown outline type: %S" (car bookmark))) + (pcase-dolist (`(,title ,page . ,rest) (cdr bookmark)) + (push `((level . ,level) + (title . ,title) + (page . ,(string-to-number (string-remove-prefix "#" page)))) + res) + (when (and rest (listp (car rest))) + (setq res (append + (doc-view--parse-djvu-outline + (cons 'bookmarks rest) + (+ level 1)) + res)))) + res)) + (defun doc-view-imenu-index (&optional file-name goto-page-fn) "Create an imenu index using \"mutool\" to extract its outline. @@ -2012,16 +2050,28 @@ doc-view-imenu-index GOTO-PAGE-FN other than `doc-view-goto-page'." (let* ((goto (or goto-page-fn 'doc-view-goto-page)) (act (lambda (_name _pos page) (funcall goto page))) - (outline (or doc-view--outline (doc-view--pdf-outline file-name)))) + (outline (or doc-view--outline (doc-view--outline file-name)))) (car (doc-view--imenu-subtree outline act)))) +(defun doc-view--outline (&optional file-name) + "Return the outline for the file FILE-NAME. +If FILE-NAME is nil, use the current file instead." + (unless file-name (setq file-name (buffer-file-name))) + (pcase doc-view-doc-type + ('djvu + (when (executable-find "djvused") + (doc-view--djvu-outline file-name))) + (_ + (when (executable-find "mutool") + (doc-view--pdf-outline file-name))))) + (defun doc-view-imenu-setup () "Set up local state in the current buffer for imenu, if needed." (when doc-view-imenu-enabled (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)) + doc-view--outline (doc-view--outline)) (when doc-view--outline (imenu-add-to-menubar "Outline")))) ;;;; User interface commands and the mode -- 2.45.2 --=-=-=--