aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2022-01-05 20:47:20 +0200
committerJuri Linkov2022-01-05 20:47:20 +0200
commit2b59a425832f6f89bb6b1267812711bfcc7a16cd (patch)
treede3d03d542604dd49a09374f53f1037d772a28c8
parent0a51652f6dcf62c598bde9bece5639e09966dbb5 (diff)
downloademacs-2b59a425832f6f89bb6b1267812711bfcc7a16cd.tar.gz
emacs-2b59a425832f6f89bb6b1267812711bfcc7a16cd.zip
* lisp/textmodes/paragraphs.el (repunctuate-sentences): Use filter variable.
(repunctuate-sentences-filter)<defun>: Reimplement without using match data. (repunctuate-sentences-filter)<defvar>: New variable. (repunctuate-sentences): Use new variable. Remove regexp group from spaces as was before. https://lists.gnu.org/archive/html/emacs-devel/2022-01/msg00395.html
-rw-r--r--lisp/textmodes/paragraphs.el22
1 files changed, 13 insertions, 9 deletions
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index fc10a0dd1b1..7daf71e990e 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -481,23 +481,27 @@ sentences. Also, every paragraph boundary terminates sentences as well."
481 481
482(defun repunctuate-sentences-filter (_start _end) 482(defun repunctuate-sentences-filter (_start _end)
483 "Search filter used by `repunctuate-sentences' to skip unneeded spaces. 483 "Search filter used by `repunctuate-sentences' to skip unneeded spaces.
484By default, it skips occurrences that already have two spaces. 484By default, it skips occurrences that already have two spaces."
485It is advised to put `advice-add' on this function to add more filters, 485 (/= 2 (- (point) (save-excursion (skip-chars-backward " ") (point)))))
486
487(defvar repunctuate-sentences-filter #'repunctuate-sentences-filter
488 "The default filter used by `repunctuate-sentences'.
489It is advised to use `add-function' on this to add more filters,
486for example, `(looking-back (rx (or \"e.g.\" \"i.e.\") \" \") 5)' 490for example, `(looking-back (rx (or \"e.g.\" \"i.e.\") \" \") 5)'
487with a set of predefined abbreviations to skip from adding two spaces." 491with a set of predefined abbreviations to skip from adding two spaces.")
488 (not (length= (match-string 4) 2)))
489 492
490(defun repunctuate-sentences (&optional no-query start end) 493(defun repunctuate-sentences (&optional no-query start end)
491 "Put two spaces at the end of sentences from point to the end of buffer. 494 "Put two spaces at the end of sentences from point to the end of buffer.
492It works using `query-replace-regexp'. In Transient Mark mode, 495It works using `query-replace-regexp'. In Transient Mark mode,
493if the mark is active, operate on the contents of the region. 496if the mark is active, operate on the contents of the region.
494Second and third arg START and END specify the region to operate on. 497Second and third arg START and END specify the region to operate on.
495If optional argument NO-QUERY is non-nil, make changes without 498If optional argument NO-QUERY is non-nil, make changes without asking
496asking for confirmation." 499for confirmation. You can use `repunctuate-sentences-filter' to add
500filters to skip occurrences of spaces that don't need to be replaced."
497 (interactive (list nil 501 (interactive (list nil
498 (if (use-region-p) (region-beginning)) 502 (if (use-region-p) (region-beginning))
499 (if (use-region-p) (region-end)))) 503 (if (use-region-p) (region-end))))
500 (let ((regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\)\\( +\\)") 504 (let ((regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +")
501 (to-string "\\1\\2\\3 ")) 505 (to-string "\\1\\2\\3 "))
502 (if no-query 506 (if no-query
503 (progn 507 (progn
@@ -507,10 +511,10 @@ asking for confirmation."
507 (unwind-protect 511 (unwind-protect
508 (progn 512 (progn
509 (add-function :after-while isearch-filter-predicate 513 (add-function :after-while isearch-filter-predicate
510 #'repunctuate-sentences-filter) 514 repunctuate-sentences-filter)
511 (query-replace-regexp regexp to-string nil start end)) 515 (query-replace-regexp regexp to-string nil start end))
512 (remove-function isearch-filter-predicate 516 (remove-function isearch-filter-predicate
513 #'repunctuate-sentences-filter))))) 517 repunctuate-sentences-filter)))))
514 518
515 519
516(defun backward-sentence (&optional arg) 520(defun backward-sentence (&optional arg)