diff options
Diffstat (limited to 'lisp/textmodes/fill.el')
| -rw-r--r-- | lisp/textmodes/fill.el | 96 |
1 files changed, 47 insertions, 49 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el index 1615da60910..7d4ee6ec00d 100644 --- a/lisp/textmodes/fill.el +++ b/lisp/textmodes/fill.el | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | ;;; fill.el --- fill commands for Emacs -*- coding: iso-2022-7bit -*- | 1 | ;;; fill.el --- fill commands for Emacs -*- coding: iso-2022-7bit -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1985,86,92,94,95,96,97,1999,2001,02,03,2004 | 3 | ;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1996, 1997, 1999, 2001, 2002, |
| 4 | ;; Free Software Foundation, Inc. | 4 | ;; 2003, 2004, 2005 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| 7 | ;; Keywords: wp | 7 | ;; Keywords: wp |
| @@ -115,7 +115,7 @@ if it would act as a paragraph-starter on the second line." | |||
| 115 | 115 | ||
| 116 | (defcustom adaptive-fill-function nil | 116 | (defcustom adaptive-fill-function nil |
| 117 | "*Function to call to choose a fill prefix for a paragraph, or nil. | 117 | "*Function to call to choose a fill prefix for a paragraph, or nil. |
| 118 | This function is used when `adaptive-fill-regexp' does not match." | 118 | nil means the function has not determined the fill prefix." |
| 119 | :type '(choice (const nil) function) | 119 | :type '(choice (const nil) function) |
| 120 | :group 'fill) | 120 | :group 'fill) |
| 121 | 121 | ||
| @@ -205,6 +205,16 @@ Remove indentation from each line." | |||
| 205 | (unless (zerop cmp) | 205 | (unless (zerop cmp) |
| 206 | (substring s1 0 cmp))))) | 206 | (substring s1 0 cmp))))) |
| 207 | 207 | ||
| 208 | (defun fill-match-adaptive-prefix () | ||
| 209 | (let ((str (or | ||
| 210 | (and adaptive-fill-function (funcall adaptive-fill-function)) | ||
| 211 | (and adaptive-fill-regexp (looking-at adaptive-fill-regexp) | ||
| 212 | (match-string-no-properties 0))))) | ||
| 213 | (if (>= (+ (current-left-margin) (length str)) (current-fill-column)) | ||
| 214 | ;; Death to insanely long prefixes. | ||
| 215 | nil | ||
| 216 | str))) | ||
| 217 | |||
| 208 | (defun fill-context-prefix (from to &optional first-line-regexp) | 218 | (defun fill-context-prefix (from to &optional first-line-regexp) |
| 209 | "Compute a fill prefix from the text between FROM and TO. | 219 | "Compute a fill prefix from the text between FROM and TO. |
| 210 | This uses the variables `adaptive-fill-regexp' and `adaptive-fill-function' | 220 | This uses the variables `adaptive-fill-regexp' and `adaptive-fill-function' |
| @@ -218,55 +228,45 @@ act as a paragraph-separator." | |||
| 218 | (if (eolp) (forward-line 1)) | 228 | (if (eolp) (forward-line 1)) |
| 219 | ;; Move to the second line unless there is just one. | 229 | ;; Move to the second line unless there is just one. |
| 220 | (move-to-left-margin) | 230 | (move-to-left-margin) |
| 221 | (let ((firstline (point)) | 231 | (let (first-line-prefix |
| 222 | first-line-prefix | ||
| 223 | ;; Non-nil if we are on the second line. | 232 | ;; Non-nil if we are on the second line. |
| 224 | second-line-prefix | 233 | second-line-prefix) |
| 225 | start) | ||
| 226 | (setq start (point)) | ||
| 227 | (setq first-line-prefix | 234 | (setq first-line-prefix |
| 228 | ;; We don't need to consider `paragraph-start' here since it | 235 | ;; We don't need to consider `paragraph-start' here since it |
| 229 | ;; will be explicitly checked later on. | 236 | ;; will be explicitly checked later on. |
| 230 | ;; Also setting first-line-prefix to nil prevents | 237 | ;; Also setting first-line-prefix to nil prevents |
| 231 | ;; second-line-prefix from being used. | 238 | ;; second-line-prefix from being used. |
| 232 | (cond ;; ((looking-at paragraph-start) nil) | 239 | ;; ((looking-at paragraph-start) nil) |
| 233 | ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) | 240 | (fill-match-adaptive-prefix)) |
| 234 | (match-string-no-properties 0)) | ||
| 235 | (adaptive-fill-function (funcall adaptive-fill-function)))) | ||
| 236 | (forward-line 1) | 241 | (forward-line 1) |
| 237 | (if (< (point) to) | 242 | (if (< (point) to) |
| 238 | (progn | 243 | (progn |
| 239 | (move-to-left-margin) | 244 | (move-to-left-margin) |
| 240 | (setq start (point)) | 245 | (setq second-line-prefix |
| 241 | (setq second-line-prefix | 246 | (cond ((looking-at paragraph-start) nil) ;Can it happen? -Stef |
| 242 | (cond ((looking-at paragraph-start) nil) ;Can it happen ? -stef | 247 | (t (fill-match-adaptive-prefix)))) |
| 243 | ((and adaptive-fill-regexp | 248 | ;; If we get a fill prefix from the second line, |
| 244 | (looking-at adaptive-fill-regexp)) | 249 | ;; make sure it or something compatible is on the first line too. |
| 245 | (buffer-substring-no-properties start (match-end 0))) | 250 | (when second-line-prefix |
| 246 | (adaptive-fill-function | 251 | (unless first-line-prefix (setq first-line-prefix "")) |
| 247 | (funcall adaptive-fill-function)))) | 252 | ;; If the non-whitespace chars match the first line, |
| 248 | ;; If we get a fill prefix from the second line, | 253 | ;; just use it (this subsumes the 2 checks used previously). |
| 249 | ;; make sure it or something compatible is on the first line too. | 254 | ;; Used when first line is `/* ...' and second-line is |
| 250 | (when second-line-prefix | 255 | ;; ` * ...'. |
| 251 | (unless first-line-prefix (setq first-line-prefix "")) | 256 | (let ((tmp second-line-prefix) |
| 252 | ;; If the non-whitespace chars match the first line, | 257 | (re "\\`")) |
| 253 | ;; just use it (this subsumes the 2 checks used previously). | 258 | (while (string-match "\\`[ \t]*\\([^ \t]+\\)" tmp) |
| 254 | ;; Used when first line is `/* ...' and second-line is | 259 | (setq re (concat re ".*" (regexp-quote (match-string 1 tmp)))) |
| 255 | ;; ` * ...'. | 260 | (setq tmp (substring tmp (match-end 0)))) |
| 256 | (let ((tmp second-line-prefix) | 261 | ;; (assert (string-match "\\`[ \t]*\\'" tmp)) |
| 257 | (re "\\`")) | 262 | |
| 258 | (while (string-match "\\`[ \t]*\\([^ \t]+\\)" tmp) | 263 | (if (string-match re first-line-prefix) |
| 259 | (setq re (concat re ".*" (regexp-quote (match-string 1 tmp)))) | 264 | second-line-prefix |
| 260 | (setq tmp (substring tmp (match-end 0)))) | 265 | |
| 261 | ;; (assert (string-match "\\`[ \t]*\\'" tmp)) | 266 | ;; Use the longest common substring of both prefixes, |
| 262 | 267 | ;; if there is one. | |
| 263 | (if (string-match re first-line-prefix) | 268 | (fill-common-string-prefix first-line-prefix |
| 264 | second-line-prefix | 269 | second-line-prefix))))) |
| 265 | |||
| 266 | ;; Use the longest common substring of both prefixes, | ||
| 267 | ;; if there is one. | ||
| 268 | (fill-common-string-prefix first-line-prefix | ||
| 269 | second-line-prefix))))) | ||
| 270 | ;; If we get a fill prefix from a one-line paragraph, | 270 | ;; If we get a fill prefix from a one-line paragraph, |
| 271 | ;; maybe change it to whitespace, | 271 | ;; maybe change it to whitespace, |
| 272 | ;; and check that it isn't a paragraph starter. | 272 | ;; and check that it isn't a paragraph starter. |
| @@ -333,7 +333,7 @@ be tested. If it returns t, fill commands do not break the line there." | |||
| 333 | Can be customized with the variables `fill-nobreak-predicate' | 333 | Can be customized with the variables `fill-nobreak-predicate' |
| 334 | and `fill-nobreak-invisible'." | 334 | and `fill-nobreak-invisible'." |
| 335 | (or | 335 | (or |
| 336 | (and fill-nobreak-invisible (line-move-invisible (point))) | 336 | (and fill-nobreak-invisible (line-move-invisible-p (point))) |
| 337 | (unless (bolp) | 337 | (unless (bolp) |
| 338 | (or | 338 | (or |
| 339 | ;; Don't break after a period followed by just one space. | 339 | ;; Don't break after a period followed by just one space. |
| @@ -1128,8 +1128,6 @@ otherwise it is made canonical." | |||
| 1128 | ncols ; new indent point or offset | 1128 | ncols ; new indent point or offset |
| 1129 | (nspaces 0) ; number of spaces between words | 1129 | (nspaces 0) ; number of spaces between words |
| 1130 | ; in line (not space characters) | 1130 | ; in line (not space characters) |
| 1131 | fracspace ; fractional amount of space to be | ||
| 1132 | ; added between each words | ||
| 1133 | (curr-fracspace 0) ; current fractional space amount | 1131 | (curr-fracspace 0) ; current fractional space amount |
| 1134 | count) | 1132 | count) |
| 1135 | (end-of-line) | 1133 | (end-of-line) |
| @@ -1338,7 +1336,7 @@ Also, if CITATION-REGEXP is non-nil, don't fill header lines." | |||
| 1338 | (forward-line 1)))) | 1336 | (forward-line 1)))) |
| 1339 | (narrow-to-region (point) max) | 1337 | (narrow-to-region (point) max) |
| 1340 | ;; Loop over paragraphs. | 1338 | ;; Loop over paragraphs. |
| 1341 | (while (let ((here (point))) | 1339 | (while (progn |
| 1342 | ;; Skip over all paragraph-separating lines | 1340 | ;; Skip over all paragraph-separating lines |
| 1343 | ;; so as to not include them in any paragraph. | 1341 | ;; so as to not include them in any paragraph. |
| 1344 | (while (and (not (eobp)) | 1342 | (while (and (not (eobp)) |
| @@ -1446,5 +1444,5 @@ Also, if CITATION-REGEXP is non-nil, don't fill header lines." | |||
| 1446 | "") | 1444 | "") |
| 1447 | string)) | 1445 | string)) |
| 1448 | 1446 | ||
| 1449 | ;;; arch-tag: 727ad455-1161-4fa9-8df5-0f74b179216d | 1447 | ;; arch-tag: 727ad455-1161-4fa9-8df5-0f74b179216d |
| 1450 | ;;; fill.el ends here | 1448 | ;;; fill.el ends here |