From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: check to see if a buffer with a certain name exists? Date: Thu, 13 Nov 2008 20:50:14 +0100 Message-ID: References: <1226590775.8767.2137.camel@localhost> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1226606105 20068 80.91.229.12 (13 Nov 2008 19:55:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Nov 2008 19:55:05 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Matt Price Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 13 20:56:08 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L0iIP-0005nD-R4 for geh-help-gnu-emacs@m.gmane.org; Thu, 13 Nov 2008 20:56:06 +0100 Original-Received: from localhost ([127.0.0.1]:46702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L0iHH-0007el-T0 for geh-help-gnu-emacs@m.gmane.org; Thu, 13 Nov 2008 14:54:55 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L0iCm-0006WH-Mo for help-gnu-emacs@gnu.org; Thu, 13 Nov 2008 14:50:16 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L0iCm-0006Vy-6T for help-gnu-emacs@gnu.org; Thu, 13 Nov 2008 14:50:16 -0500 Original-Received: from [199.232.76.173] (port=44077 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L0iCl-0006Vo-Vr for help-gnu-emacs@gnu.org; Thu, 13 Nov 2008 14:50:16 -0500 Original-Received: from dd18200.kasserver.com ([85.13.138.168]:54907) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L0iCl-0008Rg-NS for help-gnu-emacs@gnu.org; Thu, 13 Nov 2008 14:50:15 -0500 Original-Received: from thursday (dslb-084-057-156-237.pools.arcor-ip.net [84.57.156.237]) by dd18200.kasserver.com (Postfix) with ESMTP id D33D21802F49B; Thu, 13 Nov 2008 20:50:19 +0100 (CET) In-Reply-To: <1226590775.8767.2137.camel@localhost> (Matt Price's message of "Thu\, 13 Nov 2008 10\:39\:35 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2.50 (darwin) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:59758 Archived-At: Matt Price 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