help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Number of open buffers?


From: Eli Zaretskii
Subject: Re: Number of open buffers?
Date: 20 Nov 2003 18:19:37 +0200

> From: Ignoramus1904 <ignoramus1904@NOSPAM.1904.invalid>
> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]