From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: If arg, open in new frame Date: Wed, 10 Sep 2014 00:44:20 +0200 Organization: Aioe.org NNTP Server Message-ID: <87sik0wh17.fsf@debian.uxu> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1410302736 22082 80.91.229.3 (9 Sep 2014 22:45:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 9 Sep 2014 22:45:36 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 10 00:45:29 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XRUAC-00032C-Jj for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Sep 2014 00:45:28 +0200 Original-Received: from localhost ([::1]:52236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRUAC-0003If-9j for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Sep 2014 18:45:28 -0400 Original-Path: usenet.stanford.edu!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 40 Original-NNTP-Posting-Host: P0uMB9BthHuWo8+BJXB4Mw.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:gIaPuWo2WsjWjMbHPJUcup0oO2s= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:207480 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:99755 Archived-At: torys.anderson@gmail.com (Tory S. Anderson) writes: > I have a function that checks for a buffer and either > switches to it or creates it. I want it to optionally > take an arg, and if an arg is supplied, open/find > said buffer in a new frame. My elisp-fu is still > young; can you help? > > Function: > > (defun go-or-make-agenda () (interactive) > (if (get-buffer "\*Org Agenda\*") > (switch-to-buffer "\*Org Agenda\*") > (org-agenda-list))) Hint: As the data "\*Org Agenda\*" appears twice, put that in a `let' and have it appear once, then use the `let' binding all you want. As for your question, I think you can solve the frame stuff (I didn't exactly understand your motive but it doesn't matter), but take a look below for an optional (prefix) argument. Then just put it together. (defun go-or-make-agenda (&optional new-frame) (interactive "P") (if new-frame (message "frame") (message "no frame") )) ;; from Elisp (go-or-make-agenda) ; no frame (go-or-make-agenda nil) ; no frame (go-or-make-agenda t) ; frame ;; interactively M-x go-or-make-agenda RET ; no frame C-u M-x go-or-make-agenda RET ; frame -- underground experts united