changeset 14621:f989cff391f1

(canonically-space-region): Use insert-before-markers when inserting spaces at end of line. (fill-region-as-paragraph): New arg SQUEEZE-AFTER.
author Karl Heuer <kwzh@gnu.org>
date Wed, 21 Feb 1996 21:20:28 +0000
parents 794c6fdfa87d
children 3d47471d947d
files lisp/textmodes/fill.el
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/fill.el	Wed Feb 21 21:15:07 1996 +0000
+++ b/lisp/textmodes/fill.el	Wed Feb 21 21:20:28 1996 +0000
@@ -101,7 +101,8 @@
 
 (defun canonically-space-region (beg end)
   "Remove extra spaces between words in region.
-Puts one space between words in region; two between sentences.
+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').
 Remove indentation from each line."
   (interactive "r")
   (save-excursion
@@ -130,7 +131,10 @@
     (goto-char beg)
     (while (and (< (point) end)
 		(re-search-forward "[.?!][])}\"']*$" end t))
-      (insert-and-inherit ? ))))
+      ;; We insert before markers in case a caller such as
+      ;; do-auto-fill has done a save-excursion with point at the end
+      ;; of the line and wants it to stay at the end of the line.
+      (insert-before-markers-and-inherit ? ))))
 
 (defun fill-context-prefix (from to &optional first-line-regexp)
   "Compute a fill prefix from the text between FROM and TO.
@@ -163,7 +167,8 @@
 		 (string-match first-line-regexp result))
 	     result)))))
 
-(defun fill-region-as-paragraph (from to &optional justify nosqueeze)
+(defun fill-region-as-paragraph (from to &optional justify
+				      nosqueeze squeeze-after)
   "Fill the region as one paragraph.
 It removes any paragraph breaks in the region and extra newlines at the end,
 indents and fills lines between the margins given by the
@@ -174,8 +179,9 @@
 function, but with a prefix arg, does full justification instead.
 
 From a program, optional third arg JUSTIFY can specify any type of
-justification, and fourth arg NOSQUEEZE non-nil means not to make spaces
-between words canonical before filling.
+justification.  Fourth arg NOSQUEEZE non-nil means not to make spaces
+between words canonical before filling.  Firth arg SQUEEZE-AFTER, if non-nil,
+means don't canonicalize spaces before that position.
 
 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."
@@ -266,7 +272,8 @@
 			 (delete-region (point) (match-end 0)))
 		     (forward-line 1))
 		   (goto-char from)
-		   (and (looking-at fpre) (goto-char (match-end 0)))
+		   (if (looking-at fpre)
+		       (goto-char (match-end 0)))
 		   (setq from (point)))))
 	  ;; Remove indentation from lines other than the first.
 	  (beginning-of-line 2)
@@ -286,7 +293,7 @@
 	  (subst-char-in-region from (point-max) ?\n ?\ )
 	  (if (and nosqueeze (not (eq justify 'full)))
 	      nil
-	    (canonically-space-region (point) (point-max))
+	    (canonically-space-region (or squeeze-after (point)) (point-max))
 	    (goto-char (point-max))
 	    (delete-horizontal-space)
 	    (insert-and-inherit " "))