From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian Eure Newsgroups: gmane.emacs.help Subject: Re: check to see if a buffer with a certain name exists? Date: Thu, 13 Nov 2008 13:03:10 -0800 Message-ID: <3378953B-B3C3-47E1-B519-1685121B868F@digg.com> References: <1226590775.8767.2137.camel@localhost> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v929.2) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1226610300 2271 80.91.229.12 (13 Nov 2008 21:05:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Nov 2008 21:05:00 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Nikolaj Schumacher Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 13 22:06:02 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 1L0jNj-0007KX-Fw for geh-help-gnu-emacs@m.gmane.org; Thu, 13 Nov 2008 22:05:52 +0100 Original-Received: from localhost ([127.0.0.1]:53134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L0jMb-0004a5-Fy for geh-help-gnu-emacs@m.gmane.org; Thu, 13 Nov 2008 16:04:29 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L0jLO-0003q2-LY for help-gnu-emacs@gnu.org; Thu, 13 Nov 2008 16:03:14 -0500 Original-Received: from [199.232.76.173] (port=55284 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L0jLN-0003ov-CM for help-gnu-emacs@gnu.org; Thu, 13 Nov 2008 16:03:13 -0500 Original-Received: from mail.digg.com ([64.191.203.36]:60070) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L0jLM-0006Ug-Ri for help-gnu-emacs@gnu.org; Thu, 13 Nov 2008 16:03:13 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.digg.com (Postfix) with ESMTP id 35E43A85068; Thu, 13 Nov 2008 13:03:12 -0800 (PST) X-Virus-Scanned: amavisd-new at X-Spam-Score: -4.547 Original-Received: from mail.digg.com ([127.0.0.1]) by localhost (mail.digg.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SEdkF02Japla; Thu, 13 Nov 2008 13:03:11 -0800 (PST) Original-Received: from [10.2.16.90] (diggstage01.digg.com [64.191.203.34]) by mail.digg.com (Postfix) with ESMTP id 741A0A850C7; Thu, 13 Nov 2008 13:03:11 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.929.2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) 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:59761 Archived-At: On Nov 13, 2008, at 11:50 AM, Nikolaj Schumacher wrote: > 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))) > 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