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

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

Re: emacs lisp programming help


From: Pascal J. Bourguignon
Subject: Re: emacs lisp programming help
Date: Thu, 29 Jan 2009 20:37:58 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)

address@hidden writes:

> On Jan 29, 1:13 pm, address@hidden (Pascal J. Bourguignon)
> wrote:
>> In general, emacs questions (even emacs lisp) would be
>
> I was about to do that but then I hesitated and look for a forum with
> the word 'lisp' on it.
>
>> What does the quote do?  What does 'x evaluate to?
>> And what does '(a b c) evaluate to?
>> And what does '(a . b) evaluate to?
>> So what does '(font . my-default-font) evaluate to?
>
> I cannot really answer these questions. I do not know.

You can either know it by learning more emacs lisp, 
http://www.gnu.org/software/emacs/manual/elisp.html
http://www.delorie.com/gnu/docs/emacs-lisp-intro/emacs-lisp-intro_toc.html

or by asking emacs itself to give you the answer.

Go in the *scratch* buffer, put it in emacs-lisp-mode
(type M-x emacs-lisp-mode RET)
then type: 

'x C-u C-x C-e
'(a b c) C-u C-x C-e
'(a . b) C-u C-x C-e
'(font . my-default-font) C-u C-x C-e

and compare with:
(setq x 42) C-x C-e
x C-u C-x C-e
(a b c) C-u C-x C-e   (type q to get out of the debugger)
(list 'a 'b 'c)  C-u C-x C-e
(a . b) 
(cons 'a 'b)


With C-x C-e, the previous s-exp is evaluated and the result is printed in the 
mini buffer.
With C-u C-x C-e, the result is inserted at the point in the current buffer.

An alternative is to call up the REPL: M-x ielm RET
and then you can type your emacs lisp expressions and just type RET to get the 
result:

'x RET
'(a b c) RET
(list 'a 'b 'c) RET
etc...


Notice that you can use C-x C-u in almost all the modes, so if you
need to insert repeatitive code, you can quickly do it by writting  a
lisp expression to do so;

(dolist (color '(red green blue))
  (insert (format "this->setPlane(Color::%s,other->getPlane(Color::%s));\n" 
color color)))
C-x C-e 
inserts:
this->setPlane(Color::red,other->getPlane(Color::red));
this->setPlane(Color::green,other->getPlane(Color::green));
this->setPlane(Color::blue,other->getPlane(Color::blue));

(and you can keep the emacs lisp code in a C comment if you may need
to change it later).

>> What other mean to create a cons cell do you know?
>
> Using (cons ...), that helped. Many many thanks for the help.
>
> Rodrigo

-- 
__Pascal Bourguignon__


reply via email to

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