comparison lisp/textmodes/fill.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children 4c90ffeb71c5
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
1 ;;; fill.el --- fill commands for Emacs 1 ;;; fill.el --- fill commands for Emacs
2 2
3 ;; Copyright (C) 1985,86,92,94,95,96,97,1999,2001,02,2003 3 ;; Copyright (C) 1985,86,92,94,95,96,97,1999,2001,02,03,2004
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 5
6 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Keywords: wp 7 ;; Keywords: wp
8 8
27 27
28 ;; All the commands for filling text. These are documented in the Emacs 28 ;; All the commands for filling text. These are documented in the Emacs
29 ;; manual. 29 ;; manual.
30 30
31 ;;; Code: 31 ;;; Code:
32
33 (defgroup fill nil
34 "Indenting and filling text."
35 :link '(custom-manual "(emacs)Filling")
36 :group 'editing)
32 37
33 (defcustom fill-individual-varying-indent nil 38 (defcustom fill-individual-varying-indent nil
34 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'. 39 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'.
35 Non-nil means changing indent doesn't end a paragraph. 40 Non-nil means changing indent doesn't end a paragraph.
36 That mode can handle paragraphs with extra indentation on the first line, 41 That mode can handle paragraphs with extra indentation on the first line,
47 (defvar fill-paragraph-function nil 52 (defvar fill-paragraph-function nil
48 "Mode-specific function to fill a paragraph, or nil if there is none. 53 "Mode-specific function to fill a paragraph, or nil if there is none.
49 If the function returns nil, then `fill-paragraph' does its normal work.") 54 If the function returns nil, then `fill-paragraph' does its normal work.")
50 55
51 (defvar fill-paragraph-handle-comment t 56 (defvar fill-paragraph-handle-comment t
52 "If non-nil, paragraph filling will try to pay attention to comments.") 57 "Non-nil means paragraph filling will try to pay attention to comments.")
53 58
54 (defvar enable-kinsoku t 59 (defcustom enable-kinsoku t
55 "*Non-nil means enable \"kinsoku\" processing on filling paragraph. 60 "*Non-nil means enable \"kinsoku\" processing on filling paragraphs.
56 Kinsoku processing is designed to prevent certain characters from being 61 Kinsoku processing is designed to prevent certain characters from being
57 placed at the beginning or end of a line by filling. 62 placed at the beginning or end of a line by filling.
58 See the documentation of `kinsoku' for more information.") 63 See the documentation of `kinsoku' for more information."
64 :type 'boolean)
59 65
60 (defun set-fill-prefix () 66 (defun set-fill-prefix ()
61 "Set the fill prefix to the current line up to point. 67 "Set the fill prefix to the current line up to point.
62 Filling expects lines to start with the fill prefix and 68 Filling expects lines to start with the fill prefix and
63 reinserts the fill prefix in each resulting line." 69 reinserts the fill prefix in each resulting line."
315 :group 'fill 321 :group 'fill
316 :type 'hook 322 :type 'hook
317 :options '(fill-french-nobreak-p fill-single-word-nobreak-p)) 323 :options '(fill-french-nobreak-p fill-single-word-nobreak-p))
318 324
319 (defcustom fill-nobreak-invisible nil 325 (defcustom fill-nobreak-invisible nil
320 "Non-nil means that fill command do not break lines in invisible text." 326 "Non-nil means that fill commands do not break lines in invisible text."
321 :type 'boolean 327 :type 'boolean
322 :group 'fill) 328 :group 'fill)
323 329
324 (defun fill-nobreak-p () 330 (defun fill-nobreak-p ()
325 "Return nil if breaking the line at point is allowed. 331 "Return nil if breaking the line at point is allowed.
363 (defun fill-find-break-point (limit) 369 (defun fill-find-break-point (limit)
364 "Move point to a proper line breaking position of the current line. 370 "Move point to a proper line breaking position of the current line.
365 Don't move back past the buffer position LIMIT. 371 Don't move back past the buffer position LIMIT.
366 372
367 This function is called when we are going to break the current line 373 This function is called when we are going to break the current line
368 after or before a non-ascii character. If the charset of the 374 after or before a non-ASCII character. If the charset of the
369 character has the property `fill-find-break-point-function', this 375 character has the property `fill-find-break-point-function', this
370 function calls the property value as a function with one arg LINEBEG. 376 function calls the property value as a function with one arg LINEBEG.
371 If the charset has no such property, do nothing." 377 If the charset has no such property, do nothing."
372 (let* ((ch (following-char)) 378 (let* ((ch (following-char))
373 (charset (char-charset ch)) 379 (charset (char-charset ch))
421 ((not colon-double-space) (concat sentence-end "$")) 427 ((not colon-double-space) (concat sentence-end "$"))
422 ;; Try to add the : inside the `sentence-end' regexp. 428 ;; Try to add the : inside the `sentence-end' regexp.
423 ((string-match "\\[[^][]*\\(\\.\\)[^][]*\\]" sentence-end) 429 ((string-match "\\[[^][]*\\(\\.\\)[^][]*\\]" sentence-end)
424 (concat (replace-match ".:" nil nil sentence-end 1) "$")) 430 (concat (replace-match ".:" nil nil sentence-end 1) "$"))
425 ;; Can't find the right spot to insert the colon. 431 ;; Can't find the right spot to insert the colon.
426 (t "[.?!:][])}\"']*$")))) 432 (t "[.?!:][])}\"']*$")))
433 (sentence-end-without-space-list
434 (string-to-list sentence-end-without-space)))
427 (while (re-search-forward eol-double-space-re to t) 435 (while (re-search-forward eol-double-space-re to t)
428 (or (>= (point) to) (memq (char-before) '(?\t ?\ )) 436 (or (>= (point) to) (memq (char-before) '(?\t ?\ ))
437 (memq (char-after (match-beginning 0))
438 sentence-end-without-space-list)
429 (insert-and-inherit ?\ )))) 439 (insert-and-inherit ?\ ))))
430 440
431 (goto-char from) 441 (goto-char from)
432 (if enable-multibyte-characters 442 (if enable-multibyte-characters
433 ;; Delete unnecessay newlines surrounded by words. The 443 ;; Delete unnecessay newlines surrounded by words. The
726 fill-paragraph-function) 736 fill-paragraph-function)
727 (funcall function arg))) 737 (funcall function arg)))
728 ;; Then try our syntax-aware filling code. 738 ;; Then try our syntax-aware filling code.
729 (and fill-paragraph-handle-comment 739 (and fill-paragraph-handle-comment
730 ;; Our code only handles \n-terminated comments right now. 740 ;; Our code only handles \n-terminated comments right now.
731 comment-start comment-start-skip (equal comment-end "") 741 comment-start (equal comment-end "")
732 (let ((fill-paragraph-handle-comment nil)) 742 (let ((fill-paragraph-handle-comment nil))
733 (fill-comment-paragraph arg))) 743 (fill-comment-paragraph arg)))
734 ;; If it all fails, default to the good ol' text paragraph filling. 744 ;; If it all fails, default to the good ol' text paragraph filling.
735 (let ((before (point)) 745 (let ((before (point))
736 (paragraph-start paragraph-start) 746 (paragraph-start paragraph-start)
799 (concat "[ \t]*\\(?:" comment-start-skip "\\)"))) 809 (concat "[ \t]*\\(?:" comment-start-skip "\\)")))
800 (comment-fill-prefix ; Compute a fill prefix. 810 (comment-fill-prefix ; Compute a fill prefix.
801 (save-excursion 811 (save-excursion
802 (goto-char comstart) 812 (goto-char comstart)
803 (if has-code-and-comment 813 (if has-code-and-comment
804 (concat (make-string (/ (current-column) tab-width) ?\t) 814 (concat
805 (make-string (% (current-column) tab-width) ?\ ) 815 (if (not indent-tabs-mode)
806 (buffer-substring (point) comin)) 816 (make-string (current-column) ?\ )
817 (concat
818 (make-string (/ (current-column) tab-width) ?\t)
819 (make-string (% (current-column) tab-width) ?\ )))
820 (buffer-substring (point) comin))
807 (buffer-substring (line-beginning-position) comin)))) 821 (buffer-substring (line-beginning-position) comin))))
808 beg end) 822 beg end)
809 (save-excursion 823 (save-excursion
810 (save-restriction 824 (save-restriction
811 (beginning-of-line) 825 (beginning-of-line)
816 (save-excursion 830 (save-excursion
817 (while (and (zerop (forward-line -1)) 831 (while (and (zerop (forward-line -1))
818 (looking-at comment-re))) 832 (looking-at comment-re)))
819 ;; We may have gone too far. Go forward again. 833 ;; We may have gone too far. Go forward again.
820 (line-beginning-position 834 (line-beginning-position
821 (if (looking-at (concat ".*\\(?:" comment-start-skip "\\)")) 835 (if (progn
836 (goto-char
837 (or (comment-search-forward (line-end-position) t)
838 (point)))
839 (looking-at comment-re))
822 1 2)))) 840 1 2))))
823 ;; Find the beginning of the first line past the region to fill. 841 ;; Find the beginning of the first line past the region to fill.
824 (save-excursion 842 (save-excursion
825 (while (progn (forward-line 1) 843 (while (progn (forward-line 1)
826 (looking-at comment-re))) 844 (looking-at comment-re)))
834 (default-value 'paragraph-separate) "\\)")) 852 (default-value 'paragraph-separate) "\\)"))
835 (paragraph-start 853 (paragraph-start
836 (concat paragraph-start "\\|[ \t]*\\(?:" 854 (concat paragraph-start "\\|[ \t]*\\(?:"
837 comment-start-skip "\\)\\(?:" 855 comment-start-skip "\\)\\(?:"
838 (default-value 'paragraph-start) "\\)")) 856 (default-value 'paragraph-start) "\\)"))
839 (paragraph-ignore-fill-prefix nil) 857 ;; We used to reply on fill-prefix to break paragraph at
840 (fill-prefix comment-fill-prefix) 858 ;; comment-starter changes, but it did not work for the
859 ;; first line (mixed comment&code).
860 ;; We now use comment-re instead to "manually" make sure
861 ;; we treat comment-marker changes as paragraph boundaries.
862 ;; (paragraph-ignore-fill-prefix nil)
863 ;; (fill-prefix comment-fill-prefix)
841 (after-line (if has-code-and-comment 864 (after-line (if has-code-and-comment
842 (line-beginning-position 2)))) 865 (line-beginning-position 2))))
843 (setq end (progn (forward-paragraph) (point))) 866 (setq end (progn (forward-paragraph) (point)))
844 ;; If this comment starts on a line with code, 867 ;; If this comment starts on a line with code,
845 ;; include that line in the filling. 868 ;; include that line in the filling.
882 as specified by its text properties. 905 as specified by its text properties.
883 906
884 The fourth arg NOSQUEEZE non-nil means to leave 907 The fourth arg NOSQUEEZE non-nil means to leave
885 whitespace other than line breaks untouched, and fifth arg TO-EOP 908 whitespace other than line breaks untouched, and fifth arg TO-EOP
886 non-nil means to keep filling to the end of the paragraph (or next 909 non-nil means to keep filling to the end of the paragraph (or next
887 hard newline, if `use-hard-newlines' is on). 910 hard newline, if variable `use-hard-newlines' is on).
888 911
889 Return the fill-prefix used for filling the last paragraph. 912 Return the fill-prefix used for filling the last paragraph.
890 913
891 If `sentence-end-double-space' is non-nil, then period followed by one 914 If `sentence-end-double-space' is non-nil, then period followed by one
892 space does not end a sentence, so don't break a line there." 915 space does not end a sentence, so don't break a line there."
966 If the mark is active, it operates on the region. However, if the 989 If the mark is active, it operates on the region. However, if the
967 beginning and end of the region are not at paragraph breaks, they are 990 beginning and end of the region are not at paragraph breaks, they are
968 moved to the beginning and end \(respectively) of the paragraphs they 991 moved to the beginning and end \(respectively) of the paragraphs they
969 are in. 992 are in.
970 993
971 If `use-hard-newlines' is true, all hard newlines are taken to be paragraph 994 If variable `use-hard-newlines' is true, all hard newlines are
972 breaks. 995 taken to be paragraph breaks.
973 996
974 When calling from a program, operates just on region between BEGIN and END, 997 When calling from a program, operates just on region between BEGIN and END,
975 unless optional fourth arg WHOLE-PAR is non-nil. In that case bounds are 998 unless optional fourth arg WHOLE-PAR is non-nil. In that case bounds are
976 extended to include entire paragraphs as in the interactive command." 999 extended to include entire paragraphs as in the interactive command."
977 (interactive (list (if mark-active (region-beginning) (point)) 1000 (interactive (list (if mark-active (region-beginning) (point))
1404 (if (string-match citation-regexp string) 1427 (if (string-match citation-regexp string)
1405 (match-string 0 string) 1428 (match-string 0 string)
1406 "") 1429 "")
1407 string)) 1430 string))
1408 1431
1432 ;;; arch-tag: 727ad455-1161-4fa9-8df5-0f74b179216d
1409 ;;; fill.el ends here 1433 ;;; fill.el ends here