From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joe Fineman Newsgroups: gmane.emacs.help Subject: Re: Two Emacs challenges Date: Sat, 17 Jun 2006 00:26:33 GMT Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1150504843 15684 80.91.229.2 (17 Jun 2006 00:40:43 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 17 Jun 2006 00:40:43 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jun 17 02:40:39 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FrOrX-0005x4-Jr for geh-help-gnu-emacs@m.gmane.org; Sat, 17 Jun 2006 02:40:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FrOrX-0004Jv-1J for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Jun 2006 20:40:31 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!130.81.64.211.MISMATCH!cycny01.gnilink.net!spamkiller2.gnilink.net!gnilink.net!trndny03.POSTED!099a252d!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) Cancel-Lock: sha1:vtPVlQie3+xsq5QBttvGFKhaKfw= Original-Lines: 77 Original-NNTP-Posting-Host: 151.203.91.104 Original-X-Complaints-To: abuse@verizon.net Original-X-Trace: trndny03 1150503993 151.203.91.104 (Fri, 16 Jun 2006 20:26:33 EDT) Original-NNTP-Posting-Date: Fri, 16 Jun 2006 20:26:33 EDT Original-Xref: shelby.stanford.edu gnu.emacs.help:139889 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:35513 Archived-At: Leon writes: > How to bind keys such as (, [, {, " etc to perform such function > > When type once, it will insert a pair while twice insert itself for > example: `[' will insert `[]' and leave the cursor in the middle > while `[[' will insert `['? There are, IIRC, special keyings in the programming-language modes for doing the first part of this (I can't find them in the manual at the moment). For text mode, I have done the following: ---------------------------------------------------------------------- (defun close-paren () (interactive) (insert "()") (forward-char -1)) (defun close-bracket () (interactive) (insert "[]") (forward-char -1)) (defun close-brace () (interactive) (insert "{}") (forward-char -1)) (defun close-quote () (interactive) (insert "\"\"") (forward-char -1)) (global-set-key "(" 'close-paren) (global-set-key "[" 'close-bracket) (global-set-key "{" 'close-brace) (global-set-key "\"" 'close-quote) ---------------------------------------------------------------------- To get past the right fence in the most usual contexts, I have done the following: ---------------------------------------------------------------------- (defun jump-fence (n) "If this char is doubled before a right fence, jump over & insert it once." (interactive "p") (if (> n 1) (self-insert-command n) (let ((origin (point))) (self-insert-command 1) (if (= (point) (1+ origin)) (progn (if (looking-at "[])\"]\\|=[0-9][A-Z]\\|\\(\^[.\\)+") (if (= (char-after (- (point) 2)) (preceding-char)) (progn (delete-char -2) (goto-char (- (match-end 0) 2)) (self-insert-command 1)))))) ))) (global-set-key "." 'jump-fence) (global-set-key "," 'jump-fence) (global-set-key ";" 'jump-fence) (global-set-key ":" 'jump-fence) (global-set-key "?" 'jump-fence) (global-set-key "!" 'jump-fence) (global-set-key " " 'jump-fence) ---------------------------------------------------------------------- I had not thought of the second part of your request. If I want only the left fence, I just delete the right one. N.B. I am not a programmer, so I am sure all this is dreadfully naive. -- --- Joe Fineman joe_f@verizon.net ||: The tragedy is not what we suffer, but what we miss. :||