diff options
| -rw-r--r-- | lisp/textmodes/fill.el | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el index e4bdb9db65e..f8eb668a83b 100644 --- a/lisp/textmodes/fill.el +++ b/lisp/textmodes/fill.el | |||
| @@ -185,6 +185,15 @@ Remove indentation from each line." | |||
| 185 | ;; of the line and wants it to stay at the end of the line. | 185 | ;; of the line and wants it to stay at the end of the line. |
| 186 | (insert-before-markers-and-inherit ? ))))) | 186 | (insert-before-markers-and-inherit ? ))))) |
| 187 | 187 | ||
| 188 | (defun fill-common-string-prefix (s1 s2) | ||
| 189 | "Return the longest common prefix of strings S1 and S2, or nil if none." | ||
| 190 | (let ((cmp (compare-strings s1 nil nil s2 nil nil))) | ||
| 191 | (if (eq cmp t) | ||
| 192 | s1 | ||
| 193 | (setq cmp (1- (abs cmp))) | ||
| 194 | (unless (zerop cmp) | ||
| 195 | (substring s1 0 cmp))))) | ||
| 196 | |||
| 188 | (defun fill-context-prefix (from to &optional first-line-regexp) | 197 | (defun fill-context-prefix (from to &optional first-line-regexp) |
| 189 | "Compute a fill prefix from the text between FROM and TO. | 198 | "Compute a fill prefix from the text between FROM and TO. |
| 190 | This uses the variables `adaptive-fill-regexp' and `adaptive-fill-function' | 199 | This uses the variables `adaptive-fill-regexp' and `adaptive-fill-function' |
| @@ -233,13 +242,24 @@ act as a paragraph-separator." | |||
| 233 | ;; If the second line prefix is whitespace, use it. | 242 | ;; If the second line prefix is whitespace, use it. |
| 234 | (string-match "\\`[ \t]+\\'" second-line-prefix)) | 243 | (string-match "\\`[ \t]+\\'" second-line-prefix)) |
| 235 | second-line-prefix | 244 | second-line-prefix |
| 236 | ;; If the second line has the first line prefix, | 245 | |
| 237 | ;; plus whitespace, use the part that the first line shares. | 246 | ;; If using the common prefix of first-line-prefix |
| 238 | (if (string-match (concat "\\`" | 247 | ;; and second-line-prefix leads to problems, consider |
| 239 | (regexp-quote first-line-prefix) | 248 | ;; to restore the code below that's commented out, |
| 240 | "[ \t]*\\'") | 249 | ;; and document why a common prefix cannot be used. |
| 241 | second-line-prefix) | 250 | |
| 242 | first-line-prefix))) | 251 | ; ;; If the second line has the first line prefix, |
| 252 | ; ;; plus whitespace, use the part that the first line shares. | ||
| 253 | ; (if (string-match (concat "\\`" | ||
| 254 | ; (regexp-quote first-line-prefix) | ||
| 255 | ; "[ \t]*\\'") | ||
| 256 | ; second-line-prefix) | ||
| 257 | ; first-line-prefix))) | ||
| 258 | |||
| 259 | ;; Use the longest common substring of both prefixes, | ||
| 260 | ;; if there is one. | ||
| 261 | (fill-common-string-prefix first-line-prefix | ||
| 262 | second-line-prefix))) | ||
| 243 | ;; If we get a fill prefix from a one-line paragraph, | 263 | ;; If we get a fill prefix from a one-line paragraph, |
| 244 | ;; maybe change it to whitespace, | 264 | ;; maybe change it to whitespace, |
| 245 | ;; and check that it isn't a paragraph starter. | 265 | ;; and check that it isn't a paragraph starter. |