From: Ian Eure <ian@digg.com>
To: Nikolaj Schumacher <me@nschum.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: check to see if a buffer with a certain name exists?
Date: Thu, 13 Nov 2008 13:03:10 -0800 [thread overview]
Message-ID: <3378953B-B3C3-47E1-B519-1685121B868F@digg.com> (raw)
In-Reply-To: <m21vxfjthl.fsf@nschum.de>
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
next prev parent reply other threads:[~2008-11-13 21:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2008-11-14 15:38 ` Matt Price
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3378953B-B3C3-47E1-B519-1685121B868F@digg.com \
--to=ian@digg.com \
--cc=help-gnu-emacs@gnu.org \
--cc=me@nschum.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.