From fb31e14562f2a455659d122e8ff921c49b140957 Mon Sep 17 00:00:00 2001 From: Stefan Kangas 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