diff options
| author | Karl Heuer | 1997-02-20 05:33:51 +0000 |
|---|---|---|
| committer | Karl Heuer | 1997-02-20 05:33:51 +0000 |
| commit | c9d611f447ba762b947f034a81457a8e4f7fdb6b (patch) | |
| tree | 995a2dd32b053105466f1c4f20fb89419e0b3fa3 | |
| parent | 167d14181ce4d1f1cca6cb6d0e7b26f80ab7de65 (diff) | |
| download | emacs-c9d611f447ba762b947f034a81457a8e4f7fdb6b.tar.gz emacs-c9d611f447ba762b947f034a81457a8e4f7fdb6b.zip | |
(do-kinsoku): New variable.
(fill-region-as-paragraph): Handle `kinsoku' processing.
| -rw-r--r-- | lisp/textmodes/fill.el | 62 |
1 files changed, 54 insertions, 8 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el index 17237a4a235..6a8d6e7b132 100644 --- a/lisp/textmodes/fill.el +++ b/lisp/textmodes/fill.el | |||
| @@ -45,6 +45,10 @@ A value of nil means that any change in indentation starts a new paragraph.") | |||
| 45 | "Mode-specific function to fill a paragraph, or nil if there is none. | 45 | "Mode-specific function to fill a paragraph, or nil if there is none. |
| 46 | If the function returns nil, then `fill-paragraph' does its normal work.") | 46 | If the function returns nil, then `fill-paragraph' does its normal work.") |
| 47 | 47 | ||
| 48 | (defvar do-kinsoku t | ||
| 49 | "*Non-nil means do `kinsoku' processing. | ||
| 50 | See the document of `kinsoku' for more detail.") | ||
| 51 | |||
| 48 | (defun set-fill-prefix () | 52 | (defun set-fill-prefix () |
| 49 | "Set the fill prefix to the current line up to point. | 53 | "Set the fill prefix to the current line up to point. |
| 50 | Filling expects lines to start with the fill prefix and | 54 | Filling expects lines to start with the fill prefix and |
| @@ -287,6 +291,19 @@ space does not end a sentence, so don't break a line there." | |||
| 287 | (while (re-search-forward "[.?!][])}\"']*$" nil t) | 291 | (while (re-search-forward "[.?!][])}\"']*$" nil t) |
| 288 | (or (eobp) (insert-and-inherit ?\ ))) | 292 | (or (eobp) (insert-and-inherit ?\ ))) |
| 289 | (goto-char from) | 293 | (goto-char from) |
| 294 | ;; The character category `|' means that we can break a line | ||
| 295 | ;; at the character. Since we don't need a space between | ||
| 296 | ;; them, delete all newlines between them ... | ||
| 297 | (while (re-search-forward "\\c|\n\\|\n\\c|" nil t) | ||
| 298 | (if (bolp) | ||
| 299 | (delete-char -1) | ||
| 300 | (if (= (char-before (match-beginning 0)) ?\ ) | ||
| 301 | ;; ... except when there is end of sentence. The | ||
| 302 | ;; variable `sentence-end-double-space' is handled | ||
| 303 | ;; properly later. | ||
| 304 | nil | ||
| 305 | (delete-region (match-beginning 0) (1+ (match-beginning 0)))))) | ||
| 306 | (goto-char from) | ||
| 290 | (skip-chars-forward " \t") | 307 | (skip-chars-forward " \t") |
| 291 | ;; Then change all newlines to spaces. | 308 | ;; Then change all newlines to spaces. |
| 292 | (subst-char-in-region from (point-max) ?\n ?\ ) | 309 | (subst-char-in-region from (point-max) ?\n ?\ ) |
| @@ -305,8 +322,19 @@ space does not end a sentence, so don't break a line there." | |||
| 305 | (move-to-column (1+ (current-fill-column))) | 322 | (move-to-column (1+ (current-fill-column))) |
| 306 | (if (eobp) | 323 | (if (eobp) |
| 307 | (or nosqueeze (delete-horizontal-space)) | 324 | (or nosqueeze (delete-horizontal-space)) |
| 308 | ;; Move back to start of word. | 325 | ;; Move back to the point where we can break the line |
| 309 | (skip-chars-backward "^ \n" linebeg) | 326 | ;; at. We break the line between word or after/before |
| 327 | ;; the character which has character category `|'. We | ||
| 328 | ;; search space, \c| followed by a character, or \c| | ||
| 329 | ;; following a character. If not found, place | ||
| 330 | ;; the point at linebeg. | ||
| 331 | (if (re-search-backward " \\|\\c|.\\|.\\c|" linebeg 0) | ||
| 332 | ;; In case of space, we place the point at next to | ||
| 333 | ;; the point where the break occurs acutually, | ||
| 334 | ;; because we don't want to change the following | ||
| 335 | ;; logic of original Emacs. In case of \c|, the | ||
| 336 | ;; point is at the place where the break occurs. | ||
| 337 | (forward-char 1)) | ||
| 310 | ;; Don't break after a period followed by just one space. | 338 | ;; Don't break after a period followed by just one space. |
| 311 | ;; Move back to the previous place to break. | 339 | ;; Move back to the previous place to break. |
| 312 | ;; The reason is that if a period ends up at the end of a line, | 340 | ;; The reason is that if a period ends up at the end of a line, |
| @@ -319,18 +347,20 @@ space does not end a sentence, so don't break a line there." | |||
| 319 | (not (eq (following-char) ?\ )) | 347 | (not (eq (following-char) ?\ )) |
| 320 | (eq (char-after (- (point) 2)) ?\.)) | 348 | (eq (char-after (- (point) 2)) ?\.)) |
| 321 | (forward-char -2) | 349 | (forward-char -2) |
| 322 | (skip-chars-backward "^ \n" linebeg))) | 350 | (if (re-search-backward " \\|\\c|.\\|.\\c|" linebeg 0) |
| 351 | (forward-char 1)))) | ||
| 323 | ;; If the left margin and fill prefix by themselves | 352 | ;; If the left margin and fill prefix by themselves |
| 324 | ;; pass the fill-column. or if they are zero | 353 | ;; pass the fill-column. or if they are zero |
| 325 | ;; but we have no room for even one word, | 354 | ;; but we have no room for even one word, |
| 326 | ;; keep at least one word anyway. | 355 | ;; keep at least one word or a character which has |
| 356 | ;; category `|'anyway . | ||
| 327 | ;; This handles ALL BUT the first line of the paragraph. | 357 | ;; This handles ALL BUT the first line of the paragraph. |
| 328 | (if (if (zerop prefixcol) | 358 | (if (if (zerop prefixcol) |
| 329 | (save-excursion | 359 | (save-excursion |
| 330 | (skip-chars-backward " \t" linebeg) | 360 | (skip-chars-backward " \t" linebeg) |
| 331 | (bolp)) | 361 | (bolp)) |
| 332 | (>= prefixcol (current-column))) | 362 | (>= prefixcol (current-column))) |
| 333 | ;; Ok, skip at least one word. | 363 | ;; Ok, skip at least one word or one \c| character. |
| 334 | ;; Meanwhile, don't stop at a period followed by one space. | 364 | ;; Meanwhile, don't stop at a period followed by one space. |
| 335 | (let ((first t)) | 365 | (let ((first t)) |
| 336 | (move-to-column prefixcol) | 366 | (move-to-column prefixcol) |
| @@ -342,10 +372,15 @@ space does not end a sentence, so don't break a line there." | |||
| 342 | (and (looking-at "\\. ") | 372 | (and (looking-at "\\. ") |
| 343 | (not (looking-at "\\. "))))))) | 373 | (not (looking-at "\\. "))))))) |
| 344 | (skip-chars-forward " \t") | 374 | (skip-chars-forward " \t") |
| 345 | (skip-chars-forward "^ \n\t") | 375 | ;; Skip one \c| character or one word. |
| 376 | (if (looking-at "$\\|\\c|\\|[^ \t\n]+") | ||
| 377 | (goto-char (match-end 0))) | ||
| 346 | (setq first nil))) | 378 | (setq first nil))) |
| 347 | ;; Normally, move back over the single space between the words. | 379 | ;; Normally, move back over the single space between the words. |
| 348 | (forward-char -1)) | 380 | (if (= (preceding-char) ?\ ) (forward-char -1)) |
| 381 | ;; Do KINSOKU processing. | ||
| 382 | (if do-kinsoku (kinsoku linebeg))) | ||
| 383 | |||
| 349 | ;; If the left margin and fill prefix by themselves | 384 | ;; If the left margin and fill prefix by themselves |
| 350 | ;; pass the fill-column, keep at least one word. | 385 | ;; pass the fill-column, keep at least one word. |
| 351 | ;; This handles the first line of the paragraph. | 386 | ;; This handles the first line of the paragraph. |
| @@ -370,7 +405,9 @@ space does not end a sentence, so don't break a line there." | |||
| 370 | (and (looking-at "\\. ") | 405 | (and (looking-at "\\. ") |
| 371 | (not (looking-at "\\. "))))))) | 406 | (not (looking-at "\\. "))))))) |
| 372 | (skip-chars-forward " \t") | 407 | (skip-chars-forward " \t") |
| 373 | (skip-chars-forward "^ \t\n") | 408 | ;; Skip one \c| character or one word. |
| 409 | (if (looking-at "$\\|\\c|\\|[^ \t\n]+") | ||
| 410 | (goto-char (match-end 0))) | ||
| 374 | (setq first nil)))) | 411 | (setq first nil)))) |
| 375 | ;; Check again to see if we got to the end of the paragraph. | 412 | ;; Check again to see if we got to the end of the paragraph. |
| 376 | (if (save-excursion (skip-chars-forward " \t") (eobp)) | 413 | (if (save-excursion (skip-chars-forward " \t") (eobp)) |
| @@ -378,6 +415,15 @@ space does not end a sentence, so don't break a line there." | |||
| 378 | ;; Replace whitespace here with one newline, then indent to left | 415 | ;; Replace whitespace here with one newline, then indent to left |
| 379 | ;; margin. | 416 | ;; margin. |
| 380 | (skip-chars-backward " \t") | 417 | (skip-chars-backward " \t") |
| 418 | (if (and (= (following-char) ?\ ) | ||
| 419 | (or (aref (char-category-set (preceding-char)) ?|) | ||
| 420 | (looking-at "[ \t]+\\c|"))) | ||
| 421 | ;; We need one space at end of line so that | ||
| 422 | ;; further filling won't delete it. NOTE: We | ||
| 423 | ;; intentionally leave this one space to | ||
| 424 | ;; distingush the case that user wants to put | ||
| 425 | ;; space between \c| characters. | ||
| 426 | (forward-char 1)) | ||
| 381 | (insert ?\n) | 427 | (insert ?\n) |
| 382 | ;; Give newline the properties of the space(s) it replaces | 428 | ;; Give newline the properties of the space(s) it replaces |
| 383 | (set-text-properties (1- (point)) (point) | 429 | (set-text-properties (1- (point)) (point) |