From: Marcin Borkowski <mbork@mbork.pl>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 20871@debbugs.gnu.org
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
Date: Mon, 15 Jan 2018 06:30:20 +0100 [thread overview]
Message-ID: <871siradub.fsf@mbork.pl> (raw)
In-Reply-To: <874lnnaen0.fsf@mbork.pl>
[-- Attachment #1: Type: text/plain, Size: 359 bytes --]
On 2018-01-15, at 06:13, Marcin Borkowski <mbork@mbork.pl> wrote:
> On 2018-01-13, at 17:53, Eli Zaretskii <eliz@gnu.org> wrote:
>
>>> > So please post the full patch for this issue, and let's take it from
>>> > there.
>
> I see, I'll do it in a minute.
I attach the patch (which is made by squashing both the commits I made).
Best,
--
Marcin Borkowski
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-the-function-fill-polish-nobreak-p-with-tests.patch --]
[-- Type: text/x-patch, Size: 4969 bytes --]
From 96b4bd4cef5008561f336d8d1de47548d738c1ff Mon Sep 17 00:00:00 2001
From: Marcin Borkowski <mbork@mbork.pl>
Date: Wed, 27 Apr 2016 08:59:15 +0200
Subject: [PATCH] Add the function `fill-polish-nobreak-p' with tests
* 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. Fixes bug #20871.
---
doc/emacs/text.texi | 7 ++++--
etc/NEWS | 5 ++++
lisp/textmodes/fill.el | 12 ++++++++++
test/lisp/textmodes/fill-tests.el | 50 +++++++++++++++++++++++++++++++++++++++
4 files changed, 72 insertions(+), 2 deletions(-)
create mode 100644 test/lisp/textmodes/fill-tests.el
diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi
index 846d9fe8c6..2f180f82ca 100644
--- a/doc/emacs/text.texi
+++ b/doc/emacs/text.texi
@@ -636,8 +636,11 @@ Fill Commands
break the line there. Functions you can use there include:
@code{fill-single-word-nobreak-p} (don't break after the first word of
a sentence or before the last); @code{fill-single-char-nobreak-p}
-(don't break after a one-letter word); and @code{fill-french-nobreak-p}
-(don't break after @samp{(} or before @samp{)}, @samp{:} or @samp{?}).
+(don't break after a one-letter word preceded by a whitespace
+character); @code{fill-french-nobreak-p} (don't break after @samp{(}
+or before @samp{)}, @samp{:} or @samp{?}); and
+@code{fill-polish-nobreak-p} (don't break after a one letter word,
+even if preceded by a non-whitespace character).
@node Fill Prefix
@subsection The Fill Prefix
diff --git a/etc/NEWS b/etc/NEWS
index 1d546c4ec1..ed1f931547 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -69,6 +69,11 @@ detect built-in libxml support, instead of testing for that
indirectly, e.g., by checking that functions like
'libxml-parse-html-region' return nil.
++++
+** New function 'fill-polish-nobreak-p', to be used in 'fill-nobreak-predicate'.
+It blocks line breaking after a one-letter word, also in the case when
+this word is preceded by a non-space, but non-alphanumeric character.
+
\f
* Editing Changes in Emacs 27.1
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index a46f0b2a4c..6d37be870b 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -339,6 +339,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',
diff --git a/test/lisp/textmodes/fill-tests.el b/test/lisp/textmodes/fill-tests.el
new file mode 100644
index 0000000000..03323090f9
--- /dev/null
+++ b/test/lisp/textmodes/fill-tests.el
@@ -0,0 +1,50 @@
+;;; fill-test.el --- ERT tests for fill.el -*- lexical-binding: t -*-
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Marcin Borkowski <mbork@mbork.pl>
+;; Keywords: text, wp
+
+;; This file is part of GNU Emacs.
+
+;; 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 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
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package defines tests for the filling feature, specifically
+;; the `fill-polish-nobreak-p' function.
+
+;;; Code:
+
+(require 'ert)
+
+(ert-deftest fill-test-no-fill-polish-nobreak-p nil
+ "Tests of the `fill-polish-nobreak-p' function."
+ (with-temp-buffer
+ (insert "Abc d efg (h ijk).")
+ (setq fill-column 8)
+ (setq-local fill-nobreak-predicate '())
+ (fill-paragraph)
+ (should (string= (buffer-string) "Abc d\nefg (h\nijk).")))
+ (with-temp-buffer
+ (insert "Abc d efg (h ijk).")
+ (setq fill-column 8)
+ (setq-local fill-nobreak-predicate '(fill-polish-nobreak-p))
+ (fill-paragraph)
+ (should (string= (buffer-string) "Abc\nd efg\n(h ijk)."))))
+
+
+(provide 'fill-tests)
+
+;;; fill-tests.el ends here
--
2.15.1
next prev parent reply other threads:[~2018-01-15 5:30 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-22 10:19 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 Marcin Borkowski
2015-06-22 10:28 ` Marcin Borkowski
2016-04-17 6:34 ` Marcin Borkowski
2016-04-17 14:57 ` Eli Zaretskii
2016-04-17 15:34 ` Marcin Borkowski
2016-04-17 16:49 ` Eli Zaretskii
2016-04-17 17:41 ` Marcin Borkowski
2016-04-27 7:02 ` Marcin Borkowski
2016-04-27 7:20 ` Eli Zaretskii
2016-04-29 12:18 ` Marcin Borkowski
2016-04-30 11:21 ` Eli Zaretskii
2016-04-30 12:26 ` Marcin Borkowski
2016-04-30 12:38 ` Eli Zaretskii
2016-04-30 16:41 ` Marcin Borkowski
2016-04-30 17:01 ` Eli Zaretskii
2016-04-30 18:42 ` Marcin Borkowski
2016-04-30 19:01 ` Eli Zaretskii
2017-12-07 13:28 ` Marcin Borkowski
2017-12-09 11:52 ` Eli Zaretskii
2017-12-09 15:45 ` Marcin Borkowski
2017-12-19 11:44 ` Marcin Borkowski
2017-12-19 16:15 ` Eli Zaretskii
2018-01-02 8:55 ` Marcin Borkowski
2018-01-13 8:46 ` Eli Zaretskii
2018-01-13 16:01 ` Marcin Borkowski
2018-01-13 16:53 ` Eli Zaretskii
2018-01-13 17:02 ` Eli Zaretskii
2018-01-15 5:13 ` Marcin Borkowski
2018-01-15 5:13 ` Marcin Borkowski
2018-01-15 5:30 ` Marcin Borkowski [this message]
2018-01-15 13:07 ` Eli Zaretskii
2018-01-24 9:34 ` Marcin Borkowski
2018-01-24 19:16 ` Eli Zaretskii
2016-04-30 17:42 ` Drew Adams
2016-04-30 18:24 ` Eli Zaretskii
2016-04-30 18:41 ` Marcin Borkowski
2018-02-02 9:18 ` Michal Nazarewicz
[not found] <9A9C6F59-CB27-42D1-911E-F027B443B9BE@acm.org>
[not found] ` <8336i1p8zd.fsf@gnu.org>
[not found] ` <CA+pa1O3rcDznoR0u8i_AN5iHe9mM+FHqkAO=yVM2Gu5_Gc40jQ@mail.gmail.com>
2019-08-17 6:57 ` Eli Zaretskii
2019-08-17 14:17 ` Marcin Borkowski
2019-08-17 15:04 ` Eli Zaretskii
2019-08-17 15:58 ` Marcin Borkowski
2019-08-19 14:07 ` Michał Nazarewicz
2019-08-19 15:01 ` Eli Zaretskii
2019-08-19 15:36 ` Michał Nazarewicz
2019-08-19 16:16 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871siradub.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=20871@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.