Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stata support #1401

Merged
merged 14 commits into from
Jun 6, 2024
Merged
21 changes: 21 additions & 0 deletions apps/stata/stata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from talon import Context, Module

mod = Module()
ctx = Context()

mod.apps.stata = r"""
os: windows
and app.name: Stata
os: windows
and app.exe: /^statase\-64\.exe$/i
"""

ctx.matches = r"""
app: stata
"""


@ctx.action_class("code")
class CodeActions:
def language():
return "stata"
25 changes: 25 additions & 0 deletions apps/stata/stata_do_file_editor.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Commands for the Stata Do-File Editor
os: windows
app: stata
fidgetingbits marked this conversation as resolved.
Show resolved Hide resolved
win.title: /^Do-file Editor/
-
do this: key(ctrl-d)

do line:
edit.select_line()
key(ctrl-d)

do (all | file):
edit.select_all()
edit.copy()
key(ctrl-d)

do way up:
edit.extend_file_start()
edit.copy()
key(ctrl-d)

do way down:
edit.extend_file_end()
edit.copy()
key(ctrl-d)
1 change: 1 addition & 0 deletions core/modes/language_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"scss": "scss",
# 'snippets': 'snippets',
"sql": "sql",
"stata": "do ado",
"talon": "talon",
"talonlist": "talon-list",
"terraform": "tf",
Expand Down
167 changes: 167 additions & 0 deletions lang/stata/stata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
from talon import Context, actions, settings

ctx = Context()

ctx.matches = r"""
code.language: stata
"""

# functions.py
ctx.lists["user.code_parameter_name"] = {
# regressions
"V C E cluster": "vce(cluster)",
"V C E robust": "vce(robust)",
}

# functions_common.py
ctx.lists["user.code_common_function"] = {
# base stata
"global": "global",
"local": "local",
"reg": "reg",
"regress": "reg",
# packages
"estadd": "estadd",
maxbruening marked this conversation as resolved.
Show resolved Hide resolved
"estout": "estout",
"estpost": "estpost",
"eststo": "eststo",
"esttab": "esttab",
}

# libraries_gui.py
ctx.lists["user.code_libraries"] = {
"estout": "estout",
}


@ctx.action_class("user")
class UserActions:
# comment_line.py
def code_comment_line_prefix():
actions.auto_insert("* ")

# functions.py
def code_private_function(text: str):
result = "program {} \n\nend".format(
actions.user.formatted_text(
text, settings.get("user.code_private_function_formatter")
)
)
actions.user.paste(result)
actions.edit.up()
actions.key("tab")

def code_default_function(text: str):
actions.user.code_private_function(text)

def code_insert_named_argument(parameter_name: str):
actions.insert(f"{parameter_name} ")

# functions_common.py
def code_insert_function(text: str, selection: str):
text += f" {selection or ''}"
actions.user.paste(text)

# imperative.py
def code_block():
actions.auto_insert("\n")

def code_state_if():
actions.insert("if {\n\n}")
actions.key("up tab up")
actions.edit.line_end()
actions.key("left:2")

def code_state_else_if():
actions.insert("else if {\n\n}")
actions.key("up tab up")
actions.edit.line_end()
actions.key("left:2")

def code_state_else():
actions.insert("else {\n\n}")
actions.key("up tab")

def code_state_for():
actions.insert("forval {\n\n}")
actions.key("up tab up")
actions.edit.line_end()
actions.key("left:2")

def code_state_for_each():
actions.insert("foreach in {\n\n}")
actions.key("up tab up")
actions.edit.line_end()
actions.key("left:2")

def code_state_while():
actions.insert("while {\n\n}")
actions.key("up tab up")
actions.edit.line_end()
actions.key("left:2")

def code_break():
actions.insert("break")

def code_next():
actions.insert("continue")

# libraries.py
def code_import():
actions.auto_insert("ssc install ")

# libraries_gui.py
def code_insert_library(text: str, selection: str):
actions.auto_insert("ssc install ")
actions.user.paste(text + selection)

# operators_array.py
def code_operator_subscript():
actions.user.insert_between("[", "]")

# operators_assignment.py
def code_operator_assignment():
actions.auto_insert(" = ")

# operators_math.py
def code_operator_subtraction():
actions.auto_insert(" - ")

def code_operator_addition():
actions.auto_insert(" + ")

def code_operator_multiplication():
actions.auto_insert(" * ")

def code_operator_division():
actions.auto_insert(" / ")

def code_operator_modulo():
actions.user.insert_between("mod(", ")")

def code_operator_exponent():
actions.auto_insert(" ^ ")

def code_operator_equal():
actions.auto_insert(" == ")

def code_operator_not_equal():
actions.auto_insert(" != ")

def code_operator_greater_than():
actions.auto_insert(" > ")

def code_operator_less_than():
actions.auto_insert(" < ")

def code_operator_greater_than_or_equal_to():
actions.auto_insert(" >= ")

def code_operator_less_than_or_equal_to():
actions.auto_insert(" <= ")

def code_operator_and():
actions.auto_insert(" & ")

def code_operator_or():
actions.auto_insert(" | ")
28 changes: 28 additions & 0 deletions lang/stata/stata.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
code.language: stata
-
tag(): user.code_imperative

tag(): user.code_comment_block_c_like
tag(): user.code_comment_block
tag(): user.code_comment_line
tag(): user.code_functions
tag(): user.code_functions_common
tag(): user.code_libraries
tag(): user.code_libraries_gui
tag(): user.code_operators_array
tag(): user.code_operators_assignment

settings():
user.code_private_function_formatter = "SNAKE_CASE"

arg {user.code_parameter_name}: user.code_insert_named_argument(code_parameter_name)

state for val: user.code_state_for()

# alternative to saying ""state import""
s s c install: user.code_import()

s s c install <user.code_libraries>: user.code_insert_library(code_libraries, "")

toggle imports: user.code_toggle_libraries()
toggle packages: user.code_toggle_libraries()