From de24b07719bc60502c328482407218c0aa2ae966 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 10 Oct 2002 18:01:57 +0000 Subject: [PATCH] (forward-paragraph): Keep track of remaining paragraphs to skip more carefully. --- lisp/textmodes/paragraphs.el | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el index 73dbd56240..90760c22ac 100644 --- a/lisp/textmodes/paragraphs.el +++ b/lisp/textmodes/paragraphs.el @@ -173,7 +173,8 @@ a negative argument ARG = -N means move backward N paragraphs. A line which `paragraph-start' matches either separates paragraphs \(if `paragraph-separate' matches it also) or is the first line of a paragraph. A paragraph end is the beginning of a line which is not part of the paragraph -to which the end of the previous line belongs, or the end of the buffer." +to which the end of the previous line belongs, or the end of the buffer. +Returns the count of paragraphs left to move." (interactive "p") (or arg (setq arg 1)) (let* ((opoint (point)) @@ -206,7 +207,7 @@ to which the end of the previous line belongs, or the end of the buffer." (if (and (not (looking-at parsep)) (re-search-backward "^\n" (max (1- (point)) (point-min)) t) (looking-at parsep)) - nil + (setq arg (1+ arg)) (setq start (point)) ;; Move back over paragraph-separating lines. (forward-char -1) (beginning-of-line) @@ -216,6 +217,7 @@ to which the end of the previous line belongs, or the end of the buffer." (forward-line -1)) (if (bobp) nil + (setq arg (1+ arg)) ;; Go to end of the previous (non-separating) line. (end-of-line) ;; Search back for line that starts or separates paragraphs. @@ -253,8 +255,8 @@ to which the end of the previous line belongs, or the end of the buffer." (setq found-start nil) (goto-char start)) found-start) - ;; Found one. - (progn + ;; Found one. + (progn ;; Move forward over paragraph separators. ;; We know this cannot reach the place we started ;; because we know we moved back over a non-separator. @@ -270,15 +272,17 @@ to which the end of the previous line belongs, or the end of the buffer." (if (not (bolp)) (forward-line 1)))) ;; No starter or separator line => use buffer beg. - (goto-char (point-min))))) - (setq arg (1+ arg))) + (goto-char (point-min)))))) (while (and (> arg 0) (not (eobp))) - ;; Move forward over separator lines, and one more line. - (while (prog1 (and (not (eobp)) - (progn (move-to-left-margin) (not (eobp))) - (looking-at parsep)) - (forward-line 1))) + ;; Move forward over separator lines... + (while (and (not (eobp)) + (progn (move-to-left-margin) (not (eobp))) + (looking-at parsep)) + (forward-line 1)) + (unless (eobp) (setq arg (1- arg))) + ;; ... and one more line. + (forward-line 1) (if fill-prefix-regexp ;; There is a fill prefix; it overrides parstart. (while (and (not (eobp)) @@ -297,8 +301,7 @@ to which the end of the previous line belongs, or the end of the buffer." (not (get-text-property (1- start) 'hard))))) (forward-char 1)) (if (< (point) (point-max)) - (goto-char start))) - (setq arg (1- arg))) + (goto-char start)))) (constrain-to-field nil opoint t) ;; Return the number of steps that could not be done. arg)) -- 2.20.1