From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.help Subject: Re: jump between if-fi Date: Mon, 31 Dec 2007 16:24:38 +0000 Message-ID: <20071231162438.GA1211@muc.de> References: <87y7bbpz12.fsf@newsguy.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1199117801 3112 80.91.229.12 (31 Dec 2007 16:16:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 31 Dec 2007 16:16:41 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: reader@newsguy.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 31 17:16:55 2007 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 1J9NJg-0000si-Hf for geh-help-gnu-emacs@m.gmane.org; Mon, 31 Dec 2007 17:16:40 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J9NJK-0005dg-Qc for geh-help-gnu-emacs@m.gmane.org; Mon, 31 Dec 2007 11:16:18 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J9NJ1-0005cP-Qa for help-gnu-emacs@gnu.org; Mon, 31 Dec 2007 11:15:59 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J9NIx-0005Y7-BB for help-gnu-emacs@gnu.org; Mon, 31 Dec 2007 11:15:59 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J9NIx-0005Y0-4U for help-gnu-emacs@gnu.org; Mon, 31 Dec 2007 11:15:55 -0500 Original-Received: from colin.muc.de ([193.149.48.1] helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1J9NIw-0002y2-MB for help-gnu-emacs@gnu.org; Mon, 31 Dec 2007 11:15:55 -0500 Original-Received: (qmail 26333 invoked by uid 3782); 31 Dec 2007 16:15:52 -0000 Original-Received: from acm.muc.de (p57AF476D.dip.t-dialin.net [87.175.71.109]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Mon, 31 Dec 2007 17:15:49 +0100 Original-Received: (qmail 1690 invoked by uid 1000); 31 Dec 2007 16:24:38 -0000 Content-Disposition: inline In-Reply-To: <87y7bbpz12.fsf@newsguy.com> User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) X-Primary-Address: acm@muc.de X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 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:50404 Archived-At: Hi, Reader! On Sun, Dec 30, 2007 at 05:02:01PM -0600, reader@newsguy.com wrote: > I hope this isn't one of those things that is just plain obvious to > lookup in emacs but I'm striking out with M-x apropos > How can I make emacs do something similar with if-fi constructs as it > does with parens? > Even better I'd like the kind of behaviour one can get in vim with > parens, where not only does the syntax coloring show the other paren > but you can jump there with a Ctrl-% > I know emacs can do that as well but not as easily. But anyway, I use > emacs more and would like to turn its powers used in paren recognition > against the `if fi', `while done', `for done'... etc. one uses in > shell scripting. This is a moderately difficult exercise in Elisp programming. I would suggest something like this: (i) On the i of if, the i of fi, the w of when, the e of done etc., put "syntax-table" text properties of open-parenthesis and close-parenthesis. See pages "Syntax Table Internals", "Text Properties" and "Special Properties" in the Emacs Lisp manual. (ii) The best way to apply these text properties might be using abbreviations - make "if" an abbreviation for "if" together with applying the property. You'll need to check that the "if" isn't inside a comment or string, and this sort of thing. See page "Abbrevs" and its sub-pages, particularly the HOOK facility in page "Defining Abbrevs". Then again, maybe just using (iii) (below) might be better. (iii) You'll need some way of removing the properties when they should'nt be there any more - for example, when you comment out a line, or when you type the "n" of "find". You'll need an after-change function here (page "Change Hooks" in the manual) which analyses the text you're changing. Beware that font-locking sometimes uses text-properties, and you might need to synchronise with it. Be aware also that some people (including one Emacs core developer) disable font locking because it annoys them. When you've got it working, please submit it to Emacs for inclusion in Emacs 23! Best of luck! -- Alan Mackenzie (Nuremberg, Germany).