Sublime Forum

Best way to utilize the built-in settings system for a plugin?

#1

Some of you may know that I’ve been working on XCodeMapper ( Acecool’s Source Code Navigator / CodePeer / CodeNode / or other development test-build-names until I settle on one ) to improve CodeMap by adding unlimited nesting categories and better methods to output data along with modifying syntax files so function can be replaced with ƒ and highlight properly, etc…

I’m at a bit of a cross-roads while I’m looking into implementing sublime-settings files into the mapping system…

Basically - I could have the Default Mapper settings in it’s own file, then one settings file for each Syntax and the User file optionally with a simple menu command to Open the current Syntax Defaults and User ( the other issue is opening more than 2 files at the same time but that’s a different question )…

The benefit to this is Lua and GMod Lua syntax is different even though they use the same .lua file extension… But, still - because they are different the Lua settings file could choose to use Lua Vanilla mappings ( or user, etc… ) class to map the file… and the GMod Lua settings file could use the Garry’s Mod Lua mappings or my mappings or the user mappings…

This makes sense - but I’ve been having issues with setting the right syntax for files and sometimes the syntax is unselected meaning it cause the language to be mapped by an incorrect mapper…

If it works as I think it could though it would mean that downloaded syntax files could be used and configuration could be assigned to each - the issue is it could cause a lot of repeated code for people that have a lot of extra syntax files…

The other route I could go is by using the file-extension to link the configuration file… This would eliminate guesswork in regards to which mapper to use - but if someone uses more than 1 language or mapper class with a single file extension, it’d mean they would need to edit the settings file frequently to change mapping class… I could eventually add rules - ie if view filename path includes garry’s mod, acecooldev_framework, etc… then use GMod Lua mapper - if contains darkrp then use Garry’s Mod DarkRP mappings, etc… which would eliminate the need to manually edit the class…

In short - because I’ll be supporting a lot of different languages with different file-extensions, etc… Should I use what already exists ( https://www.sublimetext.com/docs/3/settings.html )

SETTINGS FILES
Settings files are consulted in this order:

Packages/Default/Preferences.sublime-settings
Packages/Default/Preferences (<platform>).sublime-settings
Packages/User/Preferences.sublime-settings
<Project Settings>
Packages/<syntax>/<syntax>.sublime-settings
Packages/User/<syntax>.sublime-settings
<Buffer Specific Settings>
In general, you should place your settin

to add the XCodeMapper settings ( which will support inheritance ) to the syntax file by default with the ability for the user to edit them with the possibility that the from syntax is selected for a file and thereby the wrong mapper would be selected…

Or should I use file-extension which reduces the level of error but would require frequent edits by the user if they use many different mappers per file extension ( although if I add a rule system to the config file this problem would be eliminated )

I’m leaning towards the file-extension method, but I just discovered the syntax method and I’ve also found out that sublime-settings allows plugins to have a file named the same in the plugin folder to add that to the file - similar to a virtual file system where same-named files are merged together ( at least this is the case for key-bindings - I’m not sure if it is for settings files but I don’t see why it wouldn’t be as I’m sure it’d use the same engine )…

I apologize for the wall of text but I just wanted to lay everything out there and get an opinion of what you think… And also I’d like to know if I’m wrong about the files being merged the same way key-bind additions are…

Thanks in advanced!

0 Likes