• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/emacs-93/emacs/lisp/textmodes/

Lines Matching +defs:adaptive +defs:fill +defs:regexp

0 ;;; fill.el --- fill commands for Emacs		-*- coding: iso-2022-7bit -*-
33 (defgroup fill nil
38 (defcustom fill-individual-varying-indent nil
39 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'.
45 :group 'fill)
50 :group 'fill)
53 (defvar fill-paragraph-function nil
54 "Mode-specific function to fill a paragraph, or nil if there is none.
55 If the function returns nil, then `fill-paragraph' does its normal work.
58 (defvar fill-paragraph-handle-comment t
67 :group 'fill)
69 (defun set-fill-prefix ()
70 "Set the fill prefix to the current line up to point.
71 Filling expects lines to start with the fill prefix and
72 reinserts the fill prefix in each resulting line."
77 (setq fill-prefix (buffer-substring left-margin-pos (point)))
78 (if (equal fill-prefix "")
79 (setq fill-prefix nil)))
80 (setq fill-prefix nil)))
81 (if fill-prefix
82 (message "fill-prefix: \"%s\"" fill-prefix)
83 (message "fill-prefix cancelled")))
85 (defcustom adaptive-fill-mode t
86 "*Non-nil means determine a paragraph's fill prefix from its text."
88 :group 'fill)
90 (defcustom adaptive-fill-regexp
101 line, but in that case `adaptive-fill-first-line-regexp' also plays
103 :type 'regexp
104 :group 'fill)
106 (defcustom adaptive-fill-first-line-regexp "\\`[ \t]*\\'"
107 "*Regexp specifying whether to set fill prefix from a one-line paragraph.
108 When a paragraph has just one line, then after `adaptive-fill-regexp'
110 match this regexp, it is replaced with whitespace.
112 By default, this regexp matches sequences of just spaces and tabs.
116 :type 'regexp
117 :group 'fill)
119 (defcustom adaptive-fill-function nil
120 "*Function to call to choose a fill prefix for a paragraph, or nil.
121 nil means the function has not determined the fill prefix."
123 :group 'fill)
125 (defvar fill-indent-according-to-mode nil ;Screws up CC-mode's filling tricks.
128 (defun current-fill-column ()
129 "Return the fill-column to use for this line.
130 The fill-column to use for a buffer is stored in the variable `fill-column',
132 subtracted from `fill-column'.
134 The fill column to use for a line is the first column at which the column
135 number equals or exceeds the local fill-column - right-margin difference."
137 (if fill-column
141 margin fill-col change col)
145 fill-col (- fill-column (or margin 0))
150 (< col fill-col)))
153 (max here-col fill-col)))))
163 ;; text don't affect the boundary, but the regexp we match against does
170 ;; Nuke tabs; they get screwed up in a fill.
207 (defun fill-common-string-prefix (s1 s2)
216 (defun fill-match-adaptive-prefix ()
218 (and adaptive-fill-function (funcall adaptive-fill-function))
219 (and adaptive-fill-regexp (looking-at adaptive-fill-regexp)
221 (if (>= (+ (current-left-margin) (length str)) (current-fill-column))
226 (defun fill-context-prefix (from to &optional first-line-regexp)
227 "Compute a fill prefix from the text between FROM and TO.
228 This uses the variables `adaptive-fill-regexp' and `adaptive-fill-function'
229 and `adaptive-fill-first-line-regexp'. `paragraph-start' also plays a role;
232 (or first-line-regexp
233 (setq first-line-regexp adaptive-fill-first-line-regexp))
248 (fill-match-adaptive-prefix))
255 (t (fill-match-adaptive-prefix))))
256 ;; If we get a fill prefix from the second line,
267 (setq re (concat re ".*" (regexp-quote (match-string 1 tmp))))
276 (fill-common-string-prefix first-line-prefix
278 ;; If we get a fill prefix from a one-line paragraph,
286 (if (or (and first-line-regexp
287 (string-match first-line-regexp
300 (defun fill-single-word-nobreak-p ()
312 (defun fill-french-nobreak-p ()
314 This is used in `fill-nobreak-predicate' to prevent breaking lines just
329 (defcustom fill-nobreak-predicate nil
332 be tested. If it returns t, fill commands do not break the line there."
333 :group 'fill
335 :options '(fill-french-nobreak-p fill-single-word-nobreak-p))
337 (defcustom fill-nobreak-invisible nil
338 "Non-nil means that fill commands do not break lines in invisible text."
340 :group 'fill)
342 (defun fill-nobreak-p ()
344 Can be customized with the variables `fill-nobreak-predicate'
345 and `fill-nobreak-invisible'."
347 (and fill-nobreak-invisible (line-move-invisible-p (point)))
371 ;; which can occur for auto-fill, don't consider the newline
375 (run-hook-with-args-until-success 'fill-nobreak-predicate)))))
377 ;; Put `fill-find-break-point-function' property to charsets which
385 (put-charset-property (car pair) 'fill-find-break-point-function (cdr pair)))
387 (defun fill-find-break-point (limit)
393 character has the property `fill-find-break-point-function', this
404 (get-charset-property charset 'fill-find-break-point-function)))
408 (defun fill-delete-prefix (from to prefix)
409 "Delete the fill prefix from every line except the first.
410 The first line may not even have a fill prefix.
411 Point is moved to just past the fill prefix on the first line."
414 (replace-regexp-in-string
416 (regexp-quote prefix))
422 ;; (current-fill-column))
423 ;; (error "fill-prefix too long for specified width"))
434 ;; The `fill-space' property carries the string with which a newline
435 ;; should be replaced when unbreaking a line (in fill-delete-newlines).
436 ;; It is added to newline characters by fill-newline when the default
437 ;; behavior of fill-delete-newlines is not what we want.
438 (add-to-list 'text-property-default-nonsticky '(fill-space . t))
440 (defun fill-delete-newlines (from to justify nosqueeze squeeze-after)
447 ;; Try to add the : inside the `sentence-end' regexp.
472 (if (get-text-property (match-beginning 0) 'fill-space)
473 (replace-match (get-text-property (match-beginning 0) 'fill-space))
496 (defun fill-move-to-break-point (linebeg)
499 ;; If the fill column is before linebeg, move to linebeg.
515 (when (fill-nobreak-p) (skip-chars-backward " \t" linebeg))))
520 ;; If the left margin and fill prefix by themselves
521 ;; pass the fill-column. or if they are zero
531 (while (and (< (point) to) (or first (fill-nobreak-p)))
552 ;; Make sure we take SOMETHING after the fill prefix if any.
553 (fill-find-break-point linebeg)))))
556 (defun fill-text-properties-at (pos)
566 (defun fill-newline ()
573 (fill-text-properties-at (point)))
580 (put-text-property (1- (point)) (point) 'fill-space (match-string 1)))
583 (if fill-nobreak-invisible
586 (if (or fill-prefix
587 (not fill-indent-according-to-mode))
588 (fill-indent-to-left-margin)
590 ;; Insert the fill prefix after indentation.
591 (and fill-prefix (not (equal fill-prefix ""))
594 (insert-before-markers-and-inherit fill-prefix)))
596 (defun fill-indent-to-left-margin ()
602 (defun fill-region-as-paragraph (from to &optional justify
607 `current-left-margin' and `current-fill-column' functions.
608 \(In most cases, the variable `fill-column' controls the width.)
619 Return the `fill-prefix' used for filling.
642 ;; to fill the comment but not the code. So only use (point) if it's
669 ;; Don't let Adaptive Fill mode alter the fill prefix permanently.
670 (let ((fill-prefix fill-prefix))
672 (when (and adaptive-fill-mode
673 (or (null fill-prefix) (string= fill-prefix "")))
674 (setq fill-prefix (fill-context-prefix from to))
675 ;; Ignore a white-space only fill-prefix
677 (when (and fill-prefix fill-indent-according-to-mode
678 (string-match "\\`[ \t]*\\'" fill-prefix))
679 (setq fill-prefix nil)))
690 (fill-indent-to-left-margin))
698 (fill-indent-to-left-margin))
699 ;; Delete the fill-prefix from every line.
700 (fill-delete-prefix from to fill-prefix)
703 ;; FROM, and point, are now before the text to fill,
704 ;; but after any fill prefix on the first line.
706 (fill-delete-newlines from to justify nosqueeze squeeze-after)
713 (move-to-column (current-fill-column))
717 (fill-move-to-break-point linebeg)
724 (fill-newline)
737 ;; Return the fill-prefix we used
738 fill-prefix)))
746 (looking-at (regexp-quote prefix))))
749 (defun fill-minibuffer-function (arg)
753 (fill-paragraph arg)))
755 (defun fill-paragraph (arg)
761 the variable `fill-column' controls the width for filling.
763 If `fill-paragraph-function' is non-nil, we call it (passing our
766 If `fill-paragraph-function' is nil, return the `fill-prefix' used for filling."
770 ;; First try fill-paragraph-function.
771 (or (and (not (eq fill-paragraph-function t))
772 (or fill-paragraph-function
775 (let ((function (or fill-paragraph-function
778 'fill-minibuffer-function))
779 ;; If fill-paragraph-function is set, it probably takes care
781 ;; fill-paragraph-handle-comment back to t explicitly or
783 (fill-paragraph-handle-comment nil)
784 (fill-paragraph-function t))
787 (and fill-paragraph-handle-comment
790 (let ((fill-paragraph-handle-comment nil))
791 (fill-comment-paragraph arg)))
796 fill-pfx)
799 (when (and fill-paragraph-handle-comment comment-start-skip)
812 (setq fill-pfx "")
816 (setq fill-pfx
818 ;; Can't use fill-region-as-paragraph, since this
820 ;; fill-region.
821 (fill-region beg end arg)
822 (fill-region-as-paragraph beg end arg))))))
823 fill-pfx)))
825 (defun fill-comment-paragraph (&optional justify)
828 can take care of filling. JUSTIFY is used as in `fill-paragraph'."
844 ;; Narrow to include only the comment, and then fill the region.
845 (let* ((fill-prefix fill-prefix)
849 ;; A regexp more specialized than comment-start-skip, that only
852 ;; The specialized regexp only works for "normal" comment
859 (concat "[ \t]*" (regexp-quote commark)
864 (comment-fill-prefix ; Compute a fill prefix.
881 ;; Find the first line we should include in the region to fill.
896 ;; Find the beginning of the first line past the region to fill.
912 ;; We used to rely on fill-prefix to break paragraph at
917 ;; (paragraph-ignore-fill-prefix nil)
918 ;; (fill-prefix comment-fill-prefix)
929 ;; Find the fill-prefix to use.
931 (fill-prefix) ; Use the user-provided fill prefix.
932 ((and adaptive-fill-mode ; Try adaptive fill mode.
933 (setq fill-prefix (fill-context-prefix beg end))
934 (string-match comment-start-skip fill-prefix)))
936 (setq fill-prefix comment-fill-prefix)))
938 ;; Don't fill with narrowing.
940 (fill-region-as-paragraph
946 (if (looking-at fill-prefix)
952 (defun fill-region (from to &optional justify nosqueeze to-eop)
955 Ordinarily the variable `fill-column' controls the width.
967 Return the fill-prefix used for filling the last paragraph.
977 (let (max beg fill-pfx)
1005 (setq fill-pfx
1006 (fill-region-as-paragraph (point) end justify nosqueeze))
1008 fill-pfx))
1022 :group 'fill)
1070 (paragraph-ignore-fill-prefix (if use-hard-newlines t
1071 paragraph-ignore-fill-prefix)))
1084 (fill-region begin (point-max) nil t))))
1132 ;; "FP" is the fill-prefix. It can be any string, including whitespace.
1145 the column given by `current-fill-column'.
1160 (let ((fc (current-fill-column))
1162 fp-end ; point at end of fill prefix
1187 ;; Skip over fill-prefix.
1188 (if (and fill-prefix
1189 (not (string-equal fill-prefix ""))
1190 (equal fill-prefix
1192 (point) (min (point-max) (+ (length fill-prefix)
1194 (forward-char (length fill-prefix))
1195 (if (and adaptive-fill-mode
1196 (looking-at adaptive-fill-regexp))
1289 ;; Position ourselves after any fill-prefix.
1290 (if (and fill-prefix
1291 (not (string-equal fill-prefix ""))
1292 (equal fill-prefix
1294 (point) (min (point-max) (+ (length fill-prefix)
1296 (forward-char (length fill-prefix)))
1316 (defun fill-nonuniform-paragraphs (min max &optional justifyp citation-regexp)
1320 using as the fill prefix the smallest indentation of any line
1323 When calling from a program, pass range to fill as first two arguments.
1327 When filling a mail message, pass a regexp for CITATION-REGEXP
1330 Also, if CITATION-REGEXP is non-nil, don't fill header lines."
1335 (let ((fill-individual-varying-indent t))
1336 (fill-individual-paragraphs min max justifyp citation-regexp)))
1338 (defun fill-individual-paragraphs (min max &optional justify citation-regexp)
1342 then fills each paragraph using its indentation level as the fill prefix.
1352 When calling from a program, pass the range to fill
1357 When filling a mail message, pass a regexp for CITATION-REGEXP
1360 Also, if CITATION-REGEXP is non-nil, don't fill header lines."
1370 (if citation-regexp
1390 fill-prefix fill-prefix-regexp)
1391 ;; Find end of paragraph, and compute the smallest fill-prefix
1394 ;; Update the fill-prefix on the first line
1396 (if (not (and fill-prefix
1397 (looking-at fill-prefix-regexp)))
1398 (setq fill-prefix
1399 (fill-individual-paragraphs-prefix
1400 citation-regexp)
1401 fill-prefix-regexp (regexp-quote fill-prefix)))
1409 (if fill-individual-varying-indent
1415 (not (and (looking-at fill-prefix-regexp)
1417 (length fill-prefix))
1421 ;; than the fill prefix wants, end the paragraph.
1422 (and (looking-at fill-prefix-regexp)
1423 ;; If fill prefix is shorter than a new
1424 ;; fill prefix computed here, end paragraph.
1425 (let ((this-line-fill-prefix
1426 (fill-individual-paragraphs-prefix
1427 citation-regexp)))
1428 (>= (length fill-prefix)
1429 (length this-line-fill-prefix)))
1432 (length fill-prefix))
1436 (not (and (equal fill-prefix "")
1437 citation-regexp
1438 (looking-at citation-regexp))))))))
1441 (fill-region-as-paragraph start (point) justify)
1444 (defun fill-individual-paragraphs-prefix (citation-regexp)
1445 (let* ((adaptive-fill-first-line-regexp ".*")
1448 ;; adaptive-fill-first-line-regexp.
1449 (fill-context-prefix (point) (line-beginning-position 2)))
1451 (fill-context-prefix (point) (line-beginning-position 3))))
1460 (fill-individual-paragraphs-citation
1461 just-one-line-prefix citation-regexp))
1463 (fill-individual-paragraphs-citation
1464 two-lines-prefix citation-regexp))
1471 (regexp-quote
1480 (defun fill-individual-paragraphs-citation (string citation-regexp)
1481 (if citation-regexp
1482 (if (string-match citation-regexp string)
1488 ;;; fill.el ends here