Reputation: 3515
I've been making a sublime text plugin and all seemed to be working fine until I started delving into more 'advanced' things. I have the following settings file:
{
"suggest_new_file": true,
"add_to_single_view": false,
"show_status_message": true,
"show_file_path": true,
"status_message": "Copied to {name}",
"keep_focus": true,
// show preview of file contents in popup menu
"show_preview": true,
// scroll the view to the end of the file being copied to
// requires 'keep_focus' to be false
"scroll_view": true,
}
However, when I type, as follows, (into the sublime terminal):
sublime.load_settings('AddToFile.sublime-settings').get("show_preview")
... it returns False, even though it is True and sublime.load_settings('AddToFile.sublime-settings').has("show_preview")
is True also. This happens the other settings too and I don't know where else my plugin is getting it's settings from
Upvotes: 1
Views: 295
Reputation: 22791
The method settings().get()
with only a single parameter will always return None
if that setting doesn't exist, so the fact that you're explicitly getting a value contrary to the one that you expect is an indication that settings files are being loaded.
This is backed up by settings.has()
returning True
, which is an indication that a setting with that name does indeed exist within the hierarchy of settings that the settings
object is referencing.
Your results are indicative of there being more than one settings file with the same name. sublime-settings
files are one of many package resource files that are additive
; that is to say that when those resources are loaded, Sublime searches every path in every known package for a file by that name and loads it, combining the results together.
This additive
nature is why sublime.load_settings()
requires you to specify just the name of the settings file and not it's path; it wouldn't make sense to provide a path because it's loading multiple files anyway.
The load order of multiple files is very specifically defined, and as files are loaded their contents are applied on top of the results of the previous load, allowing each successive file to either override a setting or add new ones.
You can use the sublime.find_resources()
API method to determine the files that exist and are being loaded (if any); the results are listed in the order that they're loaded.
>>> sublime.find_resources("AddToFile.sublime-settings")
['Packages/User/AddToFile.sublime-settings']
As seen here, I only have a single file by this name. In your case I would guess that there's more than one of them, and the one whose contents you showed above comes earlier in the list than some other file that has different settings in it, which is why your setting doesn't have the value you think it does.
Upvotes: 1