From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leon Newsgroups: gmane.emacs.help Subject: Re: Two Emacs challenges Date: Sat, 17 Jun 2006 11:07:16 +0100 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 1150538883 10210 80.91.229.2 (17 Jun 2006 10:08:03 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 17 Jun 2006 10:08:03 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jun 17 12:08:01 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 1FrXic-0002ob-BV for geh-help-gnu-emacs@m.gmane.org; Sat, 17 Jun 2006 12:07:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FrXib-000828-D0 for geh-help-gnu-emacs@m.gmane.org; Sat, 17 Jun 2006 06:07:53 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FrXiN-0007xY-2o for help-gnu-emacs@gnu.org; Sat, 17 Jun 2006 06:07:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FrXiM-0007vl-DF for help-gnu-emacs@gnu.org; Sat, 17 Jun 2006 06:07:38 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FrXiM-0007vd-7C for help-gnu-emacs@gnu.org; Sat, 17 Jun 2006 06:07:38 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FrXsA-00052E-PY for help-gnu-emacs@gnu.org; Sat, 17 Jun 2006 06:17:47 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1FrXiC-0002l7-12 for help-gnu-emacs@gnu.org; Sat, 17 Jun 2006 12:07:28 +0200 Original-Received: from sl392.st-edmunds.cam.ac.uk ([131.111.223.202]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 17 Jun 2006 12:07:28 +0200 Original-Received: from sdl.web by sl392.st-edmunds.cam.ac.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 17 Jun 2006 12:07:28 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Lines: 81 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: sl392.st-edmunds.cam.ac.uk Face: iVBORw0KGgoAAAANSUhEUgAAAEAAAAAUCAMAAAAKqMsNAAAAwFBMVEUfIB4qLCk8PjxAQT9E RkNHSUZKS0lOUE1SVFFWV1VWWFVaW1lcXltfYV5kZWNpa2hsbmtub21vcW5ydHF3eXZ5e3h7fXp+ f32Agn+EhoOGiIWKjImNjouTlZKWmJWZm5icnpugop+jpaKnqaarraqwsq6ztbG4ure7vbq+wL3D xcLJy8jP0c3R09DT1dLV19TY2tfe4Nzf4d7h5ODj5eLn6ebq7Ont7+vv8e3y9PHz9fL19/T3+fb4 +/f8/vv+//wkcdDPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gIaAyMPYYdloAAAAZlJ REFUOMudVH9TgkAQxWhqGBrqSueSQM2QUgQERxKBt9//W3V3IJKZf7A33I+927ePtxwaESWrveip oD6mEW3m4LkYbr77AWAXZ/NFaDkD+3Hfi8H7IjR8PS90fPI+ALEF6JkRFrd4m10/nH1fAvBmlAxR OEx7+cCV6O10OnQuAODgfE4qACVvw7dVPaylhbVPnMDmnNFWiSiNRDult1M1+APbtses9Yf+b4Yz 7rxKEUlGdzcwTuqceiqyhq07k6eqQplcm8Bzpv15qSo/8DjP5XRlEXktM49L3AlTJjgWJtE40Cjw O7YnvLOhbjEWSwr3URSLeDwlhDK3DtKnCAh8lA8Evm40aE0tx6mciWloeKgFlI8pfe4Lk00wgFGQ WWro6t7oXWsgY1ithuo2vCmGSiSmEWNLqgHc1E1oXR0B5llbORwB8okddZIc91UVUHrYjWCeKLSl 79D6Ss/i630FkE6WLvPvgvOC/ALAn88UzWUi3BXgHyv3+kXAv7eRdgbIKHm07QkAjMJpAL6Mev6R BMJOFrpEH4AfGukf4kwTGH0AAAAASUVORK5CYII= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.0 (gnu/linux) Cancel-Lock: sha1:+uXDwE2Yem5DRQ0H7yBzSDTEDjs= 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:35523 Archived-At: Joe Fineman writes: > 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. Thank you for sharing. I just tried out skeleton-pair-insert-maybe as suggested by William and it's great. -- Leon