I have Sublime's directory structure like this:
Packages
|-- Foo
| |-- Markdown.sublime-settings
|
|-- Bar
| |-- plugin.py
|
|-- User
|-- Markdown.sublime-settings
Then, I'm trying to get a wrap_width
value, stored in Foo/Markdown.sublime-setting
. For some reason, it seems that load_setting
method doesn't work, although save_settings
works fine.
import sublime
import sublime_plugin
class MarkdownSettings(sublime_plugin.EventListener):
def on_activated(self, view):
path = view.file_name()
if path:
e = view.file_name().split('.')[1]
if e == ("md" or "mmd"):
# Simple test. It works
x = sublime.load_settings("Markdown.sublime-settings")
wrap_width = x.get("wrap_width")
print(wrap_width) # Prints 50
# If I change directory to "../Foo", `load_setting` method would not work
x = sublime.load_settings("../Foo/Markdown.sublime-settings")
wrap_width = x.get("wrap_width")
print(wrap_width) # Prints None
# The code below is added just for demonstration purposes,
# to show that `save_setting` method works fine.
x = sublime.load_settings("../Foo/Markdown.sublime-settings")
x.set("wrap_width", 20)
sublime.save_settings("../Foo/Markdown.sublime-settings") # File updated
How I could get wrap_width
value stored in Foo/Markdown.sublime-settings
?
Using a path with load_settings
is not supported.
From http://www.sublimetext.com/docs/3/api_reference.html#sublime:
Loads the named settings. The name should include a file name and extension, but not a path. The packages will be searched for files matching the
base_name
, and the results will be collated into the settings object. Subsequent calls toload_settings()
with thebase_name
will return the same object, and not load the settings from disk again.
If you really need to do this, you should use sublime.decode_value(sublime.load_resource('Packages/Foo/Markdown.sublime-settings'))
instead.