all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#71865: [PATCH] New user option `fill-sentence-end-double-space`
@ 2024-07-01  1:07 Stefan Kangas
  2024-07-01 21:16 ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Kangas @ 2024-07-01  1:07 UTC (permalink / raw
  To: 71865

[-- Attachment #1: Type: text/plain, Size: 701 bytes --]

Severity: wishlist

Consider doing this in emacs -Q

    M-: (setq sentence-end-double-space nil) RET

Now put point at a paragraph like this

    Foo bar baz.  Hello hello.

Press M-q and end up with:

    Foo bar baz. Hello hello.

However, in some cases the user will _not_ want this be reflowed, while
still wanting to make the sentence commands navigate correctly even if
there is only one space.

For that purpose, I suggest adding a new user option
`fill-sentence-end-double-space', which controls _only_ the behavior
when refilling.  That way you can customize sentence commands separately
from fill commands.

See the attached patch (still lacking NEWS and documentation changes).

Thoughts?

[-- Attachment #2: 0001-New-user-option-fill-sentence-end-double-space.patch --]
[-- Type: text/x-patch, Size: 3982 bytes --]

From fb31e14562f2a455659d122e8ff921c49b140957 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Mon, 1 Jul 2024 02:53:25 +0200
Subject: [PATCH] New user option `fill-sentence-end-double-space`

* lisp/textmodes/fill.el
(fill-sentence-end-double-space): New user option.
(fill-sentence-end-double-space-safe-p): New function.
(fill-paragraph): Use the above new user option to decide the value of
'sentence-end-double-space' for the duration of this command.
* lisp/textmodes/paragraphs.el (sentence-end-double-space): Move user
option to :group 'sentence'.
---
 .dir-locals.el               |  2 ++
 lisp/textmodes/fill.el       | 27 ++++++++++++++++++++++++++-
 lisp/textmodes/paragraphs.el |  3 +--
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/.dir-locals.el b/.dir-locals.el
index c74da88a811..d6d82ddc8fb 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -3,6 +3,8 @@
 
 ((nil . ((tab-width . 8)
          (sentence-end-double-space . t)
+         ;; TODO: Enable this once more people are on Emacs 31.
+         ;;(fill-sentence-end-double-space . t)
          (fill-column . 72)
 	 (emacs-lisp-docstring-fill-column . 72)
          (vc-git-annotate-switches . "-w")
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 29c56f8feaf..1aa33b6a8d1 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -49,6 +49,27 @@ colon-double-space
   :type 'boolean
   :safe #'booleanp)
 
+(defun fill-sentence-end-double-space-safe-p (val)
+  "Return non-nil if VAL is one of `default', nil or t."
+  (memq val '(default t nil)))
+
+(defcustom fill-sentence-end-double-space 'default
+  "Controls if fill commands should consider two spaces to end a sentence.
+The default value, `default' means that this should be controlled by the
+user option `sentence-end-double-space'.
+
+Setting this to nil or t will override `sentence-end-double-space'
+during fill commands, and have the same meaning as if you customized
+that user option to that value.
+
+The purpose of this is to be able to customize fill commands separately
+from sentence commands."
+  :type '(choice (const :tag "Use `sentence-end-double-space'" default)
+                 (const :tag "Two spaces ends sentence" t)
+                 (const :tag "One space ends sentence" nil))
+  :safe #'fill-sentence-end-double-space-safe-p
+  :version "31.1")
+
 (defcustom fill-separate-heterogeneous-words-with-space nil
   "Non-nil means to use a space to separate words of a different kind.
 For example, when an English word at the end of a line and a CJK word
@@ -841,6 +862,10 @@ fill-paragraph
   (interactive (progn
 		 (barf-if-buffer-read-only)
 		 (list (if current-prefix-arg 'full) t)))
+  (let ((sentence-end-double-space
+         (if (eq fill-sentence-end-double-space 'default)
+             sentence-end-double-space
+           fill-sentence-end-double-space)))
   (with-buffer-unmodified-if-unchanged
     (or
      ;; 1. Fill the region if it is active when called interactively.
@@ -901,7 +926,7 @@ fill-paragraph
                        ;; fill-region.
                        (fill-region beg end justify)
                      (fill-region-as-paragraph beg end justify))))))
-       fill-pfx))))
+       fill-pfx)))))
 
 (declare-function comment-search-forward "newcomment" (limit &optional noerror))
 (declare-function comment-string-strip "newcomment" (str beforep afterp))
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index af99a96e045..5792adc0d75 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -125,8 +125,7 @@ sentence-end-double-space
 regexp describing the end of a sentence, when the value of the variable
 `sentence-end' is nil.  See Info node `(elisp)Standard Regexps'."
   :type 'boolean
