Home Download Buy Blog Forum Support

Plugins don't work, or I'm stupid

Plugins don't work, or I'm stupid

Postby cja on Tue Oct 27, 2009 6:03 pm

Ok, I have test.py in C:\Documents and Settings\[user]\Application Data\Sublime Text\Packages\User.

Contents of this test.py are:

Code: Select all
import sublime, sublimeplugin

# This simple plugin will add 'Hello, World!' to the end of the buffer when run.
# To run it, save it within the User/ directory, then open the console (Ctrl+~),
# and type: view.runCommand('sample')
#
# See http://www.sublimetext.com/docs/plugin-basics for more information
class Test1Command(sublimeplugin.TextCommand):
   def run(self, view, args):
      view.insert(view.size(), "Hello, World!\n")


I type view.runCommand('Test1') at console and nowt happens, not even an error message.

Things I've tried:

- deleting test.pyc and resaving test.py, which causes test.pyc to be recreated
- calling Test1Command other things
- view.runCommand('test1') in case it's case sensitive
- shouting, in case it can hear me

I really want to like Sublime but when the documentation says you can do something simple like this and it doesn't work then there's no way I'm paying for it. Or I'm stupid.

Assuming cleverer people help me to solve this, how do I use all the plugins in the subdirectories of C:\Documents and Settings\[user]\Application Data\Sublime Text\Packages ?

Thank you in anticipation of helpful assistance.
cja
 
Posts: 3
Joined: Tue Oct 27, 2009 5:56 pm

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

Postby vim on Tue Oct 27, 2009 7:13 pm

hi, you should expect to see hello world inside your edited file, for example, if the cursor was at the end of the last line of code, you should expect:
Code: Select all
import sublime, sublimeplugin

# This simple plugin will add 'Hello, World!' to the end of the buffer when run.
# To run it, save it within the User/ directory, then open the console (Ctrl+~),
# and type: view.runCommand('sample')
#
# See http://www.sublimetext.com/docs/plugin-basics for more information
class Test1Command(sublimeplugin.TextCommand):
   def run(self, view, args):
      view.insert(view.size(), "Hello, World!\n")Hello, World!


do you see it? the "Hello, World!"?

if it doesn't work for, you should check the following:
1. open the console
2. do a little change on your script (add empty line for example)
3. now save the file
4. look at the console do you see errors? it this python parser gives errors at this stage, the script won't even run so later nothing will happen

if you want (for example for debug) to print to console, use
Code: Select all
print "Hello, World!\n"


this example was constructed that way, because most plugins are for help you on your current edited file: do some actions, parsing etc.

good luck
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

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

Postby jps on Tue Oct 27, 2009 9:00 pm

You should be fine if you do view.runCommand('test1') rather than view.runCommand('Test1')
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

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

Postby cja on Wed Oct 28, 2009 12:09 pm

Thanks for your replies.

jps - As I said in my original post, I tried view.runCommand('test1') but that didn't work either.

vim - The file I was editing (which was the script itself) remained unchanged. I can change the script so it errors on compilation.

Can I turn on enhanced logging so I can see exactly what happens when I call view.runCommand ?
cja
 
Posts: 3
Joined: Tue Oct 27, 2009 5:56 pm

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

Postby jps on Wed Oct 28, 2009 1:00 pm

Ah, I missed that part :)

There's no reason the plugin you posted shouldn't work - certainly, it does for me. Just to narrow things down, can you use this instead:

Code: Select all
import sublime, sublimeplugin

print "plugin loaded"

class Test1Command(sublimeplugin.TextCommand):
   def run(self, view, args):
      print "command run"


And see what gets printed in the console. Do you see "plugin loaded" when saving the file?
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

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

Postby cja on Wed Oct 28, 2009 2:19 pm

Brilliant. That works exactly as you say it should. (I'm new to Python too so didn't know I could put print commands all over the place!)

Also, and quite bizarrely, my other plugin seems to work too.

Now I have two files in C:\Documents and Settings\[user]\Application Data\Sublime Text\Packages\User with a class called Test1Command (jps.py and test.py). How does Sublime know which I want?

Also, how do I use all the plugins in the other subdirectories of C:\Documents and Settings\[user]\Application Data\Sublime Text\Packages ?
cja
 
Posts: 3
Joined: Tue Oct 27, 2009 5:56 pm

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

Postby jps on Wed Oct 28, 2009 8:58 pm

All plugins are put into the same namespace, so you can run them all in the same manner. e.g., you can run the command in Packages/Default/GotoSymbol.py by doing view.runCommand('gotoSymbol').

As to which of your two plugins will be run, I believe it'll just be whichever one is loaded last.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm


Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests