emacs-diffs
[Top][All Lists]
Advanced

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

master 3aaed2e1cc 1/2: Fix problem with (narrow-to-page 1) with point at


From: Lars Ingebrigtsen
Subject: master 3aaed2e1cc 1/2: Fix problem with (narrow-to-page 1) with point at point-max
Date: Fri, 22 Apr 2022 08:35:37 -0400 (EDT)

branch: master
commit 3aaed2e1ccfcc230f813d3fe7867a7abc5b22109
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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).
---
 lisp/textmodes/page.el            | 17 ++++++++++++-----
 test/lisp/textmodes/page-tests.el | 12 ++++++++++++
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/lisp/textmodes/page.el b/lisp/textmodes/page.el
index 3fc1832334..5d6f017eb9 100644
--- a/lisp/textmodes/page.el
+++ b/lisp/textmodes/page.el
@@ -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,
diff --git a/test/lisp/textmodes/page-tests.el 
b/test/lisp/textmodes/page-tests.el
index 596f3a6ceb..b7217e69f0 100644
--- a/test/lisp/textmodes/page-tests.el
+++ b/test/lisp/textmodes/page-tests.el
@@ -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



reply via email to

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