Skip to content

Commit 6fcd300

Browse files
stata support (talonhub#1401)
Adds support for the stata language and application. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 47c2257 commit 6fcd300

File tree

5 files changed

+242
-0
lines changed

5 files changed

+242
-0
lines changed

apps/stata/stata.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from talon import Context, Module
2+
3+
mod = Module()
4+
ctx = Context()
5+
6+
mod.apps.stata = r"""
7+
os: windows
8+
and app.name: Stata
9+
os: windows
10+
and app.exe: /^statase\-64\.exe$/i
11+
"""
12+
13+
ctx.matches = r"""
14+
app: stata
15+
"""
16+
17+
18+
@ctx.action_class("code")
19+
class CodeActions:
20+
def language():
21+
return "stata"

apps/stata/stata_do_file_editor.talon

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Commands for the Stata Do-File Editor
2+
os: windows
3+
app: stata
4+
win.title: /^Do-file Editor/
5+
-
6+
do this: key(ctrl-d)
7+
8+
do line:
9+
edit.select_line()
10+
key(ctrl-d)
11+
12+
do (all | file):
13+
edit.select_all()
14+
edit.copy()
15+
key(ctrl-d)
16+
17+
do way up:
18+
edit.extend_file_start()
19+
edit.copy()
20+
key(ctrl-d)
21+
22+
do way down:
23+
edit.extend_file_end()
24+
edit.copy()
25+
key(ctrl-d)

core/modes/language_modes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"scss": "scss",
3838
# 'snippets': 'snippets',
3939
"sql": "sql",
40+
"stata": "do ado",
4041
"talon": "talon",
4142
"talonlist": "talon-list",
4243
"terraform": "tf",

lang/stata/stata.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
from talon import Context, actions, settings
2+
3+
ctx = Context()
4+
5+
ctx.matches = r"""
6+
code.language: stata
7+
"""
8+
9+
# functions.py
10+
ctx.lists["user.code_parameter_name"] = {
11+
# regressions
12+
"V C E cluster": "vce(cluster)",
13+
"V C E robust": "vce(robust)",
14+
}
15+
16+
# functions_common.py
17+
ctx.lists["user.code_common_function"] = {
18+
# base stata
19+
"global": "global",
20+
"local": "local",
21+
"reg": "reg",
22+
"regress": "reg",
23+
# packages
24+
"estadd": "estadd",
25+
"estout": "estout",
26+
"estpost": "estpost",
27+
"eststo": "eststo",
28+
"esttab": "esttab",
29+
}
30+
31+
# libraries_gui.py
32+
ctx.lists["user.code_libraries"] = {
33+
"estout": "estout",
34+
}
35+
36+
37+
@ctx.action_class("user")
38+
class UserActions:
39+
# comment_line.py
40+
def code_comment_line_prefix():
41+
actions.auto_insert("* ")
42+
43+
# functions.py
44+
def code_private_function(text: str):
45+
result = "program {} \n\nend".format(
46+
actions.user.formatted_text(
47+
text, settings.get("user.code_private_function_formatter")
48+
)
49+
)
50+
actions.user.paste(result)
51+
actions.edit.up()
52+
actions.key("tab")
53+
54+
def code_default_function(text: str):
55+
actions.user.code_private_function(text)
56+
57+
def code_insert_named_argument(parameter_name: str):
58+
actions.insert(f"{parameter_name} ")
59+
60+
# functions_common.py
61+
def code_insert_function(text: str, selection: str):
62+
text += f" {selection or ''}"
63+
actions.user.paste(text)
64+
65+
# imperative.py
66+
def code_block():
67+
actions.auto_insert("\n")
68+
69+
def code_state_if():
70+
actions.insert("if {\n\n}")
71+
actions.key("up tab up")
72+
actions.edit.line_end()
73+
actions.key("left:2")
74+
75+
def code_state_else_if():
76+
actions.insert("else if {\n\n}")
77+
actions.key("up tab up")
78+
actions.edit.line_end()
79+
actions.key("left:2")
80+
81+
def code_state_else():
82+
actions.insert("else {\n\n}")
83+
actions.key("up tab")
84+
85+
def code_state_for():
86+
actions.insert("forval {\n\n}")
87+
actions.key("up tab up")
88+
actions.edit.line_end()
89+
actions.key("left:2")
90+
91+
def code_state_for_each():
92+
actions.insert("foreach in {\n\n}")
93+
actions.key("up tab up")
94+
actions.edit.line_end()
95+
actions.key("left:2")
96+
97+
def code_state_while():
98+
actions.insert("while {\n\n}")
99+
actions.key("up tab up")
100+
actions.edit.line_end()
101+
actions.key("left:2")
102+
103+
def code_break():
104+
actions.insert("break")
105+
106+
def code_next():
107+
actions.insert("continue")
108+
109+
# libraries.py
110+
def code_import():
111+
actions.auto_insert("ssc install ")
112+
113+
# libraries_gui.py
114+
def code_insert_library(text: str, selection: str):
115+
actions.auto_insert("ssc install ")
116+
actions.user.paste(text + selection)
117+
118+
# operators_array.py
119+
def code_operator_subscript():
120+
actions.user.insert_between("[", "]")
121+
122+
# operators_assignment.py
123+
def code_operator_assignment():
124+
actions.auto_insert(" = ")
125+
126+
# operators_math.py
127+
def code_operator_subtraction():
128+
actions.auto_insert(" - ")
129+
130+
def code_operator_addition():
131+
actions.auto_insert(" + ")
132+
133+
def code_operator_multiplication():
134+
actions.auto_insert(" * ")
135+
136+
def code_operator_division():
137+
actions.auto_insert(" / ")
138+
139+
def code_operator_modulo():
140+
actions.user.insert_between("mod(", ")")
141+
142+
def code_operator_exponent():
143+
actions.auto_insert(" ^ ")
144+
145+
def code_operator_equal():
146+
actions.auto_insert(" == ")
147+
148+
def code_operator_not_equal():
149+
actions.auto_insert(" != ")
150+
151+
def code_operator_greater_than():
152+
actions.auto_insert(" > ")
153+
154+
def code_operator_less_than():
155+
actions.auto_insert(" < ")
156+
157+
def code_operator_greater_than_or_equal_to():
158+
actions.auto_insert(" >= ")
159+
160+
def code_operator_less_than_or_equal_to():
161+
actions.auto_insert(" <= ")
162+
163+
def code_operator_and():
164+
actions.auto_insert(" & ")
165+
166+
def code_operator_or():
167+
actions.auto_insert(" | ")

lang/stata/stata.talon

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
code.language: stata
2+
-
3+
tag(): user.code_imperative
4+
5+
tag(): user.code_comment_block_c_like
6+
tag(): user.code_comment_block
7+
tag(): user.code_comment_line
8+
tag(): user.code_functions
9+
tag(): user.code_functions_common
10+
tag(): user.code_libraries
11+
tag(): user.code_libraries_gui
12+
tag(): user.code_operators_array
13+
tag(): user.code_operators_assignment
14+
15+
settings():
16+
user.code_private_function_formatter = "SNAKE_CASE"
17+
18+
arg {user.code_parameter_name}: user.code_insert_named_argument(code_parameter_name)
19+
20+
state for val: user.code_state_for()
21+
22+
# alternative to saying ""state import""
23+
s s c install: user.code_import()
24+
25+
s s c install <user.code_libraries>: user.code_insert_library(code_libraries, "")
26+
27+
toggle imports: user.code_toggle_libraries()
28+
toggle packages: user.code_toggle_libraries()

0 commit comments

Comments
 (0)