-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for the stata language and application. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
47c2257
commit 6fcd300
Showing
5 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
"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(" | ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |