[Top][All Lists]

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

Re: elisp questions for Advanced Closing brackets function

From: Tim X
Subject: Re: elisp questions for Advanced Closing brackets function
Date: Wed, 21 May 2008 19:09:33 +1000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

TheLonelyStar <address@hidden> writes:

> Hi,
> I have funtions in my .emacs, which inserts "[]" when one types "[" (and
> same for "(" and "{").
> I also have functions which just jumps over a "]" when "]" is typed.
> I want to make this function more advanced!
> It should do the following:
> When one types "]" it looks for the next character which is NOT a
> whitespace. If it is "]", the functions just jumps after this. Otherwise it
> inserts an "]".
> I am just lerning elisp (just for this), but I am stuck.
> My Problems:
> - How do I check if the character under (point) is a whitespace?

Read the emacs lisp reference manual on syntax tables.

> - In an "if" statement, how do I put more than one expression into the else
> case? Like this:
> (if condition (do-if-case) ((do-else-case) (do-more-else-case))

You may be a little confused. The if statement only allows one
expression in the 'if' part, but you can have multiple expressions in
the else part - just put them inside a (). Note also that you should
look at progn. 

Often, lisp style tends to use other conditional constructs when
multiple expressions need to be executed, such as cond. Again, reading
existing code will help you identify the more common idioms.

> - If I have a funcion like this:
> (defun adanced-closing-bracket (arg)
>   ...)
> How do I compare (arg) to the character under point?

I'd strongly recommend you read the emacs lisp reference manual and you
may get a bit out of Robert J Chassell's Introduction to Emacs
Lisp. both are now bundled with emacs, but both can be found on the gnu
website. I would also recommend checking out the emacs wiki. 

I realise you are doing much of this as a learning exercise, but I'm not
sure how much you realise you are re-inventing an already overworked

have a look at paredit mode. also, check what features emacs already
has. In many cases all of this stuff is already there and of course,
with source code. You can look at the code an learn a lot of useful
techniques and tricks. 


tcross (at) rapttech dot com dot au

reply via email to

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