diff options
| author | Lars Ingebrigtsen | 2022-04-22 14:04:43 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-04-22 14:35:30 +0200 |
| commit | 3aaed2e1ccfcc230f813d3fe7867a7abc5b22109 (patch) | |
| tree | 34e98286f256f1c2a4f05323af4bda8efbed6a89 | |
| parent | f2f9e8dc76cdc7433624ee7e88ec5380a5b06902 (diff) | |
| download | emacs-3aaed2e1ccfcc230f813d3fe7867a7abc5b22109.tar.gz emacs-3aaed2e1ccfcc230f813d3fe7867a7abc5b22109.zip | |
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).
| -rw-r--r-- | lisp/textmodes/page.el | 17 | ||||
| -rw-r--r-- | 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 3fc18323349..5d6f017eb99 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 | |||
| 35 | (interactive "p") | 35 | (interactive "p") |
| 36 | (or count (setq count 1)) | 36 | (or count (setq count 1)) |
| 37 | (while (and (> count 0) (not (eobp))) | 37 | (while (and (> count 0) (not (eobp))) |
| 38 | ;; In case the page-delimiter matches the null string, | 38 | (if (and (looking-at page-delimiter) |
| 39 | ;; don't find a match without moving. | 39 | (> (match-end 0) (point))) |
| 40 | (if (bolp) (forward-char 1)) | 40 | ;; If we're standing at the page delimiter, then just skip to |
| 41 | (unless (re-search-forward page-delimiter nil t) | 41 | ;; the end of it. (But only if it's not a zero-length |
| 42 | (goto-char (point-max))) | 42 | ;; delimiter, because then we wouldn't have forward progress.) |
| 43 | (goto-char (match-end 0)) | ||
| 44 | ;; In case the page-delimiter matches the null string, | ||
| 45 | ;; don't find a match without moving. | ||
| 46 | (when (bolp) | ||
| 47 | (forward-char 1)) | ||
| 48 | (unless (re-search-forward page-delimiter nil t) | ||
| 49 | (goto-char (point-max)))) | ||
| 43 | (setq count (1- count))) | 50 | (setq count (1- count))) |
| 44 | (while (and (< count 0) (not (bobp))) | 51 | (while (and (< count 0) (not (bobp))) |
| 45 | ;; In case the page-delimiter matches the null string, | 52 | ;; 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 596f3a6ceb7..b7217e69f0c 100644 --- a/test/lisp/textmodes/page-tests.el +++ b/test/lisp/textmodes/page-tests.el | |||
| @@ -80,6 +80,17 @@ | |||
| 80 | (narrow-to-page 2) | 80 | (narrow-to-page 2) |
| 81 | (should (equal (buffer-string) "baz")) | 81 | (should (equal (buffer-string) "baz")) |
| 82 | (narrow-to-page -1) | 82 | (narrow-to-page -1) |
| 83 | (should (equal (buffer-string) "bar\n")) | ||
| 84 | |||
| 85 | (widen) | ||
| 86 | (goto-char (point-min)) | ||
| 87 | (narrow-to-page) | ||
| 88 | (should (equal (buffer-string) "foo\n")) | ||
| 89 | (goto-char (point-max)) | ||
| 90 | (narrow-to-page 2) | ||
| 91 | (should (equal (buffer-string) "baz")) | ||
| 92 | (goto-char (point-max)) | ||
| 93 | (narrow-to-page -1) | ||
| 83 | (should (equal (buffer-string) "bar\n")))) | 94 | (should (equal (buffer-string) "bar\n")))) |
| 84 | 95 | ||
| 85 | (ert-deftest page-tests-count-lines-page () | 96 | (ert-deftest page-tests-count-lines-page () |
| @@ -100,4 +111,5 @@ | |||
| 100 | (forward-page) | 111 | (forward-page) |
| 101 | (should (equal (page--what-page) '(3 4))))) | 112 | (should (equal (page--what-page) '(3 4))))) |
| 102 | 113 | ||
| 114 | |||
| 103 | ;;; page-tests.el ends here | 115 | ;;; page-tests.el ends here |