From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: Number of open buffers? Date: 20 Nov 2003 18:19:37 +0200 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: Reply-To: Eli Zaretskii NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1069345984 14946 80.91.224.253 (20 Nov 2003 16:33:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 20 Nov 2003 16:33:04 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 20 17:33:02 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AMrjp-0003qt-00 for ; Thu, 20 Nov 2003 17:33:01 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AMsXg-0005mV-PK for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Nov 2003 12:24:32 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AMsT3-0004Z0-Nb for help-gnu-emacs@gnu.org; Thu, 20 Nov 2003 12:19:45 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AMsSV-0004NM-UP for help-gnu-emacs@gnu.org; Thu, 20 Nov 2003 12:19:43 -0500 Original-Received: from [207.232.27.5] (helo=WST0054) by monty-python.gnu.org with asmtp (Exim 4.24) id 1AMsSU-0004Lh-GJ for help-gnu-emacs@gnu.org; Thu, 20 Nov 2003 12:19:11 -0500 Original-To: help-gnu-emacs@gnu.org In-reply-to: (message from Ignoramus1904 on 20 Nov 2003 15:12:12 GMT) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:14426 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:14426 > From: Ignoramus1904 > Newsgroups: gnu.emacs.help > Date: 20 Nov 2003 15:12:12 GMT > > Sometimes though I have just one file open for quick editing. Then I > do want to exit on \C-x\C-c. > > I want to modify it so that if the # of open file buffers is more than > one, emacs would ask YES/NO, if less, I exit. I am a very bad lisp > programmer, any suggestions? The expression (length (buffer-list)) will return the number of buffers in your Emacs session. You will need to make allowances for the minubuffer and buffers like *Messages* and *scratch* that are always present. There are usually 6 such buffers, so subtract 6 from what the expression above returns and compare it with 1. For a more bullet-proof code, walk the buffer list returned by the function buffer-list, and filter out any buffer which doesn't have a file associated with it (its buffer-file-name will be nil). What is left are the buffers which visit files. HTH