[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#52769: 29.0.50; [FEATURE REQUEST] repunctuate-sentences in region
From: |
Juri Linkov |
Subject: |
bug#52769: 29.0.50; [FEATURE REQUEST] repunctuate-sentences in region |
Date: |
Tue, 28 Dec 2021 21:28:21 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) |
> When I tried 'repunctuate-sentences', it stunned by its inefficiency:
> it requires a confirmation even when there are already two spaces
> at the end of the sentence! Why does it do this?
If no one has a better idea for a simpler implementation,
then this patch fixes the problem by skipping the sentences
that already have two spaces at the end:
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index 98362b8579..0b09895339 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -494,7 +494,14 @@ repunctuate-sentences
(if no-query
(while (re-search-forward regexp nil t)
(replace-match to-string))
- (query-replace-regexp regexp to-string nil start end))))
+ (let ((regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\)\\( +\\)")
+ (space-filter (lambda (_start _end)
+ (not (length= (match-string 4) 2)))))
+ (unwind-protect
+ (progn
+ (add-function :after-while isearch-filter-predicate space-filter)
+ (query-replace-regexp regexp to-string nil start end))
+ (remove-function isearch-filter-predicate space-filter))))))
(defun backward-sentence (&optional arg)