From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Stewart Newsgroups: gmane.emacs.help Subject: Re: Redefine "(" and ")" keys in every mode Date: Sun, 04 Jan 2009 08:01:48 +0800 Message-ID: <87wsdcc51v.fsf@debian.domain> References: <21265910.post@talk.nabble.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1231027565 31139 80.91.229.12 (4 Jan 2009 00:06:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 4 Jan 2009 00:06:05 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jan 04 01:07:16 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LJGWM-00033X-8O for geh-help-gnu-emacs@m.gmane.org; Sun, 04 Jan 2009 01:07:10 +0100 Original-Received: from localhost ([127.0.0.1]:55729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LJGV7-0004l4-2S for geh-help-gnu-emacs@m.gmane.org; Sat, 03 Jan 2009 19:05:53 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LJGUo-0004kt-Dz for help-gnu-emacs@gnu.org; Sat, 03 Jan 2009 19:05:34 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LJGUm-0004kh-2D for help-gnu-emacs@gnu.org; Sat, 03 Jan 2009 19:05:33 -0500 Original-Received: from [199.232.76.173] (port=58192 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LJGUl-0004ke-SN for help-gnu-emacs@gnu.org; Sat, 03 Jan 2009 19:05:31 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:53827 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LJGUl-0003bM-6F for help-gnu-emacs@gnu.org; Sat, 03 Jan 2009 19:05:31 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1LJGUi-0006SO-IZ for help-gnu-emacs@gnu.org; Sun, 04 Jan 2009 00:05:28 +0000 Original-Received: from 222.212.129.98 ([222.212.129.98]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 04 Jan 2009 00:05:28 +0000 Original-Received: from lazycat.manatee by 222.212.129.98 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 04 Jan 2009 00:05:28 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 48 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 222.212.129.98 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:ZuG9bs71/fvcPKdCW/So5e3SoKQ= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:61044 Archived-At: Hi, I recommend you install paredit.el with Emacs. It is a minor mode for performing structured editing of S-expression data. Of course, it can insert () when you type (, and type ) jump next if have next one. You can find it at: http://www.emacswiki.org/emacs/ParEdit Regards, -- Andy TheLonelyStar writes: > Hi, > > I use the following functions (bellow) for redifine the insertions if ( and > ). > The Idea is: When I type (, I want () inserted. When I type ) and the next > character is ), I want to just jump over it. > > The Problem is: This works, as long as the mode I am in does not overwrite > the "(" or ")" key. > And, at the same time, when the mode overwrites this keys, it normaly has a > reason for it. > > Has somebody an Idea how this can be done, so that it works in every mode? > Thanks! > Nathan > > The functions: > ----------------------------------- > (defun bracket (arg) > (interactive "*P") > (insert "()") > (backward-char)) > (define-key global-map (kbd "(") 'bracket) > > ;;Jump after character on insertion > (defun end-insertion (arg) > (interactive "*p") > (if (looking-at (concat "[\n \t]*" (this-command-keys))) (goto-char > (match-end 0)) (insert (this-command-keys)) (indent-according-to-mode)) > ) > > (define-key global-map (kbd ")") 'end-insertion) > (define-key c-mode-base-map (kbd ")") 'end-insertion) > ------------------------------