aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLars Brinkhoff2024-01-02 09:06:13 +0100
committerEli Zaretskii2024-01-13 12:07:34 +0200
commit740953d1a2f4ea4a200637872b9ecb7dfddfdbe4 (patch)
tree57ffc8c2a555d4674bdf1ef82b3e37101a8bc033 /lisp
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/textmodes/page.el8
1 files changed, 5 insertions, 3 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