* [rant] Should reverting a buffer really discard undo history?
@ 2005-05-30 19:57 Daniel Brockman
2005-05-30 21:28 ` Stefan Monnier
2005-05-31 17:47 ` Richard Stallman
0 siblings, 2 replies; 13+ messages in thread
From: Daniel Brockman @ 2005-05-30 19:57 UTC (permalink / raw)
Steps to reproduce:
1. C-x C-f foo RET original contents C-x C-s
2. M-! echo new contents > foo RET
3. Try to change the buffer.
4. Answer `r' to the question about really editing the buffer.
5. Note that at this point you cannot retrieve the original buffer
contents by undoing.
I managed to lose my ~/.emacs last night. It was all my fault, and
I'm still trying to forgive myself for not keeping a recent backup.
Luckily, I use Customize to tweak everything that uses `defcustom',
so I was able to reproduce a lot from my running Emacs instance.
Unfortunately, you cannot use Customize to, e.g., bind keys.
(Has implementing this ever been considered, by the way?)
Please skip the following three paragraphs unless you are interested
in the details of how the accident happened.
<long-version>
I was using a broken FTP program to upload some files to my machine
(of course, I did not at the time know that the program was broken),
and without my noticing it, the FTP program uploaded the two files
`.emacs' and `.emacs~', overwriting the ones in my home directory.
A few hours later, I'm tweaking something in a Customize buffer and
hit the button ``Save for future sessions''. Emacs tells me that the
file `.emacs' changed on disk, and asks me if I want to revert it.
Here's where I make my fatal mistake --- I say `yes'.
Yes, I did understand the question, and I did know that reverting a
buffer is a potentially dangerous opreation. (If it weren't, Emacs
probably wouldn't even ask me about it.) But, I reasoned, if the file
had changed on disk, that must be because *I* had changed it somehow.
I did not consider the possibility that a broken FTP program might
have replaced the file and its backup with what amounts to garbage.
</long-version>
Now this is a pretty unlikely scenario. But all it really takes for
the equivalent to happen is that you mess up some file that you have
in an Emacs buffer, and then revert that Emacs buffer.
My ~/.emacs would have been saved had Emacs kept the buffer contents
in undo history when reverting the file. I'd like to if there is any
way to enable this, and (if so) why Emacs does not do it by default.
By the way, the first thing I did following this incident was to set
`version-control' to t, and curse myself for not doing so earlier.
--
Daniel Brockman <daniel@brockman.se>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-05-30 19:57 [rant] Should reverting a buffer really discard undo history? Daniel Brockman
@ 2005-05-30 21:28 ` Stefan Monnier
2005-05-30 21:56 ` Juanma Barranquero
` (2 more replies)
2005-05-31 17:47 ` Richard Stallman
1 sibling, 3 replies; 13+ messages in thread
From: Stefan Monnier @ 2005-05-30 21:28 UTC (permalink / raw)
Cc: emacs-devel
> My ~/.emacs would have been saved had Emacs kept the buffer contents
> in undo history when reverting the file. I'd like to if there is any
> way to enable this, and (if so) why Emacs does not do it by default.
I have locally patched my Emacs to preserve undo info during revert, so
I completely agree it's desirable. When I suggested the change it was
rejected (it's somewhere in the archive if you're interested, tho I can't
remember the thread title and not even when it took place, I'd say about
2 years ago).
Maybe having it as a (potentially buffer-local) option is a good idea.
What do people think?
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-05-30 21:28 ` Stefan Monnier
@ 2005-05-30 21:56 ` Juanma Barranquero
2005-05-30 21:58 ` Lennart Borgman
2005-06-01 23:19 ` Dan Nicolaescu
2 siblings, 0 replies; 13+ messages in thread
From: Juanma Barranquero @ 2005-05-30 21:56 UTC (permalink / raw)
> Maybe having it as a (potentially buffer-local) option is a good idea.
>
> What do people think?
Anything simple to implement and that offers increased safety for the
user's data is good in my book.
--
/L/e/k/t/u
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-05-30 21:28 ` Stefan Monnier
2005-05-30 21:56 ` Juanma Barranquero
@ 2005-05-30 21:58 ` Lennart Borgman
2005-06-01 23:19 ` Dan Nicolaescu
2 siblings, 0 replies; 13+ messages in thread
From: Lennart Borgman @ 2005-05-30 21:58 UTC (permalink / raw)
Cc: Daniel Brockman, emacs-devel
Stefan Monnier wrote:
>>My ~/.emacs would have been saved had Emacs kept the buffer contents
>>in undo history when reverting the file. I'd like to if there is any
>>way to enable this, and (if so) why Emacs does not do it by default.
>>
>>
>
>I have locally patched my Emacs to preserve undo info during revert, so
>I completely agree it's desirable. When I suggested the change it was
>rejected (it's somewhere in the archive if you're interested, tho I can't
>remember the thread title and not even when it took place, I'd say about
>2 years ago).
>
>Maybe having it as a (potentially buffer-local) option is a good idea.
>
>What do people think?
>
>
I vote for making revert undoable! It was a surprise to me that it was not.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [rant] Should reverting a buffer really discard undo history?
[not found] <E1DcrBs-0005I0-W6@monty-python.gnu.org>
@ 2005-05-31 0:28 ` Jonathan Yavner
2005-05-31 2:30 ` Daniel Brockman
0 siblings, 1 reply; 13+ messages in thread
From: Jonathan Yavner @ 2005-05-31 0:28 UTC (permalink / raw)
> the first thing I did following this incident was to set 'version-control'
> to t, and curse myself for not doing so earlier.
This sounds like a work-around. Why isn't "revert" an undoable operation?
Maybe it would cost too much RAM when reverting a 64 MB file, but for typical
files on today's computers we can afford to treat the entire buffer text as
having been replaced.
> you cannot use Customize to, e.g., bind keys.
Nor can you use it to define your own functions that will be bound to keys.
Nor can it deal with conditional code in your .emacs dealing with platforms
other than the one you're using at the moment.
--JYavner
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-05-31 0:28 ` Jonathan Yavner
@ 2005-05-31 2:30 ` Daniel Brockman
0 siblings, 0 replies; 13+ messages in thread
From: Daniel Brockman @ 2005-05-31 2:30 UTC (permalink / raw)
Jonathan Yavner <jyavner@member.fsf.org> writes:
>> the first thing I did following this incident was to set
>> 'version-control' to t, and curse myself for not doing so earlier.
>
> This sounds like a work-around. Why isn't "revert" an undoable
> operation?
It makes no sense to me. I have not yet found the approximately
two-year-old thread that Stefan mentioned.
> Maybe it would cost too much RAM when reverting a 64 MB file,
Reverting a 64 MB file would cause the undo information to be
discarded anyway unless your `undo-outer-limit' was set really high.
> but for typical files on today's computers we can afford to treat
> the entire buffer text as having been replaced.
Yes, I very rarely, if ever, open files whose size exceed the default
value of `undo-outer-limit' (about three megabytes).
Anyway, the undo information will be saved for `C-x h C-w' followed by
`C-x i large-file RET'. So why not for `M-x revert-buffer RET'?
<off-topic>
>> you cannot use Customize to, e.g., bind keys.
Johan Bockgård linked to this thread on IRC a while ago:
<http://lists.gnu.org/archive/html/emacs-devel/2003-12/msg00682.html>
> Nor can you use it to define your own functions that will be bound
> to keys.
I don't see any point in doing this from a Customize buffer.
Simple lambdas could be specified inline in a key binding widget, but
larger functions should really be defined separately, so that you can
format them nicely, comment them, and so on.
> Nor can it deal with conditional code in your .emacs dealing with
> platforms other than the one you're using at the moment.
That is a problem, but a very complex problem. In my experience,
simply setting an option to different values depending on the platform
is rarely sufficient. (I regret not being able to cite an example
from my init file.)
</off-topic>
--
Daniel Brockman <daniel@brockman.se>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-05-30 19:57 [rant] Should reverting a buffer really discard undo history? Daniel Brockman
2005-05-30 21:28 ` Stefan Monnier
@ 2005-05-31 17:47 ` Richard Stallman
2005-05-31 18:23 ` Drew Adams
1 sibling, 1 reply; 13+ messages in thread
From: Richard Stallman @ 2005-05-31 17:47 UTC (permalink / raw)
Cc: emacs-devel
1. C-x C-f foo RET original contents C-x C-s
2. M-! echo new contents > foo RET
3. Try to change the buffer.
4. Answer `r' to the question about really editing the buffer.
5. Note that at this point you cannot retrieve the original buffer
contents by undoing.
In theory, we could treat the revert operation as an undoable change
to the buffer contents. In practice, for large buffers, that change
would be so large that it would soon be discarded from the undo list.
For even larger buffers, the result of saving the whole buffer as
an undo record would be an immediate error. It would be impossible to
revert.
So I am against this change--at least if it were the default.
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [rant] Should reverting a buffer really discard undo history?
2005-05-31 17:47 ` Richard Stallman
@ 2005-05-31 18:23 ` Drew Adams
2005-06-01 17:25 ` Richard Stallman
0 siblings, 1 reply; 13+ messages in thread
From: Drew Adams @ 2005-05-31 18:23 UTC (permalink / raw)
In theory, we could treat the revert operation as an undoable change
to the buffer contents. In practice, for large buffers, that change
would be so large that it would soon be discarded from the undo list.
For even larger buffers, the result of saving the whole buffer as
an undo record would be an immediate error. It would be impossible to
revert.
So I am against this change--at least if it were the default.
So, it could still be considered as an option? The values of the option
would reflect a performance-vs-safety/security tradeoff. The default value
would choose performance, and the doc could tell users how to opt for more
safety/security at the price of a possible performance hit.
I'm not real familiar with the mechanics of the undo list, but couldn't the
previous file contents be stored only on disk, as a temporary file, and the
value in the undo list be just a pointer to that file instead of the file
contents?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-05-31 18:23 ` Drew Adams
@ 2005-06-01 17:25 ` Richard Stallman
0 siblings, 0 replies; 13+ messages in thread
From: Richard Stallman @ 2005-06-01 17:25 UTC (permalink / raw)
Cc: emacs-devel
I'm not real familiar with the mechanics of the undo list, but couldn't the
previous file contents be stored only on disk, as a temporary file, and the
value in the undo list be just a pointer to that file instead of the file
contents?
It would be conceivable to store old undo-list contents in files. 15
years ago I wanted to implement that in Emacs. Nowadays it seems less
important, because memory is big enough to hold more undo list data
than in the past. It's only for something like this that one would
think of wanting to do that.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-05-30 21:28 ` Stefan Monnier
2005-05-30 21:56 ` Juanma Barranquero
2005-05-30 21:58 ` Lennart Borgman
@ 2005-06-01 23:19 ` Dan Nicolaescu
2005-06-01 23:31 ` Stefan Monnier
2 siblings, 1 reply; 13+ messages in thread
From: Dan Nicolaescu @ 2005-06-01 23:19 UTC (permalink / raw)
Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > My ~/.emacs would have been saved had Emacs kept the buffer contents
> > in undo history when reverting the file. I'd like to if there is any
> > way to enable this, and (if so) why Emacs does not do it by default.
>
> I have locally patched my Emacs to preserve undo info during revert, so
> I completely agree it's desirable. When I suggested the change it was
> rejected (it's somewhere in the archive if you're interested, tho I can't
> remember the thread title and not even when it took place, I'd say about
> 2 years ago).
>
> Maybe having it as a (potentially buffer-local) option is a good idea.
>
> What do people think?
It would be nice.
Maybe other users have a different experience, but for me 99% of the
time I would like undo info after a revert is when revert was invoked
by VC/pcl-cvs after a commit.
So from this users point of view if VC/pcl-cvs were not to revert the
buffer, saving undo after revert would not be missed much.
--dan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-06-01 23:19 ` Dan Nicolaescu
@ 2005-06-01 23:31 ` Stefan Monnier
2005-06-02 18:10 ` Dan Nicolaescu
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2005-06-01 23:31 UTC (permalink / raw)
Cc: emacs-devel
> Maybe other users have a different experience, but for me 99% of the
> time I would like undo info after a revert is when revert was invoked
> by VC/pcl-cvs after a commit.
> So from this users point of view if VC/pcl-cvs were not to revert the
> buffer, saving undo after revert would not be missed much.
Indeed, it may also be useful to allow the revert-undoability to be
specified on a revert-by-revert basis. And VC/PCL-CVS would be well served
by a "revert carefully" which would do something like "diff+patch" rather
than an actual revert. Note that revert already does a limited form of
diff+patch since it checks the prefix&suffix of the file/buffer which hasn't
changed, so if only one line was changed the undo would record only
a one-line change rather than a complete delete+insert of the whole buffer.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-06-01 23:31 ` Stefan Monnier
@ 2005-06-02 18:10 ` Dan Nicolaescu
2005-06-03 22:30 ` Richard Stallman
0 siblings, 1 reply; 13+ messages in thread
From: Dan Nicolaescu @ 2005-06-02 18:10 UTC (permalink / raw)
Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > Maybe other users have a different experience, but for me 99% of the
> > time I would like undo info after a revert is when revert was invoked
> > by VC/pcl-cvs after a commit.
> > So from this users point of view if VC/pcl-cvs were not to revert the
> > buffer, saving undo after revert would not be missed much.
>
> Indeed, it may also be useful to allow the revert-undoability to be
> specified on a revert-by-revert basis. And VC/PCL-CVS would be well served
> by a "revert carefully" which would do something like "diff+patch" rather
> than an actual revert. Note that revert already does a limited form of
> diff+patch since it checks the prefix&suffix of the file/buffer which hasn't
> changed, so if only one line was changed the undo would record only
> a one-line change rather than a complete delete+insert of the whole buffer.
If saving undo after revert is not implemented/accepted would it be
possible to avoid the revert if it is not needed after a commit?
Wouldn't a (string= (md5 FILE) (md5 BUFFER)) be enough to avoid
reverting?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [rant] Should reverting a buffer really discard undo history?
2005-06-02 18:10 ` Dan Nicolaescu
@ 2005-06-03 22:30 ` Richard Stallman
0 siblings, 0 replies; 13+ messages in thread
From: Richard Stallman @ 2005-06-03 22:30 UTC (permalink / raw)
Cc: monnier, emacs-devel
If saving undo after revert is not implemented/accepted would it be
possible to avoid the revert if it is not needed after a commit?
Wouldn't a (string= (md5 FILE) (md5 BUFFER)) be enough to avoid
reverting?
That sounds like a good idea.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2005-06-03 22:30 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-30 19:57 [rant] Should reverting a buffer really discard undo history? Daniel Brockman
2005-05-30 21:28 ` Stefan Monnier
2005-05-30 21:56 ` Juanma Barranquero
2005-05-30 21:58 ` Lennart Borgman
2005-06-01 23:19 ` Dan Nicolaescu
2005-06-01 23:31 ` Stefan Monnier
2005-06-02 18:10 ` Dan Nicolaescu
2005-06-03 22:30 ` Richard Stallman
2005-05-31 17:47 ` Richard Stallman
2005-05-31 18:23 ` Drew Adams
2005-06-01 17:25 ` Richard Stallman
[not found] <E1DcrBs-0005I0-W6@monty-python.gnu.org>
2005-05-31 0:28 ` Jonathan Yavner
2005-05-31 2:30 ` Daniel Brockman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).