From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Sebastien Vauban" Newsgroups: gmane.emacs.help Subject: Re: How to know is a buffer is a temporary one? Date: Tue, 30 Jul 2013 09:33:46 +0200 Organization: Sebastien Vauban Message-ID: <8661vszelh.fsf@somewhere.org> References: <86k3k975fj.fsf@somewhere.org> <861u6h42el.fsf@somewhere.org> <86fvuxf7vh.fsf@somewhere.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1375169938 14769 80.91.229.3 (30 Jul 2013 07:38:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 30 Jul 2013 07:38:58 +0000 (UTC) Cc: help-gnu-emacs-mXXj517/zsQ@public.gmane.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org-mXXj517/zsQ@public.gmane.org Tue Jul 30 09:39:00 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V44WH-0002fe-9h for geh-help-gnu-emacs@m.gmane.org; Tue, 30 Jul 2013 09:38:57 +0200 Original-Received: from localhost ([::1]:57723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V44WG-0003pi-Ha for geh-help-gnu-emacs@m.gmane.org; Tue, 30 Jul 2013 03:38:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V44Rc-0006Mw-Ag for help-gnu-emacs-mXXj517/zsQ@public.gmane.org; Tue, 30 Jul 2013 03:34:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V44RW-00072Y-A2 for help-gnu-emacs-mXXj517/zsQ@public.gmane.org; Tue, 30 Jul 2013 03:34:08 -0400 Original-Received: from dd5e0353a.access.telenet.be ([213.224.53.58]:8204 helo=mail.missioncriticalit.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V44RW-00072L-3F for help-gnu-emacs-mXXj517/zsQ@public.gmane.org; Tue, 30 Jul 2013 03:34:02 -0400 Original-Received: from MUNDANEUM. (unknown [10.10.10.51]) by mail.missioncriticalit.com (Postfix) with ESMTPS id 299485005D7; Tue, 30 Jul 2013 09:34:00 +0200 (CEST) X-Url: Under construction... X-Archive: encrypt In-Reply-To: (Stefan Monnier's message of "Mon, 29 Jul 2013 17:24:51 -0400") User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.3 (windows-nt) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 213.224.53.58 X-BeenThere: help-gnu-emacs-mXXj517/zsQ@public.gmane.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org-mXXj517/zsQ@public.gmane.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org-mXXj517/zsQ@public.gmane.org Xref: news.gmane.org gmane.emacs.help:92530 Archived-At: 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 > 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