Sublime Forum

[Solved] Is it possible to get somehow all settings keys?

#1

Currently I try to implement for my plugin the settings processing.

The settings file looks like the following:

{
	"yal_launchers": [ "default", "python", "@work"],

	"default": {
		"url": {
			 "Sublime Text 3 - Api Reference": "http://www.sublimetext.com/docs/3/api_reference.html",
			 "Sublime Text Forum": "https://forum.sublimetext.com",
		},
	},
	"python": {
		"file+sys": {
			"Head First Python": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\Head First Python\\Head First Python.pdf",
			"Introducing Python": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\Introducing Python\\Introducing Python.pdf",
			"Python Cookbook": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\Python Cookbook\\Python Cookbook.pdf",
			"Programming Python": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\Programming Python\\Programming Python.pdf",
			"O' Reilly Apps Directory": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\",
		},
		"url": {
			"Python doc": "https://docs.python.org/3/",
		}
	},

The settings are loaded in the plugin via self.settings = sublime.load_settings("YetAnotherLauncher.sublime-settings"). As it seems it isn’t possible to get from the Settings class (http://www.sublimetext.com/docs/3/api_reference.html#sublime.Settings) all available keys. Therefore I must define at first all launcher names to process them. Personally I would prefer that the launchers would work without defining yal_launchers.

0 Likes

#2

It’s not possible to iterate over all settings keys, no. Possible solutions to this include:

  1. Have a predefined list of possible launcher names so your code inherently knows what to look for
  2. Put the launcher groups inside of another well known key instead of making them top level
  3. Use some other format (e.g. JSON as outlined in my response in your other thread) so that you have more control over the settings load process.
  4. Have a setting that tells you what settings to look at (as you’re doing here)

Here option #2 is as simple as making your yal_launchers setting be your single setting, such as making it a dictionary that keys on your launcher types directly, or an array of dictionaries that contain the information, etc.

For Option #3 you have to do a bit more work but you’re in control of loading the settings instead of Sublime doing it for you. For the JSON example you would end up with a python dict object whose keys you could iterate as you want to.

2 Likes

#3

if you go for 2. the user need to copy your whole setting and add his launchers into the dict. If you have them top-level he can just add them top level without worrying about the others. You can also create two dicts (as BracketHighlighter) like launchers and launchers_user and the user should use the second one.

1 Like

#4

Thanks @OdatNurd & @r-stein, I will follow the second approach. In that way the user don’t need to define the different launchers in an extra JSON object. :slight_smile:

0 Likes