83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
from talon import Module, Context, actions, ui, imgui, settings
|
|
|
|
ctx = Context()
|
|
ctx.matches = r"""
|
|
mode: user.javascript
|
|
mode: command
|
|
and code.language: javascript
|
|
"""
|
|
# tbd
|
|
# ctx.lists["user.code_functions"] = {
|
|
# "integer": "int.TryParse",
|
|
# "print": "Console.WriteLine",
|
|
# "string": ".ToString",
|
|
# }
|
|
|
|
|
|
@ctx.action_class("user")
|
|
class user_actions:
|
|
def code_insert_function(text: str, selection: str):
|
|
if selection:
|
|
text = text + "({})".format(selection)
|
|
else:
|
|
text = text + "()"
|
|
|
|
actions.user.paste(text)
|
|
actions.edit.left()
|
|
|
|
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)
|
|
|