Home Download Buy Blog Forum Support

Perform action when user stops typing -- possible?

Perform action when user stops typing -- possible?

Postby szhorvat on Fri Nov 23, 2012 3:50 pm

Hello,

I am a new user trying out Sublime Text for the first time (watched most of the perfect workflow tutorials). I am trying to figure out if Sublime Text can replace most of the functions of my current editor (Vim).

Vim has a feature which makes it possible to execute a custom action when I stop typing (Vim users please see :he CursorHold), for example save the file. I use this when writing LaTeX to have near-real-time preview. It's possible to set a time delay before the action will be performed (I use 0.8 seconds). Is it possible to set this up in Sublime Text? Actually the only action I need is saving the file (and not show errors if it happens not to be writable).
szhorvat
 
Posts: 2
Joined: Fri Nov 23, 2012 3:41 pm

Re: Perform action when user stops typing -- possible?

Postby szhorvat on Fri Nov 23, 2012 5:00 pm

It was not easy to find, but the Idle Watcher plugin example seems to be what I was looking for.
szhorvat
 
Posts: 2
Joined: Fri Nov 23, 2012 3:41 pm

Re: Perform action when user stops typing -- possible?

Postby phillip.koebbe on Fri Nov 23, 2012 7:33 pm

I may be mistaken, but I believe that's from ST 1, not ST 2. I couldn't find anything in the v2 API docs [1] referring to an onIdle. It may be something I'm not familiar with, though.

[1] http://www.sublimetext.com/docs/2/api_reference.html
-- Phillip

Code: Select all
while self.living? do
    mistake = Mistake.new
    self.learn_from!(mistake) unless mistake.fatal?
end
phillip.koebbe
 
Posts: 208
Joined: Tue Dec 20, 2011 4:58 pm

Re: Perform action when user stops typing -- possible?

Postby facelessuser on Fri Nov 23, 2012 9:34 pm

I don't think onIdle is supposed to be a built in method even in the example as much as a method defined in the example to show how you could do something when ST2 is idle.

The concept should work just fine. I know I do something similar in some of my plugins so I don't execute on every key press, but wait until there is a pause in key presses before executing the payload again.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: Perform action when user stops typing -- possible?

Postby phillip.koebbe on Fri Nov 23, 2012 9:55 pm

That's a good point, Isaac. But then again, the example refers to 'sublimeplugin.Plugin', and the docs refer to 'sublime_plugin' (note the underscore) and I don't see a Plugin class, though that could be an ancestor of the existing plugins. I should have been more clear in that I think the API code the examples refer to is from v1 not v2.
-- Phillip

Code: Select all
while self.living? do
    mistake = Mistake.new
    self.learn_from!(mistake) unless mistake.fatal?
end
phillip.koebbe
 
Posts: 208
Joined: Tue Dec 20, 2011 4:58 pm

Re: Perform action when user stops typing -- possible?

Postby facelessuser on Fri Nov 23, 2012 10:03 pm

Yes, the syntax is probably from ST1.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 17 guests