Function: repunctuate-sentences

repunctuate-sentences is an interactive and byte-compiled function defined in paragraphs.el.gz.

Signature

(repunctuate-sentences &optional NO-QUERY START END)

Documentation

Put two spaces at the end of sentences from point to the end of buffer.

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. You can use repunctuate-sentences-filter(var)/repunctuate-sentences-filter(fun) to add filters to skip occurrences of spaces that don't need to be replaced.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/paragraphs.el.gz
(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'.  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.  You can use `repunctuate-sentences-filter' to add
filters to skip occurrences of spaces that don't need to be replaced."
  (interactive "i\nR")
  (let ((regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +")
        (to-string "\\1\\2\\3  "))
    (if no-query
        (progn
          (when start (goto-char start))
          (while (re-search-forward regexp end t)
            (replace-match to-string)))
      (unwind-protect
          (progn
            (add-function :after-while isearch-filter-predicate
                          repunctuate-sentences-filter)
            (query-replace-regexp regexp to-string nil start end))
        (remove-function isearch-filter-predicate
                         repunctuate-sentences-filter)))))