emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master af92c52669: * lisp/textmodes/paragraphs.el (repunctuate-sentences


From: Juri Linkov
Subject: master af92c52669: * lisp/textmodes/paragraphs.el (repunctuate-sentences): Support region.
Date: Tue, 28 Dec 2021 14:19:52 -0500 (EST)

branch: master
commit af92c526699daba6246420a396c086085417c4d3
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/textmodes/paragraphs.el (repunctuate-sentences): Support region.
    
    Add optional args 'start' and 'end', and pass them as region boundaries
    to query-replace-regexp (bug#52769).
---
 lisp/textmodes/paragraphs.el | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index 59b15e82a8..98362b8579 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -479,18 +479,22 @@ sentences.  Also, every paragraph boundary terminates 
sentences as well."
       (setq arg (1- arg)))
     (constrain-to-field nil opoint t)))
 
-(defun repunctuate-sentences (&optional no-query)
+(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'.
+It works using `query-replace-regexp'.  In Transient Mark mode,
+if the mark is active, operate on the contents of the region.
+Second and third arg START and END specify the region to operate on.
 If optional argument NO-QUERY is non-nil, make changes without
 asking for confirmation."
-  (interactive)
+  (interactive (list nil
+                     (if (use-region-p) (region-beginning))
+                     (if (use-region-p) (region-end))))
   (let ((regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +")
         (to-string "\\1\\2\\3  "))
     (if no-query
         (while (re-search-forward regexp nil t)
           (replace-match to-string))
-      (query-replace-regexp regexp to-string))))
+      (query-replace-regexp regexp to-string nil start end))))
 
 
 (defun backward-sentence (&optional arg)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]