Sublime Forum

Auto Backup Preference.sublime-settings file

#1

As we know, the preference file will automatically remove all the comments and formatting, when a setting is changed(such as changing font size by using Middle Mouse Wheel+Ctrl).

I m sure that lots of newbies like me use comment and proper formatting in the preference file to make it more organized and readable. But sublime text 3 do not support comments in Preference.subllime-settings file. So I manually back up the preference file every time when I add some settings in it and resume it when the comments are cleared.

Therefore, is there a solution or plugin than can automatically backup preference file when I personally change and save it(Ctrl+S). Or is there any one can provide a idea how to develop such plugin, so I can try to make it.

Waiting for Ur reply.

Thanks!

0 Likes

#2

there were some suggestions of how to avoid losing changes here:

personally I’d suggest just not writing comments as // this is my comment but as "setting_key_comment": "this is my comment"

if you want to build a plugin to back it up on save, just create an EventListener for on_post_save(_async), check whether the file is Packages/User/Preferences.sublime-settings and make a copy of it if so

1 Like

#3

The general solution is to maintain your entire ST User package as a git repository.

Then you will have version history for every file, and as a bonus can also keep your settings in sync between multiple computers.


BTW if you are doing the mouse wheel thing accidentally, it might be best to just disable that binding.

Default (Windows).sublime-mousemap

[
    {"button": "scroll_down",  "modifiers": ["ctrl"], "command": "noop"},
    {"button": "scroll_up",    "modifiers": ["ctrl"], "command": "noop"},
]
2 Likes

#4

If you want to try to make a plugin that adds comments, maybe like this:

  1. you open your preferences files in the editor, invoke the plugin command
  2. the plugin would parse the file, and add comments based on a template where you keep your comments, and that would be parsed too.
  3. the script builds in memory a string with the preferences and the added comments, then writes the file to disk.
  4. this wouldn’t be done every time the preferences are saved, only when you call the command.

Eg. the parser reads a key, and in your template you have a line:
“key”: // your comment

So the script would rewrite the section as:
// your comment
“key”…

Then it writes the edited file to disk, but you shouldn’t use the json functions to write it, since comments aren’t allowed there. You should rebuild the json as a string and save it as such.

0 Likes

#5

Thanks for Ur reply, I’ll try it. Have nice Day:smile:

0 Likes

#6

Thanks. It’s helpful. But git repository is little “big” for this I think. Besides, it’s network relied. I mean if I work offline, then this solution can not work.
BTW, thank for the information of mouse wheel thing.:wink:

0 Likes

#7

Thank your for your idea to build a plugin. I will try it when I have spare time. Keep in touch.:grin:

0 Likes