comparison lisp/textmodes/fill.el @ 90224:2d92f5c9d6ae

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-78 Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 514-518) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 104-105) - Update from CVS
author Miles Bader <miles@gnu.org>
date Fri, 26 Aug 2005 09:51:52 +0000
parents f9a65d7ebd29 a045a3e5b467
children 0ca0d9181b5e
comparison
equal deleted inserted replaced
90223:edf295560b5a 90224:2d92f5c9d6ae
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, 1986, 1992, 1994, 1995, 1996, 1997, 1999, 2001, 2002, 3 ;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1996, 1997, 1999, 2001, 2002,
4 ;; 2003, 2004, 2005 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
8 8
9 ;; This file is part of GNU Emacs. 9 ;; This file is part of GNU Emacs.
161 (goto-char beg) 161 (goto-char beg)
162 ;; Nuke tabs; they get screwed up in a fill. 162 ;; Nuke tabs; they get screwed up in a fill.
163 ;; This is quick, but loses when a tab follows the end of a sentence. 163 ;; This is quick, but loses when a tab follows the end of a sentence.
164 ;; Actually, it is difficult to tell that from "Mr.\tSmith". 164 ;; Actually, it is difficult to tell that from "Mr.\tSmith".
165 ;; Blame the typist. 165 ;; Blame the typist.
166 (subst-char-in-region beg end ?\t ?\ ) 166 (subst-char-in-region beg end ?\t ?\s)
167 (while (and (< (point) end) 167 (while (and (< (point) end)
168 (re-search-forward end-spc-re end t)) 168 (re-search-forward end-spc-re end t))
169 (delete-region 169 (delete-region
170 (cond 170 (cond
171 ;; `sentence-end' matched and did not match all spaces. 171 ;; `sentence-end' matched and did not match all spaces.
280 first-line-prefix)) 280 first-line-prefix))
281 (and comment-start-skip 281 (and comment-start-skip
282 (string-match comment-start-skip 282 (string-match comment-start-skip
283 first-line-prefix))) 283 first-line-prefix)))
284 first-line-prefix 284 first-line-prefix
285 (make-string (string-width first-line-prefix) ?\ )))) 285 (make-string (string-width first-line-prefix) ?\s))))
286 ;; But either way, reject it if it indicates the start 286 ;; But either way, reject it if it indicates the start
287 ;; of a paragraph when text follows it. 287 ;; of a paragraph when text follows it.
288 (if (not (eq 0 (string-match paragraph-start 288 (if (not (eq 0 (string-match paragraph-start
289 (concat result "a")))) 289 (concat result "a"))))
290 result))))))) 290 result)))))))
310 (skip-chars-backward " \t") 310 (skip-chars-backward " \t")
311 (unless (bolp) 311 (unless (bolp)
312 (backward-char 1) 312 (backward-char 1)
313 (or (looking-at "[([{,A+,b+(B]") 313 (or (looking-at "[([{,A+,b+(B]")
314 ;; Don't cut right after a single-letter word. 314 ;; Don't cut right after a single-letter word.
315 (and (memq (preceding-char) '(?\t ?\ )) 315 (and (memq (preceding-char) '(?\t ?\s))
316 (eq (char-syntax (following-char)) ?w))))))) 316 (eq (char-syntax (following-char)) ?w)))))))
317 317
318 (defcustom fill-nobreak-predicate nil 318 (defcustom fill-nobreak-predicate nil
319 "List of predicates for recognizing places not to break a line. 319 "List of predicates for recognizing places not to break a line.
320 The predicates are called with no arguments, with point at the place to 320 The predicates are called with no arguments, with point at the place to
437 ;; Can't find the right spot to insert the colon. 437 ;; Can't find the right spot to insert the colon.
438 (t "[.?!:][])}\"']*$"))) 438 (t "[.?!:][])}\"']*$")))
439 (sentence-end-without-space-list 439 (sentence-end-without-space-list
440 (string-to-list sentence-end-without-space))) 440 (string-to-list sentence-end-without-space)))
441 (while (re-search-forward eol-double-space-re to t) 441 (while (re-search-forward eol-double-space-re to t)
442 (or (>= (point) to) (memq (char-before) '(?\t ?\ )) 442 (or (>= (point) to) (memq (char-before) '(?\t ?\s))
443 (memq (char-after (match-beginning 0)) 443 (memq (char-after (match-beginning 0))
444 sentence-end-without-space-list) 444 sentence-end-without-space-list)
445 (insert-and-inherit ?\ )))) 445 (insert-and-inherit ?\s))))
446 446
447 (goto-char from) 447 (goto-char from)
448 (if enable-multibyte-characters 448 (if enable-multibyte-characters
449 ;; Delete unnecessay newlines surrounded by words. The 449 ;; Delete unnecessay newlines surrounded by words. The
450 ;; character category `|' means that we can break a line 450 ;; character category `|' means that we can break a line
469 (delete-char -1)))))) 469 (delete-char -1))))))
470 470
471 (goto-char from) 471 (goto-char from)
472 (skip-chars-forward " \t") 472 (skip-chars-forward " \t")
473 ;; Then change all newlines to spaces. 473 ;; Then change all newlines to spaces.
474 (subst-char-in-region from to ?\n ?\ ) 474 (subst-char-in-region from to ?\n ?\s)
475 (if (and nosqueeze (not (eq justify 'full))) 475 (if (and nosqueeze (not (eq justify 'full)))
476 nil 476 nil
477 (canonically-space-region (or squeeze-after (point)) to) 477 (canonically-space-region (or squeeze-after (point)) to)
478 ;; Remove trailing whitespace. 478 ;; Remove trailing whitespace.
479 ;; Maybe canonically-space-region should do that. 479 ;; Maybe canonically-space-region should do that.
828 (save-excursion 828 (save-excursion
829 (goto-char comstart) 829 (goto-char comstart)
830 (if has-code-and-comment 830 (if has-code-and-comment
831 (concat 831 (concat
832 (if (not indent-tabs-mode) 832 (if (not indent-tabs-mode)
833 (make-string (current-column) ?\ ) 833 (make-string (current-column) ?\s)
834 (concat 834 (concat
835 (make-string (/ (current-column) tab-width) ?\t) 835 (make-string (/ (current-column) tab-width) ?\t)
836 (make-string (% (current-column) tab-width) ?\ ))) 836 (make-string (% (current-column) tab-width) ?\s)))
837 (buffer-substring (point) comin)) 837 (buffer-substring (point) comin))
838 (buffer-substring (line-beginning-position) comin)))) 838 (buffer-substring (line-beginning-position) comin))))
839 beg end) 839 beg end)
840 (save-excursion 840 (save-excursion
841 (save-restriction 841 (save-restriction
1221 (setq curr-fracspace (+ ncols (/ (1+ nspaces) 2)) 1221 (setq curr-fracspace (+ ncols (/ (1+ nspaces) 2))
1222 count nspaces) 1222 count nspaces)
1223 (while (> count 0) 1223 (while (> count 0)
1224 (skip-chars-forward " ") 1224 (skip-chars-forward " ")
1225 (insert-and-inherit 1225 (insert-and-inherit
1226 (make-string (/ curr-fracspace nspaces) ?\ )) 1226 (make-string (/ curr-fracspace nspaces) ?\s))
1227 (search-forward " " nil t) 1227 (search-forward " " nil t)
1228 (setq count (1- count) 1228 (setq count (1- count)
1229 curr-fracspace 1229 curr-fracspace
1230 (+ (% curr-fracspace nspaces) ncols))))))) 1230 (+ (% curr-fracspace nspaces) ncols)))))))
1231 (t (error "Unknown justification value")))) 1231 (t (error "Unknown justification value"))))
1280 using as the fill prefix the smallest indentation of any line 1280 using as the fill prefix the smallest indentation of any line
1281 in the paragraph. 1281 in the paragraph.
1282 1282
1283 When calling from a program, pass range to fill as first two arguments. 1283 When calling from a program, pass range to fill as first two arguments.
1284 1284
1285 Optional third and fourth arguments JUSTIFY and MAIL-FLAG: 1285 Optional third and fourth arguments JUSTIFYP and CITATION-REGEXP:
1286 JUSTIFY to justify paragraphs (prefix arg), 1286 JUSTIFYP to justify paragraphs (prefix arg).
1287 When filling a mail message, pass a regexp for CITATION-REGEXP 1287 When filling a mail message, pass a regexp for CITATION-REGEXP
1288 which will match the prefix of a line which is a citation marker 1288 which will match the prefix of a line which is a citation marker
1289 plus whitespace, but no other kind of prefix. 1289 plus whitespace, but no other kind of prefix.
1290 Also, if CITATION-REGEXP is non-nil, don't fill header lines." 1290 Also, if CITATION-REGEXP is non-nil, don't fill header lines."
1291 (interactive (progn 1291 (interactive (progn