From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Micah Cowan Newsgroups: gmane.emacs.help Subject: Re: Number of open buffers? Date: 20 Nov 2003 10:10:17 -0800 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1069352300 31511 80.91.224.253 (20 Nov 2003 18:18:20 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 20 Nov 2003 18:18:20 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 20 19:18:16 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 1AMtNg-0003b5-00 for ; Thu, 20 Nov 2003 19:18:16 +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 1AMuI1-0002mD-Pb for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Nov 2003 14:16:29 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!washdc3-snh1.gtei.net!news.gtei.net!ngpeer.news.aol.com!feed2.newsreader.com!newsreader.com!newshosting.com!news-xfer2.atl.newshosting.com!posted2.newshosting.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Original-Lines: 60 Original-NNTP-Posting-Host: d9db00e1.news.calweb.com Original-X-Trace: DXC=Td`9<:L3X57gYX5fdemc0d9E82ZEiPM:GhdERAfY; >7:a; Z; SX; a^>iPjN6aM_lh? Original-X-Complaints-To: abuse@calweb.com Original-Xref: shelby.stanford.edu gnu.emacs.help:118493 Original-To: help-gnu-emacs@gnu.org 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:14434 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:14434 Ignoramus1904 writes: > In article , Eli Zaretskii wrote: > >> 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. I seem to get more than 6. YMMV, I think, so it can't be relied upon. > > > > 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 > > > > > > > > Thanks Eli, sounds a little bit above my head to be honest. I do C++ > and Perl and do not know Lisp well. I just thought that there was a > function like get-number-of-file-buffers, or something like that. The following is what he's talking about, I think: (defun get-number-of-file-buffers () (interactive) (let (num) (setq num 0) (dolist (buf (buffer-list)) (when (buffer-file-name buf) (setq num (+ num 1)) )) num ) ) Another possibility would be to have an alias to one or other emacs that invokes emacs in the way you want (with or without the "are you sure?" stuff): then just use one name for emacs when you don't want to be asked, and another for when you do. -- Micah J. Cowan micah@cowan.name