help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: jump between if-fi


From: Alan Mackenzie
Subject: Re: jump between if-fi
Date: Mon, 31 Dec 2007 16:24:38 +0000
User-agent: Mutt/1.5.9i

Hi, Reader!

On Sun, Dec 30, 2007 at 05:02:01PM -0600, address@hidden 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).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]