-  :safe #'booleanp
-  :group 'fill)
+  :safe #'booleanp)
 
 (defcustom sentence-end-without-period nil
   "Non-nil means a sentence will end without a period.
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#71865: [PATCH] New user option `fill-sentence-end-double-space`
  2024-07-01  1:07 bug#71865: [PATCH] New user option `fill-sentence-end-double-space` Stefan Kangas
@ 2024-07-01 21:16 ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-07-01 23:02   ` Stefan Kangas
  0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-07-01 21:16 UTC (permalink / raw
  To: Stefan Kangas; +Cc: 71865

Stefan Kangas <stefankangas@gmail.com> writes:

> Severity: wishlist
>
> Consider doing this in emacs -Q
>
>     M-: (setq sentence-end-double-space nil) RET
>
> Now put point at a paragraph like this
>
>     Foo bar baz.  Hello hello.
>
> Press M-q and end up with:
>
>     Foo bar baz. Hello hello.
>
> However, in some cases the user will _not_ want this be reflowed, while
> still wanting to make the sentence commands navigate correctly even if
> there is only one space.

I tried this example but would be interested in a clearer statement of
the problem.  Does M-a, M-e not work as intended?
>
> For that purpose, I suggest adding a new user option
> `fill-sentence-end-double-space', which controls _only_ the behavior
> when refilling.  That way you can customize sentence commands separately
> from fill commands.
>
> See the attached patch (still lacking NEWS and documentation changes).
>
> Thoughts?
>
> [2. text/x-patch; 0001-New-user-option-fill-sentence-end-double-space.patch]...





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#71865: [PATCH] New user option `fill-sentence-end-double-space`
  2024-07-01 21:16 ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-07-01 23:02   ` Stefan Kangas
  2024-07-06 21:46     ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Kangas @ 2024-07-01 23:02 UTC (permalink / raw
  To: Jeremy Bryant; +Cc: 71865

Jeremy Bryant <jb@jeremybryant.net> writes:

> I tried this example but would be interested in a clearer statement of
> the problem.  Does M-a, M-e not work as intended?

Thanks, and yes indeed, the `M-a' and `M-e' doesn't work as I'd hope if
you evaluate this in emacs -Q:

    (progn (insert "Foo. Bar. Baz.")
           (goto-char (pos-bol))
           (forward-sentence))

Point is now at the third period, after "Baz".

I think that there are some users [this one included] that will want to
set

    (setq sentence-end-double-space nil)

to make point end up at the second period instead, after "Bar", yet they
do _not_ want this paragraph to be refilled to use only one space
between sentences:

    Foo.  Bar.  Baz.

In other words, the problem is that `sentence-end-double-space' controls
both filling and sentence commands.  This rectifies that by introducing
a new variable that allows controlling the filling commands separately.

Does that make the problem more clear?





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#71865: [PATCH] New user option `fill-sentence-end-double-space`
  2024-07-01 23:02   ` Stefan Kangas
@ 2024-07-06 21:46     ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 4+ messages in thread
From: Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-07-06 21:46 UTC (permalink / raw
  To: Stefan Kangas; +Cc: 71865

Stefan Kangas <stefankangas@gmail.com> writes:

> Jeremy Bryant <jb@jeremybryant.net> writes:
>
>> I tried this example but would be interested in a clearer statement of
>> the problem.  Does M-a, M-e not work as intended?
>
> Thanks, and yes indeed, the `M-a' and `M-e' doesn't work as I'd hope if
> you evaluate this in emacs -Q:
>
>     (progn (insert "Foo. Bar. Baz.")
>            (goto-char (pos-bol))
>            (forward-sentence))
>
> Point is now at the third period, after "Baz".
>
> I think that there are some users [this one included] that will want to
> set
>
>     (setq sentence-end-double-space nil)
>
> to make point end up at the second period instead, after "Bar", yet they
> do _not_ want this paragraph to be refilled to use only one space
> between sentences:
>
>     Foo.  Bar.  Baz.
>
> In other words, the problem is that `sentence-end-double-space' controls
> both filling and sentence commands.  This rectifies that by introducing
> a new variable that allows controlling the filling commands separately.
>
> Does that make the problem more clear?

Thanks, I understand your point of view.

However it seems consistent to me that a user who wishes to terminate
sentences with one space, would generally want to reflow to adhere to
the one space convention.  The same would apply if working on documents
that happen to adhere to that convention.

However as this new option doesn't seem to break anything and introduce
flexibility, it could be a good idea.  I'll let others comment.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-06 21:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-01  1:07 bug#71865: [PATCH] New user option `fill-sentence-end-double-space` Stefan Kangas
2024-07-01 21:16 ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-01 23:02   ` Stefan Kangas
2024-07-06 21:46     ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors

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.