]> git.eshelyaron.com Git - emacs.git/commitdiff
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 10 Oct 2002 18:01:57 +0000 (18:01 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 10 Oct 2002 18:01:57 +0000 (18:01 +0000)
lisp/textmodes/paragraphs.el

index 73dbd56240d608d39d9771af1b16871610078f87..90760c22acf8689f80135781ab6178eb7fb73118 100644 (file)
@@ -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))