Home Download Buy Blog Forum Support

[SOLVED] How to create a plugin?

Re: [SOLVED] How to create a plugin?

Postby trebitzki on Sat Aug 15, 2009 9:44 am

I'll get back to you in a week, I'm offline on vakay... ta ta
trebitzki
 
Posts: 5
Joined: Wed Aug 12, 2009 10:16 pm

Re: [SOLVED] How to create a plugin?

Postby EJ12N on Mon Aug 17, 2009 7:59 pm

trebitzki wrote:Another question on creating plugins...

I want to make one that saves the current file and exits the app.

saveAndExit.py
Code: Select all
import sublime, sublimeplugin

class saveAndExit(sublimeplugin.TextCommand):
   def run(self, view, args):
      # Save the current file
      view.runCommand('save')

      # Quit Sublime
      view.runCommand('exit')


Doesn't work. I thought you can use commands like that?

http://www.sublimetext.com/docs/commands:
save Saves the current buffer, prompting for a file name if it doesn't have one yet

exit Closes all windows


BTW can anyone make a new forum category like 'tutorials'? I'd like to write this up so that people can find it right on the forum page without searching...
Would be a good place to put tips and stuff scattered around the forum and the user blogs (sublimator, EJ12N) too, eh?


That doesn't work is because you have sublimeplugin.TextCommand
you are using windows commands so you have 2 ways of accomplishing what you want...

replace:sublimeplugin.TextCommand with: sublimeplugin.WindowCommand
in the above code and instead of view use now the arg is window.

Code: Select all
import sublime, sublimeplugin

class saveAndExit(sublimeplugin.WindowCommand):
   def run(self, window, args):
      # Save the current file
      window.runCommand('save')

      # Quit Sublime
      window.runCommand('exit')

it should work =] haven't tested it yet but it should.
---
The other solution instead of doing all those changes is to use view.window().runCommand instead of view.runCommand, this is what I personally use when doing window commands :)

** I have added saveAndExit to my PowerUser package :) **
PS: as a bonus, if you use hotExit instead of exit command you preserve the session when quitting sublime :)
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: [SOLVED] How to create a plugin?

Postby trebitzki on Tue Aug 25, 2009 7:14 pm

EJ12N wrote:The other solution instead of doing all those changes is to use view.window().runCommand instead of view.runCommand, this is what I personally use when doing window commands :)


Great!! That did it! Now I have a simple Notetaking system:

  • Open Sublime Text using a windows keyboard shortcut (Ctrl+Shift+S).
  • Session data is automatically restored with the last open file, in my case the 'notes' file.
  • Ctrl+Shift+F5 starts the 'insertDateAtTop' plugin, ready to type another note.
  • Ctrl+Shift+F4 saves the file and quits the app.

Whew! [wipesweat /] That was quite a journey! At every step another nuance was presented by the helpful gurus, showing me how to get it done.

Again, there is absolutely no information on the website, explaining these intricate ins and outs of writing a plugin.

I sure would like to write this up so people can have it all in one place. Could an admin please create a 'Tutorials' section in the forum?
trebitzki
 
Posts: 5
Joined: Wed Aug 12, 2009 10:16 pm

Re: [SOLVED] How to create a plugin?

Postby EJ12N on Wed Sep 02, 2009 8:48 pm

Good job on the notetaking implementation :)

trebitzki wrote:
EJ12N wrote:The other solution instead of doing all those changes is to use view.window().runCommand instead of view.runCommand, this is what I personally use when doing window commands :)


Great!! That did it! Now I have a simple Notetaking system:

  • Open Sublime Text using a windows keyboard shortcut (Ctrl+Shift+S).
  • Session data is automatically restored with the last open file, in my case the 'notes' file.
  • Ctrl+Shift+F5 starts the 'insertDateAtTop' plugin, ready to type another note.
  • Ctrl+Shift+F4 saves the file and quits the app.

Whew! [wipesweat /] That was quite a journey! At every step another nuance was presented by the helpful gurus, showing me how to get it done.

Again, there is absolutely no information on the website, explaining these intricate ins and outs of writing a plugin.

I sure would like to write this up so people can have it all in one place. Could an admin please create a 'Tutorials' section in the forum?
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Previous

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 21 guests