]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/paragraphs.el
* lisp/gnus/gnus.el (gnus-other-frame-resume-function): Add user option.
[gnu-emacs] / lisp / textmodes / paragraphs.el
index 201eeebb6235154aafbb708628c9af05bf4d9ef5..5a5942aa29dbef0c05784af6ab6acf28dcc4b1de 100644 (file)
@@ -1,17 +1,18 @@
 ;;; paragraphs.el --- paragraph and sentence parsing
 
-;; Copyright (C) 1985, 1986, 1987, 1991, 1994, 1995, 1996, 1997, 1999, 2000,
-;;   2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 1985-1987, 1991, 1994-1997, 1999-2012
+;;   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:
 
 
 (put 'use-hard-newlines 'permanent-local t)
 (define-minor-mode use-hard-newlines
-  "Minor mode to distinguish hard and soft newlines.
-When active, the functions `newline' and `open-line' add the
+  "Toggle distinguishing between hard and soft newlines.
+With a prefix argument ARG, enable the feature if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+it if ARG is omitted or nil.
+
+When enabled, the functions `newline' and `open-line' add the
 text-property `hard' to newlines that they insert, and a line is
 only considered as a candidate to match `paragraph-start' or
 `paragraph-separate' if it follows a hard newline.
 
-Prefix argument says to turn mode on if positive, off if negative.
-When the mode is turned on, if there are newlines in the buffer but no hard
-newlines, ask the user whether to mark as hard any newlines preceeding a
-`paragraph-start' line.  From a program, second arg INSERT specifies whether
-to do this; it can be `never' to change nothing, t or `always' to force
-marking, `guess' to try to do the right thing with no questions, nil
-or anything else to ask the user.
+When enabling, if there are newlines in the buffer but no hard
+newlines, ask the user whether to mark as hard any newlines
+preceding a `paragraph-start' line.  From a program, second arg
+INSERT specifies whether to do this; it can be `never' to change
+nothing, t or `always' to force marking, `guess' to try to do the
+right thing with no questions, nil or anything else to ask the
+user.
 
 Newlines not marked hard are called \"soft\", and are always internal
 to paragraphs.  The fill functions insert and delete only soft newlines."
@@ -98,7 +101,7 @@ If the variable `use-hard-newlines' is non-nil, then only lines following a
 hard newline are considered to match."
   :group 'paragraphs
   :type 'regexp)
-;;;###autoload(put 'paragraph-start 'safe-local-variable 'stringp)
+(put 'paragraph-start 'safe-local-variable 'stringp)
 
 ;; paragraph-start requires a hard newline, but paragraph-separate does not:
 ;; It is assumed that paragraph-separate is distinctive enough to be believed
@@ -116,7 +119,7 @@ ensures that the paragraph functions will work equally within a region of
 text indented by a margin setting."
   :group 'paragraphs
   :type 'regexp)
-;;;###autoload(put 'paragraph-separate 'safe-local-variable 'stringp)
+(put 'paragraph-separate 'safe-local-variable 'stringp)
 
 (defcustom sentence-end-double-space t
   "Non-nil means a single space does not end a sentence.
@@ -128,7 +131,7 @@ regexp describing the end of a sentence, when the value of the variable
 `sentence-end' is nil.  See Info node `(elisp)Standard Regexps'."
   :type 'boolean
   :group 'fill)
-;;;###autoload(put 'sentence-end-double-space 'safe-local-variable 'booleanp)
+(put 'sentence-end-double-space 'safe-local-variable 'booleanp)
 
 (defcustom sentence-end-without-period nil
   "Non-nil means a sentence will end without a period.
@@ -140,10 +143,10 @@ regexp describing the end of a sentence, when the value of the variable
 `sentence-end' is nil.  See Info node `(elisp)Standard Regexps'."
   :type 'boolean
   :group 'fill)
-;;;###autoload(put 'sentence-end-without-period 'safe-local-variable 'booleanp)
+(put 'sentence-end-without-period 'safe-local-variable 'booleanp)
 
 (defcustom sentence-end-without-space
-  "\e$B!#!%!)!*\e$A!##.#?#!\e$(0!$!%!)!*\e$(G!$!%!)!*\e(B"
+  "。.?!"
   "String of characters that end sentence without following spaces.
 
 This value is used by the function `sentence-end' to construct the
@@ -151,7 +154,7 @@ regexp describing the end of a sentence, when the value of the variable
 `sentence-end' is nil.  See Info node `(elisp)Standard Regexps'."
   :group 'paragraphs
   :type 'string)
-;;;###autoload(put 'sentence-end-without-space 'safe-local-variable 'stringp)
+(put 'sentence-end-without-space 'safe-local-variable 'stringp)
 
 (defcustom sentence-end nil
   "Regexp describing the end of a sentence.
@@ -163,14 +166,14 @@ function `sentence-end'.  You should always use this function
 to obtain the value of this variable."
   :group 'paragraphs
   :type '(choice regexp (const :tag "Use default value" nil)))
-;;;###autoload(put 'sentence-end 'safe-local-variable 'string-or-null-p)
+(put 'sentence-end 'safe-local-variable 'string-or-null-p)
 
-(defcustom sentence-end-base "[.?!][]\"'\e$B!I\e$,1r}\e(B)}]*"
+(defcustom sentence-end-base "[.?!][]\"')}]*"
   "Regexp matching the basic end of a sentence, not including following space."
   :group 'paragraphs
   :type 'string
   :version "22.1")
-;;;###autoload(put 'sentence-end-base 'safe-local-variable 'stringp)
+(put 'sentence-end-base 'safe-local-variable 'stringp)
 
 (defun sentence-end ()
   "Return the regexp describing the end of a sentence.
@@ -185,27 +188,28 @@ end of a sentence, the ending period, question mark, or exclamation point
 must be followed by two spaces, with perhaps some closing delimiters
 in between.  See Info node `(elisp)Standard Regexps'."
   (or sentence-end
-      (concat (if sentence-end-without-period "\\w  \\|")
+      ;; We accept non-break space along with space.
+      (concat (if sentence-end-without-period "\\w[ \u00a0][ \u00a0]\\|")
              "\\("
              sentence-end-base
               (if sentence-end-double-space
-                  "\\($\\| $\\|\t\\|  \\)" "\\($\\|[\t ]\\)")
+                  "\\($\\|[ \u00a0]$\\|\t\\|[ \u00a0][ \u00a0]\\)" "\\($\\|[\t \u00a0]\\)")
               "\\|[" sentence-end-without-space "]+"
              "\\)"
-              "[ \t\n]*")))
+              "[ \u00a0\t\n]*")))
 
 (defcustom page-delimiter "^\014"
   "Regexp describing line-beginnings that separate pages."
   :group 'paragraphs
   :type 'regexp)
-;;;###autoload(put 'page-delimiter 'safe-local-variable 'stringp)
+(put 'page-delimiter 'safe-local-variable 'stringp)
 
 (defcustom paragraph-ignore-fill-prefix nil
   "Non-nil means the paragraph commands are not affected by `fill-prefix'.
 This is desirable in modes where blank lines are the paragraph delimiters."
   :group 'paragraphs
   :type 'boolean)
-;;;###autoload(put 'paragraph-ignore-fill-prefix 'safe-local-variable 'booleanp)
+(put 'paragraph-ignore-fill-prefix 'safe-local-variable 'booleanp)
 
 (defun forward-paragraph (&optional arg)
   "Move forward to end of paragraph.
@@ -217,7 +221,7 @@ A line which `paragraph-start' matches either separates paragraphs
 A paragraph end is the beginning of a line which is not part of the paragraph
 to which the end of the previous line belongs, or the end of the buffer.
 Returns the count of paragraphs left to move."
-  (interactive "p")
+  (interactive "^p")
   (or arg (setq arg 1))
   (let* ((opoint (point))
         (fill-prefix-regexp
@@ -355,13 +359,13 @@ With argument ARG, do it ARG times;
 a negative argument ARG = -N means move forward N paragraphs.
 
 A paragraph start is the beginning of a line which is a
-`first-line-of-paragraph' or which is ordinary text and follows a
-paragraph-separating line; except: if the first real line of a
+`paragraph-start' or which is ordinary text and follows a
+`paragraph-separate'ing line; except: if the first real line of a
 paragraph is preceded by a blank line, the paragraph starts at that
 blank line.
 
 See `forward-paragraph' for more information."
-  (interactive "p")
+  (interactive "^p")
   (or arg (setq arg 1))
   (forward-paragraph (- arg)))
 
@@ -410,7 +414,12 @@ negative arg -N means kill forward to Nth end of paragraph."
   (kill-region (point) (progn (backward-paragraph arg) (point))))
 
 (defun transpose-paragraphs (arg)
-  "Interchange this (or next) paragraph with previous one."
+  "Interchange the current paragraph with the next one.
+With prefix argument ARG a non-zero integer, moves the current
+paragraph past ARG paragraphs, leaving point after the current paragraph.
+If ARG is positive, moves the current paragraph forwards, if
+ARG is negative moves it backwards.  If ARG is zero, exchanges
+the current paragraph with the one containing the mark."
   (interactive "*p")
   (transpose-subr 'forward-paragraph arg))
 
@@ -440,29 +449,40 @@ negative arg -N means kill forward to Nth end of paragraph."
              (end-of-paragraph-text))))))
 
 (defun forward-sentence (&optional arg)
-  "Move forward to next `sentence-end'.  With argument, repeat.
-With negative argument, move backward repeatedly to `sentence-beginning'.
+  "Move forward to next end of sentence.  With argument, repeat.
+With negative argument, move backward repeatedly to start of sentence.
 
 The variable `sentence-end' is a regular expression that matches ends of
 sentences.  Also, every paragraph boundary terminates sentences as well."
-  (interactive "p")
+  (interactive "^p")
   (or arg (setq arg 1))
   (let ((opoint (point))
         (sentence-end (sentence-end)))
     (while (< arg 0)
       (let ((pos (point))
-           (par-beg (save-excursion (start-of-paragraph-text) (point))))
-       (if (and (re-search-backward sentence-end par-beg t)
-               (or (< (match-end 0) pos)
-                   (re-search-backward sentence-end par-beg t)))
-          (goto-char (match-end 0))
-        (goto-char par-beg)))
+           par-beg par-text-beg)
+       (save-excursion
+         (start-of-paragraph-text)
+         ;; Start of real text in the paragraph.
+         ;; We move back to here if we don't see a sentence-end.
+         (setq par-text-beg (point))
+         ;; Start of the first line of the paragraph.
+         ;; We use this as the search limit
+         ;; to allow s1entence-end to match if it is anchored at
+         ;; BOL and the paragraph starts indented.
+         (beginning-of-line)
+         (setq par-beg (point)))
+       (if (and (re-search-backward sentence-end par-beg t)
+                (or (< (match-end 0) pos)
+                    (re-search-backward sentence-end par-beg t)))
+           (goto-char (match-end 0))
+         (goto-char par-text-beg)))
       (setq arg (1+ arg)))
     (while (> arg 0)
       (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
-       (if (re-search-forward sentence-end par-end t)
-          (skip-chars-backward " \t\n")
-        (goto-char par-end)))
+       (if (re-search-forward sentence-end par-end t)
+           (skip-chars-backward " \t\n")
+         (goto-char par-end)))
       (setq arg (1- arg)))
     (constrain-to-field nil opoint t)))
 
@@ -477,7 +497,7 @@ It works using `query-replace-regexp'."
 (defun backward-sentence (&optional arg)
   "Move backward to start of sentence.  With arg, do it arg times.
 See `forward-sentence' for more information."
-  (interactive "p")
+  (interactive "^p")
   (or arg (setq arg 1))
   (forward-sentence (- arg)))
 
@@ -507,13 +527,17 @@ ones already marked."
    nil t))
 
 (defun transpose-sentences (arg)
-  "Interchange this (next) and previous sentence."
+  "Interchange the current sentence with the next one.
+With prefix argument ARG a non-zero integer, moves the current
+sentence past ARG sentences, leaving point after the current sentence.
+If ARG is positive, moves the current sentence forwards, if
+ARG is negative moves it backwards.  If ARG is zero, exchanges
+the current sentence with the one containing the mark."
   (interactive "*p")
   (transpose-subr 'forward-sentence arg))
 
 ;; Local Variables:
-;; coding: iso-2022-7bit
+;; coding: utf-8
 ;; End:
 
-;; arch-tag: e727eb1a-527a-4464-b9d7-9d3ec0d1a575
 ;;; paragraphs.el ends here