[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Detect if Emacs is running in -nw mode
From: |
Tim X |
Subject: |
Re: Detect if Emacs is running in -nw mode |
Date: |
Mon, 31 Mar 2008 18:11:44 +1000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Christian Herenz <herenz@physik.hu-berlin.de> writes:
> Rupert Swarbrick schrieb:
>
>> (unless (function-returning-nil) 1 2 3)
>>
>> evaluates to 3. Not that that matters in this situation.
>>
>> Phew. That was more than I intended to write! Hope it makes things a
>> little clearer.
>>
>> Rupert
>
> Yeah-- You wrote much, and I think you missed the point a little bit..
>
> (unless nil (do-stuff) (do-other-stuff)) ... this would only do-stuff?
>
> (unless nil ((do-stuff) (do-other-stuff)) would do-stuff and do-other-stuff?
>
> That was my actual question.
>
> Greets,
> Christian
When working with any form of lisp, code formatting is the secret. In
fact, its probably more important in lisp languages because unlike other
languages, code and data are pretty much the same thing.
So, in your current situation ....
(unless condition
body)
means unless the condition is true, execute body.
Now body can consist of more than one form, i.e.
(unless condition
(do-thing-1 arg1)
(do-thing-2)
(do-thing-3 arg1 arg2))
would execute 'do-thing-1' with one argument arg1
'do-thing-2' with no arguments
'do-thing-3' with two arguments arg1 and arg2
All of the body forms will be executed if any of them are executed and
you can have as many as you like.
If you want to execute some forms if the condition is true and execute
other forms if it is not, then you want either 'if' or 'cond'.
Note that 'if' only allows for one form in the first part e.g.
(if window-system
(do-true-thing)
(do-false-thing))
You can use progn to add morre forms to the first part, but that is
generally considered poor lisp style e.g.
(if window-system
(progn
(do-thing-1)
(do-thing-2))
(do-other-else-thing
Note that the else part can either be absent or contain multiple forms
to be evaluated.
In the case where you want to execute multiple forms for the 'true'
part, you often see a cond used (cond = conditional). cond is
particularly useful wehn you have more than a true/false
situation. Often, the last condition in a cond is 't', which evaluates
to true - think of it as the 'catch-all'. If none of the other tests
match, this one will. The cond can be useful if you run on multiple
platforms e.g.
(cond
((eq window-system 'x)
(do-something-for-x-1)
(do-something-for-x-2))
((eq eindow-system 'windows)
(do-soemthing-for-windows-1)
(do-something-for-windows-2))
(t
(do-this-if-not-x-or-windows-1)
(do-this-if-not-x-or-windows-2)))
I highly recommend you read the Introduction to Emacs Lisp as this will
make it clear.
Tim
--
tcross (at) rapttech dot com dot au
- Re: Detect if Emacs is running in -nw mode, (continued)
- Re: Detect if Emacs is running in -nw mode, BVK, 2008/03/29
- Re: Detect if Emacs is running in -nw mode, Rupert Swarbrick, 2008/03/30
- Re: Detect if Emacs is running in -nw mode, Christian Herenz, 2008/03/30
- Re: Detect if Emacs is running in -nw mode, Lennart Borgman (gmail), 2008/03/30
- Message not available
- Re: Detect if Emacs is running in -nw mode, Christian Herenz, 2008/03/30
- Re: Detect if Emacs is running in -nw mode, Lennart Borgman (gmail), 2008/03/30
- Re: Detect if Emacs is running in -nw mode, Peter Dyballa, 2008/03/30
- Message not available
- Re: Detect if Emacs is running in -nw mode, Christian Herenz, 2008/03/30
- Message not available
- Re: Detect if Emacs is running in -nw mode, Rupert Swarbrick, 2008/03/30
- Re: Detect if Emacs is running in -nw mode, Christian Herenz, 2008/03/30
- Re: Detect if Emacs is running in -nw mode,
Tim X <=
- Re: Detect if Emacs is running in -nw mode, Christian Herenz, 2008/03/31
- Re: Detect if Emacs is running in -nw mode, Nuno J. Silva, 2008/03/31
- Re: Detect if Emacs is running in -nw mode, Barry Margolin, 2008/03/30
- Re: Detect if Emacs is running in -nw mode, Christian Herenz, 2008/03/31