Sublime Forum

Plugin Class Naming Quirk

#1

While creating commands for my plugin, I didn’t realize until just today that early on I titled the plugin command class camelCaseExampleCommand(). Then I assign a keyboard shortcut to this named “camel_case_example”.

However, apparently I got lazy and later commands were simply named something like “camelCaseExample”. I didn’t realize because this ALSO works and I can call the command with “camel_case_example”.

So… while clearly labeling a command as a command in the name is nice, do I need to worry about this overly much? It seems like Sublime Text simply encodes the underscore variation on the name and doesn’t seem to care much if the word “Command” is appended to the class. However, maybe I’m injecting some inefficiency or nuanced bad behavior in there.

0 Likes

#2

The code that converts the class name to a command name is in the Command.name() method, which you can see in sublime_plugin.py (stored in the executable folder of your Sublime installation). It converts a CamelCase version of the class name to snake_case and the last thing it does is discard a trailing _command if it exists.

As you’ve seen it works both ways; it doesn’t hurt anything and basically it’s just style/convention to append Command to the names of classes that implement a command so that it’s clearer to people reading the code (or jumping to symbols with the symbol list, say) what classes do.

0 Likes

#3

Alright, and great. Thanks. I will add it to my TODO list to fix that at a low priority. I don’t see anything wrong with adhering to convention in this particular case so I should probably make sure my command names are suffixed with Command. I already split “methods that understand sublime” and “methods that understand my language” into separate files just for organizational purposes (though the Sublime one is getting pretty long the more things I add in there.).

0 Likes