From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: How to know is a buffer is a temporary one? Date: Mon, 29 Jul 2013 17:24:51 -0400 Message-ID: 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 1375133128 23741 80.91.229.3 (29 Jul 2013 21:25:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 29 Jul 2013 21:25:28 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Sebastien Vauban" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 29 23:25:28 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 1V3uwU-0004SH-PX for geh-help-gnu-emacs@m.gmane.org; Mon, 29 Jul 2013 23:25:22 +0200 Original-Received: from localhost ([::1]:44828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3uwT-0004SM-LG for geh-help-gnu-emacs@m.gmane.org; Mon, 29 Jul 2013 17:25:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3uw8-0004Nr-UM for help-gnu-emacs@gnu.org; Mon, 29 Jul 2013 17:25:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3uw1-00009g-7j for help-gnu-emacs@gnu.org; Mon, 29 Jul 2013 17:25:00 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:14339) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3uw1-00009Z-2T for help-gnu-emacs@gnu.org; Mon, 29 Jul 2013 17:24:53 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EABK/CFHO+LI//2dsb2JhbABEvw4Xc4IeAQEEAVYjEAsOJhIUGA0kiB4GwS2RCgOkeoFegxOBSiQ X-IPAS-Result: Av4EABK/CFHO+LI//2dsb2JhbABEvw4Xc4IeAQEEAVYjEAsOJhIUGA0kiB4GwS2RCgOkeoFegxOBSiQ X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="20114480" Original-Received: from 206-248-178-63.dsl.teksavvy.com (HELO pastel.home) ([206.248.178.63]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 29 Jul 2013 17:24:45 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id D4DF663C70; Mon, 29 Jul 2013 17:24:51 -0400 (EDT) In-Reply-To: <86fvuxf7vh.fsf@somewhere.org> (Sebastien Vauban's message of "Mon, 29 Jul 2013 22:06:58 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 X-BeenThere: help-gnu-emacs@gnu.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@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:92521 Archived-At: >> 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 t) is a better test. Sometimes, testing (listp buffer-undo-list) may also be a good idea. Stefan