]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/textmodes/paragraphs.el (repunctuate-sentences): Support region.
authorJuri Linkov <juri@linkov.net>
Tue, 28 Dec 2021 19:19:25 +0000 (21:19 +0200)
committerJuri Linkov <juri@linkov.net>
Tue, 28 Dec 2021 19:19:25 +0000 (21:19 +0200)
Add optional args 'start' and 'end', and pass them as region boundaries
to query-replace-regexp (bug#52769).

lisp/textmodes/paragraphs.el

index 59b15e82a8185823c4cb5c3ae5b4416719845adf..98362b857945c0a806006cd13fa3532b89fa1e49 100644 (file)
@@ -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)