* Electric punctuation replacement for editing (correcting grammar)
@ 2011-12-13 19:32 Ludwig, Mark
2011-12-13 21:30 ` Thien-Thi Nguyen
0 siblings, 1 reply; 2+ messages in thread
From: Ludwig, Mark @ 2011-12-13 19:32 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
Has anyone else tried to develop a text mode sub-mode with "electric" punctuation replacement? I use this when fixing the grammar in text. What I have handles replacement from either "direction." For example, consider the following sentence (with a comma splice):
The big horse, tired after running for so long, paused by a creek to take a drink, that was where I caught up with him.
By "direction" what I mean is that I might be going through the text one sentence at a time (with M-e), and only after skipping a sentence, I might notice that I need to back up to fix something. Then I use M-b to get to the front of a word, and type the correction. To handle that, what I have works (in the above example) when point is on the comma (",") after "drink" or the space following it, or the "t" starting "that" that follows. In any of those three positions, I can type semi-colon (";") to correct the grammar (for example), and the comma (",") gets replaced. Point is left on the "t" starting "that." If I type period (".") instead of semi-colon, the spacing increases to make a proper English sentence end. (I have to type M-c to change the case of "that" in that case.)
Changing the spacing was relatively straight-forward. More challenging is handling parentheses, because my current approach is to use the "sentence" infrastructure (e.g., sentence-end) to figure out the spacing. I don't know how to handle situations like:
I thought so (I was not sure, but suspected.
This should be:
I thought so (I was not sure), but suspected.
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.
It also doesn't handle ending a sentence with "...." properly, because I have logic to handle ellipsis ("...") in the middle of a sentence (by normalizing to a single space before and after the ellipsis).
I'd appreciate any pointers if anyone else has done anything like this.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Electric punctuation replacement for editing (correcting grammar)
2011-12-13 19:32 Electric punctuation replacement for editing (correcting grammar) Ludwig, Mark
@ 2011-12-13 21:30 ` Thien-Thi Nguyen
0 siblings, 0 replies; 2+ messages in thread
From: Thien-Thi Nguyen @ 2011-12-13 21:30 UTC (permalink / raw)
To: Ludwig, Mark; +Cc: help-gnu-emacs@gnu.org
() "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...
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-12-13 21:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-13 19:32 Electric punctuation replacement for editing (correcting grammar) Ludwig, Mark
2011-12-13 21:30 ` Thien-Thi Nguyen
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.