Home Download Buy Blog Forum Support

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

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

Postby oats on Thu Dec 03, 2009 7:52 pm

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

Code: Select all
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)

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:
Code: Select all
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:
Code: Select all
<binding key="ctrl+t" command="commentlines"/>

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?
Posts: 101
Joined: Mon Nov 09, 2009 4:39 pm

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

Postby mike on Fri Dec 04, 2009 4:47 am

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


The casing is a bit testy.

Hope it helps.
Posts: 7
Joined: Thu Oct 01, 2009 7:42 pm

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

Postby oats on Fri Dec 04, 2009 2:21 pm

mike wrote:The casing is a bit testy.

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.
Posts: 101
Joined: Mon Nov 09, 2009 4:39 pm

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

Postby icw on Sat Jan 02, 2010 9:51 pm

Python, the scripting language used, is case sensitive.
Posts: 1
Joined: Sat Jan 02, 2010 9:49 pm

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 5 guests