From: Matthew Flaschen <matthew.flaschen@gatech.edu>
To: emacs <help-gnu-emacs@gnu.org>
Subject: Re: save-buffer like save-excursion
Date: Sun, 18 Mar 2007 05:56:39 -0400 [thread overview]
Message-ID: <45FD0CD7.8030206@gatech.edu> (raw)
In-Reply-To: <pcofy82j477.fsf@shuttle.math.ntnu.no>
Harald Hanche-Olsen wrote:
> + Matthew Flaschen <matthew.flaschen@gatech.edu>:
>
> | 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?
I think so. set-buffer doesn't change the UI, only the working buffer.
Even if a function does set-buffer, at
> the end of an interactive command you are back in the buffer you had.
Right...but I'd like to preserve the buffer within interactive commands.
> 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
Right, thanks. I'll probably use something similar, or just do it
manually (depending on how often it's necessary). I might also be able
to avoid the issue neatly just by calling set-buffer again in the client
code. I was just wondering if there was already something, so I
wouldn't be wasting my time.
> The unwind-protect in there is not necessary in the case where an
> error brings you back to the interactive top-level.
I think that's the case for me. But I won't have any errors anyway! My
code is tested. ;)
Matt Flaschen
next prev parent reply other threads:[~2007-03-18 9:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1069.1174204758.7795.help-gnu-emacs@gnu.org>
2007-03-18 9:23 ` save-buffer like save-excursion Harald Hanche-Olsen
2007-03-18 9:56 ` Matthew Flaschen [this message]
2007-03-19 3:54 ` Stefan Monnier
2007-03-19 5:30 ` Matthew Flaschen
2007-03-19 7:33 ` Harald Hanche-Olsen
2007-03-19 21:36 ` Matthew Flaschen
[not found] ` <mailman.1132.1174340311.7795.help-gnu-emacs@gnu.org>
2007-03-21 19:42 ` Stefan Monnier
2007-03-23 1:35 ` Matthew Flaschen
2007-03-18 7:57 Matthew Flaschen
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=45FD0CD7.8030206@gatech.edu \
--to=matthew.flaschen@gatech.edu \
--cc=help-gnu-emacs@gnu.org \
/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).