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?
import sublime, sublimeplugin
class saveAndExit(sublimeplugin.WindowCommand):
def run(self, window, args):
# Save the current file
window.runCommand('save')
# Quit Sublime
window.runCommand('exit')
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
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?
Users browsing this forum: Crasher and 13 guests