changeset 19929:0ccbd9bdcd8f

(canonically-space-region): Doc fix. (fill-context-prefix): If the second line has the first line prefix, plus whitespace, use the part that the first line shares. (fill-individual-paragraphs): When prefix changes, usually get the new prefix from just one line, with an exception for indented first lines of paragraphs. Start a new paragraph when a line has extra indentation after the fill prefix.
author Richard M. Stallman <rms@gnu.org>
date Sun, 14 Sep 1997 20:27:34 +0000
parents 7e4718c779b2
children 1e0f347ee021
files lisp/textmodes/fill.el
diffstat 1 files changed, 48 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/fill.el	Sun Sep 14 18:18:39 1997 +0000
+++ b/lisp/textmodes/fill.el	Sun Sep 14 20:27:34 1997 +0000
@@ -136,7 +136,7 @@
 (defun canonically-space-region (beg end)
   "Remove extra spaces between words in region.
 Leave one space between words, two at end of sentences or after colons
-(depending on values of `sentence-end-double-space' and `colon-double-space').
+\(depending on values of `sentence-end-double-space' and `colon-double-space').
 Remove indentation from each line."
   (interactive "r")
   (save-excursion
@@ -217,7 +217,14 @@
 				     first-line-prefix)
 		       ;; If the second line prefix is whitespace, use it.
 		       (string-match "\\`[ \t]+\\'" second-line-prefix))
-		   second-line-prefix))
+		   second-line-prefix
+		 ;; If the second line has the first line prefix,
+		 ;; plus whitespace, use the part that the first line shares.
+		 (if (string-match (concat "\\`"
+					     (regexp-quote first-line-prefix)
+					     "[ \t]*\\'")
+				   second-line-prefix)
+		     first-line-prefix)))
 	;; If we get a fill prefix from a one-line paragraph,
 	;; maybe change it to whitespace,
 	;; and check that it isn't a paragraph starter.
@@ -915,10 +922,19 @@
 (defun fill-individual-paragraphs (min max &optional justify mailp)
   "Fill paragraphs of uniform indentation within the region.
 This command divides the region into \"paragraphs\", 
-treating every change in indentation level as a paragraph boundary,
+treating every change in indentation level or prefix as a paragraph boundary,
 then fills each paragraph using its indentation level as the fill prefix.
 
-When calling from a program, pass range to fill as first two arguments.
+There is one special case where a change in indentation does not start
+a new paragraph.  This is for text of this form:
+
+   foo>    This line with extra indentation starts
+   foo> a paragraph that continues on more lines.
+
+These lines are filled together.
+
+When calling from a program, pass the range to fill
+as the first two arguments.
 
 Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
 JUSTIFY to justify paragraphs (prefix arg),
@@ -957,10 +973,32 @@
 		   (if (not (and fill-prefix
 				 (looking-at fill-prefix-regexp)))
 		       (setq fill-prefix
-			     (or (let ((adaptive-fill-first-line-regexp ""))
-				   (fill-context-prefix
-				    (point)
-				    (save-excursion (forward-line 2) (point))))
+			     ;; Get the prefix from just the first line
+			     ;; ordinarily.
+			     ;; But if using two lines gives us a shorter
+			     ;; result, lacking some whitespace at the end,
+			     ;; use that.
+			     (or (let ((adaptive-fill-first-line-regexp "")
+				       just-one-line-prefix
+				       two-lines-prefix)
+				   (setq just-one-line-prefix
+					 (fill-context-prefix
+					  (point)
+					  (save-excursion (forward-line 1)
+							  (point))))
+				   (setq two-lines-prefix
+					 (fill-context-prefix
+					  (point)
+					  (save-excursion (forward-line 2)
+							  (point))))
+				   (if (and just-one-line-prefix
+					    two-lines-prefix
+					    (string-match (concat "\\`"
+								  (regexp-quote two-lines-prefix)
+								  "[ \t]*\\'")
+							  just-one-line-prefix))
+				       two-lines-prefix
+				     just-one-line-prefix))
 				 (buffer-substring 
 				  (point)
 				  (save-excursion (skip-chars-forward " \t")
@@ -987,7 +1025,8 @@
 			  (and (looking-at fill-prefix-regexp)
 			       (save-excursion
 				 (not (progn (forward-char (length fill-prefix))
-					     (or (looking-at paragraph-separate)
+					     (or (looking-at "[ \t]")
+						 (looking-at paragraph-separate)
 						 (looking-at paragraph-start))))))))))
 	  ;; Fill this paragraph, but don't add a newline at the end.
 	  (let ((had-newline (bolp)))