]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/fill.el
Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[gnu-emacs] / lisp / textmodes / fill.el
index af4e11c9f42ec3eb24d19a4f7253554294bdb291..5b6d5f359e64e1075e91a3f161031ca49e85d977 100644 (file)
@@ -1,17 +1,18 @@
-;;; 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.
+;; Copyright (C) 1985-1986, 1992, 1994-1997, 1999, 2001-2013 Free
+;; Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: wp
+;; Package: emacs
 
 ;; 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
@@ -19,9 +20,7 @@
 ;; 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:
 
@@ -36,7 +35,7 @@
   :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.
@@ -45,7 +44,7 @@ A value of nil means that any change in indentation starts a new paragraph."
   :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)
 (put 'colon-double-space 'safe-local-variable 'booleanp)
@@ -62,7 +61,7 @@ such as `fill-forward-paragraph-function'.")
   "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."
@@ -83,10 +82,10 @@ reinserts the fill prefix in each resulting line."
       (setq fill-prefix nil)))
   (if fill-prefix
       (message "fill-prefix: \"%s\"" fill-prefix)
-    (message "fill-prefix cancelled")))
+    (message "fill-prefix canceled")))
 
 (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)
 
@@ -94,8 +93,9 @@ reinserts the fill prefix in each resulting line."
   ;; 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.
+  ;; Update mail-mode's paragraph-separate if you change this.
+  (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.
@@ -106,8 +106,8 @@ a role."
   :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.
@@ -138,7 +138,7 @@ The fill column to use for a line is the first column at which the column
 number equals or exceeds the local fill-column - right-margin difference."
   (save-excursion
     (if fill-column
-       (let* ((here (progn (beginning-of-line) (point)))
+       (let* ((here (line-beginning-position))
               (here-col 0)
               (eol (progn (end-of-line) (point)))
               margin fill-col change col)
@@ -319,12 +319,12 @@ after an opening paren or just before a closing paren or a punctuation
 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)))))))
@@ -384,7 +384,7 @@ and `fill-nobreak-invisible'."
   "Char-table of characters that don't use space between words.")
 
 (progn
-  ;; Register `kinsoku' for scripts HAN, KANA, BOPOMPFO, and CJK-MISS.
+  ;; Register `kinsoku' for scripts HAN, KANA, BOPOMOFO, and CJK-MISC.
   ;; Also tell that they don't use space between words.
   (map-char-table
    #'(lambda (key val)
@@ -470,7 +470,7 @@ Point is moved to just past the fill prefix on the first line."
 
   (goto-char from)
   (if enable-multibyte-characters
-      ;; Delete unnecessay newlines surrounded by words.  The
+      ;; Delete unnecessary newlines surrounded by words.  The
       ;; character category `|' means that we can break a line at the
       ;; character.  And, char-table
       ;; `fill-nospace-between-words-table' tells how to concatenate
@@ -659,7 +659,7 @@ space does not end a sentence, so don't break a line there."
       (if (and oneleft
               (not (and use-hard-newlines
                         (get-text-property (1- (point)) 'hard))))
-         (delete-backward-char 1)
+         (delete-char -1)
        (backward-char 1)
        (setq oneleft t)))
     (setq to (copy-marker (point) t))
@@ -721,7 +721,11 @@ space does not end a sentence, so don't break a line there."
            (move-to-column (current-fill-column))
            (if (when (< (point) to)
                  ;; Find the position where we'll break the line.
-                 (forward-char 1) ;Use an immediately following space, if any.
+                 ;; Use an immediately following space, if any.
+                 ;; However, note that `move-to-column' may overshoot
+                 ;; if there are wide characters (Bug#3234).
+                 (unless (> (current-column) (current-fill-column))
+                   (forward-char 1))
                  (fill-move-to-break-point linebeg)
                  ;; Check again to see if we got to the end of
                  ;; the paragraph.
@@ -775,16 +779,17 @@ left to move.")
 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)))
@@ -988,7 +993,7 @@ can take care of filling.  JUSTIFY is used as in `fill-paragraph'."
 (defun fill-region (from to &optional justify nosqueeze to-eop)
   "Fill each of the paragraphs in the region.
 A prefix arg means justify as well.
-Ordinarily the variable `fill-column' controls the width.
+The `fill-column' variable controls the width.
 
 Noninteractively, the third argument JUSTIFY specifies which
 kind of justification to do: `full', `left', `right', `center',
@@ -1010,7 +1015,8 @@ space does not end a sentence, so don't break a line there."
                       (if current-prefix-arg 'full))))
   (unless (memq justify '(t nil none full center left right))
     (setq justify 'full))
-  (let (max beg fill-pfx)
+  (let ((start-point (point-marker))
+       max beg fill-pfx)
     (goto-char (max from to))
     (when to-eop
       (skip-chars-backward "\n")
@@ -1037,15 +1043,17 @@ space does not end a sentence, so don't break a line there."
          (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))))
+    (goto-char start-point)
+    (set-marker start-point nil)
     fill-pfx))
 
 \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."
@@ -1054,6 +1062,7 @@ 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)
 
@@ -1290,18 +1299,16 @@ otherwise it is made canonical."
                     (skip-chars-backward " "))
                   (setq ncols (- fc endcol))
                   ;; Ncols is number of additional space chars needed
-                  (if (and (> ncols 0) (> nspaces 0) (not eop))
-                      (progn
-                        (setq curr-fracspace (+ ncols (/ (1+ nspaces) 2))
-                              count nspaces)
-                        (while (> count 0)
-                          (skip-chars-forward " ")
-                          (insert-and-inherit
-                           (make-string (/ curr-fracspace nspaces) ?\s))
-                          (search-forward " " nil t)
-                          (setq count (1- count)
-                                curr-fracspace
-                                  (+ (% curr-fracspace nspaces) ncols)))))))
+                  (when (and (> ncols 0) (> nspaces 0) (not eop))
+                     (setq curr-fracspace (+ ncols (/ nspaces 2))
+                           count nspaces)
+                     (while (> count 0)
+                       (skip-chars-forward " ")
+                       (insert-char ?\s (/ curr-fracspace nspaces) t)
+                       (search-forward " " nil t)
+                       (setq count (1- count)
+                             curr-fracspace
+                             (+ (% curr-fracspace nspaces) ncols))))))
                (t (error "Unknown justification value"))))
        (goto-char pos)
        (move-marker pos nil)))
@@ -1519,5 +1526,4 @@ Also, if CITATION-REGEXP is non-nil, don't fill header lines."
        "")
     string))
 
-;; arch-tag: 727ad455-1161-4fa9-8df5-0f74b179216d
 ;;; fill.el ends here