-
Notifications
You must be signed in to change notification settings - Fork 9
/
q_send_async.py
32 lines (26 loc) · 1.08 KB
/
q_send_async.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sublime
import sublime_plugin
from . import QCon
from . import q_send
from . import q_select_text
#run q statement in an alternative thread using sublime.set_timeout_async
#see https://forum.sublimetext.com/t/how-to-run-part-of-my-plugin-in-the-second-thread-properly/18962/7
#and https://www.sublimetext.com/docs/3/api_reference.html
class QSendAsyncCommand(sublime_plugin.TextCommand):
def run(self, edit, output=None):
s = q_select_text.QSelectTextCommand.selectText(self.view)
con = QCon.QCon.loadFromViewWithPrompt(self.view)
if con:
#do nothing if text is empty
if s != "":
sublime.set_timeout_async(lambda: self.send(con, s, output), 0)
def send(self, con, s, output):
#print(con.toDict())
#print(s)
if (s[0] == "\\"):
s = "value\"\\" + s + "\""
s = ".Q.s " + s
res = q_send.QSendRawCommand.sendAndUpdateStatus(self.view, con, s)
if output:
self.view.run_command(output, {"input": res})
sublime.set_timeout_async(lambda: self.view.run_command("q_update_completions"), 0)