diff options
| author | Juri Linkov | 2022-01-05 20:47:20 +0200 |
|---|---|---|
| committer | Juri Linkov | 2022-01-05 20:47:20 +0200 |
| commit | 2b59a425832f6f89bb6b1267812711bfcc7a16cd (patch) | |
| tree | de3d03d542604dd49a09374f53f1037d772a28c8 | |
| parent | 0a51652f6dcf62c598bde9bece5639e09966dbb5 (diff) | |
| download | emacs-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.el | 22 |
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. |
| 484 | By default, it skips occurrences that already have two spaces. | 484 | By default, it skips occurrences that already have two spaces." |
| 485 | It 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'. | ||
| 489 | It is advised to use `add-function' on this to add more filters, | ||
| 486 | for example, `(looking-back (rx (or \"e.g.\" \"i.e.\") \" \") 5)' | 490 | for example, `(looking-back (rx (or \"e.g.\" \"i.e.\") \" \") 5)' |
| 487 | with a set of predefined abbreviations to skip from adding two spaces." | 491 | with 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. |
| 492 | It works using `query-replace-regexp'. In Transient Mark mode, | 495 | It works using `query-replace-regexp'. In Transient Mark mode, |
| 493 | if the mark is active, operate on the contents of the region. | 496 | if the mark is active, operate on the contents of the region. |
| 494 | Second and third arg START and END specify the region to operate on. | 497 | Second and third arg START and END specify the region to operate on. |
| 495 | If optional argument NO-QUERY is non-nil, make changes without | 498 | If optional argument NO-QUERY is non-nil, make changes without asking |
| 496 | asking for confirmation." | 499 | for confirmation. You can use `repunctuate-sentences-filter' to add |
| 500 | filters 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) |