Spyder: Enhancement: Implement autosave of editor files every X minutes

Created on 17 Feb 2015  Â·  34Comments  Â·  Source: spyder-ide/spyder

_From [email protected] on 2015-01-12T16:59:36Z_

Feature request / Enhancement:
1) Currently, when Spyder becomes unresponsive or just crashes, one loses all changes in edited files since last manual save.
2) Spyder does save files before a "run" action, but since other things than running the code can crash Spyder, that is not enough protection against data loss.

What is the expected output? What do you see instead?

1) Spyder should automatically save a file X minutes after the last manual or automatic save.
2) Spyder should offer a preference setting which allows the user to specify the time interval X between automatic saves and also allows to disable the automatic save.
3) The automatic save should go into a special directory "backups" under the ~/.spyder directory (or any other user-configurable place, including the parent directory of the edited file itself) and take the edited file's name with a prefix and/or suffix attached. It must not use the original file for auto-saving. What version of the product are you using? On what operating system? Spyder 2.3.2, Mac OSX 10.6

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=2111_

2–5 stars Editor Enhancement

Most helpful comment

I think the solution isn't to save files periodically, instead create a swap file that will be continuously updated, and if Spyder crash use that file for recovering. (like other editors do vim, kate) https://kate-editor.org/2010/07/12/gsoc-swap-files-for-kate/

All 34 comments

In addition to time-based autosaving, it would be nice to have an option to auto-save files when the editor loses focus.

I think the solution isn't to save files periodically, instead create a swap file that will be continuously updated, and if Spyder crash use that file for recovering. (like other editors do vim, kate) https://kate-editor.org/2010/07/12/gsoc-swap-files-for-kate/

I think the solution isn't to save files periodically, instead create a swap file that will be continuously updated, and if Spyder crash use that file for recovering. (like other editors do vim, kate) https://kate-editor.org/2010/07/12/gsoc-swap-files-for-kate/

:+1:

create a swap file that will be continuously updated

Yep, but I don't know how easy is to do that.

+1 for this feature request

+1

+1

+1
I just lost few hours of work due to spyder's crash.

@andfoy, please take a look at this one.

+1

+1

I'll have a think about this.

@andfoy I'll assume that you did not manage to do any work on this and are not working on it anymore.

Thanks a lot @jitseniesen!

I think the solution isn't to save files periodically, instead create a swap file that will be continuously updated, and if Spyder crash use that file for recovering. (like other editors do vim, kate) https://kate-editor.org/2010/07/12/gsoc-swap-files-for-kate/

Apparently, the swap file of kate contains only the changes (the delta). I can see the advantage of this when working with large files, but it does make the implementation rather more involved. So for the moment I propose to autosave the whole file, along the lines of the first comment.

Here is a rough design:

  1. Once a minute, all dirty buffers are autosaved.
  2. There is a choice on where to store the autosave file. I propose to use an autosave directory within the Spyder config directory and use the same file name for the autosave file and the original file (with some mechanism to avoid collisions).
  3. We need to store the mapping between autosave files and original files somewhere. I'll try using the same place in the config where we store which tab are open in the editor.
  4. When the user saves a file, or explicitly discards the changes by closing the tab, the autosave file is deleted. It follows that there are no autosave files after Spyder quits cleanly.
  5. When Spyder opens, it checks whether there are any autosave files. If there are, the user is given the choice to recover. The UI is not yet clear to me, but I envisage a dialog window with a list of files which can be recovered and "Recover" (for recovering from autosave file) and "Discard" (for discarding autosave file) buttons.

Any comments? Security implications that I should take into account (e.g. what if you are editing a file with passwords)? Can / should this be an editor extension?

Any comments?

Your plan looks good, please go ahead with it.

Security implications that I should take into account (e.g. what if you are editing a file with passwords)?

The user is responsible for the text he/she is writing, so I think this shouldn't be a concern for us. At any rate, we won't be saving backups in the current working directory but in a hidden one, which helps a bit.

