Home Download Buy Blog Forum Support

Auto Save on Every Keypress

Auto Save on Every Keypress

Postby geddesign on Mon Jun 25, 2012 6:59 pm

Does anyone know how to make SublimeText2 save on every keypress? I use LiveReload for web dev and would love to have it refresh without having to hit cmd+s.
geddesign
 
Posts: 4
Joined: Mon Jun 25, 2012 6:57 pm

Re: Auto Save on Every Keypress

Postby jonathan on Mon Jun 25, 2012 7:21 pm

Wouldn't that be really annoying?

What happens when your in the middle of writing an HTML tag, or haven't closed a CSS bracket...you would get some bad results.

Cmd-S is really easy to press. :)
jonathan
 
Posts: 22
Joined: Tue Aug 30, 2011 12:42 pm

Re: Auto Save on Every Keypress

Postby geddesign on Mon Jun 25, 2012 9:32 pm

I don't think it would be annoying. Maybe it could be configured to wait x milliseconds for another key before triggering the save. So that it saves on idle like WebStorm does, but without the minimum time limit of 1 second like it has.
geddesign
 
Posts: 4
Joined: Mon Jun 25, 2012 6:57 pm

Re: Auto Save on Every Keypress

Postby xapoh on Tue Jun 26, 2012 3:31 pm

Something like this might work for you. Save it into a file (e.g. AutoSave.py) and drop it into /Sublime Text 2/Packages/User folder.
Code: Select all
import sublime, sublime_plugin

class AutoSaveCommand(sublime_plugin.EventListener):
    def on_modified(self, view):
        view.run_command('save')


NOTE: it will save on every modification. To add the 'wait x ms' functionality you will have to add a new thread; waiting in the event handler is NOT a good idea.
xapoh
 
Posts: 8
Joined: Fri Jun 01, 2012 11:50 pm

Re: Auto Save on Every Keypress

Postby jbrooksuk on Tue Jun 26, 2012 4:59 pm

This is very memory intensive work though? I really don't see this being any good for anybody?
jbrooksuk
 
Posts: 754
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Auto Save on Every Keypress

Postby matthew-campbell on Wed May 22, 2013 1:54 am

How would I make it save every x number of keypresses?
matthew-campbell
 
Posts: 1
Joined: Wed May 22, 2013 1:50 am

Re: Auto Save on Every Keypress

Postby KonTrax on Wed May 22, 2013 5:36 pm

matthew-campbell wrote:How would I make it save every x number of keypresses?


Just a quick example
Code: Select all
import sublime, sublime_plugin

class AutoSaveCommand(sublime_plugin.EventListener):
    clicks = 0
    clicksTrigger = 10
    def on_modified(self, view):
        self.clicks += 1
        if self.clicks <= self.clicksTrigger:
            self.clicks = 0
            view.run_command('save')
KonTrax
 
Posts: 46
Joined: Sun Mar 17, 2013 10:24 am

Re: Auto Save on Every Keypress

Postby kristianthrane on Thu Jul 04, 2013 12:47 pm

Anybody got this to work?

Or have other solutions for an alternative to CTRL + S -> Livereload scenario?

Best regards,
Kristian Thrane
kristianthrane
 
Posts: 2
Joined: Thu Jul 04, 2013 12:45 pm

Re: Auto Save on Every Keypress

Postby layne on Thu Jul 04, 2013 3:01 pm

You can use the following setup:
Code: Select all
"save_on_focus_lost": true,

Switching to the browser will save and reload.

If you use a side by side view this will not help I know.
// my Blog //
layne
 
Posts: 39
Joined: Tue Jan 04, 2011 3:00 pm
Location: NRW // GER

Re: Auto Save on Every Keypress

Postby kristianthrane on Fri Jul 05, 2013 12:14 pm

Thanks - but yeah - I am looking for a solution that either fires the save-event every 10 keystrokes or every 3rd second-ish :)
kristianthrane
 
Posts: 2
Joined: Thu Jul 04, 2013 12:45 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 34 guests