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: Sebastien Vauban
Subject: Re: How to know is a buffer is a temporary one?
Date: Tue, 30 Jul 2013 09:33:46 +0200
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.3 (windows-nt)

Stefan Monnier wrote:
>>> 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)))

Performance-wise, both versions are equal (1.19s). Still slightly behind the
`string-match' version (1.14s).

Why are you saying that that version somehow better is? Was it for perf
reasons, or for other reasons? I'm asking because I want to learn more...

> 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.

Thanks for the extra info!

Best regards,
  Seb

-- 
Sebastien Vauban



reply via email to

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