From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: torys.anderson@gmail.com (Tory S. Anderson) Newsgroups: gmane.emacs.help Subject: RE: If arg, open in new frame Date: Wed, 10 Sep 2014 08:02:30 -0400 Message-ID: <877g1bel9l.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1410350593 16406 80.91.229.3 (10 Sep 2014 12:03:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Sep 2014 12:03:13 +0000 (UTC) To: embe8573@student.uu.se, emacs list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 10 14:03:06 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 1XRgc5-0001i2-4k for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Sep 2014 14:03:05 +0200 Original-Received: from localhost ([::1]:55688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRgc4-0000Nl-Oo for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Sep 2014 08:03:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRgbe-0008UX-OE for help-gnu-emacs@gnu.org; Wed, 10 Sep 2014 08:02:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRgbZ-0006fh-QR for help-gnu-emacs@gnu.org; Wed, 10 Sep 2014 08:02:38 -0400 Original-Received: from mail-yk0-x231.google.com ([2607:f8b0:4002:c07::231]:51837) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRgbZ-0006fd-MF for help-gnu-emacs@gnu.org; Wed, 10 Sep 2014 08:02:33 -0400 Original-Received: by mail-yk0-f177.google.com with SMTP id 79so3767939ykr.8 for ; Wed, 10 Sep 2014 05:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; bh=wpoCJNJZTLg4E6nDETcvbYCSfj66JuzmYcUzBc6IZrk=; b=C8mWJaRCuH0YsGYuyhCykpRTq62JD23NR9CpHr0etIbXN4qXaRCn6md1VNaJi6e752 AtpOuhiyvGxGwzGwAEEqQKqIdddXJ8/XV2S137CRMUuCErULnjCkBajJv/e27XsEquen /eAmtJG1hf9KfK/zed0AQxZis+VJDykB/xMFlUFZhQKZybfWksh1u+ERasYuO6KYX2LP Krojif+GlYB9UzAOS+MG7hyONqLVZYq+oVY9HB7OBEkoCpw3kCAe++pmoUFTt8FILWTf mIYshPZIxOY6YboAkoxFsP+4Oj/XHPRaah/x3c4y4D0mGTDi1su744ph2UoifJorp3QV QLlg== X-Received: by 10.236.115.103 with SMTP id d67mr62687391yhh.46.1410350553192; Wed, 10 Sep 2014 05:02:33 -0700 (PDT) Original-Received: from localhost.localdomain ([2601:0:a000:4a1:ee55:f9ff:feb5:5589]) by mx.google.com with ESMTPSA id k67sm6804677yhq.17.2014.09.10.05.02.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Sep 2014 05:02:31 -0700 (PDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4002:c07::231 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:99775 Archived-At: So, that half answered my question: thanks for showing me how to use optional args. My function is now: (defun go-or-make-agenda (&optional new-frame) (interactive "P") (let ((buffer "\*Org Agenda\*")) (if (get-buffer buffer) (switch-to-buffer buffer) (org-agenda-list)))) But I actually don't know how to open this in a new frame. I guess I should have given my more specific use case: I use this function to check my calendar. Sometimes, I want to do that without losing what I have open right now (especially when I'm reading an email in Gnus that asks me about an appointment). Right now I have to respond with, `C-x 5 2 M-x go-or-make-agenda` (the function actually being bound to ). I'd like to shorten this effort to just doing `C-u `. Google is not readily serving me for how to open in another frame in elisp. >Date: Wed, 10 Sep 2014 00:44:20 +0200 >From: Emanuel Berg >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 >