[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: check to see if a buffer with a certain name exists?
From: |
Nikolaj Schumacher |
Subject: |
Re: check to see if a buffer with a certain name exists? |
Date: |
Thu, 13 Nov 2008 20:50:14 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2.50 (darwin) |
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