[PATCH] Set the buffer to be modified after recovery (was: Re: Save recovered file with ZZ?)
Christian Brabandt wrote: > On Do, 15 Apr 2010, Tony Mechelynck wrote: > > [...] > > After recovering, you should check the results, and, if correct, do a > > "forced write" with :w or :wq (not ZZ :x :wa or :xa). But IMHO if the > > recovery modifies the buffer (i.e. makes it different from the file on > > disk), it should also set the local 'modified' option. > > This has come up on the vim_use mailinglist. The problem seems to be > that after recovery of a swap buffer, the file should be modified so you > are not loosing your changes after e.g. accidently hitting ZZ > > Signed-off-by: Christian Brabandt > --- > src/memline.c |1 + > 1 files changed, 1 insertions(+), 0 deletions(-) > > diff --git a/src/memline.c b/src/memline.c > index 102b61e..c4a0d87 100644 > --- a/src/memline.c > +++ b/src/memline.c > @@ -1326,6 +1326,7 @@ ml_recover() > * the buffer. Delete it. > */ > ml_delete(curbuf->b_ml.ml_line_count, FALSE); > +curbuf->b_changed = TRUE; > curbuf->b_flags |= BF_RECOVERED; > > recoverymode = FALSE; After reading the other messages in this thread, I think the best solution is to only mark the buffer as changed if it actually differs from the file on disk. Setting the flag always is too different from the current behavior. Never setting the flag has the danger of "ZZ" dropping the changes without the user giving a hint about that. Perhaps the code in buf_contents_changed() can be used to check if the recovered file differs from the file on disk. Or perhaps making a copy of the buffer before recovering would work. -- How To Keep A Healthy Level Of Insanity: 5. Put decaf in the coffee maker for 3 weeks. Once everyone has gotten over their caffeine addictions, switch to espresso. /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\download, build and distribute -- http://www.A-A-P.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org/// -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
Re: [PATCH] Set the buffer to be modified after recovery (was: Re: Save recovered file with ZZ?)
On Fri, Apr 16, 2010 at 10:53:34PM +0200, Lech Lorens wrote: > On 16-Apr-2010 Christian Brabandt wrote: > > Hi James! > > > > On Fr, 16 Apr 2010, James Vega wrote: > > > > > On Fri, Apr 16, 2010 at 11:28 AM, Marvin Renich wrote: > > > > * Christian Brabandt [100416 08:35]: > > > >> This has come up on the vim_use mailinglist. The problem seems to be > > > >> that after recovery of a swap buffer, the file should be modified so > > > >> you > > > >> are not loosing your changes after e.g. accidently hitting ZZ > > > >> > > > > Shouldn't this set curbuf->b_changed based on the "modified" setting > > > > from the swap file, so that if you "recover" a file that was not > > > > modified, you don't set the modified flag? > > > > > > I'd think that any time you recover from a swap file, the buffer should > > > be considered "modified". The modified flag indicates that the buffer > > > is different than the on-disk file with the same name. Whether or not > > > the buffer was modified at the time that the swap file was last updated > > > has no bearing on whether the content recovered from the swap file > > > matches the current contents of the file that was being edited. That's > > > up to the user to diagnose and decide what steps to take. > > > > That would be my understanding as well. > > Correct me if I am wrong, but I understand that the current behaviour is > that if you recover a file it does not get the "modified" attribute. As > a result if you press ZZ, you exit Vim without saving the recovered > contents. That's a very good point. Since the swap file isn't automatically deleted after a recovery, you can always re-recover if you ZZ/:x when you intended to :w. Given that perspective, I retract my suggestion that 'modified' is set. > IOW, I personally prefer the current behaviour. Still, I believe that > there might be a somewhat more complicated solution which would satisfy > both needs. IMO, that way would be performing automatic diffing of the recovered buffer with the on-disk file. If anything short of that is done, then the current behavior should be maintained. -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega signature.asc Description: Digital signature
Re: [PATCH] Set the buffer to be modified after recovery (was: Re: Save recovered file with ZZ?)
On 16-Apr-2010 Christian Brabandt wrote: > Hi James! > > On Fr, 16 Apr 2010, James Vega wrote: > > > On Fri, Apr 16, 2010 at 11:28 AM, Marvin Renich wrote: > > > * Christian Brabandt [100416 08:35]: > > >> This has come up on the vim_use mailinglist. The problem seems to be > > >> that after recovery of a swap buffer, the file should be modified so you > > >> are not loosing your changes after e.g. accidently hitting ZZ > > >> > > > Shouldn't this set curbuf->b_changed based on the "modified" setting > > > from the swap file, so that if you "recover" a file that was not > > > modified, you don't set the modified flag? > > > > I'd think that any time you recover from a swap file, the buffer should > > be considered "modified". The modified flag indicates that the buffer > > is different than the on-disk file with the same name. Whether or not > > the buffer was modified at the time that the swap file was last updated > > has no bearing on whether the content recovered from the swap file > > matches the current contents of the file that was being edited. That's > > up to the user to diagnose and decide what steps to take. > > That would be my understanding as well. Correct me if I am wrong, but I understand that the current behaviour is that if you recover a file it does not get the "modified" attribute. As a result if you press ZZ, you exit Vim without saving the recovered contents. While this might seem like a defect, I find it to prevent me from accidentally overwriting the contents of the original file on the disk. And I can always restore the contents that have not been written when I pressed ZZ by invoking Vim once again with "-r swapfile-name" arguments. IOW, I personally prefer the current behaviour. Still, I believe that there might be a somewhat more complicated solution which would satisfy both needs. But then, maybe Bram decides it's a bug in fact? -- Cheers, Lech -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php Subscription settings: http://groups.google.com/group/vim_dev/subscribe?hl=en
Re: [PATCH] Set the buffer to be modified after recovery (was: Re: Save recovered file with ZZ?)
* James Vega [100416 11:43]: > On Fri, Apr 16, 2010 at 11:28 AM, Marvin Renich wrote: > > Shouldn't this set curbuf->b_changed based on the "modified" setting > > from the swap file, so that if you "recover" a file that was not > > modified, you don't set the modified flag? > > I'd think that any time you recover from a swap file, the buffer should > be considered "modified". The modified flag indicates that the buffer > is different than the on-disk file with the same name. Whether or not > the buffer was modified at the time that the swap file was last updated > has no bearing on whether the content recovered from the swap file > matches the current contents of the file that was being edited. That's > up to the user to diagnose and decide what steps to take. Maybe I am missing something. If you are recovering from a swap file, doesn't Vim read the current version of the file from disk, then apply the changes that are in the swap file? So, if the swap file has modified=no, the buffer will match the current version of the file on disk. Is there something else going on that I have missed? I don't think this is a big deal; if you are explicitly recovering, you probably are paying attention to what you are doing, but then again, this patch is because people asked to be notified if they try to quit without saving after recovering. ...Marvin -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php Subscription settings: http://groups.google.com/group/vim_dev/subscribe?hl=en
Re: [PATCH] Set the buffer to be modified after recovery (was: Re: Save recovered file with ZZ?)
Hi James! On Fr, 16 Apr 2010, James Vega wrote: > On Fri, Apr 16, 2010 at 11:28 AM, Marvin Renich wrote: > > * Christian Brabandt [100416 08:35]: > >> This has come up on the vim_use mailinglist. The problem seems to be > >> that after recovery of a swap buffer, the file should be modified so you > >> are not loosing your changes after e.g. accidently hitting ZZ > >> > > Shouldn't this set curbuf->b_changed based on the "modified" setting > > from the swap file, so that if you "recover" a file that was not > > modified, you don't set the modified flag? > > I'd think that any time you recover from a swap file, the buffer should > be considered "modified". The modified flag indicates that the buffer > is different than the on-disk file with the same name. Whether or not > the buffer was modified at the time that the swap file was last updated > has no bearing on whether the content recovered from the swap file > matches the current contents of the file that was being edited. That's > up to the user to diagnose and decide what steps to take. That would be my understanding as well. regards, Christian -- hundred-and-one symptoms of being an internet addict: 107. When using your phone you forget that you don't have to use your keyboard. -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php Subscription settings: http://groups.google.com/group/vim_dev/subscribe?hl=en
Re: [PATCH] Set the buffer to be modified after recovery (was: Re: Save recovered file with ZZ?)
On Fri, Apr 16, 2010 at 11:28 AM, Marvin Renich wrote: > [dropping vim_use] > > * Christian Brabandt [100416 08:35]: >> This has come up on the vim_use mailinglist. The problem seems to be >> that after recovery of a swap buffer, the file should be modified so you >> are not loosing your changes after e.g. accidently hitting ZZ >> >> Signed-off-by: Christian Brabandt >> --- >> src/memline.c | 1 + >> 1 files changed, 1 insertions(+), 0 deletions(-) >> >> diff --git a/src/memline.c b/src/memline.c >> index 102b61e..c4a0d87 100644 >> --- a/src/memline.c >> +++ b/src/memline.c >> @@ -1326,6 +1326,7 @@ ml_recover() >> * the buffer. Delete it. >> */ >> ml_delete(curbuf->b_ml.ml_line_count, FALSE); >> + curbuf->b_changed = TRUE; >> curbuf->b_flags |= BF_RECOVERED; >> >> recoverymode = FALSE; >> -- >> 1.6.5.7 >> >> regards, >> Christian > > Shouldn't this set curbuf->b_changed based on the "modified" setting > from the swap file, so that if you "recover" a file that was not > modified, you don't set the modified flag? I'd think that any time you recover from a swap file, the buffer should be considered "modified". The modified flag indicates that the buffer is different than the on-disk file with the same name. Whether or not the buffer was modified at the time that the swap file was last updated has no bearing on whether the content recovered from the swap file matches the current contents of the file that was being edited. That's up to the user to diagnose and decide what steps to take. -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php Subscription settings: http://groups.google.com/group/vim_dev/subscribe?hl=en
Re: [PATCH] Set the buffer to be modified after recovery (was: Re: Save recovered file with ZZ?)
[dropping vim_use] * Christian Brabandt [100416 08:35]: > This has come up on the vim_use mailinglist. The problem seems to be > that after recovery of a swap buffer, the file should be modified so you > are not loosing your changes after e.g. accidently hitting ZZ > > Signed-off-by: Christian Brabandt > --- > src/memline.c |1 + > 1 files changed, 1 insertions(+), 0 deletions(-) > > diff --git a/src/memline.c b/src/memline.c > index 102b61e..c4a0d87 100644 > --- a/src/memline.c > +++ b/src/memline.c > @@ -1326,6 +1326,7 @@ ml_recover() > * the buffer. Delete it. > */ > ml_delete(curbuf->b_ml.ml_line_count, FALSE); > +curbuf->b_changed = TRUE; > curbuf->b_flags |= BF_RECOVERED; > > recoverymode = FALSE; > -- > 1.6.5.7 > > regards, > Christian Shouldn't this set curbuf->b_changed based on the "modified" setting from the swap file, so that if you "recover" a file that was not modified, you don't set the modified flag? ...Marvin -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php Subscription settings: http://groups.google.com/group/vim_dev/subscribe?hl=en
[PATCH] Set the buffer to be modified after recovery (was: Re: Save recovered file with ZZ?)
Hi Tony! On Do, 15 Apr 2010, Tony Mechelynck wrote: [...] > After recovering, you should check the results, and, if correct, do a > "forced write" with :w or :wq (not ZZ :x :wa or :xa). But IMHO if the > recovery modifies the buffer (i.e. makes it different from the file on > disk), it should also set the local 'modified' option. This has come up on the vim_use mailinglist. The problem seems to be that after recovery of a swap buffer, the file should be modified so you are not loosing your changes after e.g. accidently hitting ZZ Signed-off-by: Christian Brabandt --- src/memline.c |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/memline.c b/src/memline.c index 102b61e..c4a0d87 100644 --- a/src/memline.c +++ b/src/memline.c @@ -1326,6 +1326,7 @@ ml_recover() * the buffer. Delete it. */ ml_delete(curbuf->b_ml.ml_line_count, FALSE); +curbuf->b_changed = TRUE; curbuf->b_flags |= BF_RECOVERED; recoverymode = FALSE; -- 1.6.5.7 regards, Christian -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php Subscription settings: http://groups.google.com/group/vim_dev/subscribe?hl=en