]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/fill.el
Update copyright year to 2015
[gnu-emacs] / lisp / textmodes / fill.el
index feb2fa6cc73e3c6892542bf4d6b8acd539325977..5f2fbcda04ccf34a009453df55c89549bdfb07d8 100644 (file)
@@ -1,9 +1,9 @@
 ;;; fill.el --- fill commands for Emacs                -*- coding: utf-8 -*-
 
-;; Copyright (C) 1985-1986, 1992, 1994-1997, 1999, 2001-2013 Free
+;; Copyright (C) 1985-1986, 1992, 1994-1997, 1999, 2001-2015 Free
 ;; Software Foundation, Inc.
 
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: wp
 ;; Package: emacs
 
@@ -220,7 +220,7 @@ Remove indentation from each line."
   (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)))))
+                   (match-string 0)))))
     (if (>= (+ (current-left-margin) (length str)) (current-fill-column))
         ;; Death to insanely long prefixes.
         nil
@@ -329,13 +329,24 @@ places."
              (and (memq (preceding-char) '(?\t ?\s))
                   (eq (char-syntax (following-char)) ?w)))))))
 
+(defun fill-single-char-nobreak-p ()
+  "Return non-nil if a one-letter word is before point.
+This function is suitable for adding to the hook `fill-nobreak-predicate',
+to prevent the breaking of a line just after a one-letter word,
+which is an error according to some typographical conventions."
+  (save-excursion
+    (skip-chars-backward " \t")
+    (backward-char 2)
+    (looking-at "[[:space:]][[:alpha:]]")))
+
 (defcustom fill-nobreak-predicate nil
   "List of predicates for recognizing places not to break a line.
 The predicates are called with no arguments, with point at the place to
 be tested.  If it returns t, fill commands do not break the line there."
   :group 'fill
   :type 'hook
-  :options '(fill-french-nobreak-p fill-single-word-nobreak-p))
+  :options '(fill-french-nobreak-p fill-single-word-nobreak-p
+             fill-single-char-nobreak-p))
 
 (defcustom fill-nobreak-invisible nil
   "Non-nil means that fill commands do not break lines in invisible text."
@@ -721,7 +732,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.