Your plugin does not get called by the view.run_command('Node js.nodejs')
command. In order to run your plugin you should be calling the try
command, e.g. view.run_command("try")
. Here is the explanation of why:
The command names of Sublime Text plugins are derived from their class names. For example the following class...
class PrintHelloInConsoleCommand(sublime_plugin.TextCommand):
def run(self, edit):
print("Hello")
...can be run by calling the print_hello_in_console
command. e.g.
// Run from a plugin or in the console
view.run_command("print_hello_in_console")
// Run from keys by adding a key binding
{"keys": ["ctrl+shift+y"], "command": "print_hello_in_console"},
// If instead of a `TextCommand` the plugin had been a `sublime_plugin.WindowCommand`
// then the following line would be needed to run the command in the console.
window.run_command("print_hello_in_console")
To get the command name from the class name first remove the Command
postfix from the class name. Second convert what remains of the class name from CamelCase
into snake_case
. So a plugin which defines class PrintHelloInConsoleCommand
is called by the print_hello_in_console
command.
- The class name is:
PrintHelloInConsoleCommand
- Remove Command from the class name:
PrintHelloInConsoleCommand --> PrintHelloInConsole
- Convert CamelCase to snake_case:
PrintHelloInConsole --> print_hello_in_console
- The name of the command to call is:
print_hello_in_console
Your class, class TryCommand(sublime_plugin.TextCommand)
can be run by calling the try
command, i.e. view.run_command("try")
.
Here are some other examples:
class ClearConsoleCommand(sublime_plugin.WindowCommand)
? "clear_console"
command
class InsertDateTimeCommand(sublime_plugin.TextCommand)
? "insert_date_time"
command
class TestOKCommand(sublime_plugin.TextCommand)
? ""
No command created — do not use a word in uppercase, e.g. the "OK"
in "TestOK"
. Note that this does not create a "test_o_k"
command
class MoveSelection(sublime_plugin.TextCommand)
? "move_selection"
command — this works despite the omission of "Command"
in the class name. At the time of writing that requirement is not strictly enforced by ST (but that may change in future versions)
class AutoSaverEvents(sublime_plugin.EventListener)
? ""
No command created — event listeners do not get called so no command is created and ST does not expect the class name to end in "Command"
For further information about plugins, see the plugins section of the Sublime Text Unofficial Documentation which has a lot more information than the official documentation has.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…