emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add a fill nobreak predicate preventing line breaks after 1-char


From: Michal Nazarewicz
Subject: [PATCH] Add a fill nobreak predicate preventing line breaks after 1-character word.
Date: Fri, 25 Oct 2013 09:48:00 +0100

From: Michal Nazarewicz <address@hidden>

* textmodes/fill.el (fill-single-char-nobreak-p): New function
checking whether point is after a 1-letter word.  As per its name,
it should be used with fill-nobreak-predicate to prevent fill from
breaking the line after a 1-letter word, which is considered an
error in Polish and Czech typography...
---
 etc/NEWS               |  6 ++++++
 lisp/ChangeLog         |  8 ++++++++
 lisp/textmodes/fill.el | 13 ++++++++++++-
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 232a1bc..f52b522 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -176,6 +176,12 @@ some enhancements, like the ability to restore deleted 
frames.  Command
 ** The default value of `comment-use-global-state' is changed to t,
 and this variable has been marked obsolete.
 
+** `fill-single-char-nobreak-p' prevents fill from breaking a line after
+a 1-letter word, which is an error according to Polish and
+Czech typography rules.  To globally enable this feature, evaluate:
+
+  (add-hook 'fill-nobreak-predicate 'fill-single-char-nobreak-p)
+
 
 * Editing Changes in Emacs 24.4
 
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6d852d9..25036a2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
+2013-10-25  Michal Nazarewicz  <address@hidden>
+
+       * textmodes/fill.el (fill-single-char-nobreak-p): New function
+       checking whether point is after a 1-letter word.  As per its name,
+       it should be used with fill-nobreak-predicate to prevent fill from
+       breaking the line after a 1-letter word, which is considered an
+       error in Polish and Czech typography..
+
 2013-10-25  Dmitry Gutov  <address@hidden>
 
        * progmodes/ruby-mode.el (ruby-mode-menu): Use proper
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 119b4b0..49003b4 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -329,13 +329,24 @@ places."
              (and (memq (preceding-char) '(?\t ?\s))
                   (eq (char-syntax (following-char)) ?w)))))))
 
+(defun fill-single-char-nobreak-p ()
+  "Return t if point is placed just after a 1-letter word.
+This is used in `fill-nobreak-predicate' to prevent breaking line just
+after a 1-letter word (usually conjunction or preposition) which is
+considered composition error in Polish and Czech typography."
+  (save-excursion
+    (skip-chars-backward " \t")
+    (backward-char 2)
+    (looking-at "[[:space:]][a-zA-Z]")))
+
 (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."
-- 
1.8.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]