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)))