changeset 10110:18d52489f138

(fill-region-as-paragraph): If region starts in mid-line, don't fill the text before that, but count it for indentation. (fill-region): If region starts in mid-line, keep whole line in the region, but pass the region start to fill-region-as-paragraph.
author Richard M. Stallman <rms@gnu.org>
date Sun, 04 Dec 1994 19:49:21 +0000
parents 869e177ca872
children add3c6d21876
files lisp/textmodes/fill.el
diffstat 1 files changed, 37 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/fill.el	Sun Dec 04 18:58:04 1994 +0000
+++ b/lisp/textmodes/fill.el	Sun Dec 04 19:49:21 1994 +0000
@@ -97,16 +97,22 @@
 	    )))
 
     (save-restriction
-      (goto-char (max from to))
-      ;; If specified region ends before a newline,
-      ;; include that newline.
-      (if (and (eolp) (not (eobp)) (not (bolp)))
-	  (forward-char 1))
-      (narrow-to-region (min from to) (point))
-      (goto-char (point-min))
+      (let (end)
+	(goto-char (max from to))
+	;; If specified region ends before a newline,
+	;; include that newline.
+	(if (and (eolp) (not (eobp)) (not (bolp)))
+	    (forward-char 1))
+	(setq end (point))
+	(setq from (min from to))
+	(goto-char from)
+	(beginning-of-line)
+	(narrow-to-region (point) end))
       (skip-chars-forward "\n")
       (narrow-to-region (point) (point-max))
-      (setq from (point))
+      (if (> from (point))
+	  (goto-char from)
+	(setq from (point)))
       (goto-char (point-max))
       (let ((fpre (and fill-prefix (not (equal fill-prefix ""))
 		       (regexp-quote fill-prefix))))
@@ -116,13 +122,13 @@
 	     (progn
 	       (if (>= (length fill-prefix) fill-column)
 		   (error "fill-prefix too long for specified width"))
-	       (goto-char (point-min))
+	       (goto-char from)
 	       (forward-line 1)
 	       (while (not (eobp))
 		 (if (looking-at fpre)
 		     (delete-region (point) (match-end 0)))
 		 (forward-line 1))
-	       (goto-char (point-min))
+	       (goto-char from)
 	       (and (looking-at fpre) (forward-char (length fill-prefix)))
 	       (setq from (point)))))
       ;; from is now before the text to fill,
@@ -260,22 +266,27 @@
 If `sentence-end-double-space' is non-nil, then period followed by one
 space does not end a sentence, so don't break a line there."
   (interactive "r\nP")
-  (save-restriction
-    (goto-char (max from to))
-    ;; If specified region ends before a newline,
-    ;; include that newline.
-    (if (and (eolp) (not (eobp)) (not (bolp)))
-	(forward-char 1))
-    (narrow-to-region (min from to) (point))
-    (goto-char (point-min))
-    (while (not (eobp))
-      (let ((initial (point))
-	    (end (progn
-		   (forward-paragraph 1) (point))))
-	(forward-paragraph -1)
-	(if (>= (point) initial)
-	    (fill-region-as-paragraph (point) end justify-flag)
-	  (goto-char end))))))
+  (let (end beg)
+    (save-restriction
+      (goto-char (max from to))
+      ;; If specified region ends before a newline,
+      ;; include that newline.
+      (if (and (eolp) (not (eobp)) (not (bolp)))
+	  (forward-char 1))
+      (setq end (point))
+      (goto-char (setq beg (min from to)))
+      (beginning-of-line)
+      (narrow-to-region (point) end)
+      (while (not (eobp))
+	(let ((initial (point))
+	      (end (progn
+		     (forward-paragraph 1) (point))))
+	  (forward-paragraph -1)
+	  (if (< (point) beg)
+	      (goto-char beg))
+	  (if (>= (point) initial)
+	      (fill-region-as-paragraph (point) end justify-flag)
+	    (goto-char end)))))))
 
 (defun justify-current-line ()
   "Add spaces to line point is in, so it ends at `fill-column'."