Open mulle-nat opened 1 month ago
lol... the command name becomes x_xCommand
in your case. I thought trailing Command
will be striped first but it looks like it's not.
See the default name
implementation from the Command
class (in sublime_plugin.py
):
def name(self) -> str:
"""
Return the name of the command. By default this is derived from the name
of the class.
"""
clsname = self.__class__.__name__
name = clsname[0].lower()
last_upper = False
for c in clsname[1:]:
if c.isupper() and not last_upper:
name += '_'
name += c.lower()
else:
name += c
last_upper = c.isupper()
if name.endswith("_command"):
name = name[0:-8]
return name
So it looks like the underscore & lowercasing is not applied to multiple consecutive uppercase letters. And as a result _command
will not be striped from the name if there is an uppercase letter before the Command
(in your second example).
Note that the name()
method can simply be overridden if desired.
The function would be much better, if it was written like this:
def name(self) -> str:
clsname = self.__class__.__name__
if clsname.endswith("Command"):
clsname = clsname[0:-7]
name = clsname[0].lower()
last_upper = False
for c in clsname[1:]:
if c.isupper() and not last_upper:
name += '_'
name += c.lower()
last_upper = c.isupper()
return name
This ensures that "Command" is properly stripped no matter what and that all the characters are lowercase no matter what. It will produce "highlight_objectivec_selector" instead of "highlight_objective_c_selector", but that's still better, than what it did before.
Description of the bug
I wanted to write this:
but this is not possible, because the camel case conversion silently fails. I tried to figure out, if it should be in some other format but to no avail:
This has wasted me a lot of time, as I couldn't figure out, why my commands never ran. Some error message or even better a fix would improve things.,
Steps to reproduce
Create a plugin, drop in the code. Open the console, see whats been printed, when you are switching buffers.
Expected behavior
Things work.
Actual behavior
Things do not work.
Sublime Text build number
4169
Operating system & version
Ubuntu 22
(Linux) Desktop environment and/or window manager
Gnome
Additional information
No response
OpenGL context information
No response