]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/paragraphs.el
Update copyright year to 2015
[gnu-emacs] / lisp / textmodes / paragraphs.el
index a0892b5ebbae991b375eed1169f0aece54c2cf18..b18a93cd3e686763d21ea8795f4c1169acd0a3b0 100644 (file)
@@ -1,9 +1,9 @@
 ;;; paragraphs.el --- paragraph and sentence parsing
 
 ;;; paragraphs.el --- paragraph and sentence parsing
 
-;; Copyright (C) 1985-1987, 1991, 1994-1997, 1999-2011
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985-1987, 1991, 1994-1997, 1999-2015 Free Software
+;; Foundation, Inc.
 
 
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: wp
 ;; Package: emacs
 
 ;; Keywords: wp
 ;; Package: emacs
 
 
 (put 'use-hard-newlines 'permanent-local t)
 (define-minor-mode use-hard-newlines
 
 (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.
 
 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 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.
+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."
 
 Newlines not marked hard are called \"soft\", and are always internal
 to paragraphs.  The fill functions insert and delete only soft newlines."
@@ -375,8 +379,8 @@ the number of paragraphs marked equals ARG.
 If ARG is negative, point is put at end of this paragraph, mark is put
 at beginning of this or a previous paragraph.
 
 If ARG is negative, point is put at end of this paragraph, mark is put
 at beginning of this or a previous paragraph.
 
-Interactively, if this command is repeated
-or (in Transient Mark mode) if the mark is active,
+Interactively (or if ALLOW-EXTEND is non-nil), if this command is
+repeated or (in Transient Mark mode) if the mark is active,
 it marks the next ARG paragraphs after the ones already marked."
   (interactive "p\np")
   (unless arg (setq arg 1))
 it marks the next ARG paragraphs after the ones already marked."
   (interactive "p\np")
   (unless arg (setq arg 1))
@@ -456,21 +460,29 @@ sentences.  Also, every paragraph boundary terminates sentences as well."
         (sentence-end (sentence-end)))
     (while (< arg 0)
       (let ((pos (point))
         (sentence-end (sentence-end)))
     (while (< arg 0)
       (let ((pos (point))
-           ;; We used to use (start-of-paragraph-text), but this can
-           ;; prevent sentence-end from matching if it is anchored at
-           ;; BOL and the paragraph starts indented.
-           (par-beg (save-excursion (backward-paragraph) (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 sentence-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))))
       (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)))
 
       (setq arg (1- arg)))
     (constrain-to-field nil opoint t)))