emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 740953d1a2f: Fix 'what-page'


From: Eli Zaretskii
Subject: master 740953d1a2f: Fix 'what-page'
Date: Sat, 13 Jan 2024 05:09:59 -0500 (EST)

branch: master
commit 740953d1a2f4ea4a200637872b9ecb7dfddfdbe4
Author: Lars Brinkhoff <lars@nocrew.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    Fix 'what-page'
    
    * lisp/textmodes/page.el (page--what-page): Adjust for 1st
    line on page, and use 'count-lines' again.  (Bug#68215)
    
    * test/lisp/textmodes/page-tests.el (page-tests-what-page):
    Update test.
---
 lisp/textmodes/page.el            | 8 +++++---
 test/lisp/textmodes/page-tests.el | 6 +++++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/lisp/textmodes/page.el b/lisp/textmodes/page.el
index e8621ee0383..1c7561d71c6 100644
--- a/lisp/textmodes/page.el
+++ b/lisp/textmodes/page.el
@@ -159,21 +159,23 @@ point, respectively."
              total before after)))
 
 (defun page--what-page ()
-  "Return a list of the page and line number of point."
+  "Return a list of the page and line number of point.
+The line number is relative to the start of the page."
   (save-restriction
     (widen)
     (save-excursion
       (let ((count 1)
+            (adjust (if (or (bolp) (looking-back page-delimiter)) 1 0))
             (opoint (point)))
         (goto-char (point-min))
         (while (re-search-forward page-delimiter opoint t)
           (when (= (match-beginning 0) (match-end 0))
             (forward-char))
           (setq count (1+ count)))
-        (list count (line-number-at-pos opoint))))))
+        (list count (+ adjust (count-lines (point) opoint)))))))
 
 (defun what-page ()
-  "Print page and line number of point."
+  "Display the page number, and the line number within that page."
   (interactive)
   (apply #'message (cons "Page %d, line %d" (page--what-page))))
 
diff --git a/test/lisp/textmodes/page-tests.el 
b/test/lisp/textmodes/page-tests.el
index f3a2c5fbe00..617b59a54fb 100644
--- a/test/lisp/textmodes/page-tests.el
+++ b/test/lisp/textmodes/page-tests.el
@@ -106,10 +106,14 @@
     (insert "foo\n\nbar\n\nbaz")
     (goto-char (point-min))
     (should (equal (page--what-page) '(1 1)))
+    (forward-char)
+    (should (equal (page--what-page) '(1 1)))
     (forward-page)
+    (should (equal (page--what-page) '(2 1)))
+    (next-line)
     (should (equal (page--what-page) '(2 2)))
     (forward-page)
-    (should (equal (page--what-page) '(3 4)))))
+    (should (equal (page--what-page) '(3 1)))))
 
 
 ;;; page-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]