all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: "Rudolf Adamkovič" <salutis@me.com>
Cc: 52769@debbugs.gnu.org
Subject: bug#52769: 29.0.50; [FEATURE REQUEST] repunctuate-sentences in region
Date: Tue, 28 Dec 2021 21:28:21 +0200	[thread overview]
Message-ID: <86v8z8o7fu.fsf@mail.linkov.net> (raw)
In-Reply-To: <86czlkld45.fsf@mail.linkov.net> (Juri Linkov's message of "Sat,  25 Dec 2021 21:04:58 +0200")

[-- Attachment #1: Type: text/plain, Size: 353 bytes --]

> 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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: repunctuate-sentences-filter.patch --]
[-- Type: text/x-diff, Size: 893 bytes --]

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)

  reply	other threads:[~2021-12-28 19:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-24 10:13 bug#52769: 29.0.50; [FEATURE REQUEST] repunctuate-sentences in region Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-25 19:04 ` Juri Linkov
2021-12-28 19:28   ` Juri Linkov [this message]
2021-12-28 20:18     ` Juri Linkov
2021-12-28 19:20 ` Juri Linkov
2021-12-28 21:31   ` Rudolf Adamkovič 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86v8z8o7fu.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=52769@debbugs.gnu.org \
    --cc=salutis@me.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.