Specific events in sublime text 3
-
23-12-2019 - |
Question
I am writing a plugin for Sublime Text 3 such that I need to do either of two things:
1) Run a function every 300 milliseconds 2) Run a function whenever the cursor changes position
Although I have been looking over the documentation and examining the examples in the Default
package, I yet am having trouble achieving my goal. What would help me is small example that prints "hello, world" to a buffer every time one of the above 2 conditions are met. Thank you.
Solution
As an answer I gave to this question it has something similar, you also add set_timeout for running every 300ms:
annoying_helloworld.py
class someclass():
def run(x):
print("Hello world!" + str(x))
def run_with_timeout(x):
someclass.run(x)
sublime.set_timeout(lambda: someclass.run_with_timeout(123), 300)
class utfcodeCommand(sublime_plugin.EventListener):
def on_selection_modified(self, view):
someclass.run(666)
sublime.set_timeout(lambda: someclass.run_with_timeout(123), 300)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow