* If arg, open in new frame
@ 2014-09-09 21:48 Tory S. Anderson
0 siblings, 0 replies; 6+ messages in thread
From: Tory S. Anderson @ 2014-09-09 21:48 UTC (permalink / raw)
To: emacs list
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)))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: If arg, open in new frame
[not found] <mailman.8567.1410299333.1147.help-gnu-emacs@gnu.org>
@ 2014-09-09 22:44 ` Emanuel Berg
0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2014-09-09 22:44 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: If arg, open in new frame
@ 2014-09-10 12:02 Tory S. Anderson
0 siblings, 0 replies; 6+ messages in thread
From: Tory S. Anderson @ 2014-09-10 12:02 UTC (permalink / raw)
To: embe8573, emacs list
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 <F8>). I'd like to shorten this effort to just doing `C-u <F8>`. 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 <embe8573@student.uu.se>
>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
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: If arg, open in new frame
[not found] <mailman.8608.1410350561.1147.help-gnu-emacs@gnu.org>
@ 2014-09-10 22:09 ` Emanuel Berg
2014-09-11 3:28 ` Rusi
1 sibling, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2014-09-10 22:09 UTC (permalink / raw)
To: help-gnu-emacs
torys.anderson@gmail.com (Tory S. Anderson) writes:
> 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
Try these:
M-x apropos RET frame RET
or (to get only interactive functions, or commands)
M-x apropos-command RET frame RET
--
underground experts united
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: If arg, open in new frame
[not found] <mailman.8608.1410350561.1147.help-gnu-emacs@gnu.org>
2014-09-10 22:09 ` If arg, open in new frame Emanuel Berg
@ 2014-09-11 3:28 ` Rusi
2014-09-11 10:58 ` Tory S. Anderson
1 sibling, 1 reply; 6+ messages in thread
From: Rusi @ 2014-09-11 3:28 UTC (permalink / raw)
To: help-gnu-emacs
On Wednesday, September 10, 2014 5:32:30 PM UTC+5:30, Tory S. Anderson wrote:
> 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))))
Does this help?
(defun go-or-make-agenda (&optional new-frame)
(interactive "P")
(let ((buffer "\*Org Agenda\*"))
(if (get-buffer buffer)
(if new-frame
(switch-to-buffer-other-frame buffer)
(switch-to-buffer buffer))
(org-agenda-list))))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: If arg, open in new frame
2014-09-11 3:28 ` Rusi
@ 2014-09-11 10:58 ` Tory S. Anderson
0 siblings, 0 replies; 6+ messages in thread
From: Tory S. Anderson @ 2014-09-11 10:58 UTC (permalink / raw)
To: Rusi; +Cc: help-gnu-emacs
Almost perfect! Thanks! One case is missed in your code: if buffer does not yet exist, it cannot be opened in a new frame. I tried this to no avail:
(defun go-or-make-agenda (&optional new-frame)
(interactive "P")
(let ((buffer "\*Org Agenda\*"))
(if (get-buffer buffer)
(if new-frame
(switch-to-buffer-other-frame buffer)
(switch-to-buffer buffer))
(if new-frame
(switch-to-buffer-other-frame org-agenda-list) ;; not a buffer
(org-agenda-list)))))
With all this switch-to-buffer redundancy, what I'd REALLY like to do is conditionally bind the function to a variable based on (if new-frame) but I'll make that a new thread.
So now, How can I run org-agenda-list in a new frame if buffer does not exist?
Thanks
Rusi <rustompmody@gmail.com> writes:
> On Wednesday, September 10, 2014 5:32:30 PM UTC+5:30, Tory S. Anderson wrote:
>> 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))))
>
> Does this help?
>
> (defun go-or-make-agenda (&optional new-frame)
> (interactive "P")
> (let ((buffer "\*Org Agenda\*"))
> (if (get-buffer buffer)
> (if new-frame
> (switch-to-buffer-other-frame buffer)
> (switch-to-buffer buffer))
> (org-agenda-list))))
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-09-11 10:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.8608.1410350561.1147.help-gnu-emacs@gnu.org>
2014-09-10 22:09 ` If arg, open in new frame Emanuel Berg
2014-09-11 3:28 ` Rusi
2014-09-11 10:58 ` Tory S. Anderson
2014-09-10 12:02 Tory S. Anderson
[not found] <mailman.8567.1410299333.1147.help-gnu-emacs@gnu.org>
2014-09-09 22:44 ` Emanuel Berg
-- strict thread matches above, loose matches on Subject: below --
2014-09-09 21:48 Tory S. Anderson
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).