Can / should this be an editor extension?

I don't think you could implement this as an editor extension. They are designed to extend the editing part of the Editor (e.g. multi-cursor support or auto-closing quotes).

@andfoy I'll assume that you did not manage to do any work on this and are not working on it anymore.

All yours @jitseniesen

Hello everyone, looking to implement this feature a long time ago in Ninja-IDE, I made an approximation of this feature. You can guided from here.

I am currently discarding the swap file implementation, for a self-saved file every so often.
regards!

@centaurialpha Thanks, that's useful. It looks pretty similar to what I am doing. I like how you separated the feature in its own class where I am just adding more functions to an already bloated editor class. I'll have a look whether I can refactor.

One difference is that you autosave when the user does not change a file for N seconds (so you have times for every file), while I autosave all files which are changed every N seconds (so I have a global time).

Do you have issues when the user opens two files with the same names in different directories? E.g. /foo/ham.py and /bar/ham.py ?

I do not understand what you mean with "I am currently discarding the swap file implementation, for a self-saved file every so often". I guess "the swap file implementation" refers to NSwapFile, but what is a self-saved file?

An update for any lurkers out there: I have implemented the autosave part (including tests), but it needs to be tidied up a bit. I am currently working on the recover part; the recovery itself is pretty easy but the UI (and tests) is a bit more work.

Do you have issues when the user opens two files with the same names in different directories? E.g. /foo/ham.py and /bar/ham.py ?

No, because each NSwapFile object is associated with a NEditable object, a NEditable object could be said to be an intermediary between an NFile object (represents each file, each NFile has a unique file_path property) and the Editor UI.

I do not understand what you mean with "I am currently discarding the swap file implementation, for a self-saved file every so often". I guess "the swap file implementation" refers to NSwapFile, but what is a self-saved file?

Sorry, maybe I did not explain myself well, and my English is very bad.
I want to say that the implementation I did is not so good and I am ruling out keeping it. Maybe only implement the auto-save and not a swap file.

Regards

+1 for autosave feature.

+100.000.000 for auto save to swap file for file recovery after crash
Just hapend to me,like spyder but thinking of using VS permanently

+1 Sypder crashed with no warning while swapping between workspaces (desktops) in win10

+1 for autosave
I've lost dozens of hours of work in the past few months! For some unknown reason lately my system been hanging/shutting down every now and then. I don't lose work on documents or spreadsheets, but I do in spyder (where I do the majority of my my work)!

can't afford any more lost time. moving to another ide until autosave can be implemented. hope you guys bring it out soon, I'll almost definitely switch back when you do.

I'm sorry to hear that. I know the feeling. It happened to me a couple of times also when I was working on a secondary hdd that was disconnecting/sleeping from time to time. Spyder would wipe my opened files entirely.

You can follow/comment/help with the implementation of this feature in PR #7660. I think it is almost ready.

@chrisfeigl did you loose "_only_" your unsaved changes or the entire content of your files?

@chrisfeigl did you loose "_only_" your unsaved changes or the entire content of your files?

@jnsebgosselin only unsaved changes, except of course in this case of a new file though which had not yet been saved, then the entire contents would be lost. But no content from saved files has ever been lost, gratefully.

@chrisfeigl Thanks for the feedback. Then Spyder 4 will likely solve your problem then. See you back soon.

+1 for the autosave feature. Eagerly waiting for this feature.

+1 for autosave

I just lost a few hours of work...! And after reading this thread I'm not sure whether I should have any hope that there's an auto-save/swap-like feature or not??

Please add this functionality

This was fixed in Spyder 4, please update.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LDONT picture LDONT  Â·  3Comments

danieltomasz picture danieltomasz  Â·  3Comments

ok97465 picture ok97465  Â·  3Comments

JesterEE picture JesterEE  Â·  3Comments

spyder-bot picture spyder-bot  Â·  3Comments