all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: "Rudolf Adamkovič" <salutis@me.com>
Cc: 52769@debbugs.gnu.org
Subject: bug#52769: 29.0.50; [FEATURE REQUEST] repunctuate-sentences in region
Date: Sat, 25 Dec 2021 21:04:58 +0200	[thread overview]
Message-ID: <86czlkld45.fsf@mail.linkov.net> (raw)
In-Reply-To: <m27dbuwbt0.fsf@me.com> ("Rudolf Adamkovič via \"Bug reports for GNU Emacs, the Swiss army knife of text editors\""'s message of "Fri, 24 Dec 2021 11:13:15 +0100")

> Could we improve 'repunctuate-sentences' to work such that in Transient
> Mark mode and with mark active, it re-punctuates the contents of the
> region?

Thanks for the request.  Until now, I used a custom command
'canonically-double-space-region' attached below, activated
by advice when the command 'fill-paragraph' (M-q) is called
on the region.

But its heuristics is too unreliable to detect the places
where two spaces are needed.  It often misidentifies
an abbreviation as the end of the sentence.  So using
'query-replace' would be more reliably to make the decision
for every punctuation.

When I tried 'repunctuate-sentences', it stunned by its inefficiency:
it requires a confirmation even when there are already two spaces
at the end of the sentence!  Why does it do this?

PS:

#+begin_src emacs-lisp
(defun canonically-double-space-region (beg end)
  (interactive "*r")
  (canonically-space-region beg end)
  (unless (markerp end) (setq end (copy-marker end t)))
  (let* ((sentence-end-double-space nil) ; to get right regexp below
         (end-spc-re (rx (>= 5 (not (in ".?!"))) (regexp (sentence-end)))))
    (save-excursion
      (goto-char beg)
      (while (and (< (point) end)
                  (re-search-forward end-spc-re end t))
        (unless (or (>= (point) end)
                    (looking-back "[[:space:]]\\{2\\}\\|\n" 3))
          (insert " "))))))

(advice-add 'fill-paragraph :before
            (lambda (&rest _args)
              (when (use-region-p)
                (canonically-double-space-region
                 (region-beginning)
                 (region-end))))
            '((name . fill-paragraph-double-space)))
#+end_src





  reply	other threads:[~2021-12-25 19:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-24 10:13 bug#52769: 29.0.50; [FEATURE REQUEST] repunctuate-sentences in region Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-25 19:04 ` Juri Linkov [this message]
2021-12-28 19:28   ` Juri Linkov
2021-12-28 20:18     ` Juri Linkov
2021-12-28 19:20 ` Juri Linkov
2021-12-28 21:31   ` Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86czlkld45.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=52769@debbugs.gnu.org \
    --cc=salutis@me.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.