# HG changeset patch # User Richard M. Stallman # Date 733356456 0 # Node ID d03c7b8ac284936a595d287dedbd0bac2eece9ac # Parent a9c05a12b6151b006c82ccd169c62fbe539d7286 Cancel previous change; this version should be identical to version 1.17. diff -r a9c05a12b615 -r d03c7b8ac284 lisp/textmodes/fill.el --- a/lisp/textmodes/fill.el Sun Mar 28 20:17:39 1993 +0000 +++ b/lisp/textmodes/fill.el Sun Mar 28 22:07:36 1993 +0000 @@ -66,7 +66,7 @@ (if (and buffer-undo-list (not (eq buffer-undo-list t))) (setq buffer-undo-list (cons (point) buffer-undo-list))) ;; Don't let Adaptive Fill mode alter the fill prefix permanently. - (let ((fill-prefix fill-prefix) spc) + (let ((fill-prefix fill-prefix)) ;; Figure out how this paragraph is indented, if desired. (if (and adaptive-fill-mode (or (null fill-prefix) (string= fill-prefix ""))) @@ -114,48 +114,34 @@ ;; from is now before the text to fill, ;; but after any fill prefix on the first line. - ;; spc (our filler character) is normally SPC; - ;; if SPC does not have syntax class whitespace, find a filler that does. - (if (= (char-syntax ?\ ) ?\ ) - (setq spc ?\ ) - (setq spc 0) - (while (not (= (char-syntax spc) ?\ )) - (setq spc (1+ spc)))) - ;; Make sure sentences ending at end of line get an extra space. - ;; loses on split abbrevs ("Mr.\nSmith"). This is fairly specific - ;; to text mode. + ;; loses on split abbrevs ("Mr.\nSmith") (goto-char from) (while (re-search-forward "[.?!][])}\"']*$" nil t) - (insert spc)) + (insert ? )) ;; Then change all newlines to spaces. - (subst-char-in-region from to ?\n spc) - - ;; Go to beginning of paragraph (after indent) - (goto-char from) - (skip-syntax-forward " ") + (subst-char-in-region from (point-max) ?\n ?\ ) - ;; If tabs have whitespace class, nuke them; they get screwed up - ;; in a fill. This is quick, but loses when a sole tab follows - ;; the end of a sentence. actually, it is difficult to tell - ;; that from "Mr.\tSmith". Blame the typist. - (if (= (char-syntax ?\t) ?\ ) - (subst-char-in-region (point) to ?\t spc)) - - ;; Flush excess whitespace, except in the paragraph indentation. - (while (re-search-forward "\\s-\\s-\\s-*" nil t) + ;; Flush excess spaces, except in the paragraph indentation. + (goto-char from) + (skip-chars-forward " \t") + ;; nuke tabs while we're at it; they get screwed up in a fill + ;; this is quick, but loses when a sole tab follows the end of a sentence. + ;; actually, it is difficult to tell that from "Mr.\tSmith". + ;; blame the typist. + (subst-char-in-region (point) (point-max) ?\t ?\ ) + (while (re-search-forward " *" nil t) (delete-region (+ (match-beginning 0) (if (save-excursion - (skip-syntax-backward " ).") + (skip-chars-backward " ]})\"'") (memq (preceding-char) '(?. ?? ?!))) 2 1)) (match-end 0))) (goto-char (point-max)) (delete-horizontal-space) - (insert spc) - (insert spc) + (insert " ") (goto-char (point-min)) ;; This is the actual filling loop. @@ -166,7 +152,7 @@ (if (eobp) nil ;; Move back to start of word. - (skip-syntax-backward "^ " linebeg) + (skip-chars-backward "^ \n" linebeg) ;; Don't break after a period followed by just one space. ;; Move back to the previous place to break. ;; The reason is that if a period ends up at the end of a line, @@ -174,16 +160,16 @@ ;; If we now know it does not end a sentence, ;; avoid putting it at the end of the line. (while (and (> (point) (+ linebeg 2)) - (eq (char-syntax (preceding-char)) ?\ ) + (eq (preceding-char) ?\ ) (eq (char-after (- (point) 2)) ?\.)) (forward-char -2) - (skip-syntax-backward "^ " linebeg)) + (skip-chars-backward "^ \n" linebeg)) (if (if (zerop prefixcol) (bolp) (>= prefixcol (current-column))) ;; Keep at least one word even if fill prefix exceeds margin. ;; This handles all but the first line of the paragraph. (progn - (skip-syntax-forward " ") - (skip-syntax-forward "^ ")) + (skip-chars-forward " ") + (skip-chars-forward "^ \n")) ;; Normally, move back over the single space between the words. (forward-char -1))) (if (and fill-prefix (zerop prefixcol) @@ -193,12 +179,12 @@ ;; Keep at least one word even if fill prefix exceeds margin. ;; This handles the first line of the paragraph. (progn - (skip-syntax-forward " ") - (skip-syntax-forward "^ "))) + (skip-chars-forward " ") + (skip-chars-forward "^ \n"))) ;; Replace all whitespace here with one newline. ;; Insert before deleting, so we don't forget which side of ;; the whitespace point or markers used to be on. - (skip-syntax-backward " ") + (skip-chars-backward " ") (insert ?\n) (delete-horizontal-space) ;; Insert the fill prefix at start of each line. @@ -250,17 +236,17 @@ (let (ncols beg indent) (beginning-of-line) (forward-char (length fill-prefix)) - (skip-syntax-forward " " (save-excursion (end-of-line) (point))) + (skip-chars-forward " \t") (setq indent (current-column)) (setq beg (point)) (end-of-line) (narrow-to-region beg (point)) (goto-char beg) - (while (re-search-forward "\\s-\\s-\\s-*" nil t) + (while (re-search-forward " *" nil t) (delete-region (+ (match-beginning 0) (if (save-excursion - (skip-syntax-backward " ).") + (skip-chars-backward " ])\"'") (memq (preceding-char) '(?. ?? ?!))) 2 1)) (match-end 0)))