Sublime Forum

Trying to build a plug-in

#1

Hi,

I’m trying to build a new plug-in following the instructions found in [1]:

[quote]Let’s write a “Hello, World!” plugin for Sublime Text 2:

Select Tools | New Plugin… in the menu.
Save to Packages/User/hello_world.py.

[/quote]

which results in the following generated code:

class ExampleCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.insert(edit, 0, "Hello, World!")
However, nothing happens when I try it out by following these directions:

[quote]You’ve just written your first plugin. Let’s put it to use:

Create a new buffer (Ctrl+n).
Open the python console (Ctrl+`).
Type: view.run_command("example") and press enter.

You should see the text “Hello, World!” in your new buffer.[/quote]

In particular, when I when I execute view.run_command(“example”), nothing happens. That is, “Hello, World!” does not show up in file, and the only thing printed in the Python console is: >>> view.run_command(“example”).

I’m at a loss as what to do at this point. I’d be grateful for any suggestion.

Thanks,

Roger Alexander.

  1. docs.sublimetext.info/en/latest/ … ugins.html
0 Likes

#2

Worked for me straight-away? So it doesn’t type “Hello World” at the *top *of your view?

Are there any previous errors in the console?

0 Likes

#3

Are you sure you saved it to the right place ?

\Sublime Text 2\Packages\User\hello_world.py

When you start ST2, the list of loaded plugin is displayed in the console. Make sure your file is loaded.

0 Likes

#4

The console reports that …/User/hello_world.py is being loaded, and as far as I can tell, there are no errors reported:

Actually, the following showed up in the console just after I posted the above:

Can't connect Unable to fetch update url contents

0 Likes

#5

Look good.

Try adding a print statement to your plugin and look if it is printed in the console when you run your command:

class ExampleCommand(sublime_plugin.TextCommand): def run(self, edit): print "My plugin must work" self.view.insert(edit, 0, "Hello, World!")

0 Likes

#6

Just a thought but you may already have a command named “example”. Try changing it to “class VoilaCommand” and then view.run_command(“voila”).

0 Likes

#7

I tried both things:

[quote]class VoilaCommand(sublime_plugin.TextCommand):
def run(self, edit):
print “My plugin must work”
self.view.insert(edit, 0, “Hello, World!”)
print “Did my plugin work?”[/quote]

Nothing appeared in the edit window nor did either of the two print statements produce anything in the console. Further suggestions?

Thanks!

0 Likes

#8

I would try running the command from a key binding:

{ "keys": "ctrl+alt+q"], "command": "voila" }

When you choose Preferences/ Browse Packages, does it take you to the correct folder (where your command file is stored)?

Failing this you might consider a clean install of ST2. Someone might supply information/ a link to do this - there’s a way to do it without
having to un-re-install everything :question:

0 Likes