From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.help Subject: Re: Electric punctuation replacement for editing (correcting grammar) Date: Tue, 13 Dec 2011 22:30:08 +0100 Message-ID: <87r508qhwf.fsf@ambire.localdomain> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1323812024 5290 80.91.229.12 (13 Dec 2011 21:33:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 13 Dec 2011 21:33:44 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" To: "Ludwig\, Mark" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Dec 13 22:33:40 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RaZyl-0002Hw-Bl for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Dec 2011 22:33:39 +0100 Original-Received: from localhost ([::1]:49652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaZyk-0003el-Pp for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Dec 2011 16:33:38 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:37286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaZyf-0003eN-Rk for help-gnu-emacs@gnu.org; Tue, 13 Dec 2011 16:33:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaZye-0002hP-Hk for help-gnu-emacs@gnu.org; Tue, 13 Dec 2011 16:33:33 -0500 Original-Received: from smtp205.alice.it ([82.57.200.101]:54762) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaZye-0002Kd-4Y for help-gnu-emacs@gnu.org; Tue, 13 Dec 2011 16:33:32 -0500 Original-Received: from ambire.localdomain (79.51.73.116) by smtp205.alice.it (8.6.023.02) id 4ECA5FDA042026C7; Tue, 13 Dec 2011 22:33:11 +0100 Original-Received: from ttn by ambire.localdomain with local (Exim 4.69) (envelope-from ) id 1RaZvN-00026G-7L; Tue, 13 Dec 2011 22:30:09 +0100 In-Reply-To: (Mark Ludwig's message of "Tue, 13 Dec 2011 19:32:31 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 82.57.200.101 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83193 Archived-At: () "Ludwig, Mark" () 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 =E2=80=98s-q=E2=80=99. With point at= end of sentence, to go from [before] to [after] thus requires typing =E2=80=98s-q=E2=80=99 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 =E2=80=98(forward-word -1) (forward-word 1)=E2=80=99, 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...