all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Micah Cowan <micah@cowan.name>
Subject: Re: Number of open buffers?
Date: 20 Nov 2003 10:10:17 -0800	[thread overview]
Message-ID: <m31xs2c3na.fsf@localhost.localdomain> (raw)
In-Reply-To: bpirf4$8ee$2@pita.alt.net

Ignoramus1904 <ignoramus1904@NOSPAM.1904.invalid> writes:

> In article <mailman.342.1069348789.399.help-gnu-emacs@gnu.org>, Eli Zaretskii wrote:
> >> 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.

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

  parent reply	other threads:[~2003-11-20 18:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bpilkc$pq1$0@pita.alt.net>
2003-11-20 16:19 ` Number of open buffers? Eli Zaretskii
     [not found] ` <mailman.342.1069348789.399.help-gnu-emacs@gnu.org>
     [not found]   ` <bpirf4$8ee$2@pita.alt.net>
2003-11-20 18:10     ` Micah Cowan [this message]
     [not found]       ` <bpja4e$89m$1@pita.alt.net>
2003-11-20 21:15         ` David Kastrup
2003-11-20 21:50           ` lawrence mitchell
2003-11-20 22:14             ` David Kastrup
2003-11-20 22:46               ` lawrence mitchell
2003-11-20 23:40                 ` David Kastrup
2003-11-20 22:42           ` Johan Bockgård
2003-11-20 21:43         ` Lucas
     [not found]         ` <mailman.369.1069368465.399.help-gnu-emacs@gnu.org>
     [not found]           ` <bplam3$nrj$1@pita.alt.net>
2003-11-21 15:36             ` David Kastrup
2003-11-21 15:52           ` Stefan Monnier
2003-11-21 20:21             ` Lucas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m31xs2c3na.fsf@localhost.localdomain \
    --to=micah@cowan.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.