mandeep / sublime-text-conda

Work with conda environments in Sublime Text 3
BSD 3-Clause "New" or "Revised" License
26 stars 10 forks source link

Use edit_settings command instead of open_file in Main.sublime-menu #22

Closed jim-hart closed 4 years ago

jim-hart commented 4 years ago

Setting definitions are currently defined with the following pattern in Main.sublime-menu:

{
    "caption": "Settings – Default",
    "command": "open_file",
    "args": { "file": "${packages}/Conda/Conda.sublime-settings", "platform": "Platform" }
}

This works without issue, but this method comes with the following caveats:

  1. We have to open the Default/User options separately
  2. Platform specific options must be defined for all supported platforms (each with their own Defaultand User component)

We can address both of these using the edit_settings command, which sublime uses by default for its own settings. The entirety of the children key can be replaced with a single command definition:

{
    "caption": "Settings",
    "command": "edit_settings",
    "args": 
     { 
         "base_file": "${packages}/Conda/Conda (${platform}).sublime-settings", 
         "default": "{\n\t$0\n}\n"
     }
}

The ${platform} environment variable takes care of our platform component. If user settings aren't defined, the default value creates a blank template that matches the POJO containing the default, platform specific settings.

The nice part about edit_settings is that both the default and user settings are opened side by side, which allows for easy editing and customization.

While consolidating User and Default options to a single Settings label changes the menu layout for the plugin, the new behavior matches that of editing Sublime's native options, so the end result should be a familiar experience.

I don't feel the current menu-options are a negative aspect of the plugin; this pattern is common among many popular packages, and I've used it in personal plugins as well. While sublime does a lot of things well, its documentation leaves something to be desired at times. I only recently came across edit_settings (you can find usage of it in Default.sublime-commands), and after putting into my own projects, overriding defaults is now much easier.

mandeep commented 4 years ago

Hi @jim-hart, thanks for the request. I completely agree with you on this as this is one change I've felt necessary for awhile now. Feel free to submit a PR for this if you want. Otherwise, I hope to get to it sometime next week.

jim-hart commented 4 years ago

Awesome, thanks for considering it! Submitted PR #23.

mandeep commented 4 years ago

fixed by #23