Sublime Forum

Plugins don't work, or I'm stupid (2)

#1

I am making a simple plugin, based on the rot13 example.

[code]import sublime, sublimeplugin

class CommentLinesCommand(sublimeplugin.TextCommand):
def run(self, view, args):
for region in view.sel():
if not region.empty():
# Get the selected text
s = view.substr(region)
# Replace newlines
s = s.replace("\n", “\n–”)
# Replace the selection with transformed text
view.replace(region, s)
[/code]

The plugin should search for newlines in the selection, and add “–” after each newline (this is a line comment in VHDL).
I’ve saved the file as “CommentLines.py” in the “User” package, and it appears to compile fine:

Writing file C:\Documents and Settings\oats\Application Data\Sublime Text\Packages\User\CommentLines.py with encoding UTF-8 Reloading plugin C:\Documents and Settings\oats\Application Data\Sublime Text\Packages\User/CommentLines.py

This is my user bindings file, so that I can use ctrl+t to comment lines:

<bindings> <binding key="ctrl+t" command="commentlines"/> </bindings>

The plugin does not show up in the Ctrl+t does not work. Neither does running view.runCommand(‘commentlines’) in the console. My document is unchanged. I get no errors. Not helpful. If I try to run some non-existent command, view.runCommand(‘nonexists’) I do not get any errors either. Not helpful.

I’m running the latest beta, any ideas?

0 Likes

#2

I believe you should be able to get this to run if you use:

view.runCommand(‘commentLines’)

The casing is a bit testy.

Hope it helps.

0 Likes

#3

Indeed! Thank you for the help!

Interesting that I define the function: CommentLinesCommand
But to call it, there is very particular case-sensitive rule?
view.runCommand(‘CommentLines’) – doesn’t work
view.runCommand(‘commentLines’) – works
view.runCommand(‘commentlines’) – doesn’t work

This is non-intuitive, and I did not see this information in the documentation. For the sake of others, I hope future releases will:

  1. Not be case sensitive with command names.
  2. Display an error message if runCommand is called on a command which could not be found.
0 Likes

#4

Python, the scripting language used, is case sensitive.

0 Likes