[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master fb4f2aa038: * lisp/textmodes/paragraphs.el (repunctuate-sente
From: |
Juri Linkov |
Subject: |
Re: master fb4f2aa038: * lisp/textmodes/paragraphs.el (repunctuate-sentences-filter): New function. |
Date: |
Tue, 04 Jan 2022 20:03:36 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) |
>> +(defun repunctuate-sentences-filter (_start _end)
>> + "Search filter used by `repunctuate-sentences' to skip unneeded spaces.
>> +By default, it skips occurrences that already have two spaces.
>> +It is advised to put `advice-add' on this function to add more filters,
>> +for example, `(looking-back (rx (or \"e.g.\" \"i.e.\") \" \") 5)'
>> +with a set of predefined abbreviations to skip from adding two spaces."
>> + (not (length= (match-string 4) 2)))
>
> Similarly to filter-buffer-substring-function, I believe it would be
> better if this was a variable, on which 'add-function' could be used.
> This would make it easier to set buffer locally if needed.
Thanks, good idea. Then, for example,
#+begin_src emacs-lisp
(add-function :after-while (local 'repunctuate-sentences-filter)
(lambda (start end)
(not (looking-back (rx (or "e.g." "i.e.") " ") 5))))
#+end_src
will be possible with:
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index fc10a0dd1b..e3b5ecbcca 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -487,6 +487,8 @@ repunctuate-sentences-filter
with a set of predefined abbreviations to skip from adding two spaces."
(not (length= (match-string 4) 2)))
+(defvar repunctuate-sentences-filter #'repunctuate-sentences-filter)
+
(defun repunctuate-sentences (&optional no-query start end)
"Put two spaces at the end of sentences from point to the end of buffer.
It works using `query-replace-regexp'. In Transient Mark mode,
@@ -507,10 +509,10 @@ repunctuate-sentences
(unwind-protect
(progn
(add-function :after-while isearch-filter-predicate
- #'repunctuate-sentences-filter)
+ repunctuate-sentences-filter)
(query-replace-regexp regexp to-string nil start end))
(remove-function isearch-filter-predicate
- #'repunctuate-sentences-filter)))))
+ repunctuate-sentences-filter)))))
--