aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/textmodes/fill.el94
1 files changed, 47 insertions, 47 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 9cac3f49e2f..8f840d7624c 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -146,41 +146,45 @@ Leave one space between words, two at end of sentences or after colons
146and `sentence-end-without-period'). 146and `sentence-end-without-period').
147Remove indentation from each line." 147Remove indentation from each line."
148 (interactive "*r") 148 (interactive "*r")
149 (save-excursion 149 (let ((end-spc-re (concat "\\(" sentence-end "\\) *\\| +")))
150 (goto-char beg) 150 (save-excursion
151 ;; Nuke tabs; they get screwed up in a fill. 151 (goto-char beg)
152 ;; This is quick, but loses when a tab follows the end of a sentence. 152 ;; Nuke tabs; they get screwed up in a fill.
153 ;; Actually, it is difficult to tell that from "Mr.\tSmith". 153 ;; This is quick, but loses when a tab follows the end of a sentence.
154 ;; Blame the typist. 154 ;; Actually, it is difficult to tell that from "Mr.\tSmith".
155 (subst-char-in-region beg end ?\t ?\ ) 155 ;; Blame the typist.
156 (while (and (< (point) end) 156 (subst-char-in-region beg end ?\t ?\ )
157 (re-search-forward " +" end t))
158 (delete-region
159 (+ (match-beginning 0)
160 ;; Determine number of spaces to leave:
161 (save-excursion
162 (skip-chars-backward " ]})\"'")
163 (cond ((and sentence-end-double-space
164 (or (memq (preceding-char) '(?. ?? ?!))
165 (and sentence-end-without-period
166 (= (char-syntax (preceding-char)) ?w)))) 2)
167 ((and colon-double-space
168 (= (preceding-char) ?:)) 2)
169 ((char-equal (preceding-char) ?\n) 0)
170 (t 1))))
171 (match-end 0)))
172 ;; Make sure sentences ending at end of line get an extra space.
173 ;; loses on split abbrevs ("Mr.\nSmith")
174 (goto-char beg)
175 (let ((eol-double-space-re (if colon-double-space
176 "[.?!:][])}\"']*$"
177 "[.?!][])}\"']*$")))
178 (while (and (< (point) end) 157 (while (and (< (point) end)
179 (re-search-forward eol-double-space-re end t)) 158 (re-search-forward end-spc-re end t))
180 ;; We insert before markers in case a caller such as 159 (delete-region
181 ;; do-auto-fill has done a save-excursion with point at the end 160 (cond
182 ;; of the line and wants it to stay at the end of the line. 161 ;; `sentence-end' matched and did not match all spaces.
183 (insert-before-markers-and-inherit ? ))))) 162 ;; I.e. it only matched the number of spaces it needs: drop the rest.
163 ((and (match-end 1) (> (match-end 0) (match-end 1))) (match-end 1))
164 ;; `sentence-end' matched but with nothing left. Either that means
165 ;; nothing should be removed, or it means it's the "old-style"
166 ;; sentence-end which matches all it can. Keep only 2 spaces.
167 ;; We probably don't even need to check `sentence-end-double-space'.
168 ((match-end 1)
169 (min (match-end 0)
170 (+ (if sentence-end-double-space 2 1)
171 (save-excursion (goto-char (match-end 0))
172 (skip-chars-backward " ")
173 (point)))))
174 (t ;; It's not an end of sentence.
175 (+ (match-beginning 0)
176 ;; Determine number of spaces to leave:
177 (save-excursion
178 (skip-chars-backward " ]})\"'")
179 (cond ((and sentence-end-double-space
180 (or (memq (preceding-char) '(?. ?? ?!))
181 (and sentence-end-without-period
182 (= (char-syntax (preceding-char)) ?w)))) 2)
183 ((and colon-double-space
184 (= (preceding-char) ?:)) 2)
185 ((char-equal (preceding-char) ?\n) 0)
186 (t 1))))))
187 (match-end 0))))))
184 188
185(defun fill-common-string-prefix (s1 s2) 189(defun fill-common-string-prefix (s1 s2)
186 "Return the longest common prefix of strings S1 and S2, or nil if none." 190 "Return the longest common prefix of strings S1 and S2, or nil if none."
@@ -444,10 +448,9 @@ Point is moved to just past the fill prefix on the first line."
444 448
445(defun fill-move-to-break-point (linebeg) 449(defun fill-move-to-break-point (linebeg)
446 "Move to the position where the line should be broken. 450 "Move to the position where the line should be broken.
447The break position will normally be after LINEBEG and before point." 451The break position will be always after LINEBEG and generally before point."
448 ;; If the fill column is before linebeg, we have an insanely 452 ;; If the fill column is before linebeg, move to linebeg.
449 ;; wide prefix and might as well ignore it. 453 (if (> linebeg (point)) (goto-char linebeg))
450 (if (> linebeg (point)) (setq linebeg (line-beginning-position)))
451 ;; Move back to the point where we can break the line 454 ;; Move back to the point where we can break the line
452 ;; at. We break the line between word or after/before 455 ;; at. We break the line between word or after/before
453 ;; the character which has character category `|'. We 456 ;; the character which has character category `|'. We
@@ -651,10 +654,10 @@ space does not end a sentence, so don't break a line there."
651 (fill-newline))) 654 (fill-newline)))
652 ;; Justify the line just ended, if desired. 655 ;; Justify the line just ended, if desired.
653 (if justify 656 (if justify
654 (if (save-excursion (skip-chars-forward " \t") (eobp)) 657 (if (save-excursion (skip-chars-forward " \t") (>= (point) to))
655 (progn 658 (progn
656 (delete-horizontal-space) 659 (delete-horizontal-space)
657 (justify-current-line justify t t)) 660 (justify-current-line justify t t))
658 (forward-line -1) 661 (forward-line -1)
659 (justify-current-line justify nil t) 662 (justify-current-line justify nil t)
660 (forward-line 1)))))) 663 (forward-line 1))))))
@@ -692,11 +695,8 @@ If `fill-paragraph-function' is nil, return the `fill-prefix' used for filling."
692 fill-paragraph-function) 695 fill-paragraph-function)
693 (funcall function arg))) 696 (funcall function arg)))
694 (let ((before (point)) 697 (let ((before (point))
695 ;; Fill prefix used for filling the paragraph 698 ;; Fill prefix used for filling the paragraph.
696 fill-pfx 699 fill-pfx)
697 ;; If fill-paragraph is called recursively,
698 ;; don't give fill-paragraph-function a second chance.
699 fill-paragraph-function)
700 (save-excursion 700 (save-excursion
701 (forward-paragraph) 701 (forward-paragraph)
702 (or (bolp) (newline 1)) 702 (or (bolp) (newline 1))