Skip to content

Add auto-save options and finer control of backup - #5565

Merged
jmcphers merged 9 commits into
masterfrom
feature/auto-save-option
Oct 17, 2019
Merged

jmcphers merged 9 commits into
masterfrom
feature/auto-save-option

Conversation

@jmcphers

Copy link
Copy Markdown
Member

This change adds some new options that control automatic saving and backup behavior.

image

Autosave

It is now possible to have RStudio save files for you automatically, instead of requiring a manual "save" gesture. You can have this done either after a short period of inactivity (idle), when focus leaves the editor, or, if you're really paranoid, both.

Autosave doesn't pair well with Source on Save since sourcing an R file can be expensive and shouldn't be implicit. For this reason, turning on any autosave option turns off Source on Save.

Backup unsaved changes

Backing up unsaved changes (which confusingly is also sometimes referred to as "autosave") is now configurable; you can adjust the idle interval or turn it off entirely. This should be helpful primarily for users on systems like Dropbox or Google Drive who have problems with RStudio's frequent file writes.

In order to avoid tripping over its own feet, RStudio doesn't allow two different idle timers for backing up unsaved changes and auto-saving; you can only get one idle behavior.

All of this new behavior is opt-in; left at the default values, RStudio will behave exactly as it did in past releases.

Closes #3837.
Closes #4511.
Closes #5263.

@jmcphers
jmcphers requested a review from kevinushey October 16, 2019 17:56
@kevinushey

Copy link
Copy Markdown
Collaborator

Autosave doesn't pair well with Source on Save since sourcing an R file can be expensive and shouldn't be implicit. For this reason, turning on any autosave option turns off Source on Save.

How difficult would it be to ensure that Source on Save sources the file, but only for user-initiated saves and not auto-saves?

@jmcphers

Copy link
Copy Markdown
Member Author

How difficult would it be to ensure that Source on Save sources the file, but only for user-initiated saves and not auto-saves?

Not too hard, but I don't think that Source on Save is philosophically compatible with autosave. Either autosave option puts you in a world where manual saves aren't a thing, and you can just use the Source command if you want to source.

prefs_.surroundSelection().setGlobalValue(delimiterSurroundWidget_.getValue());
prefs_.executionBehavior().setGlobalValue(executionBehavior_.getValue());
prefs_.autoSaveOnIdle().setGlobalValue(autoSaveOnIdle_.getValue());
prefs_.autoSaveIdleMs().setGlobalValue(Integer.parseInt(autoSaveIdleMs_.getValue()));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth using StringUtil.parseInt(<...>, 1000) here, just to avoid a potential exception from a parse failure? (It looks like invalid options are handled in the dialog directly but being paranoid doesn't hurt here)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

getPath() != null &&
!docDisplay_.hasActiveCollabSession())
{
save();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do anything to swallow exceptions here, if the save were to fail for some reason?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm thinking of the occasional error modal that users sometimes see when trying to work with files in e.g. Dropbox, OneDrive, and so on)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


// Save (and keep track of when we initiated it)
saving_ = System.currentTimeMillis();
save(() ->

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar here: can we handle exceptions during save?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{
// Cancel any existing autosave timer
if (autoSaveTimer_.isRunning())
autoSaveTimer_.cancel();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW you can call cancel() directly (it will be a no-op if the timer is not running)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll save a couple of lines. :-)

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jmcphers
jmcphers merged commit 394689b into master Oct 17, 2019
@ghost

ghost commented Oct 18, 2019

Copy link
Copy Markdown

Hello, could you please tell me what has changed in the rstudio? I can no longer backup my project on dropbox as it sees conflict even after the selective sync. Everything disappears after the opening each rstudio project for the third time

@DanielKovar

Copy link
Copy Markdown

Where are the new auto-save options located? I don't see them under Global or Project options in RStudio 1.2.5019 on Windows 10. Thank you for tackling this incredibly aggravating issue! I know it's a niche problem, but it has been annoying me for years.

@jmcphers

Copy link
Copy Markdown
Member Author

They are part of the development version of RStudio and haven't yet made it to the stable builds. If you'd like to try the dailies, we'd appreciate any feedback you have!

https://dailies.rstudio.com/

@DanielKovar

Copy link
Copy Markdown

Thanks for the link to the dailies. I've been using version 1.3.618 on and off for a few days, and with the "Automatically save when editor loses focus" option checked, and the "When editor is idle" option set to "Do nothing," I'm no longer getting the error message. FYI, in my case, this had been happening with a project living on a shared network drive.

My only suggestion is that it might help to clarify the difference between backing up unsaved changes vs save and write changes.

@mathieurrpruvot

Copy link
Copy Markdown

Can someone explain the path to find these auto-save options, I am not finding it in Rstudio menu

@RobertWhitener

Copy link
Copy Markdown

Can someone explain the path to find these auto-save options, I am not finding it in Rstudio menu

I'm on windows, running RStudio 1.3.938 and found them in:
-> Tools
--> Global Options
---> Code
----> Saving
-----> Auto-save section.

@valerie-rstudio
valerie-rstudio deleted the feature/auto-save-option branch January 21, 2022 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants