changeset 47829:353dae5e0134

(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 10 Oct 2002 18:01:57 +0000
parents 4944e0ddf992
children ac4ceed3bbaf
files lisp/textmodes/paragraphs.el
diffstat 1 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/paragraphs.el	Thu Oct 10 17:45:17 2002 +0000
+++ b/lisp/textmodes/paragraphs.el	Thu Oct 10 18:01:57 2002 +0000
@@ -173,7 +173,8 @@
 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 @@
       (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 @@
 	  (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 @@
 		  (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 @@
 		  (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 @@
 			     (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))