From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: "Ludwig\, Mark" <ludwig.mark@siemens.com>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: Electric punctuation replacement for editing (correcting grammar)
Date: Tue, 13 Dec 2011 22:30:08 +0100 [thread overview]
Message-ID: <87r508qhwf.fsf@ambire.localdomain> (raw)
In-Reply-To: <BC5672F8AD4C054BAF167C9801500D1A6FBEA371@USSLMMBX003.net.plm.eds.com> (Mark Ludwig's message of "Tue, 13 Dec 2011 19:32:31 +0000")
() "Ludwig, Mark" <ludwig.mark@siemens.com>
() Tue, 13 Dec 2011 19:32:31 +0000
I don't know how to handle situations like:
I thought so (I was not sure, but suspected. [before]
This should be:
I thought so (I was not sure), but suspected. [after]
I want to be able to type the closing parenthesis (")") just as I might
type semi-colon (";") in the above example, and have it correctly place the
parenthesis before the comma.
Perhaps a stateful approach is indicated?
(defun ttn-electric-close-paren ()
"Insert a close-paren, or bump one just inserted backwards."
(interactive)
(save-excursion
;; futz only for subsequent invocations
(when (eq 'ttn-electric-close-paren last-command)
(search-backward ")")
(delete-char 1)
(forward-word -1))
;; keep the riff-raff out
(while (memq (char-before) '(?\s ?, ?\n ?! ?? ?.))
(forward-char -1))
(insert ")")))
To test, you can bind this command to ‘s-q’. With point at end
of sentence, to go from [before] to [after] thus requires typing
‘s-q’ three times.
Of course, this kind of approach can be tedious if the correction
occurs far way from end-of-sentence. One could modify the command
to take an optional numeric arg specifying how many words to skip
backwards initially on first invocation, for that.
Another code improvement opportunity is the loop to find the end
of word. One could test against character syntax, instead, or
perhaps simply do ‘(forward-word -1) (forward-word 1)’, or
[insert emacs var tweak here whereby (forward-word -1) DTRT].
Maybe best would be to encourage the original authors to use
Emacs and its balanc{ing,ed} facilities, to thwart the error
grievous and grating, arranging for mischievous mating...
prev parent reply other threads:[~2011-12-13 21:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-13 19:32 Electric punctuation replacement for editing (correcting grammar) Ludwig, Mark
2011-12-13 21:30 ` Thien-Thi Nguyen [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r508qhwf.fsf@ambire.localdomain \
--to=ttn@gnuvola.org \
--cc=help-gnu-emacs@gnu.org \
--cc=ludwig.mark@siemens.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).