-;;; fill.el --- fill commands for Emacs
+;;; fill.el --- fill commands for Emacs -*- coding: iso-2022-7bit -*-
-;; Copyright (C) 1985,86,92,94,95,96,97,1999,2001,02,03,2004
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1996, 1997, 1999, 2001, 2002,
+;; 2003, 2004, 2005 Free Software Foundation, Inc.
;; Maintainer: FSF
;; Keywords: wp
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
Kinsoku processing is designed to prevent certain characters from being
placed at the beginning or end of a line by filling.
See the documentation of `kinsoku' for more information."
- :type 'boolean)
+ :type 'boolean
+ :group 'fill)
(defun set-fill-prefix ()
"Set the fill prefix to the current line up to point.
(defcustom adaptive-fill-regexp
;; Added `!' for doxygen comments starting with `//!' or `/*!'.
;; Added `%' for TeX comments.
- (purecopy "[ \t]*\\([-!|#%;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*")
+ (purecopy "[ \t]*\\([-!|#%;>*\e,A7\e$,1s"s#sC\e$,2"F\e(B]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*")
"*Regexp to match text at start of line that constitutes indentation.
If Adaptive Fill mode is enabled, a prefix matching this pattern
on the first and second lines of a paragraph is used as the
(defcustom adaptive-fill-function nil
"*Function to call to choose a fill prefix for a paragraph, or nil.
-This function is used when `adaptive-fill-regexp' does not match."
+nil means the function has not determined the fill prefix."
:type '(choice (const nil) function)
:group 'fill)
and `sentence-end-without-period').
Remove indentation from each line."
(interactive "*r")
- (let ((end-spc-re (concat "\\(" sentence-end "\\) *\\| +")))
+ (let ((end-spc-re (concat "\\(" (sentence-end) "\\) *\\| +")))
(save-excursion
(goto-char beg)
;; Nuke tabs; they get screwed up in a fill.
(unless (zerop cmp)
(substring s1 0 cmp)))))
+(defun fill-match-adaptive-prefix ()
+ (let ((str (or
+ (and adaptive-fill-function (funcall adaptive-fill-function))
+ (and adaptive-fill-regexp (looking-at adaptive-fill-regexp)
+ (match-string-no-properties 0)))))
+ (if (>= (+ (current-left-margin) (length str)) (current-fill-column))
+ ;; Death to insanely long prefixes.
+ nil
+ str)))
+
(defun fill-context-prefix (from to &optional first-line-regexp)
"Compute a fill prefix from the text between FROM and TO.
This uses the variables `adaptive-fill-regexp' and `adaptive-fill-function'
(if (eolp) (forward-line 1))
;; Move to the second line unless there is just one.
(move-to-left-margin)
- (let ((firstline (point))
- first-line-prefix
+ (let (first-line-prefix
;; Non-nil if we are on the second line.
- second-line-prefix
- start)
- (setq start (point))
+ second-line-prefix)
(setq first-line-prefix
;; We don't need to consider `paragraph-start' here since it
;; will be explicitly checked later on.
;; Also setting first-line-prefix to nil prevents
;; second-line-prefix from being used.
- (cond ;; ((looking-at paragraph-start) nil)
- ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp))
- (match-string-no-properties 0))
- (adaptive-fill-function (funcall adaptive-fill-function))))
+ ;; ((looking-at paragraph-start) nil)
+ (fill-match-adaptive-prefix))
(forward-line 1)
(if (< (point) to)
- (progn
- (move-to-left-margin)
- (setq start (point))
- (setq second-line-prefix
- (cond ((looking-at paragraph-start) nil) ;Can it happen ? -stef
- ((and adaptive-fill-regexp
- (looking-at adaptive-fill-regexp))
- (buffer-substring-no-properties start (match-end 0)))
- (adaptive-fill-function
- (funcall adaptive-fill-function))))
- ;; If we get a fill prefix from the second line,
- ;; make sure it or something compatible is on the first line too.
- (when second-line-prefix
- (unless first-line-prefix (setq first-line-prefix ""))
- ;; If the non-whitespace chars match the first line,
- ;; just use it (this subsumes the 2 checks used previously).
- ;; Used when first line is `/* ...' and second-line is
- ;; ` * ...'.
- (let ((tmp second-line-prefix)
- (re "\\`"))
- (while (string-match "\\`[ \t]*\\([^ \t]+\\)" tmp)
- (setq re (concat re ".*" (regexp-quote (match-string 1 tmp))))
- (setq tmp (substring tmp (match-end 0))))
- ;; (assert (string-match "\\`[ \t]*\\'" tmp))
-
- (if (string-match re first-line-prefix)
- second-line-prefix
-
- ;; Use the longest common substring of both prefixes,
- ;; if there is one.
- (fill-common-string-prefix first-line-prefix
- second-line-prefix)))))
+ (progn
+ (move-to-left-margin)
+ (setq second-line-prefix
+ (cond ((looking-at paragraph-start) nil) ;Can it happen? -Stef
+ (t (fill-match-adaptive-prefix))))
+ ;; If we get a fill prefix from the second line,
+ ;; make sure it or something compatible is on the first line too.
+ (when second-line-prefix
+ (unless first-line-prefix (setq first-line-prefix ""))
+ ;; If the non-whitespace chars match the first line,
+ ;; just use it (this subsumes the 2 checks used previously).
+ ;; Used when first line is `/* ...' and second-line is
+ ;; ` * ...'.
+ (let ((tmp second-line-prefix)
+ (re "\\`"))
+ (while (string-match "\\`[ \t]*\\([^ \t]+\\)" tmp)
+ (setq re (concat re ".*" (regexp-quote (match-string 1 tmp))))
+ (setq tmp (substring tmp (match-end 0))))
+ ;; (assert (string-match "\\`[ \t]*\\'" tmp))
+
+ (if (string-match re first-line-prefix)
+ second-line-prefix
+
+ ;; Use the longest common substring of both prefixes,
+ ;; if there is one.
+ (fill-common-string-prefix first-line-prefix
+ second-line-prefix)))))
;; If we get a fill prefix from a one-line paragraph,
;; maybe change it to whitespace,
;; and check that it isn't a paragraph starter.
mark such as `?' or `:'. It is common in French writing to put a space
at such places, which would normally allow breaking the line at those
places."
- (or (looking-at "[ \t]*[])}»?!;:-]")
+ (or (looking-at "[ \t]*[])}\e,A;\e,b;\e(B?!;:-]")
(save-excursion
(skip-chars-backward " \t")
(unless (bolp)
(backward-char 1)
- (or (looking-at "[([{«]")
+ (or (looking-at "[([{\e,A+\e,b+\e(B]")
;; Don't cut right after a single-letter word.
(and (memq (preceding-char) '(?\t ?\ ))
(eq (char-syntax (following-char)) ?w)))))))
Can be customized with the variables `fill-nobreak-predicate'
and `fill-nobreak-invisible'."
(or
- (and fill-nobreak-invisible (line-move-invisible (point)))
+ (and fill-nobreak-invisible (line-move-invisible-p (point)))
(unless (bolp)
(or
;; Don't break after a period followed by just one space.
(save-excursion
(skip-chars-backward ". ")
(and (looking-at "\\.")
- (not (looking-at sentence-end))))
+ (not (looking-at (sentence-end)))))
;; Don't split a line if the rest would look like a new paragraph.
(unless use-hard-newlines
(save-excursion
- (skip-chars-forward " \t") (looking-at paragraph-start)))
+ (skip-chars-forward " \t")
+ ;; If this break point is at the end of the line,
+ ;; which can occur for auto-fill, don't consider the newline
+ ;; which follows as a reason to return t.
+ (and (not (eolp))
+ (looking-at paragraph-start))))
(run-hook-with-args-until-success 'fill-nobreak-predicate)))))
;; Put `fill-find-break-point-function' property to charsets which
;; loses on split abbrevs ("Mr.\nSmith")
(let ((eol-double-space-re
(cond
- ((not colon-double-space) (concat sentence-end "$"))
+ ((not colon-double-space) (concat (sentence-end) "$"))
;; Try to add the : inside the `sentence-end' regexp.
- ((string-match "\\[[^][]*\\(\\.\\)[^][]*\\]" sentence-end)
- (concat (replace-match ".:" nil nil sentence-end 1) "$"))
+ ((string-match "\\[[^][]*\\(\\.\\)[^][]*\\]" (sentence-end))
+ (concat (replace-match ".:" nil nil (sentence-end) 1) "$"))
;; Can't find the right spot to insert the colon.
(t "[.?!:][])}\"']*$")))
(sentence-end-without-space-list
;; Make sure we take SOMETHING after the fill prefix if any.
(fill-find-break-point linebeg)))))
+;; Like text-properties-at but don't include `composition' property.
+(defun fill-text-properties-at (pos)
+ (let ((l (text-properties-at pos))
+ prop-list)
+ (while l
+ (unless (eq (car l) 'composition)
+ (setq prop-list
+ (cons (car l) (cons (cadr l) prop-list))))
+ (setq l (cddr l)))
+ prop-list))
+
(defun fill-newline ()
;; Replace whitespace here with one newline, then
;; indent to left margin.
(insert ?\n)
;; Give newline the properties of the space(s) it replaces
(set-text-properties (1- (point)) (point)
- (text-properties-at (point)))
+ (fill-text-properties-at (point)))
(and (looking-at "\\( [ \t]*\\)\\(\\c|\\)?")
(or (aref (char-category-set (or (char-before (1- (point))) ?\000)) ?|)
(match-end 2))
(save-excursion
(goto-char comstart)
(if has-code-and-comment
- (concat (make-string (/ (current-column) tab-width) ?\t)
- (make-string (% (current-column) tab-width) ?\ )
- (buffer-substring (point) comin))
+ (concat
+ (if (not indent-tabs-mode)
+ (make-string (current-column) ?\ )
+ (concat
+ (make-string (/ (current-column) tab-width) ?\t)
+ (make-string (% (current-column) tab-width) ?\ )))
+ (buffer-substring (point) comin))
(buffer-substring (line-beginning-position) comin))))
beg end)
(save-excursion
ncols ; new indent point or offset
(nspaces 0) ; number of spaces between words
; in line (not space characters)
- fracspace ; fractional amount of space to be
- ; added between each words
(curr-fracspace 0) ; current fractional space amount
count)
(end-of-line)
(forward-line 1))))
(narrow-to-region (point) max)
;; Loop over paragraphs.
- (while (let ((here (point)))
+ (while (progn
;; Skip over all paragraph-separating lines
;; so as to not include them in any paragraph.
(while (and (not (eobp))
"")
string))
-;;; arch-tag: 727ad455-1161-4fa9-8df5-0f74b179216d
+;; arch-tag: 727ad455-1161-4fa9-8df5-0f74b179216d
;;; fill.el ends here