* save-buffer like save-excursion
@ 2007-03-18 7:57 Matthew Flaschen
0 siblings, 0 replies; 9+ messages in thread
From: Matthew Flaschen @ 2007-03-18 7:57 UTC (permalink / raw)
To: emacs
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?
Matt Flaschen
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: save-buffer like save-excursion
[not found] <mailman.1069.1174204758.7795.help-gnu-emacs@gnu.org>
@ 2007-03-18 9:23 ` Harald Hanche-Olsen
2007-03-18 9:56 ` Matthew Flaschen
2007-03-19 3:54 ` Stefan Monnier
1 sibling, 1 reply; 9+ messages in thread
From: Harald Hanche-Olsen @ 2007-03-18 9:23 UTC (permalink / raw)
To: help-gnu-emacs
+ 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? 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 <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: save-buffer like save-excursion
2007-03-18 9:23 ` Harald Hanche-Olsen
@ 2007-03-18 9:56 ` Matthew Flaschen
0 siblings, 0 replies; 9+ messages in thread
From: Matthew Flaschen @ 2007-03-18 9:56 UTC (permalink / raw)
To: emacs
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: save-buffer like save-excursion
[not found] <mailman.1069.1174204758.7795.help-gnu-emacs@gnu.org>
2007-03-18 9:23 ` Harald Hanche-Olsen
@ 2007-03-19 3:54 ` Stefan Monnier
2007-03-19 5:30 ` Matthew Flaschen
2007-03-19 7:33 ` Harald Hanche-Olsen
1 sibling, 2 replies; 9+ messages in thread
From: Stefan Monnier @ 2007-03-19 3:54 UTC (permalink / raw)
To: help-gnu-emacs
> 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?
with-current-buffer (or save-current-buffer).
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: save-buffer like save-excursion
2007-03-19 3:54 ` Stefan Monnier
@ 2007-03-19 5:30 ` Matthew Flaschen
2007-03-19 7:33 ` Harald Hanche-Olsen
1 sibling, 0 replies; 9+ messages in thread
From: Matthew Flaschen @ 2007-03-19 5:30 UTC (permalink / raw)
To: emacs
Stefan Monnier wrote:
>> 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?
>
> with-current-buffer (or save-current-buffer)
Thanks. I'll refactor the code (again)
Matt
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: save-buffer like save-excursion
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>
1 sibling, 2 replies; 9+ messages in thread
From: Harald Hanche-Olsen @ 2007-03-19 7:33 UTC (permalink / raw)
To: help-gnu-emacs
+ Stefan Monnier <monnier@iro.umontreal.ca>:
| with-current-buffer (or save-current-buffer).
Duh. Another wheel reinvented (in my earlier post in the thread).
--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: save-buffer like save-excursion
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>
1 sibling, 0 replies; 9+ messages in thread
From: Matthew Flaschen @ 2007-03-19 21:36 UTC (permalink / raw)
To: emacs
Harald Hanche-Olsen wrote:
> + Stefan Monnier <monnier@iro.umontreal.ca>:
>
> | with-current-buffer (or save-current-buffer).
>
> Duh. Another wheel reinvented (in my earlier post in the thread).
Anytime I work on something in emacs I have the overwhelmingly feeling
it's already been done. Half the time I turn out to be right. The
naming conventions seem totally arbitrary, so even with apropos and
everything it's hard to find the function you want.
Maybe I should ask again about the main project I'm working on. Has an
ed emulator already been made for emacs?
Matthew Flaschen
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: save-buffer like save-excursion
[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
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2007-03-21 19:42 UTC (permalink / raw)
To: help-gnu-emacs
>> + Stefan Monnier <monnier@iro.umontreal.ca>:
>>
>> | with-current-buffer (or save-current-buffer).
>>
>> Duh. Another wheel reinvented (in my earlier post in the thread).
> Anytime I work on something in emacs I have the overwhelmingly feeling
> it's already been done. Half the time I turn out to be right. The
> naming conventions seem totally arbitrary, so even with apropos and
> everything it's hard to find the function you want.
> Maybe I should ask again about the main project I'm working on. Has an
> ed emulator already been made for emacs?
I suspect some part of it might be included in viper.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: save-buffer like save-excursion
2007-03-21 19:42 ` Stefan Monnier
@ 2007-03-23 1:35 ` Matthew Flaschen
0 siblings, 0 replies; 9+ messages in thread
From: Matthew Flaschen @ 2007-03-23 1:35 UTC (permalink / raw)
To: emacs
Stefan Monnier wrote:
>>> + Stefan Monnier <monnier@iro.umontreal.ca>:
>>>
>>> | with-current-buffer (or save-current-buffer).
>>>
>>> Duh. Another wheel reinvented (in my earlier post in the thread).
>
>> Anytime I work on something in emacs I have the overwhelmingly feeling
>> it's already been done. Half the time I turn out to be right. The
>> naming conventions seem totally arbitrary, so even with apropos and
>> everything it's hard to find the function you want.
>
>> Maybe I should ask again about the main project I'm working on. Has an
>> ed emulator already been made for emacs?
>
> I suspect some part of it might be included in viper.
I don't think so. As far as I can tell, ed is almost nothing like vi.
Reviewing the Viper manual just now, I see no reference to ed. Glad to
be corrected, though.
Matt Flaschen
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-03-23 1:35 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-18 7:57 save-buffer like save-excursion Matthew Flaschen
[not found] <mailman.1069.1174204758.7795.help-gnu-emacs@gnu.org>
2007-03-18 9:23 ` Harald Hanche-Olsen
2007-03-18 9:56 ` Matthew Flaschen
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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.