Sublime Forum

Need to expand project_path in settings

#1

I need the path to sublime text project root directory as path for the project setting “directories”. The value is not being expanded:

"settings":
{
    // set project root path for OpenContextPath
    "open_context_path": {
        "directories": ["${project_path}"],
    },
},

results in:

view.settings().get(‘open_context_path’)
{‘directories’: [’${project_path}’]}

0 Likes

#2

Settings are static key-value storages.

If some custom values need variable expansion, it would need to be handled by the plugin.

It can happen by using ST’s default set of variables …

sublime.expand_variables("${project_path}", window.extract_variables())

or by a customized one:

variables = window.extract_variables()
variables['mykey'] = the_computed_value
sublime.expand_variables("${project_path}", variables)
0 Likes

#3

turns out relative paths can be accepted. I can achieve the desired result simply by:

"settings":
{
    // set project root path for OpenContextPath
    "open_context_path": {
        "directories": ["."],
    },
},
0 Likes