aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-12-04 19:49:21 +0000
committerRichard M. Stallman1994-12-04 19:49:21 +0000
commitc4b55ff15ce75f960dc1bd76475cbabe4face0b1 (patch)
tree0143fe8ede6ec8b3506389628e8a55cb42bf1706
parent00eb4c4abc907998ecb60cb5fb1b5fc770c6fa41 (diff)
downloademacs-c4b55ff15ce75f960dc1bd76475cbabe4face0b1.tar.gz
emacs-c4b55ff15ce75f960dc1bd76475cbabe4face0b1.zip
(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.
-rw-r--r--lisp/textmodes/fill.el63
1 files changed, 37 insertions, 26 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 66c0d94e51f..72aea08324a 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -97,16 +97,22 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
97 ))) 97 )))
98 98
99 (save-restriction 99 (save-restriction
100 (goto-char (max from to)) 100 (let (end)
101 ;; If specified region ends before a newline, 101 (goto-char (max from to))
102 ;; include that newline. 102 ;; If specified region ends before a newline,
103 (if (and (eolp) (not (eobp)) (not (bolp))) 103 ;; include that newline.
104 (forward-char 1)) 104 (if (and (eolp) (not (eobp)) (not (bolp)))
105 (narrow-to-region (min from to) (point)) 105 (forward-char 1))
106 (goto-char (point-min)) 106 (setq end (point))
107 (setq from (min from to))
108 (goto-char from)
109 (beginning-of-line)
110 (narrow-to-region (point) end))
107 (skip-chars-forward "\n") 111 (skip-chars-forward "\n")
108 (narrow-to-region (point) (point-max)) 112 (narrow-to-region (point) (point-max))
109 (setq from (point)) 113 (if (> from (point))
114 (goto-char from)
115 (setq from (point)))
110 (goto-char (point-max)) 116 (goto-char (point-max))
111 (let ((fpre (and fill-prefix (not (equal fill-prefix "")) 117 (let ((fpre (and fill-prefix (not (equal fill-prefix ""))
112 (regexp-quote fill-prefix)))) 118 (regexp-quote fill-prefix))))
@@ -116,13 +122,13 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
116 (progn 122 (progn
117 (if (>= (length fill-prefix) fill-column) 123 (if (>= (length fill-prefix) fill-column)
118 (error "fill-prefix too long for specified width")) 124 (error "fill-prefix too long for specified width"))
119 (goto-char (point-min)) 125 (goto-char from)
120 (forward-line 1) 126 (forward-line 1)
121 (while (not (eobp)) 127 (while (not (eobp))
122 (if (looking-at fpre) 128 (if (looking-at fpre)
123 (delete-region (point) (match-end 0))) 129 (delete-region (point) (match-end 0)))
124 (forward-line 1)) 130 (forward-line 1))
125 (goto-char (point-min)) 131 (goto-char from)
126 (and (looking-at fpre) (forward-char (length fill-prefix))) 132 (and (looking-at fpre) (forward-char (length fill-prefix)))
127 (setq from (point))))) 133 (setq from (point)))))
128 ;; from is now before the text to fill, 134 ;; from is now before the text to fill,
@@ -260,22 +266,27 @@ Prefix arg (non-nil third arg, if called from program) means justify as well.
260If `sentence-end-double-space' is non-nil, then period followed by one 266If `sentence-end-double-space' is non-nil, then period followed by one
261space does not end a sentence, so don't break a line there." 267space does not end a sentence, so don't break a line there."
262 (interactive "r\nP") 268 (interactive "r\nP")
263 (save-restriction 269 (let (end beg)
264 (goto-char (max from to)) 270 (save-restriction
265 ;; If specified region ends before a newline, 271 (goto-char (max from to))
266 ;; include that newline. 272 ;; If specified region ends before a newline,
267 (if (and (eolp) (not (eobp)) (not (bolp))) 273 ;; include that newline.
268 (forward-char 1)) 274 (if (and (eolp) (not (eobp)) (not (bolp)))
269 (narrow-to-region (min from to) (point)) 275 (forward-char 1))
270 (goto-char (point-min)) 276 (setq end (point))
271 (while (not (eobp)) 277 (goto-char (setq beg (min from to)))
272 (let ((initial (point)) 278 (beginning-of-line)
273 (end (progn 279 (narrow-to-region (point) end)
274 (forward-paragraph 1) (point)))) 280 (while (not (eobp))
275 (forward-paragraph -1) 281 (let ((initial (point))
276 (if (>= (point) initial) 282 (end (progn
277 (fill-region-as-paragraph (point) end justify-flag) 283 (forward-paragraph 1) (point))))
278 (goto-char end)))))) 284 (forward-paragraph -1)
285 (if (< (point) beg)
286 (goto-char beg))
287 (if (>= (point) initial)
288 (fill-region-as-paragraph (point) end justify-flag)
289 (goto-char end)))))))
279 290
280(defun justify-current-line () 291(defun justify-current-line ()
281 "Add spaces to line point is in, so it ends at `fill-column'." 292 "Add spaces to line point is in, so it ends at `fill-column'."