unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "Sebastien Vauban" <sva-news@mygooglest.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to know is a buffer is a temporary one?
Date: Mon, 29 Jul 2013 17:24:51 -0400	[thread overview]
Message-ID: <jwva9l5cbbl.fsf-monnier+INBOX@gnu.org> (raw)
In-Reply-To: <86fvuxf7vh.fsf@somewhere.org> (Sebastien Vauban's message of "Mon, 29 Jul 2013 22:06:58 +0200")

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



  parent reply	other threads:[~2013-07-29 21:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-29 15:26 How to know is a buffer is a temporary one? Sebastien Vauban
2013-07-29 16:19 ` Thorsten Jolitz
2013-07-29 18:34 ` Stefan Monnier
     [not found] ` <mailman.2054.1375122929.12400.help-gnu-emacs@gnu.org>
2013-07-29 19:00   ` Sebastien Vauban
2013-07-29 20:06     ` Sebastien Vauban
2013-07-29 21:09       ` Drew Adams
2013-07-29 21:24       ` Stefan Monnier [this message]
     [not found]       ` <mailman.2061.1375133109.12400.help-gnu-emacs@gnu.org>
     [not found]         ` <mailman.2061.1375133109.12400.help-gnu-emacs-mXXj517/zsQ@public.gmane.org>
2013-07-30  7:33           ` Sebastien Vauban
2013-07-30 13:26             ` Stefan Monnier
     [not found]             ` <mailman.2130.1375190796.12400.help-gnu-emacs@gnu.org>
     [not found]               ` <mailman.2130.1375190796.12400.help-gnu-emacs-mXXj517/zsQ@public.gmane.org>
2013-07-30 13:58                 ` Sebastien Vauban

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=jwva9l5cbbl.fsf-monnier+INBOX@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    --cc=sva-news@mygooglest.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).