From d0be1dd4592fbe16a4d9799031aed5a7c22fb144 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Tue, 24 Apr 2018 21:36:17 -0400 Subject: [PATCH] Fix off-by-1 error in next-page (Bug#31061) * lisp/textmodes/page-ext.el (next-page): Only go backwards if COUNT was originally negative. --- lisp/textmodes/page-ext.el | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lisp/textmodes/page-ext.el b/lisp/textmodes/page-ext.el index 8a41bc3742..1a1a62e963 100644 --- a/lisp/textmodes/page-ext.el +++ b/lisp/textmodes/page-ext.el @@ -304,19 +304,20 @@ next-page (or count (setq count 1)) (widen) ;; Cannot use forward-page because of problems at page boundaries. - (while (and (> count 0) (not (eobp))) - (if (re-search-forward page-delimiter nil t) - nil - (goto-char (point-max))) - (setq count (1- count))) - ;; If COUNT is negative, we want to go back -COUNT + 1 page boundaries. - ;; The first page boundary we reach is the top of the current page, - ;; which doesn't count. - (while (and (< count 1) (not (bobp))) - (if (re-search-backward page-delimiter nil t) - (goto-char (match-beginning 0)) - (goto-char (point-min))) - (setq count (1+ count))) + (if (>= count 0) + (while (and (> count 0) (not (eobp))) + (if (re-search-forward page-delimiter nil t) + nil + (goto-char (point-max))) + (setq count (1- count))) + ;; If COUNT is negative, we want to go back -COUNT + 1 page boundaries. + ;; The first page boundary we reach is the top of the current page, + ;; which doesn't count. + (while (and (< count 1) (not (bobp))) + (if (re-search-backward page-delimiter nil t) + (goto-char (match-beginning 0)) + (goto-char (point-min))) + (setq count (1+ count)))) (narrow-to-page) (goto-char (point-min)) (recenter 0)) -- 2.11.0