Get the number of buffers in Emacs

How to get the current number of buffers, excluding internal buffers, in Emacs?

I have it, but it looks confusing

;; number of buffers excluding internal buffers                                 
(apply '+ (mapcar
           (lambda (b)
             (if (or (buffer-file-name b)
                     (not (string-equal (substring (buffer-name b) 0 1) " ")))
                 1 0))
           (buffer-list)))

What he does is count the buffers that either visit the file, or the name does not start with a space.

I just want to add the number of buffers to the frame header.

+4
source share
1 answer

I don't know any function that does this, but here is your code simplified:

(cl-count-if
 (lambda (b)
   (or (buffer-file-name b)
       (not (string-match "^ " (buffer-name b)))))
 (buffer-list))
+6
source

All Articles