Fix problem with (narrow-to-page 1) with point at point-max

* lisp/textmodes/page.el (forward-page): Make this work more
consistently if point is on bol (bug#20663).
This commit is contained in:
Lars Ingebrigtsen 2022-04-22 14:04:43 +02:00
parent f2f9e8dc76
commit 3aaed2e1cc
2 changed files with 24 additions and 5 deletions

View file

@ -35,11 +35,18 @@ A page boundary is any line whose beginning matches the regexp
(interactive "p")
(or count (setq count 1))
(while (and (> count 0) (not (eobp)))
;; In case the page-delimiter matches the null string,
;; don't find a match without moving.
(if (bolp) (forward-char 1))
(unless (re-search-forward page-delimiter nil t)
(goto-char (point-max)))
(if (and (looking-at page-delimiter)
(> (match-end 0) (point)))
;; If we're standing at the page delimiter, then just skip to
;; the end of it. (But only if it's not a zero-length
;; delimiter, because then we wouldn't have forward progress.)
(goto-char (match-end 0))
;; In case the page-delimiter matches the null string,
;; don't find a match without moving.
(when (bolp)
(forward-char 1))
(unless (re-search-forward page-delimiter nil t)
(goto-char (point-max))))
(setq count (1- count)))
(while (and (< count 0) (not (bobp)))
;; In case the page-delimiter matches the null string,

View file

@ -80,6 +80,17 @@
(narrow-to-page 2)
(should (equal (buffer-string) "baz"))
(narrow-to-page -1)
(should (equal (buffer-string) "bar\n"))
(widen)
(goto-char (point-min))
(narrow-to-page)
(should (equal (buffer-string) "foo\n"))
(goto-char (point-max))
(narrow-to-page 2)
(should (equal (buffer-string) "baz"))
(goto-char (point-max))
(narrow-to-page -1)
(should (equal (buffer-string) "bar\n"))))
(ert-deftest page-tests-count-lines-page ()
@ -100,4 +111,5 @@
(forward-page)
(should (equal (page--what-page) '(3 4)))))
;;; page-tests.el ends here