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

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

Re: How to know is a buffer is a temporary one?


From: Stefan Monnier
Subject: Re: How to know is a buffer is a temporary one?
Date: Mon, 29 Jul 2013 17:24:51 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

>> Maybe you're better off trying to define "useful buffer" for your
>> particular case.  E.g. maybe check `buffer-file-name'.
> Then a version checking with a regexp seems slightly more efficient
> (1.19 s vs 1.14 s) than the one checking the name with a substring:

> ;; (while (< i 1000)
> ;;   (message "%s" i)
> ;;   (if (equal (substring (buffer-name) 0 2) " *")
> ;;       (message "this is a temp buffer")
> ;;     (message "this is not a temp buffer"))
> ;;   (setq i (+ i 1)))

should be

   (while (< i 1000)
     (message "%s" i)
     (message (if (eq (aref (buffer-name) 0) ?\s)
         "this is a temp buffer"
       "this is not a temp buffer"))
     (setq i (+ i 1)))

Note that some buffers that start with " *" are shown to the user.
So, the notion of temporary/internal depends on the particular situation
(which is why it's not formally defined).  In some cases
buffer-file-name is a good test, in other cases (get-buffer-window <buf>
t) is a better test.

Sometimes, testing (listp buffer-undo-list) may also be a good idea.


        Stefan



reply via email to

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