aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-11-10 17:13:56 +0000
committerRichard M. Stallman1995-11-10 17:13:56 +0000
commitd09d7ba961e9ecb15a2dbb3ad11cd83f9e7e508f (patch)
tree1e10342e3e1fb72879753119cff2410b18314e58
parent64852bcde8fd86a3411b719ff18dc0ef0a5f867b (diff)
downloademacs-d09d7ba961e9ecb15a2dbb3ad11cd83f9e7e508f.tar.gz
emacs-d09d7ba961e9ecb15a2dbb3ad11cd83f9e7e508f.zip
(fill-region-as-paragraph): Use fill-context-prefix.
(fill-context-prefix): New function. (fill-region-as-paragraph): Don't insert extra space at end of filled region. (fill-individual-paragraphs): Insist on nonempty header name, in the special mailp case.
-rw-r--r--lisp/textmodes/fill.el50
1 files changed, 27 insertions, 23 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 4855ee0bbca..884aec40a7e 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -130,6 +130,25 @@ Remove indentation from each line."
130 (re-search-forward "[.?!][])}\"']*$" end t)) 130 (re-search-forward "[.?!][])}\"']*$" end t))
131 (insert-and-inherit ? )))) 131 (insert-and-inherit ? ))))
132 132
133(defun fill-context-prefix (from to)
134 "Compute a fill prefix from the text between FROM and TO.
135This uses the variables `adapive-fill-prefix' and `adaptive-fill-function'."
136 (save-excursion
137 (goto-char from)
138 (if (eolp) (forward-line 1))
139 ;; Move to the second line unless there is just one.
140 (let ((firstline (point)))
141 (forward-line 1)
142 (if (>= (point) to)
143 (goto-char firstline)))
144 (move-to-left-margin)
145 (let ((start (point))
146 (eol (save-excursion (end-of-line) (point))))
147 (if (not (looking-at paragraph-start))
148 (cond ((re-search-forward adaptive-fill-regexp nil t)
149 (buffer-substring-no-properties start (point)))
150 (t (funcall adaptive-fill-function)))))))
151
133(defun fill-region-as-paragraph (from to &optional justify nosqueeze) 152(defun fill-region-as-paragraph (from to &optional justify nosqueeze)
134 "Fill the region as one paragraph. 153 "Fill the region as one paragraph.
135Removes any paragraph breaks in the region and extra newlines at the end, 154Removes any paragraph breaks in the region and extra newlines at the end,
@@ -187,24 +206,7 @@ space does not end a sentence, so don't break a line there."
187 ;; Figure out how this paragraph is indented, if desired. 206 ;; Figure out how this paragraph is indented, if desired.
188 (if (and adaptive-fill-mode 207 (if (and adaptive-fill-mode
189 (or (null fill-prefix) (string= fill-prefix ""))) 208 (or (null fill-prefix) (string= fill-prefix "")))
190 (save-excursion 209 (setq fill-prefix (fill-context-prefix from to)))
191 (goto-char from)
192 (if (eolp) (forward-line 1))
193 ;; Move to the second line unless there is just one.
194 (let ((firstline (point)))
195 (forward-line 1)
196 (if (>= (point) to)
197 (goto-char firstline)))
198 (move-to-left-margin)
199 (let ((start (point))
200 (eol (save-excursion (end-of-line) (point)))
201 temp)
202 (if (not (looking-at paragraph-start))
203 (cond ((re-search-forward adaptive-fill-regexp nil t)
204 (setq fill-prefix
205 (buffer-substring-no-properties start (point))))
206 ((setq temp (funcall adaptive-fill-function))
207 (setq fill-prefix temp)))))))
208 210
209 (save-restriction 211 (save-restriction
210 (goto-char from) 212 (goto-char from)
@@ -258,7 +260,7 @@ space does not end a sentence, so don't break a line there."
258 ;; Make sure sentences ending at end of line get an extra space. 260 ;; Make sure sentences ending at end of line get an extra space.
259 ;; loses on split abbrevs ("Mr.\nSmith") 261 ;; loses on split abbrevs ("Mr.\nSmith")
260 (while (re-search-forward "[.?!][])}\"']*$" nil t) 262 (while (re-search-forward "[.?!][])}\"']*$" nil t)
261 (insert-and-inherit ? )) 263 (or (eobp) (insert-and-inherit ?\ )))
262 (goto-char from) 264 (goto-char from)
263 (skip-chars-forward " \t") 265 (skip-chars-forward " \t")
264 ;; Then change all newlines to spaces. 266 ;; Then change all newlines to spaces.
@@ -565,8 +567,10 @@ it will not be stretched by full justification.
565Third arg NOSQUEEZE non-nil means to leave interior whitespace unchanged, 567Third arg NOSQUEEZE non-nil means to leave interior whitespace unchanged,
566otherwise it is made canonical." 568otherwise it is made canonical."
567 (interactive) 569 (interactive)
568 (if (eq t how) (setq how (or (current-justification) 'none))) 570 (if (eq t how) (setq how (or (current-justification) 'none))
569 (if (null how) (setq how 'full)) 571 (if (null how) (setq how 'full)
572 (or (memq how '(none left right center))
573 (setq how 'full))))
570 (or (memq how '(none left)) ; No action required for these. 574 (or (memq how '(none left)) ; No action required for these.
571 (let ((fc (current-fill-column)) 575 (let ((fc (current-fill-column))
572 (pos (point-marker)) 576 (pos (point-marker))
@@ -756,9 +760,9 @@ MAIL-FLAG for a mail message, i. e. don't fill header lines."
756 (narrow-to-region (point) max) 760 (narrow-to-region (point) max)
757 (if mailp 761 (if mailp
758 (while (and (not (eobp)) 762 (while (and (not (eobp))
759 (or (looking-at "[ \t]*[^ \t\n]*:") 763 (or (looking-at "[ \t]*[^ \t\n]+:")
760 (looking-at "[ \t]*$"))) 764 (looking-at "[ \t]*$")))
761 (if (looking-at "[ \t]*[^ \t\n]*:") 765 (if (looking-at "[ \t]*[^ \t\n]+:")
762 (search-forward "\n\n" nil 'move) 766 (search-forward "\n\n" nil 'move)
763 (forward-line 1)))) 767 (forward-line 1))))
764 (narrow-to-region (point) max) 768 (narrow-to-region (point) max)