From: Stefan Kangas <stefankangas@gmail.com>
To: 71865@debbugs.gnu.org
Subject: bug#71865: [PATCH] New user option `fill-sentence-end-double-space`
Date: Sun, 30 Jun 2024 18:07:29 -0700 [thread overview]
Message-ID: <CADwFkm=_M7vz3Yb_fqQdBTR5BHNVCmy1iAb=mO0UBbjPqBbkkA@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2024-07-01 1:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-01 1:07 Stefan Kangas [this message]
2024-07-01 21:16 ` bug#71865: [PATCH] New user option `fill-sentence-end-double-space` 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
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADwFkm=_M7vz3Yb_fqQdBTR5BHNVCmy1iAb=mO0UBbjPqBbkkA@mail.gmail.com' \
--to=stefankangas@gmail.com \
--cc=71865@debbugs.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).