all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: lawrence mitchell <wence@gmx.li>
Subject: Re: trouble writing a conditional, or with lambda
Date: Sat, 24 May 2003 17:14:14 +0100	[thread overview]
Message-ID: <?fnord?87znlcz5ih.fsf@ID-97657.usr.dfncis.de> (raw)
In-Reply-To: m3d6i8cond.fsf@russel.teuto37

Florian von Savigny wrote:

> Sigh ...

> some basic lisp, I'm afraid, but I did consult the manual and tested
> in lisp-interaction-mode, but did not get any the wiser.

Have you tried reading the Emacs Lisp Introduction?  It might
already be available on your system, try by doing
C-h i d m Emacs Lisp Intro RET

> I'm trying to get a function to work differently depending on whether
> emacs runs under X or on a terminal:

>    (if (eq window-system nil)
>        ; running under a terminal
>        (lambda ()
> 	       (split-window)
> 	       (switch-to-buffer "*foo*")
> 	       )
>     ; running under a window system
>     (lambda ()
> 	     (select-frame (make-frame))
> 	     (set-frame-size (selected-frame) 50 24)
> 	     (set-frame-position (selected-frame) 150 120)
> 	     ))

Note that LAMBDA is a self-quoting form, and hence, the above
would return a lambda expression which you would have to FUNCALL
to achieve the result you're looking for (though this is
probably not what you want):

(lambda ()
  (split-window)
  (switch-to-buffer "*foo*"))
    => (lambda ()
         (split-window)
         (switch-to-buffer "*foo*"))

I presume you're using lambdas because the "then" part of an IF
statement in emacs lisp has to be a single expression.  However,
you probably want to be using PROGN:

(if some-condition
    (progn (do-first-thing) (do-second-thing)))

The "else" branch has what is known as an implicit PROGN, i.e.,
you can execute multiple statements without needing to wrap them
in a PROGN.

(if some-condition-that-isn't-true
    nil
    ;; both these will be executed.
    (do-first-thing)
    (do-second-thing))

Note also that you do not need to check WINDOW-SYSTEM being NIL,
you can just reverse the logic of your IF statement.  This is
due to the fact that NIL is the only false truth value in elisp.

(if window-system
    ;; This will be executed unless running on a tty
    (progn (do-stuff-for-window-system))
    ;; This will be executed when running on a tty
    (do-stuff-for-tty))

[...]

> Can anybody help how to get this simple conditional to work?

Try something like:

(if window-system
    (progn (select-frame (make-frame))
           (set-frame-size (selected-frame) 50 24)
           (set-frame-position (selected-frame) 150 120)))
    (split-window)
    (switch-to-buffer (get-buffer-create "*foo*")))

-- 
lawrence mitchell <wence@gmx.li>

  parent reply	other threads:[~2003-05-24 16:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-24 16:09 trouble writing a conditional, or with lambda Florian von Savigny
2003-05-24 15:37 ` Thomas Gehrlein
2003-05-24 16:08 ` Oliver Scholz
2003-05-24 16:14 ` lawrence mitchell [this message]
2003-05-25 12:04   ` Florian von Savigny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='?fnord?87znlcz5ih.fsf@ID-97657.usr.dfncis.de' \
    --to=wence@gmx.li \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.