Sublime Forum

ST3: possible to change plugin settings in *.sublime-project?

#1

I know that section “settings” can be added into .sublime-project file to change editor’s settings. But some plugin settings need to be different across various projects, what should i do now? Is it possible to change plugin settings inside the *.sublime-project file?

0 Likes

#2

Yes. See how I do it with phpunitkit.

Also keep in mind the [notes] (https://github.com/gerardroche/sublime-phpunit/issues/41) about refactoring the settings for the next version.

0 Likes

#3

@gerry hi gerry, i checked the some code of your repository, but i’m no expert of python or sublime development.
I guess when i add settings in the *.sublime-project, plugin can fetch the setting via get() interface of sublime.Settings class directly, am i right?

so it seems that plugin developer to do some extra work to make project-dependent plugin-setting feature happen. Is there any way for editor itself to locate plugin settings from project file automatically?
For example, ClangAutoComplete plugin has a setting called “include_dirs”, when i write “ClangAutoComplete.include_dirs” into project file, plugin can automatically know the user has a override setting in project file.

0 Likes

#4

In your plugin add a Preferences.sublime-settings file and put all the plugins settings in it.

I recommend prefixing all the settings {PLUGIN}.. For example in phpunitkit all settings are prefixed phpunit..

{
    // Enable composer support. If a composer installed PHPUnit is found then it is used to run tests.
    "phpunit.composer": true,

    // Enable the default keymaps.
    "phpunit.keymaps": true,

    // ...
}

See https://github.com/gerardroche/sublime-phpunit/blob/master/Preferences.sublime-settings

You can access all the settings in code.

window = sublime.active_window()
view = window.active_view()
settings = view.settings()

is_composer_enabled = view.settings().get('phpunit.composer')

See https://github.com/gerardroche/sublime-phpunit/blob/master/plugin.py#L18

Or anywhere else like keymaps.

 { "keys": [",", "."], "command": "phpunit_switch_file", "context": [{ "key": "setting.command_mode" }, { "key": "setting.phpunit.keymaps" }, { "key": "setting.phpunit.vi_keymaps" }] },

See https://github.com/gerardroche/sublime-phpunit/blob/master/Default%20(Linux).sublime-keymap

Setting preferences

1. User Preferences

Open: Menu > Preferences > Settings

File: User\Preferrences.sublime-settings

{
     "phpunit.composer": true
}

1. Per-Project

Open: Menu > Project > Edit Projeect

File: Path\To\Project\Name.sublime-project

{
    "settings": {
        "phpunit.composer": true
    }
}

Notice how we use the “settings” key in per-project settings. But the settings are still the same.

0 Likes