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: David Kastrup
Subject: Re: Number of open buffers?
Date: 20 Nov 2003 22:15:14 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Ignoramus1904 <address@hidden> writes:

> In article <address@hidden>, Micah Cowan wrote:
> > Ignoramus1904 <address@hidden> writes:
> > 
> >> Eli Zaretskii wrote:
> >> >> From: Ignoramus1904 <address@hidden>
> >> >> 
> >> >> 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?
> >> > 
> >> > 
> >> > 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.
> >> > 
> >> 
> >> 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
> >     )
> >   )

Somewhat shorter:

(defun get-number-of-file-buffers ()
  (interactive)
  (let ((num 0))
    (dolist (buf (buffer-list) num)
      (when (buffer-file-name buf)
          (setq num (1+ num))))))

> Thanks. When I try to run it via eval-expr, saying
> 
> (insert get-number-of-file-buffers)
> 
> It says: Error: void-variable. Data: get-number-of-file-buffers

Yes.  One calls a function by putting it after an opening
parenthesis.  The way you tried to "call" it, just a variable of that
name got referenced, and there is no such variable.  In addition, the
function returns a numeric expression, and `insert' expects a string.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum


reply via email to

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