-;;; fill.el --- fill commands for Emacs -*- coding: iso-2022-7bit -*-
+;;; fill.el --- fill commands for Emacs -*- coding: utf-8 -*-
;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1996, 1997, 1999, 2001, 2002,
-;; 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
;; Maintainer: FSF
;; Keywords: wp
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; 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., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
:group 'editing)
(defcustom fill-individual-varying-indent nil
- "*Controls criterion for a new paragraph in `fill-individual-paragraphs'.
+ "Controls criterion for a new paragraph in `fill-individual-paragraphs'.
Non-nil means changing indent doesn't end a paragraph.
That mode can handle paragraphs with extra indentation on the first line,
but it requires separator lines between paragraphs.
:group 'fill)
(defcustom colon-double-space nil
- "*Non-nil means put two spaces after a colon when filling."
+ "Non-nil means put two spaces after a colon when filling."
:type 'boolean
:group 'fill)
-;;;###autoload(put 'colon-double-space 'safe-local-variable 'booleanp)
+(put 'colon-double-space 'safe-local-variable 'booleanp)
(defvar fill-paragraph-function nil
"Mode-specific function to fill a paragraph, or nil if there is none.
If the function returns nil, then `fill-paragraph' does its normal work.
-A value of t means explicitly \"do nothing special\".")
+A value of t means explicitly \"do nothing special\".
+Note: This only affects `fill-paragraph' and not `fill-region'
+nor `auto-fill-mode', so it is often better to use some other hook,
+such as `fill-forward-paragraph-function'.")
(defvar fill-paragraph-handle-comment t
"Non-nil means paragraph filling will try to pay attention to comments.")
(defcustom enable-kinsoku t
- "*Non-nil means enable \"kinsoku\" processing on filling paragraphs.
+ "Non-nil means enable \"kinsoku\" processing on filling paragraphs.
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."
(message "fill-prefix cancelled")))
(defcustom adaptive-fill-mode t
- "*Non-nil means determine a paragraph's fill prefix from its text."
+ "Non-nil means determine a paragraph's fill prefix from its text."
:type 'boolean
:group 'fill)
;; Added `!' for doxygen comments starting with `//!' or `/*!'.
;; Added `%' for TeX comments.
;; RMS: deleted the code to match `1.' and `(1)'.
- "[ \t]*\\([-!|#%;>*\e,A7\e$,1s"s#sC\e$,2"F\e(B]+[ \t]*\\)*"
- "*Regexp to match text at start of line that constitutes indentation.
+ (purecopy "[ \t]*\\([-!|#%;>*·•‣⁃◦]+[ \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
standard indentation for the whole paragraph.
:type 'regexp
:group 'fill)
-(defcustom adaptive-fill-first-line-regexp "\\`[ \t]*\\'"
- "*Regexp specifying whether to set fill prefix from a one-line paragraph.
+(defcustom adaptive-fill-first-line-regexp (purecopy "\\`[ \t]*\\'")
+ "Regexp specifying whether to set fill prefix from a one-line paragraph.
When a paragraph has just one line, then after `adaptive-fill-regexp'
finds the prefix at the beginning of the line, if it doesn't
match this regexp, it is replaced with whitespace.
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]*[])}\e,A;\e,b;\e(B?!;:-]")
+ (or (looking-at "[ \t]*[])}»?!;:-]")
(save-excursion
(skip-chars-backward " \t")
(unless (bolp)
(backward-char 1)
- (or (looking-at "[([{\e,A+\e,b+\e(B]")
+ (or (looking-at "[([{«]")
;; Don't cut right after a single-letter word.
(and (memq (preceding-char) '(?\t ?\s))
(eq (char-syntax (following-char)) ?w)))))))
(narrow-to-region (minibuffer-prompt-end) (point-max))
(fill-paragraph arg)))
+(defvar fill-forward-paragraph-function 'forward-paragraph
+ "Function to move over paragraphs used by the filling code.
+It is called with a single argument specifying the number of paragraphs to move.
+Just like `forward-paragraph', it should return the number of paragraphs
+left to move.")
+
+(defun fill-forward-paragraph (arg)
+ (funcall fill-forward-paragraph-function arg))
+
(defun fill-paragraph (&optional justify region)
"Fill paragraph at or after point.
If JUSTIFY is non-nil (interactively, with prefix argument), justify as well.
If `sentence-end-double-space' is non-nil, then period followed by one
space does not end a sentence, so don't break a line there.
-the variable `fill-column' controls the width for filling.
+The variable `fill-column' controls the width for filling.
If `fill-paragraph-function' is non-nil, we call it (passing our
argument to it), and if it returns non-nil, we simply return its value.
If `fill-paragraph-function' is nil, return the `fill-prefix' used for filling.
-Interactively (when `region' is non-nil) in Transient Mark mode when
-the mark is active, call `fill-region' to fill each of the paragraphs
-in the active region."
+The REGION argument is non-nil if called interactively; in that
+case, if Transient Mark mode is enabled and the mark is active,
+call `fill-region' to fill each of the paragraphs in the active
+region, instead of just filling the current paragraph."
(interactive (progn
(barf-if-buffer-read-only)
(list (if current-prefix-arg 'full) t)))
(or (fill-region (region-beginning) (region-end) justify) t))
;; 2. Try fill-paragraph-function.
(and (not (eq fill-paragraph-function t))
- (or fill-paragraph-function
- (and (minibufferp (current-buffer))
- (= 1 (point-min))))
- (let ((function (or fill-paragraph-function
- ;; In the minibuffer, don't count the width
- ;; of the prompt.
- 'fill-minibuffer-function))
- ;; If fill-paragraph-function is set, it probably takes care
- ;; of comments and stuff. If not, it will have to set
- ;; fill-paragraph-handle-comment back to t explicitly or
- ;; return nil.
- (fill-paragraph-handle-comment nil)
- (fill-paragraph-function t))
- (funcall function justify)))
+ (or fill-paragraph-function
+ (and (minibufferp (current-buffer))
+ (= 1 (point-min))))
+ (let ((function (or fill-paragraph-function
+ ;; In the minibuffer, don't count the width
+ ;; of the prompt.
+ 'fill-minibuffer-function))
+ ;; If fill-paragraph-function is set, it probably takes care
+ ;; of comments and stuff. If not, it will have to set
+ ;; fill-paragraph-handle-comment back to t explicitly or
+ ;; return nil.
+ (fill-paragraph-handle-comment nil)
+ (fill-paragraph-function t))
+ (funcall function justify)))
;; 3. Try our syntax-aware filling code.
(and fill-paragraph-handle-comment
- ;; Our code only handles \n-terminated comments right now.
- comment-start (equal comment-end "")
- (let ((fill-paragraph-handle-comment nil))
- (fill-comment-paragraph justify)))
+ ;; Our code only handles \n-terminated comments right now.
+ comment-start (equal comment-end "")
+ (let ((fill-paragraph-handle-comment nil))
+ (fill-comment-paragraph justify)))
;; 4. If it all fails, default to the good ol' text paragraph filling.
(let ((before (point))
- (paragraph-start paragraph-start)
- ;; Fill prefix used for filling the paragraph.
- fill-pfx)
+ (paragraph-start paragraph-start)
+ ;; Fill prefix used for filling the paragraph.
+ fill-pfx)
;; Try to prevent code sections and comment sections from being
;; filled together.
(when (and fill-paragraph-handle-comment comment-start-skip)
(setq paragraph-start
- (concat paragraph-start "\\|[ \t]*\\(?:"
- comment-start-skip "\\)")))
+ (concat paragraph-start "\\|[ \t]*\\(?:"
+ comment-start-skip "\\)")))
(save-excursion
;; To make sure the return value of forward-paragraph is meaningful,
;; we have to start from the beginning of line, otherwise skipping
;; a paragraph (and not skipping any chars at EOB would not count
;; as a paragraph even if it is).
(move-to-left-margin)
- (if (not (zerop (forward-paragraph)))
- ;; There's no paragraph at or after point: give up.
- (setq fill-pfx "")
- (let ((end (point))
- (beg (progn (backward-paragraph) (point))))
- (goto-char before)
- (setq fill-pfx
- (if use-hard-newlines
- ;; Can't use fill-region-as-paragraph, since this
- ;; paragraph may still contain hard newlines. See
- ;; fill-region.
- (fill-region beg end justify)
- (fill-region-as-paragraph beg end justify))))))
+ (if (not (zerop (fill-forward-paragraph 1)))
+ ;; There's no paragraph at or after point: give up.
+ (setq fill-pfx "")
+ (let ((end (point))
+ (beg (progn (fill-forward-paragraph -1) (point))))
+ (goto-char before)
+ (setq fill-pfx
+ (if use-hard-newlines
+ ;; Can't use fill-region-as-paragraph, since this
+ ;; paragraph may still contain hard newlines. See
+ ;; fill-region.
+ (fill-region beg end justify)
+ (fill-region-as-paragraph beg end justify))))))
fill-pfx)))
(declare-function comment-search-forward "newcomment" (limit &optional noerror))
(goto-char comstart) (skip-chars-backward " \t")
(setq has-code-and-comment (not (bolp)))))
- (if (not comstart)
+ (if (not (and comstart
+ ;; Make sure the comment-start mark we found is accepted by
+ ;; comment-start-skip. If not, all bets are off, and
+ ;; we'd better not mess with it.
+ (string-match comment-start-skip
+ (buffer-substring comstart comin))))
+
;; Return nil, so the normal filling will take place.
nil
(goto-char (max from to))
(when to-eop
(skip-chars-backward "\n")
- (forward-paragraph))
+ (fill-forward-paragraph 1))
(setq max (copy-marker (point) t))
(goto-char (setq beg (min from to)))
(beginning-of-line)
(goto-char (1+ end)))
(setq end (if end (min max (1+ end)) max))
(goto-char initial))
- (forward-paragraph 1)
+ (fill-forward-paragraph 1)
(setq end (min max (point)))
- (forward-paragraph -1))
+ (fill-forward-paragraph -1))
(if (< (point) beg)
(goto-char beg))
- (if (>= (point) initial)
+ (if (and (>= (point) initial) (< (point) end))
(setq fill-pfx
(fill-region-as-paragraph (point) end justify nosqueeze))
(goto-char end))))
\f
(defcustom default-justification 'left
- "*Method of justifying text not otherwise specified.
+ "Method of justifying text not otherwise specified.
Possible values are `left', `right', `full', `center', or `none'.
The requested kind of justification is done whenever lines are filled.
The `justification' text-property can locally override this variable."
(const full)
(const center)
(const none))
+ :safe 'symbolp
:group 'fill)
(make-variable-buffer-local 'default-justification)