init commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
list: user.code_common_function
|
||||
code.language: javascript
|
||||
code.language: typescript
|
||||
code.language: javascriptreact
|
||||
code.language: typescriptreact
|
||||
-
|
||||
|
||||
abs: Math.abs
|
||||
entries: Object.entries
|
||||
fetch: fetch
|
||||
floor: Math.floor
|
||||
from entries: Object.fromEntries
|
||||
keys: Object.keys
|
||||
log: console.log
|
||||
max: Math.max
|
||||
min: Math.min
|
||||
print: console.log
|
||||
round: Math.round
|
||||
values: Object.values
|
||||
@@ -0,0 +1,203 @@
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
mod = Module()
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: javascript
|
||||
code.language: typescript
|
||||
code.language: javascriptreact
|
||||
code.language: typescriptreact
|
||||
"""
|
||||
|
||||
mod.list("code_common_member_function", "Function to use in a dotted chain, eg .foo()")
|
||||
|
||||
ctx.lists["user.code_common_member_function"] = {
|
||||
"catch": "catch",
|
||||
"concat": "concat",
|
||||
"filter": "filter",
|
||||
"finally": "finally",
|
||||
"find": "find",
|
||||
"flat map": "flatMap",
|
||||
"for each": "forEach",
|
||||
"join": "join",
|
||||
"includes": "includes",
|
||||
"map": "map",
|
||||
"pop": "pop",
|
||||
"push": "push",
|
||||
"reduce": "reduce",
|
||||
"slice": "slice",
|
||||
"some": "some",
|
||||
"split": "split",
|
||||
"substring": "substring",
|
||||
"then": "then",
|
||||
}
|
||||
|
||||
ctx.lists["user.code_keyword"] = {
|
||||
"a sink": "async ",
|
||||
"await": "await ",
|
||||
"break": "break",
|
||||
"class": "class ",
|
||||
"const": "const ",
|
||||
"continue": "continue",
|
||||
"default": "default ",
|
||||
"export": "export ",
|
||||
"false": "false",
|
||||
"function": "function ",
|
||||
"import": "import ",
|
||||
"let": "let ",
|
||||
"new": "new ",
|
||||
"null": "null",
|
||||
"private": "private ",
|
||||
"protected": "protected ",
|
||||
"public": "public ",
|
||||
"return": "return ",
|
||||
"throw": "throw ",
|
||||
"true": "true",
|
||||
"try": "try ",
|
||||
"undefined": "undefined",
|
||||
"yield": "yield ",
|
||||
}
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
ASSIGNMENT_OR=" ||= ",
|
||||
ASSIGNMENT_ADDITION=" += ",
|
||||
ASSIGNMENT_SUBTRACTION=" -= ",
|
||||
ASSIGNMENT_MULTIPLICATION=" *= ",
|
||||
ASSIGNMENT_DIVISION=" /= ",
|
||||
ASSIGNMENT_MODULO=" %= ",
|
||||
ASSIGNMENT_INCREMENT="++",
|
||||
ASSIGNMENT_BITWISE_AND=" &= ",
|
||||
ASSIGNMENT_BITWISE_OR=" |= ",
|
||||
ASSIGNMENT_BITWISE_EXCLUSIVE_OR=" ^= ",
|
||||
ASSIGNMENT_BITWISE_LEFT_SHIFT=" <<= ",
|
||||
ASSIGNMENT_BITWISE_RIGHT_SHIFT=" >>= ",
|
||||
# code_operators_bitwise
|
||||
BITWISE_AND=" & ",
|
||||
BITWISE_OR=" | ",
|
||||
BITWISE_EXCLUSIVE_OR=" ^ ",
|
||||
BITWISE_LEFT_SHIFT=" << ",
|
||||
BITWISE_RIGHT_SHIFT=" >> ",
|
||||
# code_operators_lambda
|
||||
LAMBDA=" => ",
|
||||
# code_operators_math
|
||||
MATH_ADD=" + ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" % ",
|
||||
MATH_EXPONENT=" ** ",
|
||||
MATH_EQUAL=" === ",
|
||||
MATH_NOT_EQUAL=" !== ",
|
||||
MATH_OR=" || ",
|
||||
MATH_AND=" && ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
MATH_WEAK_EQUAL=" == ",
|
||||
MATH_WEAK_NOT_EQUAL=" != ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.auto_insert(" !== null")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.auto_insert(" === null")
|
||||
|
||||
def code_self():
|
||||
actions.auto_insert("this")
|
||||
|
||||
def code_operator_object_accessor():
|
||||
actions.auto_insert(".")
|
||||
|
||||
def code_insert_true():
|
||||
actions.auto_insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.auto_insert("false")
|
||||
|
||||
def code_insert_null():
|
||||
actions.auto_insert("null")
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
text += f"({selection or ''})"
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
def code_default_function(text: str):
|
||||
"""Inserts function declaration without modifiers"""
|
||||
result = "function {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.code_insert_function(result, None)
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "function {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.code_insert_function(result, None)
|
||||
|
||||
# def code_private_static_function(text: str):
|
||||
# """Inserts private static function"""
|
||||
# result = "private static void {}".format(
|
||||
# actions.user.formatted_text(
|
||||
# text, settings.get("user.code_private_function_formatter")
|
||||
# )
|
||||
# )
|
||||
|
||||
# actions.user.code_insert_function(result, None)
|
||||
|
||||
def code_protected_function(text: str):
|
||||
result = "function {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_protected_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.code_insert_function(result, None)
|
||||
|
||||
# def code_protected_static_function(text: str):
|
||||
# result = "protected static void {}".format(
|
||||
# actions.user.formatted_text(
|
||||
# text, settings.get("user.code_protected_function_formatter")
|
||||
# )
|
||||
# )
|
||||
|
||||
# actions.user.code_insert_function(result, None)
|
||||
|
||||
def code_public_function(text: str):
|
||||
result = "function {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_public_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.code_insert_function(result, None)
|
||||
|
||||
# def code_public_static_function(text: str):
|
||||
# result = "public static void {}".format(
|
||||
# actions.user.formatted_text(
|
||||
# text, settings.get("user.code_public_function_formatter")
|
||||
# )
|
||||
# )
|
||||
|
||||
# actions.user.code_insert_function(result, None)
|
||||
@@ -0,0 +1,62 @@
|
||||
code.language: javascript
|
||||
code.language: typescript
|
||||
code.language: javascriptreact
|
||||
code.language: typescriptreact
|
||||
-
|
||||
tag(): user.code_imperative
|
||||
tag(): user.code_object_oriented
|
||||
|
||||
tag(): user.code_comment_line
|
||||
tag(): user.code_comment_block_c_like
|
||||
tag(): user.code_data_bool
|
||||
tag(): user.code_data_null
|
||||
tag(): user.code_functions
|
||||
tag(): user.code_functions_common
|
||||
tag(): user.code_keywords
|
||||
tag(): user.code_libraries
|
||||
tag(): user.code_operators_array
|
||||
tag(): user.code_operators_assignment
|
||||
tag(): user.code_operators_bitwise
|
||||
tag(): user.code_operators_lambda
|
||||
tag(): user.code_operators_math
|
||||
|
||||
settings():
|
||||
user.code_private_function_formatter = "PRIVATE_CAMEL_CASE"
|
||||
user.code_protected_function_formatter = "PRIVATE_CAMEL_CASE"
|
||||
user.code_public_function_formatter = "PRIVATE_CAMEL_CASE"
|
||||
user.code_private_variable_formatter = "PRIVATE_CAMEL_CASE"
|
||||
user.code_protected_variable_formatter = "PRIVATE_CAMEL_CASE"
|
||||
user.code_public_variable_formatter = "PRIVATE_CAMEL_CASE"
|
||||
|
||||
(op | is) strict equal:
|
||||
user.deprecate_command("2025-03-4", "(op | is) strict equal", "is equal")
|
||||
user.code_operator("MATH_EQUAL")
|
||||
|
||||
(op | is) strict not equal:
|
||||
user.deprecate_command("2025-03-4", "(op | is) strict not equal", "is not equal")
|
||||
user.code_operator("MATH_NOT_EQUAL")
|
||||
|
||||
op null else: " ?? "
|
||||
|
||||
state const: "const "
|
||||
|
||||
state let: "let "
|
||||
|
||||
state var: "var "
|
||||
|
||||
state export: "export "
|
||||
|
||||
state async: "async "
|
||||
|
||||
state await: "await "
|
||||
|
||||
dot {user.code_common_member_function}:
|
||||
user.insert_between(".{code_common_member_function}(", ")")
|
||||
|
||||
state map: app.notify('ERROR: Command deprecated; please use "dot map"')
|
||||
state filter: app.notify('ERROR: Command deprecated; please use "dot filter"')
|
||||
state reduce: app.notify('ERROR: Command deprecated; please use "dot reduce"')
|
||||
|
||||
state spread: "..."
|
||||
|
||||
from import: user.insert_between(' from "', '"')
|
||||
Reference in New Issue
Block a user