* check to see if a buffer with a certain name exists?
@ 2008-11-13 15:39 Matt Price
2008-11-13 16:45 ` Drew Adams
2008-11-13 19:50 ` Nikolaj Schumacher
0 siblings, 2 replies; 6+ messages in thread
From: Matt Price @ 2008-11-13 15:39 UTC (permalink / raw
To: help-gnu-emacs
hi folks,
first thanks to everyone who's answered my question about mail, i'm
going to be back to that in a second.
but in the meantime: i want to be able to check if there's a buffer
open named *Mutt* . what's the best way to do this? in python, for
instance, i would just say:
if "*Mutt*" in buffer-list :
return true
else :
return false
in lisp i'm not seeing a quick way to test for something like this.
best i can see right now is to use dolist thus:
(dolist (name (buffer-list) foundit)
(let ((foundit 0))
(if (string-match "*scratch*" name)
(setq foundit 1))
)
)
which isn't quite right, i have a variabletype mismatch. i'd love some
help -- still having trouble navigating the documentation... thanks
again,
matt
--
Matt Price
matt.price@utoronto.ca
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: check to see if a buffer with a certain name exists?
2008-11-13 15:39 check to see if a buffer with a certain name exists? Matt Price
@ 2008-11-13 16:45 ` Drew Adams
2008-11-14 15:35 ` Matt Price
2008-11-13 19:50 ` Nikolaj Schumacher
1 sibling, 1 reply; 6+ messages in thread
From: Drew Adams @ 2008-11-13 16:45 UTC (permalink / raw
To: 'Matt Price', help-gnu-emacs
> i want to be able to check if there's a buffer
> open named *Mutt* . what's the best way to do this? in python, for
> instance, i would just say:
> if "*Mutt*" in buffer-list : return true else : return false
> in lisp i'm not seeing a quick way to test for something like this.
C-h f get-buffer
(get-buffer "*Mutt*")
The Elisp manual is your friend. In the manual, `i buffer RET' takes you to the
Buffers chapter. Buffer Names in the menu there shows you this:
Function: get-buffer buffer-or-name
This function returns the buffer specified by BUFFER-OR-NAME. If
BUFFER-OR-NAME is a string and there is no buffer with that name,
the value is `nil'. If BUFFER-OR-NAME is a buffer, it is returned
as given; that is not very useful, so the argument is usually a
name. For example:
(setq b (get-buffer "lewis"))
=> #<buffer lewis>
(get-buffer b)
=> #<buffer lewis>
(get-buffer "Frazzle-nots")
=> nil
See also the function `get-buffer-create' in *note Creating
Buffers::.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: check to see if a buffer with a certain name exists?
2008-11-13 16:45 ` Drew Adams
@ 2008-11-14 15:35 ` Matt Price
0 siblings, 0 replies; 6+ messages in thread
From: Matt Price @ 2008-11-14 15:35 UTC (permalink / raw
To: Drew Adams; +Cc: help-gnu-emacs
On Thu, 2008-11-13 at 08:45 -0800, Drew Adams wrote:
> > i want to be able to check if there's a buffer
> > open named *Mutt* . what's the best way to do this? in python, for
> > instance, i would just say:
> > if "*Mutt*" in buffer-list : return true else : return false
> > in lisp i'm not seeing a quick way to test for something like this.
>
> C-h f get-buffer
>
> (get-buffer "*Mutt*")
>
> The Elisp manual is your friend. In the manual, `i buffer RET' takes you to the
> Buffers chapter. Buffer Names in the menu there shows you this:
>
> Function: get-buffer buffer-or-name
> This function returns the buffer specified by BUFFER-OR-NAME. If
> BUFFER-OR-NAME is a string and there is no buffer with that name,
> the value is `nil'. If BUFFER-OR-NAME is a buffer, it is returned
> as given; that is not very useful, so the argument is usually a
> name. For example:
>
> (setq b (get-buffer "lewis"))
> => #<buffer lewis>
> (get-buffer b)
> => #<buffer lewis>
> (get-buffer "Frazzle-nots")
> => nil
>
> See also the function `get-buffer-create' in *note Creating
> Buffers::.
>
thanks Drew! i am still getting used to info, thanks. i had looked up
buffers inthe online manual but missed get-buffer, clearly it's exactly
what i'm looking for, thanks again!
matt
--
Matt Price
matt.price@utoronto.ca
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: check to see if a buffer with a certain name exists?
2008-11-13 15:39 check to see if a buffer with a certain name exists? Matt Price
2008-11-13 16:45 ` Drew Adams
@ 2008-11-13 19:50 ` Nikolaj Schumacher
2008-11-13 21:03 ` Ian Eure
2008-11-14 15:38 ` Matt Price
1 sibling, 2 replies; 6+ messages in thread
From: Nikolaj Schumacher @ 2008-11-13 19:50 UTC (permalink / raw
To: Matt Price; +Cc: help-gnu-emacs
Matt Price <matt.price@utoronto.ca> wrote:
> in lisp i'm not seeing a quick way to test for something like this.
> best i can see right now is to use dolist thus:
>
> (dolist (name (buffer-list) foundit)
> (let ((foundit 0))
> (if (string-match "*scratch*" name)
> (setq foundit 1))
> )
> )
Drew already gave you the cleaner way. Let me also tell you, why yours
is not working.
First, you bind foundit inside the `dolist' body. The value is lost when
the `let' block exits, and the variable is undefined.
Second, `buffer-list' returns buffer "objects", not strings.
Here's how it would work:
(let ((foundit 0))
(dolist (name (buffer-list) foundit)
(if (string-match "*scratch*" (buffer-name name))
(setq foundit 1))))
Or the Awesome Lisp Way(TM):
(member "*scratch*" (mapcar 'buffer-name (buffer-list)))
regards,
Nikolaj Schumacher
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: check to see if a buffer with a certain name exists?
2008-11-13 19:50 ` Nikolaj Schumacher
@ 2008-11-13 21:03 ` Ian Eure
2008-11-14 15:38 ` Matt Price
1 sibling, 0 replies; 6+ messages in thread
From: Ian Eure @ 2008-11-13 21:03 UTC (permalink / raw
To: Nikolaj Schumacher; +Cc: help-gnu-emacs
On Nov 13, 2008, at 11:50 AM, Nikolaj Schumacher wrote:
> Matt Price <matt.price@utoronto.ca> wrote:
>
>> in lisp i'm not seeing a quick way to test for something like this.
>> best i can see right now is to use dolist thus:
>>
>> (dolist (name (buffer-list) foundit)
>> (let ((foundit 0))
>> (if (string-match "*scratch*" name)
>> (setq foundit 1))
>> )
>> )
>
> Drew already gave you the cleaner way. Let me also tell you, why
> yours
> is not working.
>
> First, you bind foundit inside the `dolist' body. The value is lost
> when
> the `let' block exits, and the variable is undefined.
>
> Second, `buffer-list' returns buffer "objects", not strings.
>
> Here's how it would work:
>
> (let ((foundit 0))
> (dolist (name (buffer-list) foundit)
> (if (string-match "*scratch*" (buffer-name name))
> (setq foundit 1))))
>
> Or the Awesome Lisp Way(TM):
>
> (member "*scratch*" (mapcar 'buffer-name (buffer-list)))
>
Is there something wrong with:
(get-buffer "*Mutt*")
...which returns the #buffer object?
Or if you really care about t/nil, you can do:
(bufferp (get-buffer "*Mutt*"))
- Ian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: check to see if a buffer with a certain name exists?
2008-11-13 19:50 ` Nikolaj Schumacher
2008-11-13 21:03 ` Ian Eure
@ 2008-11-14 15:38 ` Matt Price
1 sibling, 0 replies; 6+ messages in thread
From: Matt Price @ 2008-11-14 15:38 UTC (permalink / raw
To: Nikolaj Schumacher; +Cc: help-gnu-emacs
On Thu, 2008-11-13 at 20:50 +0100, Nikolaj Schumacher wrote:
> (member "*scratch*" (mapcar 'buffer-name (buffer-list)))
wow, i really like the Awesome LISP Way (TM). thanks for the debugging
help...
matt
--
Matt Price
matt.price@utoronto.ca
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-11-14 15:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-13 15:39 check to see if a buffer with a certain name exists? Matt Price
2008-11-13 16:45 ` Drew Adams
2008-11-14 15:35 ` Matt Price
2008-11-13 19:50 ` Nikolaj Schumacher
2008-11-13 21:03 ` Ian Eure
2008-11-14 15:38 ` Matt Price
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.