aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Brinkhoff2024-01-02 09:06:13 +0100
committerEli Zaretskii2024-01-13 12:07:34 +0200
commit740953d1a2f4ea4a200637872b9ecb7dfddfdbe4 (patch)
tree57ffc8c2a555d4674bdf1ef82b3e37101a8bc033
parent9b8b352ebc09de3259f655fa4d491507109044b3 (diff)
downloademacs-740953d1a2f4ea4a200637872b9ecb7dfddfdbe4.tar.gz
emacs-740953d1a2f4ea4a200637872b9ecb7dfddfdbe4.zip
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.
-rw-r--r--lisp/textmodes/page.el8
-rw-r--r--test/lisp/textmodes/page-tests.el6
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."
159 total before after))) 159 total before after)))
160 160
161(defun page--what-page () 161(defun page--what-page ()
162 "Return a list of the page and line number of point." 162 "Return a list of the page and line number of point.
163The line number is relative to the start of the page."
163 (save-restriction 164 (save-restriction
164 (widen) 165 (widen)
165 (save-excursion 166 (save-excursion
166 (let ((count 1) 167 (let ((count 1)
168 (adjust (if (or (bolp) (looking-back page-delimiter)) 1 0))
167 (opoint (point))) 169 (opoint (point)))
168 (goto-char (point-min)) 170 (goto-char (point-min))
169 (while (re-search-forward page-delimiter opoint t) 171 (while (re-search-forward page-delimiter opoint t)
170 (when (= (match-beginning 0) (match-end 0)) 172 (when (= (match-beginning 0) (match-end 0))
171 (forward-char)) 173 (forward-char))
172 (setq count (1+ count))) 174 (setq count (1+ count)))
173 (list count (line-number-at-pos opoint)))))) 175 (list count (+ adjust (count-lines (point) opoint)))))))
174 176
175(defun what-page () 177(defun what-page ()
176 "Print page and line number of point." 178 "Display the page number, and the line number within that page."
177 (interactive) 179 (interactive)
178 (apply #'message (cons "Page %d, line %d" (page--what-page)))) 180 (apply #'message (cons "Page %d, line %d" (page--what-page))))
179 181
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 @@
106 (insert "foo\n \nbar\n \nbaz") 106 (insert "foo\n \nbar\n \nbaz")
107 (goto-char (point-min)) 107 (goto-char (point-min))
108 (should (equal (page--what-page) '(1 1))) 108 (should (equal (page--what-page) '(1 1)))
109 (forward-char)
110 (should (equal (page--what-page) '(1 1)))
109 (forward-page) 111 (forward-page)
112 (should (equal (page--what-page) '(2 1)))
113 (next-line)
110 (should (equal (page--what-page) '(2 2))) 114 (should (equal (page--what-page) '(2 2)))
111 (forward-page) 115 (forward-page)
112 (should (equal (page--what-page) '(3 4))))) 116 (should (equal (page--what-page) '(3 1)))))
113 117
114 118
115;;; page-tests.el ends here 119;;; page-tests.el ends here