init commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
list: user.code_common_function
|
||||
code.language: stata
|
||||
-
|
||||
|
||||
# base stata
|
||||
global
|
||||
local
|
||||
reg
|
||||
regress: reg
|
||||
# packages
|
||||
estadd
|
||||
estout
|
||||
estpost
|
||||
eststo
|
||||
esttab
|
||||
@@ -0,0 +1,78 @@
|
||||
from talon import Context, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
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)",
|
||||
}
|
||||
|
||||
# libraries.py
|
||||
ctx.lists["user.code_libraries"] = {
|
||||
"estout": "estout",
|
||||
}
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
# code_operators_math
|
||||
MATH_ADD=" + ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=lambda: actions.user.insert_between("mod(", ")"),
|
||||
MATH_EXPONENT=" ^ ",
|
||||
MATH_EQUAL=" == ",
|
||||
MATH_NOT_EQUAL=" != ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
MATH_AND=" & ",
|
||||
MATH_OR=" | ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
# 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):
|
||||
substitutions = {"1": text}
|
||||
if selection:
|
||||
substitutions["0"] = selection
|
||||
actions.user.insert_snippet_by_name("functionCall", substitutions)
|
||||
|
||||
# libraries.py
|
||||
def code_insert_library(text: str, selection: str):
|
||||
library_text = text + selection
|
||||
actions.user.insert_snippet_by_name("importStatement", {"0": library_text})
|
||||
@@ -0,0 +1,25 @@
|
||||
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_operators_array
|
||||
tag(): user.code_operators_assignment
|
||||
tag(): user.code_operators_math
|
||||
|
||||
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.insert_snippet_by_name("forLoopStatement")
|
||||
|
||||
# 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, "")
|
||||
Reference in New Issue
Block a user