Subject: bug#20871: 25.0.50; fill-single-char-nobreak-p does not recognize a single-letter word when it is preceded by an open paren

From: Marcin Borkowski <[email-masked]>
Date: Fri, 29 Apr 2016 14:18:34 +0200

On 2016-04-27, at 10:20, Eli Zaretskii <[email-masked]> wrote:

>> From: Marcin Borkowski <[email-masked]>
>> Cc: [email-masked]
>> Date: Wed, 27 Apr 2016 09:02:36 +0200
>> 
>> >> I see.  So you suggest that instead of patching
>> >> `fill-single-char-nobreak-p' I should have provided another function,
>> >> customized for Polish?
>> >
>> > Yes, I think so.  There's already fill-french-nobreak-p, why shouldn't
>> > there be a Polish predicate?
>> 
>> I attach a new patch. Is it better now?
>
> Yes, thanks.
>
> Just one comment, for your consideration:
>
>> +    (looking-at "[^[:alpha:]][[:alpha:]]")))
>
> You should be aware that starting with Emacs 25.1 [:alpha:] matches a
> very large class of characters, some of them having nothing in common
> with those used in Polish.  So perhaps it is better to use '\cl'
> instead, which will only capture Latin characters?  Just a thought --
> your call.

I guess you are right, Eli - in fact, all one-letter words in Polish are
matched by [aiouwz].  I decided to go with \cl, as you suggested,
though - this way, the function could be (probably) useful also for
Slovaks, for instance.  I attach the corrected patch.

Just to be sure: in my Emacs, \cl matches also ą, ę, ż, ź, á, ö etc.  Is
it intentional?  Is it documented somewhere?

Thanks and best regards,

-- 
Marcin
>From a3b46e0e260f011e9c5257bece8f2fdb123214e5 Mon Sep 17 00:00:00 2001
From: Marcin Borkowski <[email-masked]>
Date: Wed, 27 Apr 2016 08:59:15 +0200
Subject: [PATCH] Add the function `fill-polish-nobreak-p'

* lisp/textmodes/fill.el (fill-polish-nobreak-p): Prevent line-breaking
after a single-letter word even if this word is not preceded by
a space.  (Bug #20871)
---
 lisp/textmodes/fill.el | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 173d1c9..80f7e96 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -329,6 +329,18 @@ fill-french-nobreak-p
 	      (and (memq (preceding-char) '(?\t ?\s))
 		   (eq (char-syntax (following-char)) ?w)))))))
 
+(defun fill-polish-nobreak-p ()
+  "Return nil if Polish style allows breaking the line at point.
+This function may be used in the `fill-nobreak-predicate' hook.
+It is almost the same as `fill-single-char-nobreak-p', with the
+exception that it does not require the one-letter word to be
+preceded by a space.  This blocks line-breaking in cases like
+\"(a jednak)\"."
+  (save-excursion
+    (skip-chars-backward " \t")
+    (backward-char 2)
+    (looking-at "[^[:alpha:]]\\cl")))
+
 (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',
-- 
2.4.3