Sublime Forum

Perform action when user stops typing -- possible?

#1

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).

0 Likes

#2

It was not easy to find, but the Idle Watcher plugin example seems to be what I was looking for.

0 Likes

#3

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] sublimetext.com/docs/2/api_reference.html

0 Likes

#4

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.

0 Likes

#5

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.

0 Likes

#6

Yes, the syntax is probably from ST1.

0 Likes