branch: elpa/pdf-tools
commit 1cde7b311d55b778bb4c6886993b8e57a7e6b105
Author: Rafael Beirigo <[email protected]>
Commit: GitHub <[email protected]>

    feat: add option to display page labels in mode line
    
    Add two new customization options:
    - `pdf-view-mode-line-position-prefix`: customize the page prefix (default: 
"P")
    - `pdf-view-mode-line-position-use-labels`: show page labels instead of 
numbers
    
    When enabled, displays PDF page labels (Roman numerals, section
    numbers, etc.) in the mode line with safe fallback to numeric pages.
    
    Closes: #331
    Author: @rafaelbeirigo
---
 lisp/pdf-view.el | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el
index dc7736898eb..c94fe1aa6fe 100644
--- a/lisp/pdf-view.el
+++ b/lisp/pdf-view.el
@@ -213,6 +213,16 @@ Must be one of `glyph', `word', or `line'."
                  (const word)
                  (const line)))
 
+(defcustom pdf-view-mode-line-position-prefix "P"
+  "Prefix for page number shown in the mode line."
+  :group 'pdf-view
+  :type 'string)
+
+(defcustom pdf-view-mode-line-position-use-labels nil
+  "Whether current page should come from page labels."
+  :group 'pdf-view
+  :type 'boolean)
+
 
 ;; * ================================================================== *
 ;; * Internal variables and macros
@@ -390,7 +400,13 @@ PNG images in Emacs buffers."
 
   ;; Setup other local variables.
   (setq-local mode-line-position
-              '(" P" (:eval (number-to-string (pdf-view-current-page)))
+              '(" " pdf-view-mode-line-position-prefix
+                ;; Show page label when enabled and available,
+                ;; otherwise show numeric page. Guard against errors.
+                (:eval
+                 (or (and pdf-view-mode-line-position-use-labels
+                          (ignore-errors (pdf-view-current-pagelabel)))
+                     (number-to-string (pdf-view-current-page))))
                 ;; Avoid errors during redisplay.
                 "/" (:eval (or (ignore-errors
                                  (number-to-string 
(pdf-cache-number-of-pages)))

Reply via email to