From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: lawrence mitchell Newsgroups: gmane.emacs.help Subject: Re: trouble writing a conditional, or with lambda Date: Sat, 24 May 2003 17:14:14 +0100 Organization: funfunfun Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1053792877 25084 80.91.224.249 (24 May 2003 16:14:37 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 24 May 2003 16:14:37 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Sat May 24 18:14:35 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19JbfH-0006WM-00 for ; Sat, 24 May 2003 18:14:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19JbgT-0006nT-RG for gnu-help-gnu-emacs@m.gmane.org; Sat, 24 May 2003 12:15:49 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!feed.news.nacamar.de!fu-berlin.de!uni-berlin.de!vegetable.demon.co.UK!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 81 Original-NNTP-Posting-Host: vegetable.demon.co.uk (80.177.16.3) Original-X-Trace: fu-berlin.de 1053792856 1894353 80.177.16.3 (16 [97657]) X-No-Yes: No Mail-Copies-To: nobody User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 Cancel-Lock: sha1:45I8kY/uaxfRnPAmGWjhadhF/dI= Original-Xref: shelby.stanford.edu gnu.emacs.help:113657 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:10153 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:10153 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