* Detect if Emacs is running in -nw mode
@ 2008-03-29 22:37 Christian Herenz
2008-03-29 22:43 ` Tom Rauchenwald
[not found] ` <mailman.9603.1206831074.18990.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 24+ messages in thread
From: Christian Herenz @ 2008-03-29 22:37 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
How can I detect in .emacs, if emacs is running in -nw mode or in a non X
environment?
I want to have set(menu-bar-mode nil) at start in -nw mode.
Greets,
Christian
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-29 22:37 Detect if Emacs is running in -nw mode Christian Herenz
@ 2008-03-29 22:43 ` Tom Rauchenwald
[not found] ` <mailman.9603.1206831074.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 24+ messages in thread
From: Tom Rauchenwald @ 2008-03-29 22:43 UTC (permalink / raw)
To: help-gnu-emacs
Christian Herenz <herenz@physik.hu-berlin.de> writes:
> Hi,
>
> How can I detect in .emacs, if emacs is running in -nw mode or in a
> non X environment?
>
> I want to have set(menu-bar-mode nil) at start in -nw mode.
(when (window-system)
(menu-bar-mode -1))
or similiar should work
> Greets,
> Christian
Tom
--
Then I drew in a breath, and my renewed will with it, lifted the rod
in my right hand, murmured a phrase in a language I didn't know, and
blew the tires off his fucking truck.
-- Harry Dresden
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
[not found] ` <mailman.9603.1206831074.18990.help-gnu-emacs@gnu.org>
@ 2008-03-29 23:52 ` Christian Herenz
2008-03-30 0:35 ` Roland Winkler
` (2 more replies)
0 siblings, 3 replies; 24+ messages in thread
From: Christian Herenz @ 2008-03-29 23:52 UTC (permalink / raw)
To: help-gnu-emacs
Tom Rauchenwald schrieb:
>> I want to have set(menu-bar-mode nil) at start in -nw mode.
>
> (when (window-system)
> (menu-bar-mode -1))
>
> or similiar should work
>
Is there something when NOT, so that I could set
[PSEUDO-CODE]:
(when not (window-system)
(menu-bar-mode nil)
(other commands i want to use when not windowed))
Greets,
Christian
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-29 23:52 ` Christian Herenz
@ 2008-03-30 0:35 ` Roland Winkler
2008-03-31 2:18 ` Barry Margolin
2008-03-30 0:44 ` Lennart Borgman (gmail)
[not found] ` <mailman.9613.1206837866.18990.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 24+ messages in thread
From: Roland Winkler @ 2008-03-30 0:35 UTC (permalink / raw)
To: help-gnu-emacs
Christian Herenz <herenz@physik.hu-berlin.de> writes:
> Is there something when NOT, so that I could set
> [PSEUDO-CODE]:
> (when not (window-system)
> (menu-bar-mode nil)
> (other commands i want to use when not windowed))
You can test whether the DISPLAY environment variable is set using
(getenv "DISPLAY")
In this way you can distinguish between emacs -nw running in an X
or a "pure tty" environment. Is that what you want?
Roland
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-29 23:52 ` Christian Herenz
2008-03-30 0:35 ` Roland Winkler
@ 2008-03-30 0:44 ` Lennart Borgman (gmail)
2008-03-30 1:13 ` Drew Adams
[not found] ` <mailman.9613.1206837866.18990.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 24+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-30 0:44 UTC (permalink / raw)
To: Christian Herenz; +Cc: help-gnu-emacs
Christian Herenz wrote:
> Tom Rauchenwald schrieb:
>
>>> I want to have set(menu-bar-mode nil) at start in -nw mode.
>>
>> (when (window-system)
>> (menu-bar-mode -1))
>>
>> or similiar should work
>>
>
> Is there something when NOT, so that I could set
> [PSEUDO-CODE]:
> (when not (window-system)
> (menu-bar-mode nil)
> (other commands i want to use when not windowed))
>
>
> Greets,
> Christian
There is (not ...) ;-)
(when (not (window-system))
...)
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
[not found] ` <mailman.9613.1206837866.18990.help-gnu-emacs@gnu.org>
@ 2008-03-30 1:10 ` Will Parsons
2008-03-30 1:22 ` Christian Herenz
0 siblings, 1 reply; 24+ messages in thread
From: Will Parsons @ 2008-03-30 1:10 UTC (permalink / raw)
To: help-gnu-emacs
Lennart Borgman (gmail) wrote:
> Christian Herenz wrote:
>> Tom Rauchenwald schrieb:
>>
>>>> I want to have set(menu-bar-mode nil) at start in -nw mode.
>>>
>>> (when (window-system)
>>> (menu-bar-mode -1))
>>>
>>> or similiar should work
>>>
>>
>> Is there something when NOT, so that I could set
>> [PSEUDO-CODE]:
>> (when not (window-system)
>> (menu-bar-mode nil)
>> (other commands i want to use when not windowed))
>>
>>
>> Greets,
>> Christian
>
> There is (not ...) ;-)
>
> (when (not (window-system))
> ...)
Or how about (unless ...)
(unless (window-system)
...)
--
Will
^ permalink raw reply [flat|nested] 24+ messages in thread
* RE: Detect if Emacs is running in -nw mode
2008-03-30 0:44 ` Lennart Borgman (gmail)
@ 2008-03-30 1:13 ` Drew Adams
0 siblings, 0 replies; 24+ messages in thread
From: Drew Adams @ 2008-03-30 1:13 UTC (permalink / raw)
To: 'Lennart Borgman (gmail)', 'Christian Herenz'
Cc: help-gnu-emacs
> There is (not ...) ;-)
>
> (when (not (window-system))
> ...)
Which is also (unless (window-system)...)
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 1:10 ` Will Parsons
@ 2008-03-30 1:22 ` Christian Herenz
2008-03-30 3:34 ` BVK
2008-03-30 11:23 ` Rupert Swarbrick
0 siblings, 2 replies; 24+ messages in thread
From: Christian Herenz @ 2008-03-30 1:22 UTC (permalink / raw)
To: help-gnu-emacs
Will Parsons schrieb:
>> There is (not ...) ;-)
>>
>> (when (not (window-system))
>> ...)
>
> Or how about (unless ...)
>
> (unless (window-system)
> ...)
>
So... That should do the trick. One last question, i assume that window-system
can either be true or false. I searched the help for a variable called
window-system but I found no explanation?
Where do I have to search for emacs "system-variables"?
Greets and thanks,
Christian
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 1:22 ` Christian Herenz
@ 2008-03-30 3:34 ` BVK
2008-03-30 11:23 ` Rupert Swarbrick
1 sibling, 0 replies; 24+ messages in thread
From: BVK @ 2008-03-30 3:34 UTC (permalink / raw)
To: Christian Herenz; +Cc: help-gnu-emacs
On Sun, Mar 30, 2008 at 6:52 AM, Christian Herenz
<herenz@physik.hu-berlin.de> wrote:
>
> So... That should do the trick. One last question, i assume that window-system
> can either be true or false. I searched the help for a variable called
> window-system but I found no explanation?
>
C-h v window-system gave me this documentation:
window-system is a variable defined in `C source code'.
Its value is nil
Documentation:
Name of window system that Emacs is displaying through.
The value is a symbol--for instance, `x' for X windows.
The value is nil if Emacs is using a text-only terminal.
--
bvk-chaitanya
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 1:22 ` Christian Herenz
2008-03-30 3:34 ` BVK
@ 2008-03-30 11:23 ` Rupert Swarbrick
2008-03-30 12:17 ` Christian Herenz
1 sibling, 1 reply; 24+ messages in thread
From: Rupert Swarbrick @ 2008-03-30 11:23 UTC (permalink / raw)
To: help-gnu-emacs
On Sun, 30 Mar 2008 03:22:55 +0200, Christian Herenz wrote:
> Will Parsons schrieb:
>
>>> There is (not ...) ;-)
>>>
>>> (when (not (window-system))
>>> ...)
>>
>> Or how about (unless ...)
>>
>> (unless (window-system)
>> ...)
>>
>>
> So... That should do the trick. One last question, i assume that
> window-system can either be true or false. I searched the help for a
> variable called window-system but I found no explanation? Where do I
> have to search for emacs "system-variables"?
>
> Greets and thanks,
> Christian
Hi,
Two things:
1) In lisp, something referenced like (window-system) is a function
(unless you're in a weird macro, but let's ignore that) and the statement
`` (window-system) '' means call the function called window-system with
no arguments and evaluate to the result(s).
In emacs, looking up functions is different from variables, and you need
to check C-h f <function-name> (it has tab completion, just like C-h v).
The reason that there are two different look-up commands is that in any
lisp-2 (which includes elisp), there are two different lists of symbols:
one for functions and one for variables. Thus I could have a function
called x and also a variable called x and (+ 1 x) and (x "foo") would
both do the right thing. Starting "(" tells the lisp reader that the next
symbol name it's looking at is going to be a function.
2) However, there was actually a typo from Tom Rauchenwald's answer - in
fact is *is* a variable called window-system (I just fired up emacs to
check)
You might want to try C-h v window-system to read the docs for it.
And your code would be:
(unless window-system (menu-bar-mode -1))
Hope this helps!
Rupert
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 11:23 ` Rupert Swarbrick
@ 2008-03-30 12:17 ` Christian Herenz
2008-03-30 12:43 ` Lennart Borgman (gmail)
[not found] ` <mailman.9635.1206881018.18990.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 24+ messages in thread
From: Christian Herenz @ 2008-03-30 12:17 UTC (permalink / raw)
To: help-gnu-emacs
Rupert Swarbrick schrieb:
> And your code would be:
>
> (unless window-system (menu-bar-mode -1))
>
>
> Hope this helps!
>
Thanks for your long answer, I am beginning to understand... But I also get a
little bit confused. As I stated before, I want to run more commannds, is this
as simple as:
(unless window-system (menu-bar-mode -1) (color-theme-arjen)) ?
Thanks again for your answer Rupert, I really learned something.
Greets,
Christian
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 12:17 ` Christian Herenz
@ 2008-03-30 12:43 ` Lennart Borgman (gmail)
[not found] ` <mailman.9635.1206881018.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 24+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-30 12:43 UTC (permalink / raw)
To: Christian Herenz; +Cc: help-gnu-emacs
Christian Herenz wrote:
> Rupert Swarbrick schrieb:
>
>> And your code would be:
>>
>> (unless window-system (menu-bar-mode -1))
>>
>>
>> Hope this helps!
>>
>
> Thanks for your long answer, I am beginning to understand... But I also
> get a little bit confused. As I stated before, I want to run more
> commannds, is this as simple as:
>
> (unless window-system (menu-bar-mode -1) (color-theme-arjen)) ?
Do
C-h f unless RET
to read the documentation for "unless". You can see there that is says
"body forms".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
[not found] ` <mailman.9635.1206881018.18990.help-gnu-emacs@gnu.org>
@ 2008-03-30 14:24 ` Christian Herenz
2008-03-30 14:45 ` Lennart Borgman (gmail)
` (4 more replies)
0 siblings, 5 replies; 24+ messages in thread
From: Christian Herenz @ 2008-03-30 14:24 UTC (permalink / raw)
To: help-gnu-emacs
Lennart Borgman (gmail) schrieb:
>
> Do
>
> C-h f unless RET
>
> to read the documentation for "unless". You can see there that is says
> "body forms".
>
C-h f unless RET yields here:
--
|unless is a Lisp macro in `subr'.
|(unless COND &rest BODY)
|
|If COND yields nil, do BODY, else return nil.
--
But what about more than one function inside the Body?
I do it like this atm (because i dont really understand the above help):
(unless window-system (menu-bar-mode nil))
(unless window-system (color-theme-arjen))
But is it possible to do the 2 functions withe evaluating the condition only once:
(unless window-system ((menu-bar-mode nil) (color-theme-arjen)))
Sorry, its a noob question :) But I really would like to know :)
Greets,
Christian
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 14:24 ` Christian Herenz
@ 2008-03-30 14:45 ` Lennart Borgman (gmail)
2008-03-30 15:13 ` Peter Dyballa
` (3 subsequent siblings)
4 siblings, 0 replies; 24+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-30 14:45 UTC (permalink / raw)
To: Christian Herenz; +Cc: help-gnu-emacs
Christian Herenz wrote:
> Lennart Borgman (gmail) schrieb:
>
>>
>> Do
>>
>> C-h f unless RET
>>
>> to read the documentation for "unless". You can see there that is says
>> "body forms".
>>
>
> C-h f unless RET yields here:
> --
> |unless is a Lisp macro in `subr'.
> |(unless COND &rest BODY)
> |
> |If COND yields nil, do BODY, else return nil.
> --
>
> But what about more than one function inside the Body?
The documentation should be exact enough to show that. If not then it is
a documentation bug.
In this case it says "body forms", not "body form". A form is something
inside a pair of (). So it is ok with several functions here.
If it was not you could have used progn for example.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 14:24 ` Christian Herenz
2008-03-30 14:45 ` Lennart Borgman (gmail)
@ 2008-03-30 15:13 ` Peter Dyballa
[not found] ` <mailman.9643.1206890035.18990.help-gnu-emacs@gnu.org>
` (2 subsequent siblings)
4 siblings, 0 replies; 24+ messages in thread
From: Peter Dyballa @ 2008-03-30 15:13 UTC (permalink / raw)
To: Christian Herenz; +Cc: help-gnu-emacs
Am 30.03.2008 um 16:24 schrieb Christian Herenz:
> But is it possible to do the 2 functions withe evaluating the
> condition only once:
>
> (unless window-system ((menu-bar-mode nil) (color-theme-arjen)))
>
> Sorry, its a noob question :) But I really would like to know :)
You could make a test like that:
(unless window-system (message "Oh, no!") (message "Windows -- I
mean: not Losedos but X11"))
--
Mit friedvollen Grüßen
Pete
Hard Disk, n.:
A device that allows users to delete vast quantities
of data with simple mnemonic commands.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
[not found] ` <mailman.9643.1206890035.18990.help-gnu-emacs@gnu.org>
@ 2008-03-30 15:31 ` Christian Herenz
0 siblings, 0 replies; 24+ messages in thread
From: Christian Herenz @ 2008-03-30 15:31 UTC (permalink / raw)
To: help-gnu-emacs
Peter Dyballa schrieb:
> (unless window-system (message "Oh, no!") (message "Windows -- I
> mean: not Losedos but X11"))
>
Thanks! I think I now understand (at least a little bit) how conditions work :-)
Greets,
Christian
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
[not found] ` <mailman.9641.1206888365.18990.help-gnu-emacs@gnu.org>
@ 2008-03-30 16:10 ` Rupert Swarbrick
2008-03-30 17:56 ` Christian Herenz
0 siblings, 1 reply; 24+ messages in thread
From: Rupert Swarbrick @ 2008-03-30 16:10 UTC (permalink / raw)
To: help-gnu-emacs
On Sun, 30 Mar 2008 16:45:57 +0200, Lennart Borgman (gmail) wrote:
> The documentation should be exact enough to show that. If not then it is
> a documentation bug.
>
> In this case it says "body forms", not "body form". A form is something
> inside a pair of (). So it is ok with several functions here.
>
> If it was not you could have used progn for example.
I'm not sure and if I'm wrong, Christian, please correct me, but:
I think the problem is that Christian doesn't know what "body" means. In
lisp, a function is defined using something called a lambda list, so I
might define a function foo like:
(defun foo (arg1 arg2 arg3) (do-some-stuff))
In this case arg1, arg2 and arg3 are three different arguments, so we'd
call foo like this
(foo 1 2 3)
Great. However, if you want to write a useful unless function/macro, you
want to allow any number of elements in the list - a bit like varargs do
in C, if you know about that.
Anyhow, you write something like
(defun bar (arg1 &rest others) (do-some-stuff))
or (pretty much equivalently)
(defun bar (arg1 &body others) (do-some-stuff))
For bar, arg1 is just a normal argument. But others is a bit magic:
(bar 1 2 3 4 5 6)
sets arg1 to 1 and others to (2 3 4 5 6) (a list). Now, unless is
actually a macro and the bit it does next depends on a whole new can of
worms based on macro expansion and ,@ but I'm not going to go into that.
The main point however is that the documentation says:
> --
> |unless is a Lisp macro in `subr'.
> |(unless COND &rest BODY)
> |
> |If COND yields nil, do BODY, else return nil.
> --
So the &rest bit means that body can contain as much as you like. FWIW,
unless executes BODY in a progn, so for example
(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
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 16:10 ` Rupert Swarbrick
@ 2008-03-30 17:56 ` Christian Herenz
2008-03-31 7:32 ` Nuno J. Silva
2008-03-31 8:11 ` Tim X
0 siblings, 2 replies; 24+ messages in thread
From: Christian Herenz @ 2008-03-30 17:56 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 0:35 ` Roland Winkler
@ 2008-03-31 2:18 ` Barry Margolin
0 siblings, 0 replies; 24+ messages in thread
From: Barry Margolin @ 2008-03-31 2:18 UTC (permalink / raw)
To: help-gnu-emacs
In article <m34papoxpo.fsf@tfkp07.physik.uni-erlangen.de>,
Roland Winkler <Roland.Winkler@physik.uni-erlangen.de> wrote:
> Christian Herenz <herenz@physik.hu-berlin.de> writes:
> > Is there something when NOT, so that I could set
> > [PSEUDO-CODE]:
> > (when not (window-system)
> > (menu-bar-mode nil)
> > (other commands i want to use when not windowed))
>
> You can test whether the DISPLAY environment variable is set using
>
> (getenv "DISPLAY")
>
> In this way you can distinguish between emacs -nw running in an X
> or a "pure tty" environment. Is that what you want?
There are other window systems besides X.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 14:24 ` Christian Herenz
` (3 preceding siblings ...)
[not found] ` <mailman.9641.1206888365.18990.help-gnu-emacs@gnu.org>
@ 2008-03-31 2:22 ` Barry Margolin
2008-03-31 8:38 ` Christian Herenz
4 siblings, 1 reply; 24+ messages in thread
From: Barry Margolin @ 2008-03-31 2:22 UTC (permalink / raw)
To: help-gnu-emacs
In article <fso7rr$io2$1@registered.motzarella.org>,
Christian Herenz <herenz@physik.hu-berlin.de> wrote:
> Lennart Borgman (gmail) schrieb:
>
> >
> > Do
> >
> > C-h f unless RET
> >
> > to read the documentation for "unless". You can see there that is says
> > "body forms".
> >
>
> C-h f unless RET yields here:
> --
> |unless is a Lisp macro in `subr'.
>
> |(unless COND &rest BODY)
>
> |
> |If COND yields nil, do BODY, else return nil.
> --
>
> But what about more than one function inside the Body?
> I do it like this atm (because i dont really understand the above help):
Do you understand what "&rest" means? It means that there can be an
arbitrary number of arguments there.
>
> (unless window-system (menu-bar-mode nil))
> (unless window-system (color-theme-arjen))
Even if only one form were allowed, why wouldn't you use progn to
combine multiple forms into one:
(unless window-system
(progn
(menu-bar-mode nil)
(color-theme-arjen)))
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 17:56 ` Christian Herenz
@ 2008-03-31 7:32 ` Nuno J. Silva
2008-03-31 8:11 ` Tim X
1 sibling, 0 replies; 24+ messages in thread
From: Nuno J. Silva @ 2008-03-31 7:32 UTC (permalink / raw)
To: help-gnu-emacs
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?
This will do-stuff and do-other-stuff.
> (unless nil ((do-stuff) (do-other-stuff)) would do-stuff and
> do-other-stuff?
And this will raise an error, I'm afraid.
>
> That was my actual question.
--
Nuno J. Silva (aka njsg)
LEIC student at Instituto Superior Técnico
Lisbon, Portugal
Homepage: http://njsg.no.sapo.pt/
Gopherspace: gopher://sdf-eu.org/11/users/njsg
Registered Linux User #402207 - http://counter.li.org
-=-=-
A computer is like an air conditioner, it stops working when you open
Windows.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-30 17:56 ` Christian Herenz
2008-03-31 7:32 ` Nuno J. Silva
@ 2008-03-31 8:11 ` Tim X
2008-03-31 8:34 ` Christian Herenz
1 sibling, 1 reply; 24+ messages in thread
From: Tim X @ 2008-03-31 8:11 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-31 8:11 ` Tim X
@ 2008-03-31 8:34 ` Christian Herenz
0 siblings, 0 replies; 24+ messages in thread
From: Christian Herenz @ 2008-03-31 8:34 UTC (permalink / raw)
To: help-gnu-emacs
Tim X schrieb:
> (unless condition
> (do-thing-1 arg1)
> (do-thing-2)
> (do-thing-3 arg1 arg2))
>
OK!
> (if window-system
> (do-true-thing)
> (do-false-thing))
See! That was what confused me, I thought unless works like if, but obviously
there is a difference.
Thank you very much :-)
Greets,
Christian
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: Detect if Emacs is running in -nw mode
2008-03-31 2:22 ` Barry Margolin
@ 2008-03-31 8:38 ` Christian Herenz
0 siblings, 0 replies; 24+ messages in thread
From: Christian Herenz @ 2008-03-31 8:38 UTC (permalink / raw)
To: help-gnu-emacs
Barry Margolin schrieb:
> (unless window-system
> (progn
> (menu-bar-mode nil)
> (color-theme-arjen)))
>
In a post above TimX wrote:
> 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))
However, since I have "now finally" a little bit structure in my .emacs I have
seperated parts about general appereance and color themes - which makes this
just an intersting "theoretical" conversation, but is at the moment not of
practiacal use for me :-)
Greets,
Christian
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2008-03-31 8:38 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-29 22:37 Detect if Emacs is running in -nw mode Christian Herenz
2008-03-29 22:43 ` Tom Rauchenwald
[not found] ` <mailman.9603.1206831074.18990.help-gnu-emacs@gnu.org>
2008-03-29 23:52 ` Christian Herenz
2008-03-30 0:35 ` Roland Winkler
2008-03-31 2:18 ` Barry Margolin
2008-03-30 0:44 ` Lennart Borgman (gmail)
2008-03-30 1:13 ` Drew Adams
[not found] ` <mailman.9613.1206837866.18990.help-gnu-emacs@gnu.org>
2008-03-30 1:10 ` Will Parsons
2008-03-30 1:22 ` Christian Herenz
2008-03-30 3:34 ` BVK
2008-03-30 11:23 ` Rupert Swarbrick
2008-03-30 12:17 ` Christian Herenz
2008-03-30 12:43 ` Lennart Borgman (gmail)
[not found] ` <mailman.9635.1206881018.18990.help-gnu-emacs@gnu.org>
2008-03-30 14:24 ` Christian Herenz
2008-03-30 14:45 ` Lennart Borgman (gmail)
2008-03-30 15:13 ` Peter Dyballa
[not found] ` <mailman.9643.1206890035.18990.help-gnu-emacs@gnu.org>
2008-03-30 15:31 ` Christian Herenz
[not found] ` <mailman.9641.1206888365.18990.help-gnu-emacs@gnu.org>
2008-03-30 16:10 ` Rupert Swarbrick
2008-03-30 17:56 ` Christian Herenz
2008-03-31 7:32 ` Nuno J. Silva
2008-03-31 8:11 ` Tim X
2008-03-31 8:34 ` Christian Herenz
2008-03-31 2:22 ` Barry Margolin
2008-03-31 8:38 ` Christian Herenz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).