GNU bug report logs - #52769
29.0.50; [FEATURE REQUEST] repunctuate-sentences in region

Previous Next

Package: emacs;

Reported by: Rudolf Adamkovič <salutis <at> me.com>

Date: Fri, 24 Dec 2021 10:14:01 UTC

Severity: wishlist

Fixed in version 29.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Juri Linkov <juri <at> linkov.net>
To: Rudolf Adamkovič <salutis <at> me.com>
Cc: 52769 <at> debbugs.gnu.org
Subject: bug#52769: 29.0.50; [FEATURE REQUEST] repunctuate-sentences in region
Date: Tue, 28 Dec 2021 21:28:21 +0200
[Message part 1 (text/plain, inline)]
> 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:

[repunctuate-sentences-filter.patch (text/x-diff, inline)]
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)

This bug report was last modified 3 years and 146 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.