From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Harald Hanche-Olsen Newsgroups: gmane.emacs.help Subject: Re: save-buffer like save-excursion Date: Sun, 18 Mar 2007 10:23:08 +0100 Organization: Norwegian university of science and technology Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1174210746 7078 80.91.229.12 (18 Mar 2007 09:39:06 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 18 Mar 2007 09:39:06 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 18 10:38:58 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HSrqr-0002H8-24 for geh-help-gnu-emacs@m.gmane.org; Sun, 18 Mar 2007 10:38:57 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HSrsC-0004Gx-0g for geh-help-gnu-emacs@m.gmane.org; Sun, 18 Mar 2007 04:40:20 -0500 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!news.tiscali.de!uio.no!ntnu.no!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 40 Original-NNTP-Posting-Host: fiinbeck.math.ntnu.no Original-X-Trace: orkan.itea.ntnu.no 1174208818 7292 129.241.15.140 (18 Mar 2007 09:06:58 GMT) Original-X-Complaints-To: usenet@itea.ntnu.no Original-NNTP-Posting-Date: Sun, 18 Mar 2007 09:06:58 +0000 (UTC) User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.0 (berkeley-unix) Cancel-Lock: sha1:igqVQtly4ainXztCFZVpTRj/jc8= Original-Xref: shelby.stanford.edu gnu.emacs.help:146432 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:42036 Archived-At: + Matthew Flaschen : | Is there a command like save-excursion that only saves the buffer? I | have several functions that must set-buffer temporarily, then do things | that change point. I always want these point changes, but if set-buffer | changed the buffer (not necessarily true), I want to reverse that change. | | So, is there already a command for this? You are aware of the difference between set-buffer and swith-to-buffer, I presume? Even if a function does set-buffer, at the end of an interactive command you are back in the buffer you had. So there may not be a need to do what you want at all. On the other hand, if you want to temporarily change the buffer within a function, you can use macro like this one: (defmacro with-saved-buffer (&rest command) (let ((cur (make-symbol "cur"))) `(let ((,cur (current-buffer))) (unwind-protect (progn ,@command) (set-buffer ,cur))))) and use it like (with-saved-buffer (set-buffer "blah") ...) ;; here, the buffer is back to what it was The unwind-protect in there is not necessary in the case where an error brings you back to the interactive top-level. But if your code performs a non-local exit for some reason, it's essential. -- * Harald Hanche-Olsen - It is undesirable to believe a proposition when there is no ground whatsoever for supposing it is true. -- Bertrand Russell