init commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
from talon import Context, actions
|
||||
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: batch
|
||||
"""
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_comment_line_prefix():
|
||||
actions.user.insert_snippet_by_name("commentLine")
|
||||
@@ -0,0 +1,16 @@
|
||||
code.language: batch
|
||||
-
|
||||
tag(): user.code_comment_line
|
||||
|
||||
# exit without killing cmd shell
|
||||
soft exit: "exit /B 1\n"
|
||||
# exit with killing cmd shell
|
||||
hard exit: "exit 1\n"
|
||||
echo: "echo "
|
||||
echo off: "@echo off\n"
|
||||
call: "call "
|
||||
call shell: "call cmd \\c "
|
||||
if error: "if errorlevel 1 "
|
||||
go to: "goto "
|
||||
delayed expansion: "SETLOCAL EnableDelayedExpansion\n"
|
||||
arg <number_small>: "%{number_small}"
|
||||
@@ -0,0 +1,241 @@
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
mod = Module()
|
||||
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: c
|
||||
"""
|
||||
|
||||
ctx.lists["self.c_pointers"] = {
|
||||
"pointer": "*",
|
||||
"pointer to pointer": "**",
|
||||
}
|
||||
|
||||
ctx.lists["self.stdint_signed"] = {
|
||||
"signed": "",
|
||||
"unsigned": "u",
|
||||
"you": "u",
|
||||
}
|
||||
|
||||
ctx.lists["self.c_signed"] = {
|
||||
"signed": "signed",
|
||||
"unsigned": "unsigned",
|
||||
}
|
||||
|
||||
ctx.lists["self.c_keywords"] = {
|
||||
"static": "static",
|
||||
"volatile": "volatile",
|
||||
"register": "register",
|
||||
}
|
||||
|
||||
ctx.lists["self.stdint_types"] = {
|
||||
"character": "int8_t",
|
||||
"char": "int8_t",
|
||||
"short": "int16_t",
|
||||
"long": "int32_t",
|
||||
"long long": "int64_t",
|
||||
"int": "int32_t",
|
||||
"integer": "int32_t",
|
||||
"void": "void",
|
||||
"double": "double",
|
||||
"struct": "struct",
|
||||
"struck": "struct",
|
||||
"num": "enum",
|
||||
"union": "union",
|
||||
"float": "float",
|
||||
}
|
||||
|
||||
ctx.lists["self.c_types"] = {
|
||||
"character": "char",
|
||||
"char": "char",
|
||||
"short": "short",
|
||||
"long": "long",
|
||||
"int": "int",
|
||||
"integer": "int",
|
||||
"void": "void",
|
||||
"double": "double",
|
||||
"struct": "struct",
|
||||
"struck": "struct",
|
||||
"num": "enum",
|
||||
"union": "union",
|
||||
"float": "float",
|
||||
}
|
||||
|
||||
ctx.lists["user.code_libraries"] = {
|
||||
"assert": "assert.h",
|
||||
"type": "ctype.h",
|
||||
"error": "errno.h",
|
||||
"float": "float.h",
|
||||
"limits": "limits.h",
|
||||
"locale": "locale.h",
|
||||
"math": "math.h",
|
||||
"set jump": "setjmp.h",
|
||||
"signal": "signal.h",
|
||||
"arguments": "stdarg.h",
|
||||
"definition": "stddef.h",
|
||||
"input": "stdio.h",
|
||||
"output": "stdio.h",
|
||||
"library": "stdlib.h",
|
||||
"string": "string.h",
|
||||
"time": "time.h",
|
||||
"standard int": "stdint.h",
|
||||
}
|
||||
|
||||
mod.list("c_pointers", desc="Common C pointers")
|
||||
mod.list("c_signed", desc="Common C datatype signed modifiers")
|
||||
mod.list("c_keywords", desc="C keywords")
|
||||
mod.list("c_types", desc="Common C types")
|
||||
mod.list("stdint_types", desc="Common stdint C types")
|
||||
mod.list("stdint_signed", desc="Common stdint C datatype signed modifiers")
|
||||
|
||||
|
||||
@mod.capture(rule="{self.c_pointers}")
|
||||
def c_pointers(m) -> str:
|
||||
"Returns a string"
|
||||
return m.c_pointers
|
||||
|
||||
|
||||
@mod.capture(rule="{self.c_signed}")
|
||||
def c_signed(m) -> str:
|
||||
"Returns a string"
|
||||
return m.c_signed
|
||||
|
||||
|
||||
@mod.capture(rule="{self.c_keywords}")
|
||||
def c_keywords(m) -> str:
|
||||
"Returns a string"
|
||||
return m.c_keywords
|
||||
|
||||
|
||||
@mod.capture(rule="{self.c_types}")
|
||||
def c_types(m) -> str:
|
||||
"Returns a string"
|
||||
return m.c_types
|
||||
|
||||
|
||||
@mod.capture(rule="{self.stdint_types}")
|
||||
def stdint_types(m) -> str:
|
||||
"Returns a string"
|
||||
return m.stdint_types
|
||||
|
||||
|
||||
@mod.capture(rule="{self.stdint_signed}")
|
||||
def stdint_signed(m) -> str:
|
||||
"Returns a string"
|
||||
return m.stdint_signed
|
||||
|
||||
|
||||
@mod.capture(rule="[<self.c_signed>] <self.c_types> [<self.c_pointers>+]")
|
||||
def c_cast(m) -> str:
|
||||
"Returns a string"
|
||||
return "(" + " ".join(list(m)) + ")"
|
||||
|
||||
|
||||
@mod.capture(rule="[<self.stdint_signed>] <self.stdint_types> [<self.c_pointers>+]")
|
||||
def stdint_cast(m) -> str:
|
||||
"Returns a string"
|
||||
return "(" + "".join(list(m)) + ")"
|
||||
|
||||
|
||||
@mod.capture(rule="[<self.c_signed>] <self.c_types> [<self.c_pointers>]")
|
||||
def c_variable(m) -> str:
|
||||
"Returns a string"
|
||||
return " ".join(list(m))
|
||||
|
||||
|
||||
operators = Operators(
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
ASSIGNMENT=" = ",
|
||||
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=" >>= ",
|
||||
BITWISE_AND=" & ",
|
||||
BITWISE_OR=" | ",
|
||||
BITWISE_NOT="~",
|
||||
BITWISE_EXCLUSIVE_OR=" ^ ",
|
||||
BITWISE_LEFT_SHIFT=" << ",
|
||||
BITWISE_RIGHT_SHIFT=" >> ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" % ",
|
||||
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=" || ",
|
||||
MATH_NOT="!",
|
||||
POINTER_INDIRECTION="*",
|
||||
POINTER_ADDRESS_OF="&",
|
||||
POINTER_STRUCTURE_DEREFERENCE="->",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_insert_null():
|
||||
actions.auto_insert("NULL")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.auto_insert(" == NULL ")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.auto_insert(" != NULL")
|
||||
|
||||
def code_insert_true():
|
||||
actions.auto_insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.auto_insert("false")
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
if selection:
|
||||
text = text + f"({selection})"
|
||||
else:
|
||||
text = text + "()"
|
||||
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
# TODO - it would be nice that you integrate that types from c_cast
|
||||
# instead of defaulting to void
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "void {}".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 = "static void {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.code_insert_function(result, None)
|
||||
|
||||
def code_insert_library(text: str, selection: str):
|
||||
actions.user.paste(f"#include <{text}>")
|
||||
@@ -0,0 +1,86 @@
|
||||
code.language: c
|
||||
-
|
||||
tag(): user.code_imperative
|
||||
|
||||
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_libraries
|
||||
tag(): user.code_operators_array
|
||||
tag(): user.code_operators_assignment
|
||||
tag(): user.code_operators_bitwise
|
||||
tag(): user.code_operators_math
|
||||
tag(): user.code_operators_pointer
|
||||
|
||||
settings():
|
||||
user.code_private_function_formatter = "SNAKE_CASE"
|
||||
user.code_protected_function_formatter = "SNAKE_CASE"
|
||||
user.code_public_function_formatter = "SNAKE_CASE"
|
||||
user.code_private_variable_formatter = "SNAKE_CASE"
|
||||
user.code_protected_variable_formatter = "SNAKE_CASE"
|
||||
user.code_public_variable_formatter = "SNAKE_CASE"
|
||||
|
||||
# NOTE: migrated from generic, as they were only used here, though once cpp support is added, perhaps these should be migrated to a tag together with the commands below
|
||||
state include: user.insert_snippet_by_name("importStatement")
|
||||
state include system: user.insert_snippet_by_name("includeSystemStatement")
|
||||
state include local: user.insert_snippet_by_name("includeLocalStatement")
|
||||
state type deaf: insert("typedef ")
|
||||
state type deaf struct: user.insert_snippet_by_name("typedefStructDeclaration")
|
||||
|
||||
# XXX - create a preprocessor tag for these, as they will match cpp, etc
|
||||
state define: user.insert_snippet_by_name("preprocessorDefineStatement")
|
||||
state (undefine | undeaf): user.insert_snippet_by_name("preprocessorUndefineStatement")
|
||||
state if (define | deaf): user.insert_snippet_by_name("preprocessorIfDefineStatement")
|
||||
[state] define <user.text>$:
|
||||
user.insert_snippet_by_name_with_phrase("preprocessorDefineStatement", text)
|
||||
[state] (undefine | undeaf) <user.text>$:
|
||||
user.insert_snippet_by_name_with_phrase("preprocessorUndefineStatement", text)
|
||||
[state] if (define | deaf) <user.text>$:
|
||||
user.insert_snippet_by_name_with_phrase("preprocessorIfDefineStatement", text)
|
||||
|
||||
# XXX - preprocessor instead of pre?
|
||||
state pre if: user.insert_snippet_by_name("preprocessorIfStatement")
|
||||
state error: user.insert_snippet_by_name("preprocessorErrorStatement")
|
||||
state pre else if: user.insert_snippet_by_name("preprocessorElseIfStatement")
|
||||
state pre end: user.insert_snippet_by_name("preprocessorEndIfStatement")
|
||||
state pragma: user.insert_snippet_by_name("preprocessorPragmaStatement")
|
||||
state default: "default:\nbreak;"
|
||||
|
||||
#control flow
|
||||
#best used with a push like command
|
||||
#the below example may not work in editors that automatically add the closing brace
|
||||
#if so uncomment the two lines and comment out the rest accordingly
|
||||
push braces:
|
||||
edit.line_end()
|
||||
#insert("{")
|
||||
#key(enter)
|
||||
insert("{}")
|
||||
edit.left()
|
||||
key(enter)
|
||||
key(enter)
|
||||
edit.up()
|
||||
|
||||
# Declare variables or structs etc.
|
||||
# Ex. * int myList
|
||||
<user.c_variable> <phrase>:
|
||||
insert("{c_variable} ")
|
||||
insert(user.formatted_text(phrase, "PRIVATE_CAMEL_CASE,NO_SPACES"))
|
||||
|
||||
<user.c_variable> <user.letter>: insert("{c_variable} {letter} ")
|
||||
|
||||
# Ex. (int *)
|
||||
cast to <user.c_cast>: "{c_cast}"
|
||||
standard cast to <user.stdint_cast>: "{stdint_cast}"
|
||||
<user.c_types>: "{c_types}"
|
||||
<user.c_pointers>: "{c_pointers}"
|
||||
<user.c_keywords>: "{c_keywords}"
|
||||
<user.c_signed>: "{c_signed} "
|
||||
standard <user.stdint_types>: "{stdint_types}"
|
||||
int main: user.insert_between("int main(", ")")
|
||||
|
||||
include <user.code_libraries>:
|
||||
user.code_insert_library(code_libraries, "")
|
||||
key(end enter)
|
||||
@@ -0,0 +1,47 @@
|
||||
list: user.code_common_function
|
||||
code.language: c
|
||||
-
|
||||
|
||||
alloc ah: alloca
|
||||
ay to eye: atoi
|
||||
ef close: fclose
|
||||
ef open: fopen
|
||||
ef read: fread
|
||||
ef write: fwrite
|
||||
em map: mmap
|
||||
em un map: munmap
|
||||
es en print eff: sprintf
|
||||
es print eff: sprintf
|
||||
exit
|
||||
free
|
||||
get char: getchar
|
||||
get op: getopt
|
||||
is digit: isdigit
|
||||
ma map: mmap
|
||||
malloc
|
||||
mem copy: memcpy
|
||||
mem set: memset
|
||||
print eff: printf
|
||||
re alloc: realloc
|
||||
see alloc: calloc
|
||||
set jump: setjmp
|
||||
signal
|
||||
size of: sizeof
|
||||
stir cat: strcat
|
||||
string cat: strcat
|
||||
stir comp: strcmp
|
||||
stir copy: strcpy
|
||||
stir dupe: strdup
|
||||
string dupe: strdup
|
||||
stir elle cat: strlcat
|
||||
stir l cat: strlcat
|
||||
stir elle copy: strlcpy
|
||||
stir l copy: strlcpy
|
||||
stir en cat: strncat
|
||||
stir en copy: strncpy
|
||||
stir en comp: strncmp
|
||||
stir len: strlen
|
||||
string len: strlen
|
||||
stir to int: strtoint
|
||||
stir to unsigned int: strtouint
|
||||
string char: strchr
|
||||
@@ -0,0 +1,16 @@
|
||||
from talon import Context, Module
|
||||
|
||||
from ..c.c import operators
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
|
||||
ctx.matches = r"""
|
||||
code.language: cpp
|
||||
"""
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
@@ -0,0 +1,8 @@
|
||||
code.language: cpp
|
||||
-
|
||||
|
||||
tag(): user.code_operators_array
|
||||
tag(): user.code_operators_assignment
|
||||
tag(): user.code_operators_bitwise
|
||||
tag(): user.code_operators_math
|
||||
tag(): user.code_operators_pointer
|
||||
@@ -0,0 +1,7 @@
|
||||
list: user.code_common_function
|
||||
code.language: csharp
|
||||
-
|
||||
|
||||
integer: int.TryParse
|
||||
print: Console.WriteLine
|
||||
string: .ToString
|
||||
@@ -0,0 +1,142 @@
|
||||
from talon import Context, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: csharp
|
||||
"""
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
ASSIGNMENT_ADDITION=" += ",
|
||||
ASSIGNMENT_SUBTRACTION=" -= ",
|
||||
ASSIGNMENT_DIVISION=" /= ",
|
||||
ASSIGNMENT_MULTIPLICATION=" *= ",
|
||||
ASSIGNMENT_MODULO=" %= ",
|
||||
ASSIGNMENT_BITWISE_AND=" &= ",
|
||||
ASSIGNMENT_BITWISE_EXCLUSIVE_OR=" ^= ",
|
||||
ASSIGNMENT_BITWISE_LEFT_SHIFT=" <<= ",
|
||||
ASSIGNMENT_BITWISE_OR=" |= ",
|
||||
ASSIGNMENT_BITWISE_RIGHT_SHIFT=" >>= ",
|
||||
ASSIGNMENT_INCREMENT="++",
|
||||
# code_operators_bitwise
|
||||
BITWISE_NOT="~",
|
||||
BITWISE_AND=" & ",
|
||||
BITWISE_EXCLUSIVE_OR=" ^ ",
|
||||
BITWISE_LEFT_SHIFT=" << ",
|
||||
BITWISE_OR=" | ",
|
||||
BITWISE_RIGHT_SHIFT=" >> ",
|
||||
# code_operators_lambda
|
||||
LAMBDA="=>",
|
||||
# code_operators_pointer
|
||||
MATH_ADD=" + ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" % ",
|
||||
MATH_EQUAL=" == ",
|
||||
MATH_NOT_EQUAL=" != ",
|
||||
MATH_OR=" || ",
|
||||
MATH_AND=" && ",
|
||||
MATH_NOT="!",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
# code_operators_pointer
|
||||
POINTER_ADDRESS_OF="&",
|
||||
POINTER_INDIRECTION="*",
|
||||
POINTER_STRUCTURE_DEREFERENCE="->",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_self():
|
||||
actions.auto_insert("this")
|
||||
|
||||
def code_operator_object_accessor():
|
||||
actions.auto_insert(".")
|
||||
|
||||
def code_insert_null():
|
||||
actions.auto_insert("null")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.auto_insert(" == null ")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.auto_insert(" != null")
|
||||
|
||||
def code_insert_true():
|
||||
actions.auto_insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.auto_insert("false")
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
text += f"({selection or ''})"
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "private void {}".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 = "private void {}".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 = "public void {}".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,26 @@
|
||||
code.language: csharp
|
||||
-
|
||||
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_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
|
||||
tag(): user.code_operators_pointer
|
||||
|
||||
settings():
|
||||
user.code_private_function_formatter = "PRIVATE_CAMEL_CASE"
|
||||
user.code_protected_function_formatter = "PUBLIC_CAMEL_CASE"
|
||||
user.code_public_function_formatter = "PUBLIC_CAMEL_CASE"
|
||||
user.code_private_variable_formatter = "PRIVATE_CAMEL_CASE"
|
||||
user.code_protected_variable_formatter = "PUBLIC_CAMEL_CASE"
|
||||
user.code_public_variable_formatter = "PUBLIC_CAMEL_CASE"
|
||||
@@ -0,0 +1,54 @@
|
||||
list: user.code_common_function
|
||||
code.language: css
|
||||
code.language: scss
|
||||
-
|
||||
|
||||
# reference
|
||||
attribute: attr
|
||||
env
|
||||
url
|
||||
var
|
||||
variable: var
|
||||
# mathematical
|
||||
calc
|
||||
calculate: calc
|
||||
clamp
|
||||
max
|
||||
min
|
||||
# color
|
||||
HSL: hsl
|
||||
hue sat light: hsl
|
||||
HSLA: hsla
|
||||
lab
|
||||
LCH: lch
|
||||
RGB: rgb
|
||||
red green blue: rgb
|
||||
RGBA: rgba
|
||||
color
|
||||
# image functions
|
||||
linear gradient: linear-gradient
|
||||
# counter functions
|
||||
counter
|
||||
counters
|
||||
symbols
|
||||
# filter
|
||||
blur
|
||||
brightness
|
||||
contrast
|
||||
drop shadow: drop-shadow
|
||||
grayscale
|
||||
hue rotate: hue-rotate
|
||||
invert
|
||||
opacity
|
||||
saturate
|
||||
sepia
|
||||
# grid
|
||||
fit content: fit-content
|
||||
min max: minmax
|
||||
repeat
|
||||
# transform
|
||||
matrix
|
||||
rotate
|
||||
scale
|
||||
skew
|
||||
translate
|
||||
@@ -0,0 +1,81 @@
|
||||
from talon import Context, Module, actions
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
mod = Module()
|
||||
global_ctx = Context()
|
||||
ctx = Context()
|
||||
ctx.matches = """
|
||||
code.language: css
|
||||
code.language: scss
|
||||
"""
|
||||
|
||||
mod.list("css_at_rule", desc="List of CSS @rules")
|
||||
mod.list("css_unit", desc="List of CSS units")
|
||||
mod.list("css_global_value", desc="CSS-wide values")
|
||||
|
||||
global_ctx.lists["self.css_unit"] = {
|
||||
# distance (length)
|
||||
"char": "ch",
|
||||
"em": "em",
|
||||
"rem": "rem",
|
||||
"pixels": "px",
|
||||
"points": "pt",
|
||||
"view height": "vh",
|
||||
"view width": "vw",
|
||||
# angle
|
||||
"degrees": "deg",
|
||||
"radians": "rad",
|
||||
"turn": "turn",
|
||||
# duration (time)
|
||||
"seconds": "s",
|
||||
"millis": "ms",
|
||||
# resolution
|
||||
"dots per pixel": "dppx",
|
||||
# flexible length (flex) - grid
|
||||
"fraction": "fr",
|
||||
}
|
||||
|
||||
global_ctx.lists["self.css_at_rule"] = {
|
||||
# regular
|
||||
"charset": "charset",
|
||||
"import": "import",
|
||||
"namespace": "namespace",
|
||||
# conditional group
|
||||
"media": "media",
|
||||
"supports": "supports",
|
||||
# other nested
|
||||
"page": "page",
|
||||
"font face": "font-face",
|
||||
"keyframes": "keyframes",
|
||||
# CSS Modules
|
||||
"value": "value",
|
||||
}
|
||||
|
||||
global_ctx.lists["self.css_global_value"] = ["initial", "inherit", "unset", "revert"]
|
||||
|
||||
|
||||
operators = Operators(
|
||||
MATH_ADD=" + ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_AND=" and ",
|
||||
MATH_OR=" or ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
substitutions = {"1": text}
|
||||
if selection:
|
||||
substitutions["0"] = selection
|
||||
actions.user.insert_snippet_by_name("functionCall", substitutions)
|
||||
@@ -0,0 +1,45 @@
|
||||
code.language: css
|
||||
code.language: scss
|
||||
-
|
||||
|
||||
tag(): user.code_comment_block_c_like
|
||||
tag(): user.code_functions_common
|
||||
tag(): user.code_libraries
|
||||
tag(): user.code_operators_math
|
||||
|
||||
settings():
|
||||
user.code_public_variable_formatter = "DASH_SEPARATED"
|
||||
|
||||
block: user.code_block()
|
||||
|
||||
attribute [<user.text>]:
|
||||
name = user.formatted_text(text or "", "DASH_SEPARATED")
|
||||
user.insert_between("[{name}", "]")
|
||||
|
||||
prop <user.text>:
|
||||
name = user.formatted_text(text, "DASH_SEPARATED")
|
||||
user.insert_between("{name}: ", ";")
|
||||
|
||||
# for media/supports queries, or if you don't like prop
|
||||
rule <user.text>:
|
||||
name = user.formatted_text(text, "DASH_SEPARATED")
|
||||
insert("{name}: ")
|
||||
|
||||
value <user.number_string> [{user.css_unit}]: "{number_string}{css_unit or ''}"
|
||||
value <user.number_string> point <digit_string> [{user.css_unit}]:
|
||||
"{number_string}.{digit_string}{css_unit or ''}"
|
||||
|
||||
(value | state) {user.css_global_value}: "{css_global_value}"
|
||||
value <user.text>: user.insert_formatted(text, "DASH_SEPARATED")
|
||||
|
||||
variable <user.text>:
|
||||
name = user.formatted_text(text, "DASH_SEPARATED")
|
||||
insert("var(--{name})")
|
||||
|
||||
op var: user.insert_between("var(--", ")")
|
||||
|
||||
at {user.css_at_rule}: "@{css_at_rule} "
|
||||
unit {user.css_unit}: insert(css_unit)
|
||||
|
||||
[value] current color: "currentColor"
|
||||
op important: " !important"
|
||||
@@ -0,0 +1,129 @@
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
ctx.matches = r"""
|
||||
code.language: elixir
|
||||
"""
|
||||
|
||||
# Elixir keywords and constructs
|
||||
ctx.lists["user.code_keyword"] = {
|
||||
"def": "def ",
|
||||
"def p": "defp ",
|
||||
"def module": "defmodule ",
|
||||
"do": "do ",
|
||||
"end": "end",
|
||||
"if": "if ",
|
||||
"else": "else ",
|
||||
"cond": "cond ",
|
||||
"case": "case ",
|
||||
"when": "when ",
|
||||
"f n": "fn ",
|
||||
"receive": "receive ",
|
||||
"after": "after ",
|
||||
"try": "try ",
|
||||
"catch": "catch ",
|
||||
"rescue": "rescue ",
|
||||
"raise": "raise ",
|
||||
"with": "with ",
|
||||
"unless": "unless ",
|
||||
"import": "import ",
|
||||
"alias": "alias ",
|
||||
"require": "require ",
|
||||
"use": "use ",
|
||||
}
|
||||
|
||||
operators = Operators(
|
||||
LAMBDA="->",
|
||||
ASSIGNMENT=" = ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_EQUAL=" === ",
|
||||
MATH_NOT_EQUAL=" !== ",
|
||||
MATH_WEAK_EQUAL=" == ",
|
||||
MATH_WEAK_NOT_EQUAL=" != ",
|
||||
MATH_WEAK_AND=" && ",
|
||||
MATH_WEAK_OR=" || ",
|
||||
MATH_WEAK_NOT="!",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
MATH_AND=" and ",
|
||||
MATH_OR=" or ",
|
||||
MATH_NOT="not ",
|
||||
MATH_IN=" in ",
|
||||
MATH_NOT_IN=" not in ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_self():
|
||||
actions.auto_insert("self")
|
||||
|
||||
def code_insert_true():
|
||||
actions.auto_insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.auto_insert("false")
|
||||
|
||||
def code_insert_null():
|
||||
actions.insert("nil")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.insert(" == nil")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.insert(" != nil")
|
||||
|
||||
def code_state_else_if():
|
||||
actions.user.insert_between("else if ", " do\nend")
|
||||
|
||||
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):
|
||||
result = "def {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.code_insert_function(result, None)
|
||||
|
||||
def code_public_function(text: str):
|
||||
actions.user.code_default_function(text)
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "defp {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.code_insert_function(result, None)
|
||||
|
||||
def code_import_module(text: str):
|
||||
actions.auto_insert("import ")
|
||||
actions.insert(text)
|
||||
|
||||
def code_alias_module(text: str):
|
||||
actions.auto_insert("alias ")
|
||||
actions.insert(text)
|
||||
|
||||
def code_require_module(text: str):
|
||||
actions.auto_insert("require ")
|
||||
actions.insert(text)
|
||||
|
||||
def code_use_module(text: str):
|
||||
actions.auto_insert("use ")
|
||||
actions.insert(text)
|
||||
@@ -0,0 +1,40 @@
|
||||
code.language: elixir
|
||||
-
|
||||
tag(): user.code_functional
|
||||
tag(): user.code_concurrent
|
||||
|
||||
tag(): user.code_comment_line
|
||||
tag(): user.code_data_bool
|
||||
tag(): user.code_data_null
|
||||
tag(): user.code_functions
|
||||
tag(): user.code_keywords
|
||||
tag(): user.code_libraries
|
||||
tag(): user.code_operators_array
|
||||
tag(): user.code_operators_assignment
|
||||
tag(): user.code_operators_math
|
||||
tag(): user.code_operators_lambda
|
||||
|
||||
settings():
|
||||
user.code_private_function_formatter = "SNAKE_CASE"
|
||||
user.code_public_function_formatter = "SNAKE_CASE"
|
||||
user.code_private_variable_formatter = "SNAKE_CASE"
|
||||
user.code_public_variable_formatter = "SNAKE_CASE"
|
||||
|
||||
# Elixir-specific grammars
|
||||
state def: "def "
|
||||
state defp: "defp "
|
||||
state if: "if "
|
||||
state else: "else"
|
||||
state case: "case "
|
||||
state cond: "cond do"
|
||||
state try: "try do"
|
||||
state rescue: "rescue"
|
||||
state after: "after"
|
||||
state end: "end"
|
||||
|
||||
op pipe: " |> "
|
||||
|
||||
# Elixir-specific keywords and symbols
|
||||
[state] raise {user.elixir_exception}: user.insert_between("raise ", "")
|
||||
|
||||
[state] rescue {user.elixir_exception}: "rescue {elixir_exception}"
|
||||
@@ -0,0 +1,26 @@
|
||||
list: user.code_common_function
|
||||
code.language: go
|
||||
-
|
||||
|
||||
# golang builtin functions
|
||||
append
|
||||
length: len
|
||||
make
|
||||
# formatting
|
||||
format print: fmt.Printf
|
||||
format print eff: fmt.Printf
|
||||
format sprint: fmt.Sprintf
|
||||
format es print eff: fmt.Sprintf
|
||||
format print line: fmt.Println
|
||||
# time
|
||||
time hour: time.Hour
|
||||
time minute: time.Minute
|
||||
time second: time.Second
|
||||
time millisecond: time.Millisecond
|
||||
time microsecond: time.Microsecond
|
||||
time nanosecond: time.Nanosecond
|
||||
# IO
|
||||
buf I O: bufio.
|
||||
# strings
|
||||
string convert: strconv.
|
||||
string convert to int: strconv.AtoI
|
||||
@@ -0,0 +1,132 @@
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
ctx.matches = r"""
|
||||
code.language: go
|
||||
"""
|
||||
|
||||
# Primitive Types
|
||||
ctx.lists["self.code_type"] = {
|
||||
"boolean": "bool",
|
||||
"int": "int",
|
||||
"float": "float",
|
||||
"byte": "byte",
|
||||
"double": "double",
|
||||
"short": "short",
|
||||
"long": "long",
|
||||
"char": "char",
|
||||
"string": "string",
|
||||
"rune": "rune",
|
||||
"void": "void",
|
||||
"channel": "channel",
|
||||
}
|
||||
|
||||
ctx.lists["user.code_keyword"] = {
|
||||
"break": "break",
|
||||
"continue": "continue",
|
||||
"struct": "struct",
|
||||
"type": "type",
|
||||
"return": "return",
|
||||
"package": "package",
|
||||
"import": "import",
|
||||
"null": "nil",
|
||||
"nil": "nil",
|
||||
"true": "true",
|
||||
"false": "false",
|
||||
"defer": "defer",
|
||||
"go": "go",
|
||||
"if": "if",
|
||||
"else": "else",
|
||||
"switch": "switch",
|
||||
"select": "select",
|
||||
"const": "const",
|
||||
}
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
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_EQUAL=" == ",
|
||||
MATH_NOT_EQUAL=" != ",
|
||||
MATH_OR=" || ",
|
||||
MATH_AND=" && ",
|
||||
MATH_EXPONENT=" ^ ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
# code_operators_pointer
|
||||
POINTER_ADDRESS_OF="&",
|
||||
POINTER_INDIRECTION="*",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_self():
|
||||
actions.insert("this")
|
||||
|
||||
def code_operator_object_accessor():
|
||||
actions.insert(".")
|
||||
|
||||
def code_insert_null():
|
||||
actions.insert("nil")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.insert(" == nil")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.insert(" != nil")
|
||||
|
||||
def code_insert_true():
|
||||
actions.insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.insert("false")
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
text += f"({selection or ''})"
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "func {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.code_insert_function(result, None)
|
||||
@@ -0,0 +1,38 @@
|
||||
code.language: go
|
||||
-
|
||||
|
||||
tag(): user.code_imperative
|
||||
|
||||
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_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
|
||||
tag(): user.code_operators_pointer
|
||||
|
||||
settings():
|
||||
user.code_private_function_formatter = "PRIVATE_CAMEL_CASE"
|
||||
user.code_protected_function_formatter = "PRIVATE_CAMEL_CASE"
|
||||
user.code_public_function_formatter = "PUBLIC_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"
|
||||
|
||||
(variadic | spread): "..."
|
||||
declare: " := "
|
||||
channel (receive | send): " <- "
|
||||
|
||||
[state] if (err | error):
|
||||
insert("if err != nil {")
|
||||
key("enter")
|
||||
|
||||
[state] if not (err | error):
|
||||
insert("if err == nil {")
|
||||
key("enter")
|
||||
@@ -0,0 +1,4 @@
|
||||
code.language: html
|
||||
code.language: javascriptreact
|
||||
code.language: typescriptreact
|
||||
-
|
||||
@@ -0,0 +1,64 @@
|
||||
list: user.code_keyword
|
||||
code.language: java
|
||||
-
|
||||
|
||||
abstract: "abstract "
|
||||
assert: "assert "
|
||||
boolean: "boolean "
|
||||
break
|
||||
byte: "byte "
|
||||
case: "case "
|
||||
catch
|
||||
char: "char "
|
||||
class: "class "
|
||||
continue
|
||||
default
|
||||
do: "do "
|
||||
double: "double "
|
||||
else
|
||||
enum: "enum "
|
||||
exports: "exports "
|
||||
extends: " extends "
|
||||
final: "final "
|
||||
finally: "finally "
|
||||
float: "float "
|
||||
for: "for "
|
||||
if: "if "
|
||||
implements: " implements "
|
||||
import: "import "
|
||||
instance of: "instanceof "
|
||||
int: "int "
|
||||
interface: "interface "
|
||||
long: "long "
|
||||
module: "module "
|
||||
native: "native "
|
||||
new: "new "
|
||||
open: "open "
|
||||
opens: "opens "
|
||||
package: "package "
|
||||
private: "private "
|
||||
protected: "protected "
|
||||
provides: "provides "
|
||||
public: "public "
|
||||
requires: "requires "
|
||||
return: "return "
|
||||
short: "short "
|
||||
static: "static "
|
||||
strict eff pee: "strictfp "
|
||||
super
|
||||
switch: "switch "
|
||||
synchronized: "synchronized "
|
||||
this
|
||||
throw: "throw "
|
||||
throws: "throws "
|
||||
to: " to "
|
||||
transient: "transient "
|
||||
transitive: "transitive "
|
||||
try: "try "
|
||||
uses: "uses "
|
||||
var: "var "
|
||||
void: "void "
|
||||
volatile: "volatile "
|
||||
while: "while "
|
||||
with: " with "
|
||||
yield: "yield "
|
||||
@@ -0,0 +1,218 @@
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
ctx.matches = r"""
|
||||
code.language: java
|
||||
"""
|
||||
|
||||
# Primitive Types
|
||||
java_primitive_types = {
|
||||
"boolean": "boolean",
|
||||
"int": "int",
|
||||
"float": "float",
|
||||
"byte": "byte",
|
||||
"double": "double",
|
||||
"short": "short",
|
||||
"long": "long",
|
||||
"char": "char",
|
||||
"void": "void",
|
||||
}
|
||||
|
||||
# Java Boxed Types
|
||||
java_boxed_types = {
|
||||
"Byte": "Byte",
|
||||
"Integer": "Integer",
|
||||
"Double": "Double",
|
||||
"Short": "Short",
|
||||
"Float": "Float",
|
||||
"Long": "Long",
|
||||
"Boolean": "Boolean",
|
||||
"Character": "Character",
|
||||
"Void": "Void",
|
||||
}
|
||||
|
||||
mod.list("java_boxed_type", desc="Java Boxed Types")
|
||||
ctx.lists["self.java_boxed_type"] = java_boxed_types
|
||||
|
||||
# Common Classes
|
||||
java_common_classes = {
|
||||
"Object": "Object",
|
||||
"string": "String",
|
||||
"thread": "Thread",
|
||||
"exception": "Exception",
|
||||
}
|
||||
|
||||
mod.list("java_common_class", desc="Java Common Classes")
|
||||
ctx.lists["self.java_common_class"] = java_common_classes
|
||||
|
||||
|
||||
# Java Generic Data Structures
|
||||
java_generic_data_structures = {
|
||||
# Interfaces
|
||||
"set": "Set",
|
||||
"list": "List",
|
||||
"queue": "Queue",
|
||||
"deque": "Deque",
|
||||
"map": "Map",
|
||||
# Classes
|
||||
"hash set": "HashSet",
|
||||
"array list": "ArrayList",
|
||||
"hash map": "HashMap",
|
||||
}
|
||||
|
||||
unboxed_types = java_primitive_types.copy()
|
||||
unboxed_types.update(java_common_classes)
|
||||
unboxed_types.update(java_generic_data_structures)
|
||||
|
||||
ctx.lists["user.code_type"] = unboxed_types
|
||||
|
||||
mod.list("java_generic_data_structure", desc="Java Generic Data Structures")
|
||||
ctx.lists["self.java_generic_data_structure"] = java_generic_data_structures
|
||||
|
||||
# Java Modifies
|
||||
java_modifiers = {
|
||||
"public": "public",
|
||||
"private": "private",
|
||||
"protected": "protected",
|
||||
"static": "static",
|
||||
"synchronized": "synchronized",
|
||||
"volatile": "volatile",
|
||||
"transient": "transient",
|
||||
"abstract": "abstract",
|
||||
"interface": "interface",
|
||||
"final": "final",
|
||||
}
|
||||
|
||||
mod.list("java_modifier", desc="Java Modifiers")
|
||||
ctx.lists["self.java_modifier"] = java_modifiers
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
ASSIGNMENT_SUBTRACTION=" -= ",
|
||||
ASSIGNMENT_ADDITION=" += ",
|
||||
ASSIGNMENT_MULTIPLICATION=" *= ",
|
||||
ASSIGNMENT_DIVISION=" /= ",
|
||||
ASSIGNMENT_MODULO=" %= ",
|
||||
ASSIGNMENT_INCREMENT="++",
|
||||
ASSIGNMENT_BITWISE_AND=" &= ",
|
||||
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_SUBTRACT=" - ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" % ",
|
||||
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=" || ",
|
||||
MATH_NOT="!",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_self():
|
||||
actions.insert("this")
|
||||
|
||||
def code_operator_object_accessor():
|
||||
actions.insert(".")
|
||||
|
||||
def code_insert_null():
|
||||
actions.insert("null")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.insert(" == null")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.insert(" != null")
|
||||
|
||||
def code_insert_true():
|
||||
actions.insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.insert("false")
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
text += f"({selection or ''})"
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "private void {}".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 = "void {}".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 = "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 = "public void {}".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,44 @@
|
||||
code.language: java
|
||||
-
|
||||
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_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
|
||||
tag(): user.code_keywords
|
||||
|
||||
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"
|
||||
|
||||
state var: "var "
|
||||
|
||||
# Types Commands
|
||||
boxed [type] {user.java_boxed_type}: insert(user.java_boxed_type + " ")
|
||||
|
||||
generic [type] {user.java_generic_data_structure}:
|
||||
user.insert_between(java_generic_data_structure + "<", ">")
|
||||
|
||||
# Arrays
|
||||
type {user.code_type} array:
|
||||
insert(user.code_type)
|
||||
user.code_operator_subscript()
|
||||
|
||||
[state] {user.java_modifier}: insert(user.java_modifier + " ")
|
||||
|
||||
op array: user.code_operator_subscript()
|
||||
|
||||
op new: insert("new ")
|
||||
@@ -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 "', '"')
|
||||
@@ -0,0 +1,125 @@
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
ctx.matches = r"""
|
||||
code.language: kotlin
|
||||
"""
|
||||
|
||||
ctx.lists["user.code_keyword"] = {
|
||||
"var": "var ",
|
||||
"val": "val ",
|
||||
"lateinit": "lateinit ",
|
||||
"public": "public ",
|
||||
"private": "private ",
|
||||
"protected": "protected ",
|
||||
"companion object": "companion object ",
|
||||
"synchronized": "synchronized ",
|
||||
"volatile": "volatile ",
|
||||
"transient": "transient ",
|
||||
"abstract": "abstract ",
|
||||
"interface": "interface ",
|
||||
"final": "final ",
|
||||
"return": "return ",
|
||||
}
|
||||
|
||||
ctx.lists["user.code_type"] = {
|
||||
"boolean": "Boolean",
|
||||
"byte": "Byte",
|
||||
"short": "Short",
|
||||
"int": "Int",
|
||||
"long": "Long",
|
||||
"float": "Float",
|
||||
"double": "Double",
|
||||
"char": "Char",
|
||||
"string": "String",
|
||||
"array": "Array",
|
||||
"map": "Map",
|
||||
"any": "Any",
|
||||
"nothing": "Nothing",
|
||||
"unit": "Unit",
|
||||
}
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
ASSIGNMENT_ADDITION=" += ",
|
||||
ASSIGNMENT_SUBTRACTION=" -= ",
|
||||
ASSIGNMENT_MULTIPLICATION=" *= ",
|
||||
ASSIGNMENT_DIVISION=" /= ",
|
||||
ASSIGNMENT_MODULO=" %= ",
|
||||
ASSIGNMENT_INCREMENT="++",
|
||||
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_bitwise
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" % ",
|
||||
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=" || ",
|
||||
MATH_NOT="!",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_self():
|
||||
actions.auto_insert("this")
|
||||
|
||||
def code_insert_null():
|
||||
actions.insert("null")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.insert(" == null")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.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):
|
||||
result = "fun {}".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):
|
||||
actions.user.code_default_function(text)
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "private fun {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.code_insert_function(result, None)
|
||||
@@ -0,0 +1,25 @@
|
||||
code.language: kotlin
|
||||
-
|
||||
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_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
|
||||
tag(): user.code_keywords
|
||||
|
||||
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"
|
||||
@@ -0,0 +1,47 @@
|
||||
list: user.code_common_function
|
||||
code.language: lua
|
||||
-
|
||||
|
||||
to number: "tonumber"
|
||||
I pairs: "ipairs"
|
||||
print: "print"
|
||||
print F: "printf"
|
||||
type: "type"
|
||||
assert: "assert"
|
||||
get meta table: "getmetatable"
|
||||
set meta table: "setmetatable"
|
||||
# io
|
||||
I O write: "io.write"
|
||||
I O read: "io.read"
|
||||
I O open: "io.open"
|
||||
# string
|
||||
format: "string.format"
|
||||
string G find: "string.gfind"
|
||||
string find: "string.strfind"
|
||||
string len: "string.strlen"
|
||||
string upper: "string.strupper"
|
||||
string lower: "string.strlower"
|
||||
string sub: "string.strsub"
|
||||
string G sub: "string.gsub"
|
||||
string match: "string.match"
|
||||
string G match: "string.gmatch"
|
||||
# table
|
||||
table unpack: "table.unpack"
|
||||
table insert: "table.insert"
|
||||
tabel get N: "table.getn"
|
||||
tabel sort: "table.sort"
|
||||
# math
|
||||
math max: "math.max"
|
||||
# json
|
||||
jason parse: "json.parse"
|
||||
# http
|
||||
H T T P get: "http.get"
|
||||
web get: "http.get"
|
||||
# os
|
||||
O S date: "os.date"
|
||||
O S time: "os.time"
|
||||
O S clock: "os.clock"
|
||||
O S rename: "os.rename"
|
||||
O S remove: "os.remove"
|
||||
O S getenv: "os.getenv"
|
||||
O S execute: "os.execute"
|
||||
@@ -0,0 +1,197 @@
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
mod = Module()
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: lua
|
||||
"""
|
||||
|
||||
mod.setting(
|
||||
"lua_version",
|
||||
type=float,
|
||||
default=5.1,
|
||||
desc="The default lua version to use. Dictates certain operators",
|
||||
)
|
||||
mod.tag("stylua", desc="Tag for stylua linting commands")
|
||||
|
||||
ctx.lists["user.code_libraries"] = {
|
||||
"bit": "bit",
|
||||
"I O": "io",
|
||||
"string": "string",
|
||||
"U T F eight": "utf8",
|
||||
"table": "table",
|
||||
"math": "math",
|
||||
"O S": "os",
|
||||
"debug": "debug",
|
||||
"L F S": "lfs",
|
||||
"socket": "socket",
|
||||
"H T T P": "http",
|
||||
"web": "http",
|
||||
"jason": "json",
|
||||
}
|
||||
|
||||
|
||||
@mod.capture(rule="{self.lua_functions}")
|
||||
def lua_functions(m) -> str:
|
||||
"Returns a string"
|
||||
return m.lua_functions
|
||||
|
||||
|
||||
###
|
||||
# code_operators_bitwise
|
||||
###
|
||||
|
||||
|
||||
# NOTE: < 5.3 assumes Lua BitOp usage
|
||||
# > 5.2 assumes native bitwise operators
|
||||
# TODO: Possibly add settings to define which library to use, as 5.2
|
||||
# includes bit32. Neovim uses luajit, which uses Lua BitOp
|
||||
def code_operator_bitwise_and():
|
||||
if settings.get("user.lua_version") > 5.2:
|
||||
actions.insert(" & ")
|
||||
else:
|
||||
actions.insert(" bit.band() ")
|
||||
|
||||
|
||||
def code_operator_bitwise_or():
|
||||
if settings.get("user.lua_version") > 5.2:
|
||||
actions.insert(" | ")
|
||||
else:
|
||||
actions.insert(" bit.bor() ")
|
||||
|
||||
|
||||
def code_operator_bitwise_exclusive_or():
|
||||
if settings.get("user.lua_version") > 5.2:
|
||||
actions.insert(" ~ ")
|
||||
else:
|
||||
actions.insert(" bit.xor() ")
|
||||
|
||||
|
||||
def code_operator_bitwise_left_shift():
|
||||
if settings.get("user.lua_version") > 5.2:
|
||||
actions.insert(" << ")
|
||||
else:
|
||||
actions.insert(" bit.lshift() ")
|
||||
|
||||
|
||||
def code_operator_bitwise_right_shift():
|
||||
if settings.get("user.lua_version") > 5.2:
|
||||
actions.insert(" >> ")
|
||||
else:
|
||||
actions.insert(" bit.rshift() ")
|
||||
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
# code_operators_bitwise
|
||||
BITWISE_AND=code_operator_bitwise_and,
|
||||
BITWISE_OR=code_operator_bitwise_or,
|
||||
BITWISE_EXCLUSIVE_OR=code_operator_bitwise_exclusive_or,
|
||||
BITWISE_LEFT_SHIFT=code_operator_bitwise_left_shift,
|
||||
BITWISE_RIGHT_SHIFT=code_operator_bitwise_right_shift,
|
||||
# code_operators_assignment
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_INTEGER_DIVIDE=" // ",
|
||||
MATH_MODULO=" % ",
|
||||
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=" and ",
|
||||
MATH_OR=" or ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
# tag-related actions listed first, indicated by comment. corresponds to
|
||||
# the tag(): user.code_imperative style declaration in the language .talon
|
||||
# file
|
||||
|
||||
##
|
||||
# code_comment_block
|
||||
##
|
||||
def code_comment_block_prefix():
|
||||
actions.insert("--[[")
|
||||
|
||||
def code_comment_block_suffix():
|
||||
actions.insert("--]]")
|
||||
|
||||
##
|
||||
# code_data_bool
|
||||
##
|
||||
def code_insert_true():
|
||||
actions.insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.insert("false")
|
||||
|
||||
##
|
||||
# code_data_null
|
||||
##
|
||||
def code_insert_null():
|
||||
actions.insert("nil")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.insert(" == nil")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.insert(" ~= nil")
|
||||
|
||||
##
|
||||
# code_functions
|
||||
##
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "local function {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.insert("\n\nend")
|
||||
actions.key("up:2")
|
||||
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.insert("\n\nend")
|
||||
actions.key("up:2")
|
||||
actions.user.code_insert_function(result, None)
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
if selection:
|
||||
text = text + f"({selection})"
|
||||
else:
|
||||
text = text + "()"
|
||||
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
##
|
||||
# code_libraries
|
||||
##
|
||||
def code_insert_library(text: str, selection: str):
|
||||
substitutions = {"1": selection, "0": selection}
|
||||
actions.user.insert_snippet_by_name("importStatement", substitutions)
|
||||
|
||||
# non-tag related actions
|
||||
@@ -0,0 +1,67 @@
|
||||
code.language: lua
|
||||
-
|
||||
|
||||
tag(): user.code_imperative
|
||||
|
||||
tag(): user.code_comment_line
|
||||
tag(): user.code_comment_block
|
||||
tag(): user.code_data_bool
|
||||
tag(): user.code_data_null
|
||||
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_bitwise
|
||||
tag(): user.code_operators_math
|
||||
|
||||
# Use this tag if you use the stylua linter
|
||||
#tag(): user.stylua
|
||||
|
||||
settings():
|
||||
user.code_private_function_formatter = "SNAKE_CASE"
|
||||
user.code_public_function_formatter = "SNAKE_CASE"
|
||||
user.code_private_variable_formatter = "SNAKE_CASE"
|
||||
user.code_public_variable_formatter = "SNAKE_CASE"
|
||||
|
||||
state local: "local"
|
||||
state end: "end"
|
||||
state then: "then"
|
||||
state repeat: "repeat"
|
||||
state until: "until"
|
||||
state return (null | nil): "return nil"
|
||||
state return true: "return true"
|
||||
state return false: "return false"
|
||||
state return table: user.insert_between("return {", "}")
|
||||
state append string: " .. "
|
||||
|
||||
state label <user.text>:
|
||||
insert("::")
|
||||
user.insert_formatted(text, "SNAKE_CASE")
|
||||
insert("::")
|
||||
|
||||
require <user.code_libraries>:
|
||||
user.code_insert_library("", code_libraries)
|
||||
key(end enter)
|
||||
|
||||
state (variable | var) [<user.text>] [over]: user.code_public_variable_formatter(text)
|
||||
|
||||
state local (variable | var) [<user.text>] [over]:
|
||||
insert("local ")
|
||||
user.code_private_variable_formatter(text)
|
||||
|
||||
# for built in object methods, ex: foo:gsub()
|
||||
method <user.text>:
|
||||
insert(":")
|
||||
user.code_public_function_formatter(text)
|
||||
insert("()")
|
||||
edit.left()
|
||||
|
||||
self dot: "self."
|
||||
|
||||
index <user.word>: '["{word}"]'
|
||||
index (var | variable) <user.text>:
|
||||
var = user.formatted_text(text, "SNAKE_CASE")
|
||||
insert("[{var}]")
|
||||
|
||||
state return dick: user.insert_between("return {", "}")
|
||||
@@ -0,0 +1,6 @@
|
||||
tag: user.stylua
|
||||
-
|
||||
|
||||
lint ignore: "-- stylua: ignore"
|
||||
lint ignore start: "-- stylua: ignore start"
|
||||
lint ignore end: "-- stylua: ignore end"
|
||||
@@ -0,0 +1,21 @@
|
||||
from talon import Context, Module
|
||||
|
||||
mod = Module()
|
||||
ctx = Context()
|
||||
|
||||
ctx.matches = r"""
|
||||
code.language: markdown
|
||||
"""
|
||||
|
||||
mod.list("markdown_code_block_language", desc="Languages for code blocks")
|
||||
ctx.lists["user.markdown_code_block_language"] = {
|
||||
"typescript": "typescript",
|
||||
"python": "python",
|
||||
"code": "",
|
||||
"ruby": "ruby",
|
||||
"shell": "shell",
|
||||
"bash": "bash",
|
||||
"json": "json",
|
||||
"are": "r",
|
||||
"markdown": "markdown",
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
code.language: markdown
|
||||
-
|
||||
(level | heading | header) one:
|
||||
edit.line_start()
|
||||
"# "
|
||||
(level | heading | header) two:
|
||||
edit.line_start()
|
||||
"## "
|
||||
(level | heading | header) three:
|
||||
edit.line_start()
|
||||
"### "
|
||||
(level | heading | header) four:
|
||||
edit.line_start()
|
||||
"#### "
|
||||
(level | heading | header) five:
|
||||
edit.line_start()
|
||||
"##### "
|
||||
(level | heading | header) six:
|
||||
edit.line_start()
|
||||
"###### "
|
||||
|
||||
list [one]:
|
||||
edit.line_start()
|
||||
"- "
|
||||
list two:
|
||||
edit.line_start()
|
||||
" - "
|
||||
list three:
|
||||
edit.line_start()
|
||||
" - "
|
||||
list four:
|
||||
edit.line_start()
|
||||
" - "
|
||||
list five:
|
||||
edit.line_start()
|
||||
" - "
|
||||
list six:
|
||||
edit.line_start()
|
||||
" - "
|
||||
|
||||
{user.markdown_code_block_language} block:
|
||||
user.insert_snippet("```{markdown_code_block_language}\n$0\n```")
|
||||
|
||||
link: user.insert_snippet_by_name("link")
|
||||
@@ -0,0 +1,160 @@
|
||||
from talon import Context, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: php
|
||||
"""
|
||||
|
||||
ctx.lists["user.code_type"] = {
|
||||
"int": "int",
|
||||
"float": "float",
|
||||
"string": "string",
|
||||
"bool": "bool",
|
||||
"array": "array",
|
||||
"null": "null",
|
||||
"void": "void",
|
||||
}
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
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=" >> ",
|
||||
BITWISE_NOT="~",
|
||||
# code_operators_math
|
||||
MATH_ADD=" + ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" % ",
|
||||
MATH_EXPONENT=" ** ",
|
||||
MATH_EQUAL=" === ",
|
||||
MATH_NOT_EQUAL=" !== ",
|
||||
MATH_WEAK_EQUAL=" == ",
|
||||
MATH_WEAK_NOT_EQUAL=" != ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
MATH_NOT="!",
|
||||
MATH_AND=" && ",
|
||||
MATH_OR=" || ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_self():
|
||||
actions.auto_insert("$this")
|
||||
|
||||
def code_operator_object_accessor():
|
||||
actions.auto_insert("->")
|
||||
|
||||
def code_comment_block_prefix():
|
||||
actions.auto_insert("/*")
|
||||
|
||||
def code_comment_block_suffix():
|
||||
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_is_null():
|
||||
actions.auto_insert("is_null()")
|
||||
actions.edit.left()
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.auto_insert("isset()")
|
||||
actions.edit.left()
|
||||
|
||||
def code_default_function(text: str):
|
||||
actions.user.code_public_function(text)
|
||||
|
||||
def code_protected_function(text: str):
|
||||
"""Inserts protected function declaration"""
|
||||
result = "protected function {}()".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_protected_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.paste(result)
|
||||
actions.edit.left()
|
||||
|
||||
def code_public_function(text: str):
|
||||
"""Inserts public function declaration"""
|
||||
result = "public function {}()".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_public_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.paste(result)
|
||||
actions.edit.left()
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "private function {}()".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_public_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.paste(result)
|
||||
actions.edit.left()
|
||||
|
||||
def code_private_static_function(text: str):
|
||||
"""Inserts private static function declaration"""
|
||||
result = "private static function {}()".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_protected_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.paste(result)
|
||||
actions.edit.left()
|
||||
|
||||
def code_protected_static_function(text: str):
|
||||
"""Inserts protected static function declaration"""
|
||||
result = "protected static function {}()".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_protected_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.paste(result)
|
||||
actions.edit.left()
|
||||
|
||||
def code_public_static_function(text: str):
|
||||
"""Inserts public static function declaration"""
|
||||
result = "public static function {}()".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_public_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.paste(result)
|
||||
actions.edit.left()
|
||||
|
||||
def code_insert_return_type(type: str):
|
||||
actions.insert(f": {type}")
|
||||
@@ -0,0 +1,36 @@
|
||||
code.language: php
|
||||
-
|
||||
tag(): user.code_imperative
|
||||
tag(): user.code_object_oriented
|
||||
tag(): user.code_libraries
|
||||
|
||||
tag(): user.code_comment_line
|
||||
tag(): user.code_comment_block
|
||||
tag(): user.code_comment_documentation
|
||||
tag(): user.code_data_bool
|
||||
tag(): user.code_data_null
|
||||
tag(): user.code_operators_assignment
|
||||
tag(): user.code_operators_math
|
||||
tag(): user.code_functions
|
||||
|
||||
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) loosely equal:
|
||||
user.deprecate_command("2025-03-20", "(op | is) loosely equal", "is weak equal")
|
||||
insert(" == ")
|
||||
(op | is) loosely not equal:
|
||||
user.deprecate_command("2025-03-20", "(op | is) loosely not equal", "is weak not equal")
|
||||
insert(" != ")
|
||||
|
||||
state try: user.insert_snippet_by_name("tryStatement")
|
||||
state catch: user.insert_snippet_by_name("catchStatement")
|
||||
|
||||
var <phrase> [over]:
|
||||
insert("$")
|
||||
insert(user.formatted_text(phrase, "PRIVATE_CAMEL_CASE"))
|
||||
@@ -0,0 +1,26 @@
|
||||
from talon import Context, Module
|
||||
|
||||
mod = Module()
|
||||
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: protobuf
|
||||
"""
|
||||
|
||||
ctx.lists["user.code_type"] = {
|
||||
"string": "string",
|
||||
"bytes": "bytes",
|
||||
"you sixty four": "uint64",
|
||||
"you thirty two": "uint32",
|
||||
"eye sixty four": "int64",
|
||||
"eye thirty two": "int32",
|
||||
"sin sixty four": "sint64",
|
||||
"sin thirty two": "sint32",
|
||||
"fixed sixty four": "fixed64",
|
||||
"fixed thirty two": "fixed32",
|
||||
"as fixed sixty four": "sfixed64",
|
||||
"as fixed thirty two": "sfixed32",
|
||||
"boolean": "bool",
|
||||
"double": "double",
|
||||
"float": "float",
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
code.language: protobuf
|
||||
-
|
||||
|
||||
# this is pretty bare-bones, further contributions welcome
|
||||
block: user.code_block()
|
||||
|
||||
state message: "message "
|
||||
state package: "package "
|
||||
state reserved: "reserved "
|
||||
state enum: "enum "
|
||||
op equals: " = "
|
||||
state import: "import "
|
||||
state import public: "import public "
|
||||
state option: "option "
|
||||
state repeated: "repeated "
|
||||
|
||||
type {user.code_type}: "{code_type}"
|
||||
repeated type {user.code_type}: "repeated {code_type}"
|
||||
@@ -0,0 +1,14 @@
|
||||
list: user.code_common_function
|
||||
code.language: python
|
||||
-
|
||||
|
||||
enumerate
|
||||
integer: "int"
|
||||
length: "len"
|
||||
list
|
||||
print
|
||||
range
|
||||
set
|
||||
split
|
||||
string: "str"
|
||||
update
|
||||
@@ -0,0 +1,41 @@
|
||||
list: user.code_keyword
|
||||
code.language: python
|
||||
-
|
||||
|
||||
and: " and "
|
||||
as: " as "
|
||||
assert: "assert "
|
||||
async: "async "
|
||||
await: "await "
|
||||
break: "break"
|
||||
case: "case "
|
||||
class: "class "
|
||||
deaf: "def "
|
||||
define: "def "
|
||||
dell: "del "
|
||||
elif: "elif "
|
||||
else: "else "
|
||||
except: "except "
|
||||
false: "False"
|
||||
for: "for "
|
||||
from: "from "
|
||||
global: "global "
|
||||
if: "if "
|
||||
import: "import "
|
||||
in: " in "
|
||||
is: " is "
|
||||
lambda: "lambda "
|
||||
match: "match "
|
||||
none: "None"
|
||||
not: "not "
|
||||
null: "None"
|
||||
or: " or "
|
||||
pass: "pass"
|
||||
raise: "raise "
|
||||
return: "return "
|
||||
true: "True"
|
||||
try: "try"
|
||||
type: "type"
|
||||
while: "while "
|
||||
with: "with "
|
||||
yield: "yield "
|
||||
@@ -0,0 +1,7 @@
|
||||
list: user.code_keyword_unprefixed
|
||||
code.language: python
|
||||
-
|
||||
|
||||
continue: "continue"
|
||||
finally: "finally"
|
||||
nonlocal: "nonlocal "
|
||||
@@ -0,0 +1,231 @@
|
||||
import re
|
||||
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
mod = Module()
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: python
|
||||
"""
|
||||
|
||||
"""a set of fields used in python docstrings that will follow the
|
||||
reStructuredText format"""
|
||||
docstring_fields = {
|
||||
"class": ":class:",
|
||||
"function": ":func:",
|
||||
"parameter": ":param:",
|
||||
"raise": ":raise:",
|
||||
"returns": ":return:",
|
||||
"type": ":type:",
|
||||
"return type": ":rtype:",
|
||||
# these are sphinx-specific
|
||||
"see also": ".. seealso:: ",
|
||||
"notes": ".. notes:: ",
|
||||
"warning": ".. warning:: ",
|
||||
"todo": ".. todo:: ",
|
||||
}
|
||||
|
||||
mod.list("python_docstring_fields", desc="python docstring fields")
|
||||
ctx.lists["user.python_docstring_fields"] = docstring_fields
|
||||
|
||||
ctx.lists["user.code_type"] = {
|
||||
"boolean": "bool",
|
||||
"integer": "int",
|
||||
"string": "str",
|
||||
"none": "None",
|
||||
"dick": "Dict",
|
||||
"float": "float",
|
||||
"any": "Any",
|
||||
"tuple": "Tuple",
|
||||
"union": "UnionAny",
|
||||
"iterable": "Iterable",
|
||||
"vector": "Vector",
|
||||
"bytes": "bytes",
|
||||
"sequence": "Sequence",
|
||||
"callable": "Callable",
|
||||
"list": "List",
|
||||
"no return": "NoReturn",
|
||||
}
|
||||
|
||||
exception_list = [
|
||||
"BaseException",
|
||||
"SystemExit",
|
||||
"KeyboardInterrupt",
|
||||
"GeneratorExit",
|
||||
"Exception",
|
||||
"StopIteration",
|
||||
"StopAsyncIteration",
|
||||
"ArithmeticError",
|
||||
"FloatingPointError",
|
||||
"OverflowError",
|
||||
"ZeroDivisionError",
|
||||
"AssertionError",
|
||||
"AttributeError",
|
||||
"BufferError",
|
||||
"EOFError",
|
||||
"ImportError",
|
||||
"ModuleNotFoundError",
|
||||
"LookupError",
|
||||
"IndexError",
|
||||
"KeyError",
|
||||
"MemoryError",
|
||||
"NameError",
|
||||
"UnboundLocalError",
|
||||
"OSError",
|
||||
"BlockingIOError",
|
||||
"ChildProcessError",
|
||||
"ConnectionError",
|
||||
"BrokenPipeError",
|
||||
"ConnectionAbortedError",
|
||||
"ConnectionRefusedError",
|
||||
"ConnectionResetError",
|
||||
"FileExistsError",
|
||||
"FileNotFoundError",
|
||||
"InterruptedError",
|
||||
"IsADirectoryError",
|
||||
"NotADirectoryError",
|
||||
"PermissionError",
|
||||
"ProcessLookupError",
|
||||
"TimeoutError",
|
||||
"ReferenceError",
|
||||
"RuntimeError",
|
||||
"NotImplementedError",
|
||||
"RecursionError",
|
||||
"SyntaxError",
|
||||
"IndentationError",
|
||||
"TabError",
|
||||
"SystemError",
|
||||
"TypeError",
|
||||
"ValueError",
|
||||
"UnicodeError",
|
||||
"UnicodeDecodeError",
|
||||
"UnicodeEncodeError",
|
||||
"UnicodeTranslateError",
|
||||
"Warning",
|
||||
"DeprecationWarning",
|
||||
"PendingDeprecationWarning",
|
||||
"RuntimeWarning",
|
||||
"SyntaxWarning",
|
||||
"UserWarning",
|
||||
"FutureWarning",
|
||||
"ImportWarning",
|
||||
"UnicodeWarning",
|
||||
"BytesWarning",
|
||||
"ResourceWarning",
|
||||
]
|
||||
mod.list("python_exception", desc="python exceptions")
|
||||
ctx.lists["user.python_exception"] = {
|
||||
" ".join(re.findall("[A-Z][^A-Z]*", exception)).lower(): exception
|
||||
for exception in exception_list
|
||||
}
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
ASSIGNMENT_SUBTRACTION=" -= ",
|
||||
ASSIGNMENT_ADDITION=" += ",
|
||||
ASSIGNMENT_MULTIPLICATION=" *= ",
|
||||
ASSIGNMENT_DIVISION=" /= ",
|
||||
ASSIGNMENT_MODULO=" %= ",
|
||||
ASSIGNMENT_INCREMENT=" += 1",
|
||||
ASSIGNMENT_BITWISE_AND=" &= ",
|
||||
ASSIGNMENT_BITWISE_OR=" |= ",
|
||||
ASSIGNMENT_BITWISE_EXCLUSIVE_OR=" ^= ",
|
||||
ASSIGNMENT_BITWISE_LEFT_SHIFT=" <<= ",
|
||||
ASSIGNMENT_BITWISE_RIGHT_SHIFT=" >>= ",
|
||||
# code_operators_bitwise
|
||||
BITWISE_NOT="~",
|
||||
BITWISE_AND=" & ",
|
||||
BITWISE_OR=" | ",
|
||||
BITWISE_EXCLUSIVE_OR=" ^ ",
|
||||
BITWISE_LEFT_SHIFT=" << ",
|
||||
BITWISE_RIGHT_SHIFT=" >> ",
|
||||
# code_operators_lambda
|
||||
LAMBDA=lambda: actions.user.insert_between("lambda ", ": "),
|
||||
# code_operators_math
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_INTEGER_DIVIDE=" // ",
|
||||
MATH_MODULO=" % ",
|
||||
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=" and ",
|
||||
MATH_OR=" or ",
|
||||
MATH_NOT=" not ",
|
||||
MATH_IN=" in ",
|
||||
MATH_NOT_IN=" not in ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_self():
|
||||
actions.auto_insert("self")
|
||||
|
||||
def code_operator_object_accessor():
|
||||
actions.auto_insert(".")
|
||||
|
||||
def code_insert_null():
|
||||
actions.auto_insert("None")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.auto_insert(" is None")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.auto_insert(" is not None")
|
||||
|
||||
def code_insert_true():
|
||||
actions.auto_insert("True")
|
||||
|
||||
def code_insert_false():
|
||||
actions.auto_insert("False")
|
||||
|
||||
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):
|
||||
actions.user.code_public_function(text)
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "def _{}():".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.paste(result)
|
||||
actions.edit.left()
|
||||
actions.edit.left()
|
||||
|
||||
def code_public_function(text: str):
|
||||
result = "def {}():".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_public_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.paste(result)
|
||||
actions.edit.left()
|
||||
actions.edit.left()
|
||||
|
||||
def code_insert_type_annotation(type: str):
|
||||
actions.insert(f": {type}")
|
||||
|
||||
def code_insert_return_type(type: str):
|
||||
actions.insert(f" -> {type}")
|
||||
@@ -0,0 +1,53 @@
|
||||
code.language: python
|
||||
-
|
||||
tag(): user.code_imperative
|
||||
tag(): user.code_object_oriented
|
||||
|
||||
tag(): user.code_comment_documentation
|
||||
tag(): user.code_comment_line
|
||||
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 = "SNAKE_CASE"
|
||||
user.code_protected_function_formatter = "SNAKE_CASE"
|
||||
user.code_public_function_formatter = "SNAKE_CASE"
|
||||
user.code_private_variable_formatter = "SNAKE_CASE"
|
||||
user.code_protected_variable_formatter = "SNAKE_CASE"
|
||||
user.code_public_variable_formatter = "SNAKE_CASE"
|
||||
|
||||
#python-specific grammars
|
||||
dunder in it: "__init__"
|
||||
state (def | deaf | deft): "def "
|
||||
state try: "try:\n"
|
||||
state except: "except "
|
||||
state raise: "raise "
|
||||
self taught: "self."
|
||||
pie test: "pytest"
|
||||
state past: "pass"
|
||||
|
||||
[state] raise {user.python_exception}:
|
||||
user.insert_between("raise {python_exception}(", ")")
|
||||
[state] except {user.python_exception}: "except {python_exception}:"
|
||||
|
||||
dock string: user.code_comment_documentation()
|
||||
dock {user.python_docstring_fields}:
|
||||
insert("{python_docstring_fields}")
|
||||
edit.left()
|
||||
dock type {user.code_type}: user.insert_between(":type ", ": {code_type}")
|
||||
dock returns type {user.code_type}: user.insert_between(":rtype ", ": {code_type}")
|
||||
|
||||
import <user.code_libraries>:
|
||||
user.code_insert_library(code_libraries, "")
|
||||
key(end enter)
|
||||
|
||||
from import: user.insert_snippet_by_name("importFromStatement")
|
||||
@@ -0,0 +1,157 @@
|
||||
list: user.code_common_function
|
||||
code.language: r
|
||||
-
|
||||
|
||||
# base R
|
||||
as character: "as.character"
|
||||
as data frame: "as.data.frame"
|
||||
as date: "as.Date"
|
||||
as double: "as.double"
|
||||
as factor: "as.factor"
|
||||
as integer: "as.integer"
|
||||
as numeric: "as.numeric"
|
||||
base read RDS: "readRDS"
|
||||
base save RDS: "saveRDS"
|
||||
cable: "kable"
|
||||
correlation: "cor"
|
||||
count: "count"
|
||||
covariance: "cov"
|
||||
describe: "describe"
|
||||
eigen: "eigen"
|
||||
ex table: "xtable"
|
||||
get working directory: "getwd"
|
||||
head: "head"
|
||||
if else: "ifelse"
|
||||
install packages: "install.packages"
|
||||
is NA: "is.na"
|
||||
is not NA: "!is.na"
|
||||
length: "length"
|
||||
library: "library"
|
||||
list files: "list.files"
|
||||
list: "list"
|
||||
lm: "lm"
|
||||
log: "log"
|
||||
make directory: "dir.create"
|
||||
margins: "margins"
|
||||
max: "max"
|
||||
mean: "mean"
|
||||
min: "min"
|
||||
names: "names"
|
||||
paste: "paste0"
|
||||
print: "print"
|
||||
reorder: "reorder"
|
||||
repeat: "rep"
|
||||
scale: "scale"
|
||||
sequence along: "seq_along"
|
||||
sequence length: "seq_len"
|
||||
sequence: "seq"
|
||||
set working directory: "setwd"
|
||||
sort: "sort"
|
||||
subset: "subset"
|
||||
sum: "sum"
|
||||
summary: "summary"
|
||||
tail: "tail"
|
||||
tidy: "tidy"
|
||||
trim white space: "trimws"
|
||||
type: "typeof"
|
||||
unique: "unique"
|
||||
vector: "c"
|
||||
vee table: "vtable"
|
||||
view: "View"
|
||||
# dplyr
|
||||
anti join: "anti_join"
|
||||
arrange: "arrange"
|
||||
as tibble: "as_tibble"
|
||||
bind rows: "bind_rows"
|
||||
case when: "case_when"
|
||||
distinct: "distinct"
|
||||
everything: "everything"
|
||||
filter: "filter"
|
||||
full join: "full_join"
|
||||
glimpse: "glimpse"
|
||||
group by: "group_by"
|
||||
inner join: "inner_join"
|
||||
left join: "left_join"
|
||||
mutate: "mutate"
|
||||
pull: "pull"
|
||||
rename all: "rename_all"
|
||||
rename: "rename"
|
||||
right join: "right_join"
|
||||
select all: "select_all"
|
||||
select: "select"
|
||||
semi join: "semi_join"
|
||||
starts with: "starts_with"
|
||||
summarise: "summarise"
|
||||
tibble: "tibble"
|
||||
ungroup: "ungroup"
|
||||
# ggplot2
|
||||
coord cartesian: "coor_cartesian"
|
||||
element text: "element_text"
|
||||
element blank: "element_blank"
|
||||
facet grid: "facet_grid"
|
||||
facet wrap: "facet_wrap"
|
||||
geom A B line: "geom_abline"
|
||||
geom area: "geom_area"
|
||||
geom bar: "geom_bar"
|
||||
geom boxplot: "geom_boxplot"
|
||||
geom histogram: "geom_histogram"
|
||||
geom horizontal line: "geom_hline"
|
||||
geom line: "geom_line"
|
||||
geom point: "geom_point"
|
||||
geom pointrange: "geom_pointrange"
|
||||
geom polygon: "geom_polygon"
|
||||
geom ribbon: "geom_ribbon"
|
||||
geom segment: "geom_segment"
|
||||
geom smooth: "geom_smooth"
|
||||
geom vertical line: "geom_vline"
|
||||
geom violin: "geom_violin"
|
||||
labs: "labs"
|
||||
scale colour manual: "scale_colour_manual"
|
||||
scale fill manual: "scale_fill_manual"
|
||||
scale fill viridis: "scale_fill_viridis_c"
|
||||
scale colour viridis: "scale_colour_viridis_c"
|
||||
theme set: "theme_set"
|
||||
# purrr
|
||||
map character: "map_chr"
|
||||
map data frame: "map_dfr"
|
||||
map double: "map_dbl"
|
||||
map: "map"
|
||||
P map: "pmap"
|
||||
# stringr
|
||||
string contains: "str_detect"
|
||||
string detect: "str_detect"
|
||||
string replace all: "str_replace_all"
|
||||
string replace: "str_replace"
|
||||
# tidyr
|
||||
drop NA: "drop_na"
|
||||
gather: "gather"
|
||||
nest: "nest"
|
||||
pivot longer: "pivot_longer"
|
||||
pivot wider: "pivot_wider"
|
||||
spread: "spread"
|
||||
un nest: "unnest"
|
||||
# readr readxl and other non-base R reading/writing
|
||||
read E views: "readEViews"
|
||||
read CSV: "read_csv"
|
||||
read RDS: "read_rds"
|
||||
read excel: "read_xlsx"
|
||||
write CSV: "write_csv"
|
||||
write RDS: "write_rds"
|
||||
# Shiny
|
||||
shine ui: "shinyUI"
|
||||
title panel: "titlePanel"
|
||||
main panel: "mainPanel"
|
||||
tab panel: "tabPanel"
|
||||
navigation list panel: "navlistPanel"
|
||||
conditional panel: "conditionalPanel"
|
||||
input panel: "inputPanel"
|
||||
ui output: "uiOutput"
|
||||
text output: "textOutput"
|
||||
table output: "tableOutput"
|
||||
data table output: "dataTableOutput"
|
||||
select size input: "selectizeInput"
|
||||
action button: "actionButton"
|
||||
download button: "downloadButton"
|
||||
render ui: "renderUI"
|
||||
observe event: "observeEvent"
|
||||
# Base
|
||||
@@ -0,0 +1,151 @@
|
||||
from talon import Context, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
|
||||
ctx.matches = r"""
|
||||
code.language: r
|
||||
"""
|
||||
|
||||
|
||||
ctx.lists["user.code_libraries"] = {
|
||||
"bayes plot": "bayesplot",
|
||||
"BRMS": "brms",
|
||||
"cable": "kable",
|
||||
"car": "car",
|
||||
"D plier": "dplyr",
|
||||
"dev tools": "devtools",
|
||||
"future": "future",
|
||||
"furr": "furrr",
|
||||
"gap minder": "gapminder",
|
||||
"gee animate": "gganimate",
|
||||
"gee highlight": "gghighlight",
|
||||
"gee map": "ggmap",
|
||||
"gee repel": "ggrepel",
|
||||
"grid extra": "gridExtra",
|
||||
"gee gee plot": "ggplot2",
|
||||
"GLMM TMB": "glmmTMB",
|
||||
"here": "here",
|
||||
"knitter": "knitr",
|
||||
"LME four": "lme4",
|
||||
"LM test": "lmtest",
|
||||
"lubridate": "lubridate",
|
||||
"margins": "margins",
|
||||
"inla": "INLA",
|
||||
"NLME": "nlme",
|
||||
"psych": "psych",
|
||||
"purr": "purrr",
|
||||
"R markdown": "rmarkdown",
|
||||
"R stan": "rstan",
|
||||
"R stan arm": "rstanarm",
|
||||
"R color brewer": "RColorBrewer",
|
||||
"read R": "readr",
|
||||
"stargazer": "stargazer",
|
||||
"tidy verse": "tidyverse",
|
||||
"tidier": "tidyr",
|
||||
"tidy bayes": "tidybayes",
|
||||
"TMB": "TMB",
|
||||
"vee table": "vtable",
|
||||
"viridis": "viridis",
|
||||
"viridis light": "viridisLite",
|
||||
"shiny alert": "shinyalert",
|
||||
}
|
||||
|
||||
ctx.lists["user.code_parameter_name"] = {
|
||||
"alpha": "alpha",
|
||||
"breaks": "breaks",
|
||||
"colour": "colour",
|
||||
"data": "data",
|
||||
"fill": "fill",
|
||||
"H just": "hjust",
|
||||
"keep": ".keep",
|
||||
"label": "label",
|
||||
"labels": "labels",
|
||||
"log": "log",
|
||||
"main": "main",
|
||||
"mapping": "mapping",
|
||||
"method": "method",
|
||||
"NA remove": "na.rm",
|
||||
"path": "path",
|
||||
"position": "position",
|
||||
"plex label": "xlab",
|
||||
"plex limit": "xlim",
|
||||
"scales": "scales",
|
||||
"size": "size",
|
||||
"show legend": "show.legend",
|
||||
"sort": "sort",
|
||||
"title": "title",
|
||||
"type": "type",
|
||||
"vee just": "vjust",
|
||||
"width": "width",
|
||||
"with ties": "with_ties",
|
||||
"why label": "ylab",
|
||||
"why limit": "ylim",
|
||||
"why max": "ymax",
|
||||
"why min": "ymin",
|
||||
}
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" <- ",
|
||||
# code_operators_bitwise
|
||||
BITWISE_AND=" & ",
|
||||
# code_operators_math:
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_EXPONENT=" ** ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" %% ",
|
||||
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=" | ",
|
||||
MATH_IN=" %in% ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_insert_null():
|
||||
actions.auto_insert("NULL")
|
||||
|
||||
def code_insert_true():
|
||||
actions.auto_insert("TRUE")
|
||||
|
||||
def code_insert_false():
|
||||
actions.auto_insert("FALSE")
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
text += f"({selection or ''})"
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
def code_private_function(text: str):
|
||||
result = "{} <- function () {{\n\n}}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.paste(result)
|
||||
actions.edit.up()
|
||||
actions.edit.up()
|
||||
actions.edit.line_end()
|
||||
actions.edit.left()
|
||||
actions.edit.left()
|
||||
actions.edit.left()
|
||||
|
||||
def code_insert_library(text: str, selection: str):
|
||||
actions.user.insert_snippet_by_name("importStatement", {"0": text + selection})
|
||||
|
||||
def code_insert_named_argument(parameter_name: str):
|
||||
actions.insert(f"{parameter_name} = ")
|
||||
@@ -0,0 +1,38 @@
|
||||
code.language: r
|
||||
-
|
||||
tag(): user.code_imperative
|
||||
|
||||
tag(): user.code_comment_line
|
||||
tag(): user.code_data_bool
|
||||
tag(): user.code_data_null
|
||||
tag(): user.code_functions
|
||||
tag(): user.code_functions_common
|
||||
tag(): user.code_libraries
|
||||
tag(): user.code_operators_assignment
|
||||
tag(): user.code_operators_bitwise
|
||||
tag(): user.code_operators_math
|
||||
|
||||
settings():
|
||||
user.code_private_function_formatter = "SNAKE_CASE"
|
||||
user.code_protected_function_formatter = "SNAKE_CASE"
|
||||
user.code_public_function_formatter = "SNAKE_CASE"
|
||||
user.code_private_variable_formatter = "SNAKE_CASE"
|
||||
user.code_protected_variable_formatter = "SNAKE_CASE"
|
||||
user.code_public_variable_formatter = "SNAKE_CASE"
|
||||
|
||||
library <user.code_libraries>:
|
||||
user.code_insert_library(code_libraries, "")
|
||||
key(end enter)
|
||||
|
||||
# R specific commands
|
||||
(chain | pipe that):
|
||||
key(end)
|
||||
" %>%"
|
||||
key(enter)
|
||||
state na: insert("NA")
|
||||
|
||||
# TODO: migrate to function tag
|
||||
^function define <user.text>$: user.code_private_function(text)
|
||||
|
||||
named arg {user.code_parameter_name}:
|
||||
user.code_insert_named_argument(code_parameter_name)
|
||||
@@ -0,0 +1,95 @@
|
||||
from talon import Context, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: ruby
|
||||
"""
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
ASSIGNMENT_OR=" ||= ",
|
||||
ASSIGNMENT_SUBTRACTION=" -= ",
|
||||
ASSIGNMENT_ADDITION=" += ",
|
||||
ASSIGNMENT_MULTIPLICATION=" *= ",
|
||||
ASSIGNMENT_DIVISION=" /= ",
|
||||
ASSIGNMENT_MODULO=" %= ",
|
||||
ASSIGNMENT_INCREMENT=" += 1",
|
||||
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_NOT="~",
|
||||
BITWISE_EXCLUSIVE_OR=" ^ ",
|
||||
BITWISE_LEFT_SHIFT=" << ",
|
||||
BITWISE_RIGHT_SHIFT=" >> ",
|
||||
# code_operators_lambda
|
||||
LAMBDA="->",
|
||||
# code_operators_math
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_EXPONENT=" ** ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" % ",
|
||||
MATH_EQUAL=" == ",
|
||||
MATH_NOT_EQUAL=" != ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
MATH_NOT="!",
|
||||
MATH_AND=" && ",
|
||||
MATH_OR=" || ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_self():
|
||||
actions.auto_insert("self")
|
||||
|
||||
def code_operator_object_accessor():
|
||||
actions.auto_insert(".")
|
||||
|
||||
def code_insert_null():
|
||||
actions.auto_insert("nil")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.auto_insert(".nil?")
|
||||
|
||||
# Technically .present? is provided by Rails
|
||||
def code_insert_is_not_null():
|
||||
actions.auto_insert(".present?")
|
||||
|
||||
def code_insert_true():
|
||||
actions.auto_insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.auto_insert("false")
|
||||
|
||||
def code_comment_documentation():
|
||||
actions.insert("##")
|
||||
actions.key("enter")
|
||||
actions.key("space")
|
||||
### Extra non-standard things
|
||||
|
||||
def code_default_function(text: str):
|
||||
"""Inserts function definition"""
|
||||
|
||||
result = "def {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_public_function_formatter")
|
||||
)
|
||||
)
|
||||
actions.user.paste(result)
|
||||
@@ -0,0 +1,38 @@
|
||||
code.language: ruby
|
||||
-
|
||||
tag(): user.code_imperative
|
||||
tag(): user.code_object_oriented
|
||||
|
||||
tag(): user.code_comment_line
|
||||
tag(): user.code_comment_documentation
|
||||
tag(): user.code_data_bool
|
||||
tag(): user.code_data_null
|
||||
tag(): user.code_functions
|
||||
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 = "SNAKE_CASE"
|
||||
user.code_protected_function_formatter = "SNAKE_CASE"
|
||||
user.code_public_function_formatter = "SNAKE_CASE"
|
||||
user.code_private_variable_formatter = "SNAKE_CASE"
|
||||
user.code_protected_variable_formatter = "SNAKE_CASE"
|
||||
user.code_public_variable_formatter = "SNAKE_CASE"
|
||||
|
||||
args pipe: user.insert_between("|", "|")
|
||||
|
||||
# NOTE: this command is created for backward compatibility, but the documentation comments are not actually strings in Ruby.
|
||||
dock string: user.code_comment_documentation()
|
||||
|
||||
state end: "end"
|
||||
state begin: "begin"
|
||||
state rescue: "rescue "
|
||||
state module: "module "
|
||||
|
||||
^instance <user.text>$:
|
||||
insert("@")
|
||||
user.code_public_variable_formatter(text)
|
||||
@@ -0,0 +1,392 @@
|
||||
from typing import Any, Callable, TypeVar
|
||||
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
mod = Module()
|
||||
# rust specific grammar
|
||||
mod.list("code_type_modifier", desc="List of type modifiers for active language")
|
||||
mod.list("code_macros", desc="List of macros for active language")
|
||||
mod.list("code_trait", desc="List of traits for active language")
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_state_implements():
|
||||
"""Inserts implements block, positioning the cursor appropriately"""
|
||||
|
||||
def code_insert_macro(text: str, selection: str):
|
||||
"""Inserts a macro and positions the cursor appropriately"""
|
||||
|
||||
def code_insert_macro_array(text: str, selection: str):
|
||||
"""Inserts a macro array and positions the cursor appropriately"""
|
||||
|
||||
def code_insert_macro_block(text: str, selection: str):
|
||||
"""Inserts a macro block and positions the cursor appropriately"""
|
||||
|
||||
def code_state_unsafe():
|
||||
"""Inserts an unsafe block and positions the cursor appropriately"""
|
||||
|
||||
def code_comment_documentation_block():
|
||||
"""Inserts a block document comment and positions the cursor appropriately"""
|
||||
|
||||
def code_comment_documentation_inner():
|
||||
"""Inserts an inner document comment and positions the cursor appropriately"""
|
||||
|
||||
def code_comment_documentation_block_inner():
|
||||
"""Inserts an inner block document comment and positions the cursor appropriately"""
|
||||
|
||||
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: rust
|
||||
"""
|
||||
|
||||
scalar_types = {
|
||||
"eye eight": "i8",
|
||||
"you eight": "u8",
|
||||
"bytes": "u8",
|
||||
"eye sixteen": "i16",
|
||||
"you sixteen": "u16",
|
||||
"eye thirty two": "i32",
|
||||
"you thirty two": "u32",
|
||||
"eye sixty four": "i64",
|
||||
"you sixty four": "u64",
|
||||
"eye one hundred and twenty eight": "i128",
|
||||
"you one hundred and twenty eight": "u128",
|
||||
"eye size": "isize",
|
||||
"you size": "usize",
|
||||
"float thirty two": "f32",
|
||||
"float sixty four": "f64",
|
||||
"boolean": "bool",
|
||||
"character": "char",
|
||||
}
|
||||
|
||||
compound_types = {
|
||||
"tuple": "()",
|
||||
"array": "[]",
|
||||
}
|
||||
|
||||
standard_library_types = {
|
||||
"box": "Box",
|
||||
"vector": "Vec",
|
||||
"string": "String",
|
||||
"string slice": "&str",
|
||||
"os string": "OsString",
|
||||
"os string slice": "&OsStr",
|
||||
"see string": "CString",
|
||||
"see string slice": "&CStr",
|
||||
"option": "Option",
|
||||
"result": "Result",
|
||||
"hashmap": "HashMap",
|
||||
"hash set": "HashSet",
|
||||
"reference count": "Rc",
|
||||
}
|
||||
|
||||
standard_sync_types = {
|
||||
"arc": "Arc",
|
||||
"barrier": "Barrier",
|
||||
"condition variable": "Condvar",
|
||||
"mutex": "Mutex",
|
||||
"once": "Once",
|
||||
"read write lock": "RwLock",
|
||||
"receiver": "Receiver",
|
||||
"sender": "Sender",
|
||||
"sink sender": "SyncSender",
|
||||
}
|
||||
|
||||
all_types = {
|
||||
**scalar_types,
|
||||
**compound_types,
|
||||
**standard_library_types,
|
||||
**standard_sync_types,
|
||||
}
|
||||
|
||||
standard_function_macros = {
|
||||
"panic": "panic!",
|
||||
"format": "format!",
|
||||
"concatenate": "concat!",
|
||||
"print": "print!",
|
||||
"print line": "println!",
|
||||
"error print line": "eprintln!",
|
||||
"to do": "todo!",
|
||||
}
|
||||
|
||||
standard_array_macros = {
|
||||
"vector": "vec!",
|
||||
}
|
||||
|
||||
standard_block_macros = {
|
||||
"macro rules": "macro_rules!",
|
||||
}
|
||||
|
||||
logging_macros = {
|
||||
"debug": "debug!",
|
||||
"info": "info!",
|
||||
"warning": "warn!",
|
||||
"error": "error!",
|
||||
}
|
||||
|
||||
testing_macros = {
|
||||
"assert": "assert!",
|
||||
"assert equal": "assert_eq!",
|
||||
"assert not equal": "assert_ne!",
|
||||
}
|
||||
|
||||
all_function_macros = {
|
||||
**standard_function_macros,
|
||||
**logging_macros,
|
||||
**testing_macros,
|
||||
}
|
||||
|
||||
all_array_macros = {
|
||||
**standard_array_macros,
|
||||
}
|
||||
|
||||
all_block_macros = {
|
||||
**standard_block_macros,
|
||||
}
|
||||
|
||||
all_macros = {
|
||||
**all_function_macros,
|
||||
**all_array_macros,
|
||||
**all_block_macros,
|
||||
}
|
||||
|
||||
all_function_macro_values = set(all_function_macros.values())
|
||||
all_array_macro_values = set(all_array_macros.values())
|
||||
all_block_macro_values = set(all_block_macros.values())
|
||||
|
||||
closure_traits = {
|
||||
"closure": "Fn",
|
||||
"closure once": "FnOnce",
|
||||
"closure mutable": "FnMut",
|
||||
}
|
||||
|
||||
conversion_traits = {
|
||||
"into": "Into",
|
||||
"from": "From",
|
||||
}
|
||||
|
||||
iterator_traits = {
|
||||
"iterator": "Iterator",
|
||||
}
|
||||
|
||||
all_traits = {
|
||||
**closure_traits,
|
||||
**conversion_traits,
|
||||
**iterator_traits,
|
||||
}
|
||||
|
||||
|
||||
# tag: libraries
|
||||
ctx.lists["user.code_libraries"] = {
|
||||
"eye oh": "std::io",
|
||||
"file system": "std::fs",
|
||||
"envy": "std::env",
|
||||
"collections": "std::collections",
|
||||
}
|
||||
|
||||
# tag: functions_common
|
||||
ctx.lists["user.code_common_function"] = {
|
||||
"drop": "drop",
|
||||
"catch unwind": "catch_unwind",
|
||||
"iterator": "iter",
|
||||
"into iterator": "into_iter",
|
||||
"from iterator": "from_iter",
|
||||
**all_macros,
|
||||
}
|
||||
|
||||
# tag: functions
|
||||
ctx.lists["user.code_type"] = all_types
|
||||
|
||||
# rust specific grammar
|
||||
ctx.lists["user.code_type_modifier"] = {
|
||||
"mutable": "mut ",
|
||||
"mute": "mut ",
|
||||
"borrowed": "&",
|
||||
"borrowed mutable": "&mut ",
|
||||
"borrowed mute": "&mut ",
|
||||
"mutable borrowed": "&mut ",
|
||||
"mute borrowed": "&mut ",
|
||||
}
|
||||
|
||||
|
||||
@ctx.capture("user.code_type", rule="[{user.code_type_modifier}] {user.code_type}")
|
||||
def code_type(m) -> str:
|
||||
"""Returns a macro name"""
|
||||
return "".join(m)
|
||||
|
||||
|
||||
ctx.lists["user.code_macros"] = all_macros
|
||||
|
||||
ctx.lists["user.code_trait"] = all_traits
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
ASSIGNMENT_ADDITION=" += ",
|
||||
ASSIGNMENT_SUBTRACTION=" -= ",
|
||||
ASSIGNMENT_MULTIPLICATION=" *= ",
|
||||
ASSIGNMENT_DIVISION=" /= ",
|
||||
ASSIGNMENT_MODULO=" %= ",
|
||||
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_math
|
||||
MATH_ADD=" + ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" % ",
|
||||
MATH_EXPONENT=lambda: actions.user.insert_between(".pow(", ")"),
|
||||
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=" || ",
|
||||
ASSIGNMENT_INCREMENT=" += 1",
|
||||
# code_operators_pointer
|
||||
POINTER_INDIRECTION="*",
|
||||
POINTER_ADDRESS_OF="&",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
# tag: imperative
|
||||
|
||||
# tag: object_oriented
|
||||
|
||||
def code_operator_object_accessor():
|
||||
actions.auto_insert(".")
|
||||
|
||||
def code_self():
|
||||
actions.auto_insert("self")
|
||||
|
||||
def code_define_class():
|
||||
actions.user.insert_snippet_by_name("structDeclaration")
|
||||
|
||||
# tag: data_bool
|
||||
|
||||
def code_insert_true():
|
||||
actions.auto_insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.auto_insert("false")
|
||||
|
||||
# tag: data_null
|
||||
|
||||
def code_insert_null():
|
||||
actions.auto_insert("None")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.auto_insert(".is_none()")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.auto_insert(".is_some()")
|
||||
|
||||
# tag: functions
|
||||
|
||||
def code_default_function(text: str):
|
||||
actions.user.code_private_function(text)
|
||||
|
||||
def code_private_function(text: str):
|
||||
actions.auto_insert("fn ")
|
||||
formatter = settings.get("user.code_private_function_formatter")
|
||||
function_name = actions.user.formatted_text(text, formatter)
|
||||
actions.user.code_insert_function(function_name, None)
|
||||
|
||||
def code_protected_function(text: str):
|
||||
actions.auto_insert("pub(crate) fn ")
|
||||
formatter = settings.get("user.code_protected_function_formatter")
|
||||
function_name = actions.user.formatted_text(text, formatter)
|
||||
actions.user.code_insert_function(function_name, None)
|
||||
|
||||
def code_public_function(text: str):
|
||||
actions.auto_insert("pub fn ")
|
||||
formatter = settings.get("user.code_public_function_formatter")
|
||||
function_name = actions.user.formatted_text(text, formatter)
|
||||
actions.user.code_insert_function(function_name, None)
|
||||
|
||||
def code_insert_type_annotation(type: str):
|
||||
actions.auto_insert(f": {type}")
|
||||
|
||||
def code_insert_return_type(type: str):
|
||||
actions.auto_insert(f" -> {type}")
|
||||
|
||||
# tag: functions_gui
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
code_insert_function_or_macro(text, selection, "(", ")")
|
||||
|
||||
# tag: libraries
|
||||
|
||||
def code_insert_library(text: str, selection: str):
|
||||
actions.user.insert_snippet_by_name("importStatement", {"0": text})
|
||||
|
||||
# rust specific grammar
|
||||
|
||||
def code_state_implements():
|
||||
actions.user.insert_snippet_by_name("implementsStruct")
|
||||
|
||||
def code_insert_macro(text: str, selection: str):
|
||||
if text in all_array_macro_values:
|
||||
code_insert_function_or_macro(text, selection, "[", "]")
|
||||
elif text in all_block_macro_values:
|
||||
code_insert_function_or_macro(text, selection, "{", "}")
|
||||
else:
|
||||
code_insert_function_or_macro(text, selection, "(", ")")
|
||||
|
||||
def code_state_unsafe():
|
||||
actions.user.insert_snippet_by_name("unsafeBlock")
|
||||
|
||||
def code_comment_documentation_block():
|
||||
actions.user.insert_between("/**", "*/")
|
||||
actions.key("enter")
|
||||
|
||||
def code_comment_documentation_inner():
|
||||
actions.auto_insert("//! ")
|
||||
|
||||
def code_comment_documentation_block_inner():
|
||||
actions.user.insert_between("/*!", "*/")
|
||||
actions.key("enter")
|
||||
|
||||
|
||||
def code_insert_function_or_macro(
|
||||
text: str,
|
||||
selection: str,
|
||||
left_delim: str,
|
||||
right_delim: str,
|
||||
):
|
||||
if selection:
|
||||
out_text = text + f"{left_delim}{selection}{right_delim}"
|
||||
else:
|
||||
out_text = text + f"{left_delim}{right_delim}"
|
||||
actions.user.paste(out_text)
|
||||
actions.edit.left()
|
||||
|
||||
|
||||
RT = TypeVar("RT") # return type
|
||||
|
||||
|
||||
def repeat_call(n: int, f: Callable[..., RT], *args: Any, **kwargs: Any):
|
||||
for i in range(n):
|
||||
f(*args, **kwargs)
|
||||
@@ -0,0 +1,102 @@
|
||||
code.language: rust
|
||||
-
|
||||
tag(): user.code_comment_line
|
||||
tag(): user.code_comment_block_c_like
|
||||
tag(): user.code_comment_documentation
|
||||
|
||||
tag(): user.code_imperative
|
||||
tag(): user.code_object_oriented
|
||||
|
||||
tag(): user.code_data_bool
|
||||
tag(): user.code_data_null
|
||||
|
||||
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_bitwise
|
||||
tag(): user.code_operators_math
|
||||
tag(): user.code_operators_pointer
|
||||
|
||||
settings():
|
||||
user.code_private_function_formatter = "SNAKE_CASE"
|
||||
user.code_protected_function_formatter = "SNAKE_CASE"
|
||||
user.code_public_function_formatter = "SNAKE_CASE"
|
||||
user.code_private_variable_formatter = "SNAKE_CASE"
|
||||
user.code_protected_variable_formatter = "SNAKE_CASE"
|
||||
user.code_public_variable_formatter = "SNAKE_CASE"
|
||||
|
||||
# rust-specific grammars
|
||||
|
||||
## for unsafe rust
|
||||
state unsafe: "unsafe "
|
||||
unsafe block: user.code_state_unsafe()
|
||||
|
||||
## rust centric struct and enum definitions
|
||||
state (struct | structure) <user.text>:
|
||||
insert("struct ")
|
||||
insert(user.formatted_text(text, "PUBLIC_CAMEL_CASE"))
|
||||
|
||||
state enum <user.text>:
|
||||
insert("enum ")
|
||||
insert(user.formatted_text(text, "PUBLIC_CAMEL_CASE"))
|
||||
|
||||
## Simple aliases
|
||||
borrow: "&"
|
||||
borrow mutable: "&mut "
|
||||
state (a sink | async | asynchronous): "async "
|
||||
state (pub | public): "pub "
|
||||
state (pub | public) crate: "pub(crate) "
|
||||
state (dyn | dynamic): "dyn "
|
||||
state constant: "const "
|
||||
state (funk | func | function): "fn "
|
||||
state (imp | implements): "impl "
|
||||
state let mute: "let mut "
|
||||
state let: "let "
|
||||
state (mute | mutable): "mut "
|
||||
state (mod | module): "mod "
|
||||
state ref (mute | mutable): "ref mut "
|
||||
state ref: "ref "
|
||||
state trait: "trait "
|
||||
state (some | sum): "Some"
|
||||
state static: "static "
|
||||
self taught: "self."
|
||||
state use: user.code_import()
|
||||
|
||||
use <user.code_libraries>:
|
||||
user.code_insert_library(code_libraries, "")
|
||||
key(enter)
|
||||
|
||||
## specialist flow control
|
||||
state if let some: user.insert_between("if let Some(", ")")
|
||||
state if let (ok | okay): user.insert_between("if let Ok(", ")")
|
||||
state if let error: user.insert_between("if let Err(", ")")
|
||||
|
||||
## rust centric synonyms
|
||||
is some: user.code_insert_is_not_null()
|
||||
|
||||
## for implementing
|
||||
implement (struct | structure): user.code_state_implements()
|
||||
|
||||
## for annotating function parameters
|
||||
is implemented trait {user.code_trait}: ": impl {code_trait}"
|
||||
is implemented trait: ": impl "
|
||||
returns implemented trait {user.code_trait}: " -> impl {code_trait}"
|
||||
returns implemented trait: " -> impl "
|
||||
|
||||
## for generic reference of traits
|
||||
trait {user.code_trait}: insert("{code_trait}")
|
||||
implemented trait {user.code_trait}: insert("impl {code_trait}")
|
||||
dynamic trait {user.code_trait}: insert("dyn {code_trait}")
|
||||
|
||||
## for generic reference of macro
|
||||
macro {user.code_macros}: user.code_insert_macro(code_macros, "")
|
||||
macro wrap {user.code_macros}:
|
||||
user.code_insert_macro(code_macros, edit.selected_text())
|
||||
|
||||
## rust specific document comments
|
||||
block dock comment: user.code_comment_documentation_block()
|
||||
inner dock comment: user.code_comment_documentation_inner()
|
||||
inner block dock comment: user.code_comment_documentation_block_inner()
|
||||
@@ -0,0 +1,209 @@
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
ctx.matches = r"""
|
||||
code.language: scala
|
||||
"""
|
||||
|
||||
# Scala Common Types
|
||||
scala_common_types = {
|
||||
"boolean": "Boolean",
|
||||
"int": "Int",
|
||||
"float": "Float",
|
||||
"byte": "Byte",
|
||||
"double": "Double",
|
||||
"short": "Short",
|
||||
"long": "Long",
|
||||
"char": "Char",
|
||||
"unit": "Unit",
|
||||
"any": "Any",
|
||||
"any val": "AnyVal",
|
||||
"string": "String",
|
||||
"thread": "Thread",
|
||||
"exception": "Exception",
|
||||
"throwable": "Throwable",
|
||||
"none": "None",
|
||||
"success": "Success",
|
||||
"failure": "Failure",
|
||||
}
|
||||
|
||||
# Scala Common Generic Types
|
||||
scala_common_generic_types = {
|
||||
"array": "Array",
|
||||
"deck": "Deque",
|
||||
"future": "Future",
|
||||
"list": "List",
|
||||
"map": "Map",
|
||||
"nil": "Nil",
|
||||
"option": "Option",
|
||||
"queue": "Queue",
|
||||
"seek": "Seq",
|
||||
"set": "Set",
|
||||
"some": "Some",
|
||||
"stack": "Stack",
|
||||
"try": "Try",
|
||||
}
|
||||
|
||||
scala_types = scala_common_types.copy()
|
||||
scala_types.update(scala_common_generic_types)
|
||||
ctx.lists["user.code_type"] = scala_types
|
||||
|
||||
# Scala Modifies
|
||||
scala_modifiers = {
|
||||
"public": "public",
|
||||
"private": "private",
|
||||
"protected": "protected",
|
||||
}
|
||||
|
||||
mod.list("scala_modifier", desc="Scala Modifiers")
|
||||
ctx.lists["user.scala_modifier"] = scala_modifiers
|
||||
|
||||
scala_keywords = {
|
||||
"abstract": "abstract",
|
||||
"case class": "case class",
|
||||
"def": "def",
|
||||
"extends": "extends",
|
||||
"implicit": "implicit",
|
||||
"lazy val": "lazy val",
|
||||
"new": "new",
|
||||
"object": "object",
|
||||
"override": "override",
|
||||
"package": "package",
|
||||
"sealed": "sealed",
|
||||
"throw": "throw",
|
||||
"trait": "trait",
|
||||
"type": "type",
|
||||
"val": "val",
|
||||
"var": "var",
|
||||
"with": "with",
|
||||
"yield": "yield",
|
||||
}
|
||||
|
||||
mod.list("scala_keyword", desc="Scala Keywords")
|
||||
ctx.lists["user.scala_keyword"] = scala_keywords
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_array
|
||||
SUBSCRIPT=lambda: actions.user.insert_between("(", ")"),
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" = ",
|
||||
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_NOT="~",
|
||||
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_EQUAL=" == ",
|
||||
MATH_NOT_EQUAL=" != ",
|
||||
MATH_NOT="!",
|
||||
MATH_OR=" || ",
|
||||
MATH_AND=" && ",
|
||||
MATH_EXPONENT=" ^ ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_self():
|
||||
actions.insert("this")
|
||||
|
||||
def code_insert_null():
|
||||
actions.insert("null")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.insert(" == null")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.insert(" != null")
|
||||
|
||||
def code_insert_true():
|
||||
actions.insert("true")
|
||||
|
||||
def code_insert_false():
|
||||
actions.insert("false")
|
||||
|
||||
def code_comment_block_prefix():
|
||||
actions.insert("/*")
|
||||
|
||||
def code_comment_block_suffix():
|
||||
actions.insert("*/")
|
||||
|
||||
def code_insert_type_annotation(type: str):
|
||||
actions.insert(f": {type}")
|
||||
|
||||
def code_insert_return_type(type: str):
|
||||
actions.insert(f": {type}")
|
||||
|
||||
def code_operator_object_accessor():
|
||||
actions.insert(".")
|
||||
|
||||
def code_default_function(text: str):
|
||||
"""Inserts function declaration"""
|
||||
actions.user.code_public_function(text)
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
if selection:
|
||||
text = text + f"({selection})"
|
||||
else:
|
||||
text = text + "()"
|
||||
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
result = "private def {}".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 = "protected def {}".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 = "def {}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_public_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.code_insert_function(result, None)
|
||||
@@ -0,0 +1,37 @@
|
||||
code.language: scala
|
||||
-
|
||||
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_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"
|
||||
|
||||
state {user.scala_modifier}: insert("{user.scala_modifier} ")
|
||||
|
||||
state {user.scala_keyword}: insert("{scala_keyword} ")
|
||||
|
||||
op right arrow: " -> "
|
||||
op left arrow: " <- "
|
||||
op plus plus: " ++ "
|
||||
op subtype: " <: "
|
||||
|
||||
block string:
|
||||
insert('""""""')
|
||||
key("left left left")
|
||||
@@ -0,0 +1,8 @@
|
||||
list: user.code_common_function
|
||||
code.language: sql
|
||||
-
|
||||
|
||||
# these vary by dialect
|
||||
count: Count
|
||||
min: Min
|
||||
max: Max
|
||||
@@ -0,0 +1,46 @@
|
||||
from talon import Context, actions
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
ctx.matches = r"""
|
||||
code.language: sql
|
||||
"""
|
||||
|
||||
operators = Operators(
|
||||
MATH_ADD=" + ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_EQUAL=" = ",
|
||||
MATH_NOT_EQUAL=" <> ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
MATH_IN=lambda: actions.user.insert_between(" IN (", ")"),
|
||||
MATH_NOT_IN=lambda: actions.user.insert_between(" NOT IN (", ")"),
|
||||
MATH_AND=" AND ",
|
||||
MATH_OR=" OR ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_insert_null():
|
||||
actions.auto_insert("NULL")
|
||||
|
||||
def code_insert_is_null():
|
||||
actions.auto_insert(" IS NULL")
|
||||
|
||||
def code_insert_is_not_null():
|
||||
actions.auto_insert(" IS NOT NULL")
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
substitutions = {"1": text}
|
||||
if selection:
|
||||
substitutions["0"] = selection
|
||||
actions.user.insert_snippet_by_name("functionCall", substitutions)
|
||||
@@ -0,0 +1,33 @@
|
||||
code.language: sql
|
||||
-
|
||||
tag(): user.code_operators_math
|
||||
tag(): user.code_comment_line
|
||||
tag(): user.code_comment_block_c_like
|
||||
tag(): user.code_data_null
|
||||
tag(): user.code_functions_common
|
||||
|
||||
select: "SELECT "
|
||||
distinct: "DISTINCT "
|
||||
from: "FROM "
|
||||
select star from: "SELECT *\nFROM "
|
||||
where: "WHERE "
|
||||
order by: "ORDER BY "
|
||||
group by: "GROUP BY "
|
||||
having: "HAVING "
|
||||
descending: " DESC"
|
||||
ascending: " ASC"
|
||||
dot i d: ".id"
|
||||
inner join: user.insert_between("INNER JOIN ", " ON ")
|
||||
inner join using: user.insert_between("INNER JOIN ", " USING ")
|
||||
left outer join: user.insert_between("LEFT OUTER JOIN ", " ON ")
|
||||
right outer join: user.insert_between("RIGHT OUTER JOIN ", " ON ")
|
||||
|
||||
with: user.insert_snippet_by_name("withStatement")
|
||||
|
||||
column:
|
||||
key(return)
|
||||
", "
|
||||
|
||||
count: user.code_insert_function("Count", "")
|
||||
|
||||
date: user.insert_between("DATE '", "'")
|
||||
@@ -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, "")
|
||||
@@ -0,0 +1,38 @@
|
||||
from talon import Context, Module, actions
|
||||
|
||||
c_like_ctx = Context()
|
||||
mod = Module()
|
||||
|
||||
mod.tag("code_comment_block", desc="Tag for enabling generic block comment commands")
|
||||
mod.tag("code_comment_block_c_like", desc="Denotes usage of C-style block comments")
|
||||
|
||||
c_like_ctx.matches = """
|
||||
tag: user.code_comment_block_c_like
|
||||
"""
|
||||
c_like_ctx.tags = ["user.code_comment_block"]
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_comment_block():
|
||||
"""Block comment"""
|
||||
actions.user.insert_snippet_by_name("commentBlock")
|
||||
|
||||
def code_comment_block_prefix():
|
||||
"""Block comment start syntax"""
|
||||
|
||||
def code_comment_block_suffix():
|
||||
"""Block comment end syntax"""
|
||||
|
||||
|
||||
@c_like_ctx.action_class("user")
|
||||
class CActions:
|
||||
def code_comment_block():
|
||||
actions.insert("/*\n\n*/")
|
||||
actions.edit.up()
|
||||
|
||||
def code_comment_block_prefix():
|
||||
actions.auto_insert("/*")
|
||||
|
||||
def code_comment_block_suffix():
|
||||
actions.auto_insert("*/")
|
||||
@@ -0,0 +1,49 @@
|
||||
tag: user.code_comment_block
|
||||
-
|
||||
block comment: user.code_comment_block()
|
||||
block comment line:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
edit.line_start()
|
||||
user.code_comment_block_prefix()
|
||||
key(space)
|
||||
edit.line_end()
|
||||
key(space)
|
||||
user.code_comment_block_suffix()
|
||||
#adds comment to the start of the line
|
||||
block comment line <user.text> over:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
edit.line_start()
|
||||
user.code_comment_block()
|
||||
insert(user.text)
|
||||
block comment <user.text> over:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
user.code_comment_block()
|
||||
insert(user.text)
|
||||
block comment <user.text>$:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
user.code_comment_block()
|
||||
insert(user.text)
|
||||
(line | inline) block comment <user.text> over:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
edit.line_end()
|
||||
user.code_comment_block_prefix()
|
||||
key(space)
|
||||
insert(user.text)
|
||||
key(space)
|
||||
user.code_comment_block_suffix()
|
||||
(line | inline) block comment <user.text>$:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
edit.line_end()
|
||||
user.code_comment_block_prefix()
|
||||
key(space)
|
||||
insert(user.text)
|
||||
key(space)
|
||||
user.code_comment_block_suffix()
|
||||
open block comment: user.code_comment_block_prefix()
|
||||
close block comment: user.code_comment_block_suffix()
|
||||
@@ -0,0 +1,15 @@
|
||||
from talon import Context, Module, actions
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
|
||||
mod.tag(
|
||||
"code_comment_documentation", desc="Tag for enabling generic documentation commands"
|
||||
)
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_comment_documentation():
|
||||
"""Inserts a document comment and positions the cursor appropriately"""
|
||||
actions.user.insert_snippet_by_name("commentDocumentation")
|
||||
@@ -0,0 +1,3 @@
|
||||
tag: user.code_comment_documentation
|
||||
-
|
||||
dock comment: user.code_comment_documentation()
|
||||
@@ -0,0 +1,13 @@
|
||||
from talon import Context, Module, actions
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
|
||||
mod.tag("code_comment_line", desc="Tag for enabling generic line comment commands")
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_comment_line_prefix():
|
||||
"""Inserts line comment prefix at current cursor location"""
|
||||
actions.user.insert_snippet_by_name("commentLine")
|
||||
@@ -0,0 +1,38 @@
|
||||
tag: user.code_comment_line
|
||||
-
|
||||
comment: user.code_comment_line_prefix()
|
||||
comment line:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
edit.line_start()
|
||||
user.code_comment_line_prefix()
|
||||
#adds comment to the start of the line
|
||||
comment line <user.text> over:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
edit.line_start()
|
||||
user.code_comment_line_prefix()
|
||||
insert(user.text)
|
||||
insert(" ")
|
||||
comment <user.text> over:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
user.code_comment_line_prefix()
|
||||
insert(user.text)
|
||||
comment <user.text>$:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
user.code_comment_line_prefix()
|
||||
insert(user.text)
|
||||
(line | inline) comment <user.text> over:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
edit.line_end()
|
||||
user.code_comment_line_prefix()
|
||||
insert(user.text)
|
||||
(line | inline) comment <user.text>$:
|
||||
#todo: this should probably be a single function once
|
||||
#.talon supports implementing actions with parameters?
|
||||
edit.line_end()
|
||||
user.code_comment_line_prefix()
|
||||
insert(user.text)
|
||||
@@ -0,0 +1,15 @@
|
||||
from talon import Context, Module
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
|
||||
mod.tag("code_data_bool", desc="Tag for enabling commands for inserting Boolean data")
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_insert_true():
|
||||
"""Insert True value"""
|
||||
|
||||
def code_insert_false():
|
||||
"""Insert False value"""
|
||||
@@ -0,0 +1,4 @@
|
||||
tag: user.code_data_bool
|
||||
-
|
||||
state true: user.code_insert_true()
|
||||
state false: user.code_insert_false()
|
||||
@@ -0,0 +1,18 @@
|
||||
from talon import Context, Module
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
|
||||
mod.tag("code_data_null", desc="Tag for enabling commands relating to null")
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_insert_null():
|
||||
"""Inserts null"""
|
||||
|
||||
def code_insert_is_null():
|
||||
"""Inserts check for null"""
|
||||
|
||||
def code_insert_is_not_null():
|
||||
"""Inserts check for non-null"""
|
||||
@@ -0,0 +1,5 @@
|
||||
tag: user.code_data_null
|
||||
-
|
||||
state (no | none | nil | null): user.code_insert_null()
|
||||
is not (none | null): user.code_insert_is_not_null()
|
||||
is (none | null): user.code_insert_is_null()
|
||||
@@ -0,0 +1,149 @@
|
||||
from typing import Union
|
||||
|
||||
from talon import Context, Module, actions, settings
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
|
||||
# TODO: abstract visibilities using a list (#663)
|
||||
|
||||
mod.tag("code_functions", desc="Tag for enabling commands for functions")
|
||||
|
||||
mod.list("code_type", desc="List of types for active language")
|
||||
mod.list(
|
||||
"code_parameter_name", desc="List of common parameter names for active language"
|
||||
)
|
||||
mod.list(
|
||||
"code_function_modifier",
|
||||
desc="List of function modifiers (e.g. private, async, static)",
|
||||
)
|
||||
|
||||
ctx.lists["user.code_function_modifier"] = {
|
||||
"pub": "public",
|
||||
"pro": "protected",
|
||||
"private": "private",
|
||||
"static": "static",
|
||||
}
|
||||
|
||||
|
||||
@mod.capture(rule="{user.code_type}")
|
||||
def code_type(m) -> str:
|
||||
"""Returns a macro name"""
|
||||
return m.code_type
|
||||
|
||||
|
||||
mod.setting("code_private_function_formatter", str)
|
||||
mod.setting("code_protected_function_formatter", str)
|
||||
mod.setting("code_public_function_formatter", str)
|
||||
mod.setting("code_private_variable_formatter", str)
|
||||
mod.setting("code_protected_variable_formatter", str)
|
||||
mod.setting("code_public_variable_formatter", str)
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_modified_function(modifiers: Union[list[str], int], text: str):
|
||||
"""
|
||||
Inserts function declaration with the given modifiers. modifiers == 0
|
||||
implies no modifiers (.talon files don't have empty list literal
|
||||
syntax)
|
||||
"""
|
||||
mods = {} if modifiers == 0 else set(modifiers)
|
||||
|
||||
if mods == {}:
|
||||
return actions.user.code_default_function(text)
|
||||
elif mods == {"static"}:
|
||||
return actions.user.code_private_static_function(text)
|
||||
elif mods == {"private"}:
|
||||
return actions.user.code_private_function(text)
|
||||
elif mods == {"private", "static"}:
|
||||
return actions.user.code_private_static_function(text)
|
||||
elif mods == {"protected"}:
|
||||
return actions.user.code_protected_function(text)
|
||||
elif mods == {"protected", "static"}:
|
||||
return actions.user.code_protected_static_function(text)
|
||||
elif mods == {"public"}:
|
||||
return actions.user.code_public_function(text)
|
||||
elif mods == {"public", "static"}:
|
||||
return actions.user.code_public_static_function(text)
|
||||
else:
|
||||
raise RuntimeError(f"Unhandled modifier set: {mods}")
|
||||
|
||||
def code_default_function(text: str):
|
||||
"""Inserts function declaration"""
|
||||
actions.user.code_private_function(text)
|
||||
|
||||
def code_private_function(text: str):
|
||||
"""Inserts private function declaration"""
|
||||
|
||||
def code_private_static_function(text: str):
|
||||
"""Inserts private static function"""
|
||||
|
||||
def code_protected_function(text: str):
|
||||
"""Inserts protected function declaration"""
|
||||
|
||||
def code_protected_static_function(text: str):
|
||||
"""Inserts public function"""
|
||||
|
||||
def code_public_function(text: str):
|
||||
"""Inserts public function"""
|
||||
|
||||
def code_public_static_function(text: str):
|
||||
"""Inserts public function"""
|
||||
|
||||
def code_private_function_formatter(name: str):
|
||||
"""Inserts private function name with formatter"""
|
||||
actions.insert(
|
||||
actions.user.formatted_text(
|
||||
name, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
def code_protected_function_formatter(name: str):
|
||||
"""inserts properly formatted private function name"""
|
||||
actions.insert(
|
||||
actions.user.formatted_text(
|
||||
name, settings.get("user.code_protected_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
def code_public_function_formatter(name: str):
|
||||
"""inserts properly formatted private function name"""
|
||||
actions.insert(
|
||||
actions.user.formatted_text(
|
||||
name, settings.get("user.code_public_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
def code_private_variable_formatter(name: str):
|
||||
"""inserts properly formatted private function name"""
|
||||
actions.insert(
|
||||
actions.user.formatted_text(
|
||||
name, settings.get("user.code_private_variable_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
def code_protected_variable_formatter(name: str):
|
||||
"""inserts properly formatted private function name"""
|
||||
actions.insert(
|
||||
actions.user.formatted_text(
|
||||
name, settings.get("user.code_protected_variable_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
def code_public_variable_formatter(name: str):
|
||||
"""inserts properly formatted private function name"""
|
||||
actions.insert(
|
||||
actions.user.formatted_text(
|
||||
name, settings.get("user.code_public_variable_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
def code_insert_type_annotation(type: str):
|
||||
"""Inserts a type annotation"""
|
||||
|
||||
def code_insert_return_type(type: str):
|
||||
"""Inserts a return type"""
|
||||
|
||||
def code_insert_named_argument(parameter_name: str):
|
||||
"""Inserts a named argument"""
|
||||
@@ -0,0 +1,26 @@
|
||||
tag: user.code_functions
|
||||
-
|
||||
# Default implementation of capture listens for the following keywords in any
|
||||
# order: private pro pub static
|
||||
#
|
||||
# The default action implementation looks for the token combination on the left
|
||||
# (funky is added here for searchability) and calls the function on the right:
|
||||
#
|
||||
# * funky -> code_default_function
|
||||
# * private funky -> code_private_function
|
||||
# * pro funky -> code_protected_function
|
||||
# * pub funky -> code_public_function
|
||||
# * static funky -> code_private_static_function
|
||||
# * private static funky -> code_private_static_function
|
||||
# * pro static funky -> code_protected_static_function
|
||||
# * pub static funky -> code_public_static_function
|
||||
#
|
||||
^{user.code_function_modifier}* funky <user.text>$:
|
||||
user.code_modified_function(code_function_modifier_list or 0, text)
|
||||
|
||||
# for annotating function parameters
|
||||
is type <user.code_type>: user.code_insert_type_annotation(code_type)
|
||||
returns [type] <user.code_type>: user.code_insert_return_type(code_type)
|
||||
|
||||
# for generic reference of types
|
||||
type <user.code_type>: insert(code_type)
|
||||
@@ -0,0 +1,91 @@
|
||||
from talon import Context, Module, actions, imgui, registry
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
|
||||
mod.list("code_common_function", desc="List of common functions for active language")
|
||||
|
||||
# global
|
||||
function_list = []
|
||||
|
||||
|
||||
@mod.capture(rule="{user.code_common_function}")
|
||||
def code_common_function(m) -> str:
|
||||
"""Returns a function name"""
|
||||
return m.code_common_function
|
||||
|
||||
|
||||
mod.tag("code_functions_common", desc="Tag for enabling support for common functions")
|
||||
mod.tag(
|
||||
"code_functions_common_gui_active",
|
||||
desc="Active when the function picker GUI is showing",
|
||||
)
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_toggle_functions():
|
||||
"""GUI: List functions for active language"""
|
||||
global function_list
|
||||
if gui_functions.showing:
|
||||
function_list = []
|
||||
gui_functions.hide()
|
||||
ctx.tags = []
|
||||
else:
|
||||
update_function_list_and_freeze()
|
||||
|
||||
def code_select_function(number: int, selection: str):
|
||||
"""Inserts the selected function when the imgui is open"""
|
||||
if gui_functions.showing and number < len(function_list):
|
||||
talon_list = actions.user.talon_get_active_registry_list(
|
||||
"user.code_common_function"
|
||||
)
|
||||
actions.user.code_insert_function(
|
||||
talon_list[function_list[number]],
|
||||
selection,
|
||||
)
|
||||
|
||||
# TODO: clarify the relation between `code_insert_function`
|
||||
# and the various functions declared in the functions
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
"""Inserts a function and positions the cursor appropriately"""
|
||||
|
||||
|
||||
def update_function_list_and_freeze():
|
||||
global function_list
|
||||
if "user.code_common_function" in registry.lists:
|
||||
talon_list = actions.user.talon_get_active_registry_list(
|
||||
"user.code_common_function"
|
||||
)
|
||||
function_list = sorted(talon_list.keys())
|
||||
else:
|
||||
function_list = []
|
||||
|
||||
gui_functions.show()
|
||||
ctx.tags = ["user.code_functions_common_gui_active"]
|
||||
|
||||
|
||||
@imgui.open()
|
||||
def gui_functions(gui: imgui.GUI):
|
||||
gui.text("Functions")
|
||||
gui.line()
|
||||
|
||||
for i, entry in enumerate(function_list, 1):
|
||||
talon_list = actions.user.talon_get_active_registry_list(
|
||||
"user.code_common_function"
|
||||
)
|
||||
if entry in talon_list:
|
||||
gui.text(f"{i}. {entry}: {talon_list[entry]}")
|
||||
|
||||
gui.spacer()
|
||||
if gui.button("Toggle funk (close window)"):
|
||||
actions.user.code_toggle_functions()
|
||||
|
||||
|
||||
def commands_updated(_):
|
||||
if gui_functions.showing:
|
||||
update_function_list_and_freeze()
|
||||
|
||||
|
||||
registry.register("update_commands", commands_updated)
|
||||
@@ -0,0 +1,8 @@
|
||||
tag: user.code_functions_common
|
||||
-
|
||||
toggle funk: user.code_toggle_functions()
|
||||
funk <user.code_common_function>: user.code_insert_function(code_common_function, "")
|
||||
funk cell <number>: user.code_select_function(number - 1, "")
|
||||
funk wrap <user.code_common_function>:
|
||||
user.code_insert_function(code_common_function, edit.selected_text())
|
||||
funk wrap <number>: user.code_select_function(number - 1, edit.selected_text())
|
||||
@@ -0,0 +1,4 @@
|
||||
tag: user.code_functions_common_gui_active
|
||||
-
|
||||
# Toggle prefix to be mentally similar to the 'toggle funk' show command
|
||||
toggle funk: user.code_toggle_functions()
|
||||
@@ -0,0 +1,150 @@
|
||||
from talon import Context, Module, actions
|
||||
|
||||
mod = Module()
|
||||
|
||||
mod.tag(
|
||||
"code_imperative",
|
||||
desc="Tag for enabling basic imperative programming commands (loops, functions, etc)",
|
||||
)
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_block():
|
||||
"""Inserts equivalent of {\n} for the active language, and places the cursor appropriately"""
|
||||
actions.user.insert_snippet_by_name("codeBlock")
|
||||
|
||||
def code_state_if():
|
||||
"""Inserts if statement"""
|
||||
actions.user.insert_snippet_by_name("ifStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_if",
|
||||
'user.insert_snippet_by_name("ifStatement")',
|
||||
)
|
||||
|
||||
def code_state_else_if():
|
||||
"""Inserts else if statement"""
|
||||
actions.user.insert_snippet_by_name("elseIfStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_else_if",
|
||||
'user.insert_snippet_by_name("elseIfStatement")',
|
||||
)
|
||||
|
||||
def code_state_else():
|
||||
"""Inserts else statement"""
|
||||
actions.user.insert_snippet_by_name("elseStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_else",
|
||||
'user.insert_snippet_by_name("elseStatement")',
|
||||
)
|
||||
|
||||
def code_state_do():
|
||||
"""Inserts do statement"""
|
||||
actions.user.insert_snippet_by_name("doWhileLoopStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_do",
|
||||
'user.insert_snippet_by_name("doWhileLoopStatement")',
|
||||
)
|
||||
|
||||
def code_state_switch():
|
||||
"""Inserts switch statement"""
|
||||
actions.user.insert_snippet_by_name("switchStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_switch",
|
||||
'user.insert_snippet_by_name("switchStatement")',
|
||||
)
|
||||
|
||||
def code_state_case():
|
||||
"""Inserts case statement"""
|
||||
actions.user.insert_snippet_by_name("caseStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_case",
|
||||
'user.insert_snippet_by_name("caseStatement")',
|
||||
)
|
||||
|
||||
def code_state_for():
|
||||
"""Inserts for statement"""
|
||||
actions.user.insert_snippet_by_name("forLoopStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_for",
|
||||
'user.insert_snippet_by_name("forLoopStatement")',
|
||||
)
|
||||
|
||||
def code_state_for_each():
|
||||
"""Inserts for each equivalent statement"""
|
||||
actions.user.insert_snippet_by_name("forEachStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_for_each",
|
||||
'user.insert_snippet_by_name("forEachStatement")',
|
||||
)
|
||||
|
||||
def code_state_go_to():
|
||||
"""inserts go-to statement"""
|
||||
actions.user.insert_snippet_by_name("goToStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_go_to",
|
||||
'user.insert_snippet_by_name("goToStatement")',
|
||||
)
|
||||
|
||||
def code_state_while():
|
||||
"""Inserts while statement"""
|
||||
actions.user.insert_snippet_by_name("whileLoopStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_while",
|
||||
'user.insert_snippet_by_name("whileLoopStatement")',
|
||||
)
|
||||
|
||||
def code_state_infinite_loop():
|
||||
"""Inserts infinite loop statement"""
|
||||
actions.user.insert_snippet_by_name("infiniteLoopStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_infinite_loop",
|
||||
'user.insert_snippet_by_name("infiniteLoopStatement")',
|
||||
)
|
||||
|
||||
def code_state_return():
|
||||
"""Inserts return statement"""
|
||||
actions.user.insert_snippet_by_name("returnStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_state_return",
|
||||
'user.insert_snippet_by_name("returnStatement")',
|
||||
)
|
||||
|
||||
def code_break():
|
||||
"""Inserts break statement"""
|
||||
actions.user.insert_snippet_by_name("breakStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_break",
|
||||
'user.insert_snippet_by_name("breakStatement")',
|
||||
)
|
||||
|
||||
def code_next():
|
||||
"""Inserts next/continue statement"""
|
||||
actions.user.insert_snippet_by_name("continueStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_next",
|
||||
'user.insert_snippet_by_name("continueStatement")',
|
||||
)
|
||||
|
||||
def code_try_catch():
|
||||
"""Inserts try/catch. If selection is true, does so around the selection"""
|
||||
actions.user.insert_snippet_by_name("tryCatchStatement")
|
||||
actions.user.deprecate_action(
|
||||
"2025-06-24",
|
||||
"user.code_try_catch",
|
||||
'user.insert_snippet_by_name("tryCatchStatement")',
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
tag: user.code_imperative
|
||||
-
|
||||
block: user.code_block()
|
||||
state if: user.insert_snippet_by_name("ifStatement")
|
||||
state else if: user.insert_snippet_by_name("elseIfStatement")
|
||||
state else: user.insert_snippet_by_name("elseStatement")
|
||||
state while: user.insert_snippet_by_name("whileLoopStatement")
|
||||
state loop: user.insert_snippet_by_name("infiniteLoopStatement")
|
||||
state for: user.insert_snippet_by_name("forLoopStatement")
|
||||
state for in: user.insert_snippet_by_name("forEachStatement")
|
||||
state (switch | match): user.insert_snippet_by_name("switchStatement")
|
||||
state case: user.insert_snippet_by_name("caseStatement")
|
||||
state do: user.insert_snippet_by_name("doWhileLoopStatement")
|
||||
state goto: user.insert_snippet_by_name("goToStatement")
|
||||
state return: user.insert_snippet_by_name("returnStatement")
|
||||
state break: user.insert_snippet_by_name("breakStatement")
|
||||
state (continue | next): user.insert_snippet_by_name("continueStatement")
|
||||
@@ -0,0 +1,35 @@
|
||||
from talon import Module, actions
|
||||
|
||||
mod = Module()
|
||||
|
||||
mod.tag("code_keywords", desc="Tag for enabling commands for keywords")
|
||||
|
||||
mod.list("code_keyword", desc="List of keywords for active language")
|
||||
mod.list(
|
||||
"code_keyword_unprefixed",
|
||||
desc="List of keywords for active language that can be dictated by name alone or the put (name) command",
|
||||
)
|
||||
|
||||
|
||||
@mod.capture(rule=("{user.code_keyword}|{user.code_keyword_unprefixed}"))
|
||||
def code_keyword(m) -> str:
|
||||
return str(m)
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_keyword(keywords: list[str]):
|
||||
"""Adds keywords"""
|
||||
if len(keywords) == 1:
|
||||
actions.insert(keywords[0])
|
||||
else:
|
||||
# every keyword is separated by a space
|
||||
# the spacing before the first keyword and after the last keyword is kept
|
||||
leading_word = keywords[0].rstrip()
|
||||
trailing_word = keywords[-1].lstrip()
|
||||
stripped_words = (
|
||||
[leading_word]
|
||||
+ [keyword.strip() for keyword in keywords[1:-1]]
|
||||
+ [trailing_word]
|
||||
)
|
||||
actions.insert(" ".join(stripped_words))
|
||||
@@ -0,0 +1,4 @@
|
||||
tag: user.code_keywords
|
||||
-
|
||||
(keyword | put) (<user.code_keyword>+): user.code_keyword(code_keyword_list)
|
||||
{user.code_keyword_unprefixed}+: user.code_keyword(code_keyword_unprefixed_list)
|
||||
@@ -0,0 +1,27 @@
|
||||
from talon import Context, Module, actions
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
|
||||
mod.tag(
|
||||
"code_libraries",
|
||||
desc="Tag for enabling commands for importing libraries",
|
||||
)
|
||||
|
||||
mod.list("code_libraries", desc="List of libraries for active language")
|
||||
|
||||
|
||||
@mod.capture(rule="{user.code_libraries}")
|
||||
def code_libraries(m) -> str:
|
||||
"""Returns a type"""
|
||||
return m.code_libraries
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_import():
|
||||
"""import/using equivalent"""
|
||||
actions.user.insert_snippet_by_name("importStatement")
|
||||
|
||||
def code_insert_library(text: str, selection: str):
|
||||
"""Inserts a library and positions the cursor appropriately"""
|
||||
@@ -0,0 +1,3 @@
|
||||
tag: user.code_libraries
|
||||
-
|
||||
state import: user.code_import()
|
||||
@@ -0,0 +1,22 @@
|
||||
from talon import Context, Module, actions
|
||||
|
||||
ctx = Context()
|
||||
mod = Module()
|
||||
|
||||
mod.tag(
|
||||
"code_object_oriented",
|
||||
desc="Tag for enabling basic object oriented programming commands (objects, classes, etc)",
|
||||
)
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_operator_object_accessor():
|
||||
"""Inserts the object accessor operator (e.g., Java's "." or PHP's "->)"""
|
||||
|
||||
def code_self():
|
||||
"""Inserts a reference to the current object (e.g., C++ "this" or Python's "self")"""
|
||||
|
||||
def code_define_class():
|
||||
"""Starts a class definition (e.g., Java's "class" keyword)"""
|
||||
actions.user.insert_snippet_by_name("classDeclaration")
|
||||
@@ -0,0 +1,10 @@
|
||||
tag: user.code_object_oriented
|
||||
-
|
||||
|
||||
self dot:
|
||||
user.code_self()
|
||||
user.code_operator_object_accessor()
|
||||
|
||||
state self: user.code_self()
|
||||
|
||||
state class: user.code_define_class()
|
||||
@@ -0,0 +1,216 @@
|
||||
from typing import Callable, TypedDict
|
||||
|
||||
from talon import Module, actions
|
||||
|
||||
mod = Module()
|
||||
|
||||
mod.tag("code_operators_array", desc="Tag for enabling array operator commands")
|
||||
mod.tag("code_operators_assignment", desc="Tag for enabling assignment commands")
|
||||
mod.tag("code_operators_bitwise", desc="Tag for enabling bitwise operator commands")
|
||||
mod.tag(
|
||||
"code_operators_lambda", desc="Tag for enabling commands for anonymous functions"
|
||||
)
|
||||
mod.tag("code_operators_math", desc="Tag for enabling mathematical operator commands")
|
||||
mod.tag("code_operators_pointer", desc="Tag for enabling pointer operator commands")
|
||||
|
||||
mod.list("code_operators_array", desc="List of code operators for arrays")
|
||||
mod.list("code_operators_assignment", desc="List of code operators for assignments")
|
||||
mod.list("code_operators_bitwise", desc="List of code operators for bitwise operations")
|
||||
mod.list("code_operators_lambda", desc="List of code operators for anonymous functions")
|
||||
mod.list(
|
||||
"code_operators_math",
|
||||
desc="List of code operators for mathematical operations",
|
||||
)
|
||||
mod.list(
|
||||
"code_operators_math_comparison",
|
||||
desc="List of code operators for mathematical comparison operations",
|
||||
)
|
||||
mod.list("code_operators_pointer", desc="List of code operators for pointers")
|
||||
|
||||
|
||||
Operator = str | Callable[[], None]
|
||||
|
||||
|
||||
class Operators(TypedDict, total=False):
|
||||
# code_operators_array
|
||||
SUBSCRIPT: Operator
|
||||
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT: Operator
|
||||
ASSIGNMENT_OR: Operator
|
||||
ASSIGNMENT_SUBTRACTION: Operator
|
||||
ASSIGNMENT_ADDITION: Operator
|
||||
ASSIGNMENT_MULTIPLICATION: Operator
|
||||
ASSIGNMENT_DIVISION: Operator
|
||||
ASSIGNMENT_MODULO: Operator
|
||||
ASSIGNMENT_INCREMENT: Operator
|
||||
ASSIGNMENT_BITWISE_AND: Operator
|
||||
ASSIGNMENT_BITWISE_OR: Operator
|
||||
ASSIGNMENT_BITWISE_EXCLUSIVE_OR: Operator
|
||||
ASSIGNMENT_BITWISE_LEFT_SHIFT: Operator
|
||||
ASSIGNMENT_BITWISE_RIGHT_SHIFT: Operator
|
||||
|
||||
# code_operators_bitwise
|
||||
BITWISE_AND: Operator
|
||||
BITWISE_OR: Operator
|
||||
BITWISE_NOT: Operator
|
||||
BITWISE_EXCLUSIVE_OR: Operator
|
||||
BITWISE_LEFT_SHIFT: Operator
|
||||
BITWISE_RIGHT_SHIFT: Operator
|
||||
|
||||
# code_operators_lambda
|
||||
LAMBDA: Operator
|
||||
|
||||
# code_operators_math
|
||||
MATH_SUBTRACT: Operator
|
||||
MATH_ADD: Operator
|
||||
MATH_MULTIPLY: Operator
|
||||
MATH_DIVIDE: Operator
|
||||
MATH_INTEGER_DIVIDE: Operator
|
||||
MATH_MODULO: Operator
|
||||
MATH_EXPONENT: Operator
|
||||
MATH_EQUAL: Operator
|
||||
MATH_NOT_EQUAL: Operator
|
||||
# For weak comparison operators. Strict comparison should use standard operators.
|
||||
MATH_WEAK_EQUAL: Operator
|
||||
MATH_WEAK_NOT_EQUAL: Operator
|
||||
MATH_WEAK_AND: Operator
|
||||
MATH_WEAK_OR: Operator
|
||||
MATH_WEAK_NOT: Operator
|
||||
MATH_GREATER_THAN: Operator
|
||||
MATH_GREATER_THAN_OR_EQUAL: Operator
|
||||
MATH_LESS_THAN: Operator
|
||||
MATH_LESS_THAN_OR_EQUAL: Operator
|
||||
MATH_AND: Operator
|
||||
MATH_OR: Operator
|
||||
MATH_NOT: Operator
|
||||
MATH_IN: Operator
|
||||
MATH_NOT_IN: Operator
|
||||
|
||||
# code_operators_pointer
|
||||
POINTER_INDIRECTION: Operator
|
||||
POINTER_ADDRESS_OF: Operator
|
||||
POINTER_STRUCTURE_DEREFERENCE: Operator
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_operator(identifier: str):
|
||||
"""Insert a code operator"""
|
||||
try:
|
||||
operators: Operators = actions.user.code_get_operators()
|
||||
operator = operators.get(identifier)
|
||||
|
||||
if operator is None:
|
||||
raise ValueError(f"Operator {identifier} not found")
|
||||
|
||||
if callable(operator):
|
||||
operator()
|
||||
else:
|
||||
actions.insert(operator)
|
||||
except NotImplementedError:
|
||||
# This language has not implement the operators dict and we therefore use the fallback
|
||||
operators_fallback(identifier)
|
||||
return
|
||||
|
||||
def code_get_operators() -> Operators:
|
||||
"""Get code operators dictionary"""
|
||||
|
||||
|
||||
# Fallback is to rely on the legacy actions
|
||||
def operators_fallback(identifier: str) -> None:
|
||||
match identifier:
|
||||
# code_operators_array
|
||||
case "SUBSCRIPT":
|
||||
actions.user.code_operator_subscript()
|
||||
|
||||
# code_operators_assignment
|
||||
case "ASSIGNMENT":
|
||||
actions.user.code_operator_assignment()
|
||||
case "ASSIGNMENT_OR":
|
||||
actions.user.code_or_operator_assignment()
|
||||
case "ASSIGNMENT_SUBTRACTION":
|
||||
actions.user.code_operator_subtraction_assignment()
|
||||
case "ASSIGNMENT_ADDITION":
|
||||
actions.user.code_operator_addition_assignment()
|
||||
case "ASSIGNMENT_MULTIPLICATION":
|
||||
actions.user.code_operator_multiplication_assignment()
|
||||
case "ASSIGNMENT_MODULO":
|
||||
actions.user.code_operator_modulo_assignment()
|
||||
case "ASSIGNMENT_INCREMENT":
|
||||
actions.user.code_operator_increment()
|
||||
case "ASSIGNMENT_BITWISE_AND":
|
||||
actions.user.code_operator_bitwise_and_assignment()
|
||||
case "ASSIGNMENT_BITWISE_OR":
|
||||
actions.user.code_operator_bitwise_or_assignment()
|
||||
case "ASSIGNMENT_BITWISE_EXCLUSIVE_OR":
|
||||
actions.user.code_operator_bitwise_exclusive_or_assignment()
|
||||
case "ASSIGNMENT_BITWISE_LEFT_SHIFT":
|
||||
actions.user.code_operator_bitwise_left_shift_assignment()
|
||||
case "ASSIGNMENT_BITWISE_RIGHT_SHIFT":
|
||||
actions.user.code_operator_bitwise_right_shift_assignment()
|
||||
|
||||
# code_operators_bitwise
|
||||
case "BITWISE_AND":
|
||||
actions.user.code_operator_bitwise_and()
|
||||
case "BITWISE_OR":
|
||||
actions.user.code_operator_bitwise_or()
|
||||
case "BITWISE_NOT":
|
||||
actions.user.code_operator_bitwise_not()
|
||||
case "BITWISE_EXCLUSIVE_OR":
|
||||
actions.user.code_operator_bitwise_exclusive_or()
|
||||
case "BITWISE_LEFT_SHIFT":
|
||||
actions.user.code_operator_bitwise_left_shift()
|
||||
case "BITWISE_RIGHT_SHIFT":
|
||||
actions.user.code_operator_bitwise_right_shift()
|
||||
|
||||
# code_operators_lambda
|
||||
case "LAMBDA":
|
||||
actions.user.code_operator_lambda()
|
||||
|
||||
# code_operators_math
|
||||
case "MATH_SUBTRACT":
|
||||
actions.user.code_operator_subtraction()
|
||||
case "MATH_ADD":
|
||||
actions.user.code_operator_addition()
|
||||
case "MATH_MULTIPLY":
|
||||
actions.user.code_operator_multiplication()
|
||||
case "MATH_DIVIDE":
|
||||
actions.user.code_operator_division()
|
||||
case "MATH_MODULO":
|
||||
actions.user.code_operator_modulo()
|
||||
case "MATH_EXPONENT":
|
||||
actions.user.code_operator_exponent()
|
||||
case "MATH_EQUAL":
|
||||
actions.user.code_operator_equal()
|
||||
case "MATH_NOT_EQUAL":
|
||||
actions.user.code_operator_not_equal()
|
||||
case "MATH_GREATER_THAN":
|
||||
actions.user.code_operator_greater_than()
|
||||
case "MATH_GREATER_THAN_OR_EQUAL":
|
||||
actions.user.code_operator_greater_than_or_equal_to()
|
||||
case "MATH_LESS_THAN":
|
||||
actions.user.code_operator_less_than()
|
||||
case "MATH_LESS_THAN_OR_EQUAL":
|
||||
actions.user.code_operator_less_than_or_equal_to()
|
||||
case "MATH_AND":
|
||||
actions.user.code_operator_and()
|
||||
case "MATH_OR":
|
||||
actions.user.code_operator_or()
|
||||
case "MATH_NOT":
|
||||
actions.user.code_operator_not()
|
||||
case "MATH_IN":
|
||||
actions.user.code_operator_in()
|
||||
case "MATH_NOT_IN":
|
||||
actions.user.code_operator_not_in()
|
||||
|
||||
# code_operators_pointer
|
||||
case "POINTER_INDIRECTION":
|
||||
actions.user.code_operator_indirection()
|
||||
case "POINTER_ADDRESS_OF":
|
||||
actions.user.code_operator_address_of()
|
||||
case "POINTER_STRUCTURE_DEREFERENCE":
|
||||
actions.user.code_operator_structure_dereference()
|
||||
|
||||
case _:
|
||||
raise ValueError(f"Operator {identifier} not found")
|
||||
@@ -0,0 +1,10 @@
|
||||
# Note: the "help operators" command will currently display "op" and "is" regardless of what the commands are
|
||||
# so changing those commands will make the "help operators" command display the wrong prefixes
|
||||
op {user.code_operators_array}: user.code_operator(code_operators_array)
|
||||
op {user.code_operators_assignment}: user.code_operator(code_operators_assignment)
|
||||
op {user.code_operators_bitwise}: user.code_operator(code_operators_bitwise)
|
||||
op {user.code_operators_lambda}: user.code_operator(code_operators_lambda)
|
||||
op {user.code_operators_pointer}: user.code_operator(code_operators_pointer)
|
||||
op {user.code_operators_math}: user.code_operator(code_operators_math)
|
||||
is {user.code_operators_math_comparison}:
|
||||
user.code_operator(code_operators_math_comparison)
|
||||
@@ -0,0 +1,9 @@
|
||||
from talon import Module
|
||||
|
||||
mod = Module()
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_operator_subscript():
|
||||
"""code_operator_subscript (e.g., C++ [])"""
|
||||
@@ -0,0 +1,5 @@
|
||||
list: user.code_operators_array
|
||||
tag: user.code_operators_array
|
||||
-
|
||||
|
||||
subscript: SUBSCRIPT
|
||||
@@ -0,0 +1,45 @@
|
||||
from talon import Module
|
||||
|
||||
mod = Module()
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_operator_assignment():
|
||||
"""code_operator_assignment"""
|
||||
|
||||
def code_or_operator_assignment():
|
||||
"""code_operator_assignment"""
|
||||
|
||||
def code_operator_subtraction_assignment():
|
||||
"""code_operator_subtraction_assignment"""
|
||||
|
||||
def code_operator_addition_assignment():
|
||||
"""code_operator_addition_assignment"""
|
||||
|
||||
def code_operator_increment():
|
||||
"""code_operator_increment"""
|
||||
|
||||
def code_operator_multiplication_assignment():
|
||||
"""code_operator_multiplication_assignment"""
|
||||
|
||||
def code_operator_division_assignment():
|
||||
"""code_operator_division_assignment"""
|
||||
|
||||
def code_operator_modulo_assignment():
|
||||
"""code_operator_modulo_assignment"""
|
||||
|
||||
def code_operator_bitwise_and_assignment():
|
||||
"""code_operator_and_assignment"""
|
||||
|
||||
def code_operator_bitwise_or_assignment():
|
||||
"""code_operator_or_assignment"""
|
||||
|
||||
def code_operator_bitwise_exclusive_or_assignment():
|
||||
"""code_operator_bitwise_exclusive_or_assignment"""
|
||||
|
||||
def code_operator_bitwise_left_shift_assignment():
|
||||
"""code_operator_bitwise_left_shift_assigment"""
|
||||
|
||||
def code_operator_bitwise_right_shift_assignment():
|
||||
"""code_operator_bitwise_right_shift_assignment"""
|
||||
@@ -0,0 +1,22 @@
|
||||
list: user.code_operators_assignment
|
||||
tag: user.code_operators_assignment
|
||||
-
|
||||
|
||||
# Assignment
|
||||
equals: ASSIGNMENT
|
||||
or equals: ASSIGNMENT_OR
|
||||
|
||||
# Combined computation and assignment
|
||||
minus equals: ASSIGNMENT_SUBTRACTION
|
||||
plus equals: ASSIGNMENT_ADDITION
|
||||
times equals: ASSIGNMENT_MULTIPLICATION
|
||||
divide equals: ASSIGNMENT_DIVISION
|
||||
mod equals: ASSIGNMENT_MODULO
|
||||
increment: ASSIGNMENT_INCREMENT
|
||||
|
||||
# Bitwise operators
|
||||
bitwise and equals: ASSIGNMENT_BITWISE_AND
|
||||
bitwise or equals: ASSIGNMENT_BITWISE_OR
|
||||
bitwise exclusive or equals: ASSIGNMENT_BITWISE_EXCLUSIVE_OR
|
||||
left shift equals: ASSIGNMENT_BITWISE_LEFT_SHIFT
|
||||
right shift equals: ASSIGNMENT_BITWISE_RIGHT_SHIFT
|
||||
@@ -0,0 +1,47 @@
|
||||
tag: user.code_operators_assignment
|
||||
-
|
||||
tag(): user.code_operators_math
|
||||
tag(): user.code_operators_bitwise
|
||||
|
||||
# assignment
|
||||
op assign:
|
||||
user.deprecate_command("2025-01-19", "op assign", "op equals")
|
||||
user.code_operator("ASSIGNMENT")
|
||||
|
||||
# combined computation and assignment
|
||||
op subtract equals:
|
||||
user.deprecate_command("2025-01-19", "op subtract equals", "op minus equals")
|
||||
user.code_operator("ASSIGNMENT_SUBTRACTION")
|
||||
|
||||
op add equals:
|
||||
user.deprecate_command("2025-01-19", "op add equals", "op plus equals")
|
||||
user.code_operator("ASSIGNMENT_ADDITION")
|
||||
|
||||
op multiply equals:
|
||||
user.deprecate_command("2025-01-19", "op multiply equals", "op times equals")
|
||||
user.code_operator("ASSIGNMENT_MULTIPLICATION")
|
||||
|
||||
increment:
|
||||
user.deprecate_command("2025-01-19", "increment", "op increment")
|
||||
user.code_operator("ASSIGNMENT_INCREMENT")
|
||||
|
||||
#bitwise operators
|
||||
[op] bit [wise] and equals:
|
||||
user.deprecate_command("2025-01-19", "[op] bit [wise] and equals", "op bitwise and equals")
|
||||
user.code_operator("ASSIGNMENT_BITWISE_AND")
|
||||
|
||||
[op] bit [wise] or equals:
|
||||
user.deprecate_command("2025-01-19", "[op] bit [wise] or equals", "op bitwise or equals")
|
||||
user.code_operator("ASSIGNMENT_BITWISE_OR")
|
||||
|
||||
(op | logical | bitwise) (ex | exclusive) or equals:
|
||||
user.deprecate_command("2025-01-19", "(op | logical | bitwise) (ex | exclusive) or equals", "op bitwise exclusive or equals")
|
||||
user.code_operator("ASSIGNMENT_BITWISE_EXCLUSIVE_OR")
|
||||
|
||||
[(op | logical | bitwise)] (left shift | shift left) equals:
|
||||
user.deprecate_command("2025-01-19", "[(op | logical | bitwise)] (left shift | shift left) equals", "op left shift equals")
|
||||
user.code_operator("ASSIGNMENT_BITWISE_LEFT_SHIFT")
|
||||
|
||||
[(op | logical | bitwise)] (right shift | shift right) equals:
|
||||
user.deprecate_command("2025-01-19", "[(op | logical | bitwise)] (right shift | shift right) equals", "op right shift equals")
|
||||
user.code_operator("ASSIGNMENT_BITWISE_RIGHT_SHIFT")
|
||||
@@ -0,0 +1,24 @@
|
||||
from talon import Module
|
||||
|
||||
mod = Module()
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_operator_bitwise_and():
|
||||
"""code_operator_bitwise_and"""
|
||||
|
||||
def code_operator_bitwise_or():
|
||||
"""code_operator_bitwise_or"""
|
||||
|
||||
def code_operator_bitwise_not():
|
||||
"""code_operator_bitwise_not"""
|
||||
|
||||
def code_operator_bitwise_exclusive_or():
|
||||
"""code_operator_bitwise_exclusive_or"""
|
||||
|
||||
def code_operator_bitwise_left_shift():
|
||||
"""code_operator_bitwise_left_shift"""
|
||||
|
||||
def code_operator_bitwise_right_shift():
|
||||
"""code_operator_bitwise_right_shift"""
|
||||
@@ -0,0 +1,11 @@
|
||||
list: user.code_operators_bitwise
|
||||
tag: user.code_operators_bitwise
|
||||
-
|
||||
|
||||
bitwise and: BITWISE_AND
|
||||
bitwise or: BITWISE_OR
|
||||
bitwise not: BITWISE_NOT
|
||||
|
||||
bitwise ex or: BITWISE_EXCLUSIVE_OR
|
||||
bitwise left shift: BITWISE_LEFT_SHIFT
|
||||
bitwise right shift: BITWISE_RIGHT_SHIFT
|
||||
@@ -0,0 +1,27 @@
|
||||
tag: user.code_operators_bitwise
|
||||
-
|
||||
|
||||
#bitwise operators
|
||||
bitwise and:
|
||||
user.deprecate_command("2025-01-19", "bitwise and", "op bitwise and")
|
||||
user.code_operator("BITWISE_AND")
|
||||
|
||||
bitwise or:
|
||||
user.deprecate_command("2025-01-19", "bitwise or", "op bitwise or")
|
||||
user.code_operator("BITWISE_OR")
|
||||
|
||||
bitwise not:
|
||||
user.deprecate_command("2025-01-19", "bitwise not", "op bitwise not")
|
||||
user.code_operator("BITWISE_NOT")
|
||||
|
||||
(op | logical | bitwise) (ex | exclusive) or:
|
||||
user.deprecate_command("2025-01-19", "(op | logical | bitwise) (ex | exclusive) or", "op bitwise ex or")
|
||||
user.code_operator("BITWISE_EXCLUSIVE_OR")
|
||||
|
||||
(op | logical | bitwise) (left shift | shift left):
|
||||
user.deprecate_command("2025-01-19", "(op | logical | bitwise) (left shift | shift left)", "op bitwise left shift")
|
||||
user.code_operator("BITWISE_LEFT_SHIFT")
|
||||
|
||||
(op | logical | bitwise) (right shift | shift right):
|
||||
user.deprecate_command("2025-01-19", "(op | logical | bitwise) (right shift | shift right)", "op bitwise right shift")
|
||||
user.code_operator("BITWISE_RIGHT_SHIFT")
|
||||
@@ -0,0 +1,9 @@
|
||||
from talon import Module
|
||||
|
||||
mod = Module()
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_operator_lambda():
|
||||
"""code_operator_lambda"""
|
||||
@@ -0,0 +1,5 @@
|
||||
list: user.code_operators_lambda
|
||||
tag: user.code_operators_lambda
|
||||
-
|
||||
|
||||
lambda: LAMBDA
|
||||
@@ -0,0 +1,57 @@
|
||||
from talon import Module
|
||||
|
||||
mod = Module()
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_operator_subtraction():
|
||||
"""code_operator_subtraction"""
|
||||
|
||||
def code_operator_addition():
|
||||
"""code_operator_addition"""
|
||||
|
||||
def code_operator_multiplication():
|
||||
"""code_operator_multiplication"""
|
||||
|
||||
def code_operator_exponent():
|
||||
"""code_operator_exponent"""
|
||||
|
||||
def code_operator_division():
|
||||
"""code_operator_division"""
|
||||
|
||||
def code_operator_modulo():
|
||||
"""code_operator_modulo"""
|
||||
|
||||
def code_operator_equal():
|
||||
"""code_operator_equal"""
|
||||
|
||||
def code_operator_not_equal():
|
||||
"""code_operator_not_equal"""
|
||||
|
||||
def code_operator_greater_than():
|
||||
"""code_operator_greater_than"""
|
||||
|
||||
def code_operator_greater_than_or_equal_to():
|
||||
"""code_operator_greater_than_or_equal_to"""
|
||||
|
||||
def code_operator_less_than():
|
||||
"""code_operator_less_than"""
|
||||
|
||||
def code_operator_less_than_or_equal_to():
|
||||
"""code_operator_less_than_or_equal_to"""
|
||||
|
||||
def code_operator_and():
|
||||
"""code_operator_and"""
|
||||
|
||||
def code_operator_or():
|
||||
"""code_operator_or"""
|
||||
|
||||
def code_operator_not():
|
||||
"""code_operator_not"""
|
||||
|
||||
def code_operator_in():
|
||||
"""code_operator_in"""
|
||||
|
||||
def code_operator_not_in():
|
||||
"""code_operator_not_in"""
|
||||
@@ -0,0 +1,20 @@
|
||||
list: user.code_operators_math
|
||||
tag: user.code_operators_math
|
||||
-
|
||||
|
||||
# Math operators
|
||||
minus: MATH_SUBTRACT
|
||||
plus: MATH_ADD
|
||||
times: MATH_MULTIPLY
|
||||
divide: MATH_DIVIDE
|
||||
int divide: MATH_INTEGER_DIVIDE
|
||||
mod: MATH_MODULO
|
||||
power: MATH_EXPONENT
|
||||
|
||||
# logical operators
|
||||
and: MATH_AND
|
||||
or: MATH_OR
|
||||
not: MATH_NOT
|
||||
weak and: MATH_WEAK_AND
|
||||
weak or: MATH_WEAK_OR
|
||||
weak not: MATH_WEAK_NOT
|
||||
@@ -0,0 +1,17 @@
|
||||
list: user.code_operators_math_comparison
|
||||
tag: user.code_operators_math
|
||||
-
|
||||
|
||||
# Comparison operators
|
||||
equal: MATH_EQUAL
|
||||
not equal: MATH_NOT_EQUAL
|
||||
weak equal: MATH_WEAK_EQUAL
|
||||
weak not equal: MATH_WEAK_NOT_EQUAL
|
||||
greater: MATH_GREATER_THAN
|
||||
less: MATH_LESS_THAN
|
||||
greater or equal: MATH_GREATER_THAN_OR_EQUAL
|
||||
less or equal: MATH_LESS_THAN_OR_EQUAL
|
||||
|
||||
# Set operators
|
||||
in: MATH_IN
|
||||
not in: MATH_NOT_IN
|
||||
@@ -0,0 +1,53 @@
|
||||
tag: user.code_operators_math
|
||||
-
|
||||
|
||||
# math operators
|
||||
op subtract:
|
||||
user.deprecate_command("2025-01-19", "op subtract", "op minus")
|
||||
user.code_operator("MATH_SUBTRACT")
|
||||
|
||||
op add:
|
||||
user.deprecate_command("2025-01-19", "op add", "op plus")
|
||||
user.code_operator("MATH_ADD")
|
||||
|
||||
op multiply:
|
||||
user.deprecate_command("2025-01-19", "op multiply", "op times")
|
||||
user.code_operator("MATH_MULTIPLY")
|
||||
|
||||
op (exponent | to the power [of]):
|
||||
user.deprecate_command("2025-01-19", "op (exponent | to the power [of])", "op power")
|
||||
user.code_operator("MATH_EXPONENT")
|
||||
|
||||
# comparison operators
|
||||
is more:
|
||||
user.deprecate_command("2025-01-19", "is more", "is greater")
|
||||
user.code_operator("MATH_GREATER_THAN")
|
||||
|
||||
is below [than]:
|
||||
user.deprecate_command("2025-01-19", "is below [than]", "is less")
|
||||
user.code_operator("MATH_LESS_THAN")
|
||||
|
||||
is greater than or equal:
|
||||
user.deprecate_command("2025-01-19", "is greater than or equal", "is greater or equal")
|
||||
user.code_operator("MATH_GREATER_THAN_OR_EQUAL")
|
||||
|
||||
is less than or equal:
|
||||
user.deprecate_command("2025-01-19", "is less than or equal", "is less or equal")
|
||||
user.code_operator("MATH_LESS_THAN_OR_EQUAL")
|
||||
|
||||
# logical operators
|
||||
logical and:
|
||||
user.deprecate_command("2025-01-19", "logical and", "op and")
|
||||
user.code_operator("MATH_AND")
|
||||
|
||||
logical or:
|
||||
user.deprecate_command("2025-01-19", "logical or", "op or")
|
||||
user.code_operator("MATH_OR")
|
||||
|
||||
logical not:
|
||||
user.deprecate_command("2025-01-19", "logical not", "op not")
|
||||
user.code_operator("MATH_NOT")
|
||||
|
||||
op colon:
|
||||
user.deprecate_command("2025-01-19", "op colon", "pad colon")
|
||||
insert(" : ")
|
||||
@@ -0,0 +1,15 @@
|
||||
from talon import Module
|
||||
|
||||
mod = Module()
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def code_operator_indirection():
|
||||
"""code_operator_indirection"""
|
||||
|
||||
def code_operator_address_of():
|
||||
"""code_operator_address_of (e.g., C++ & op)"""
|
||||
|
||||
def code_operator_structure_dereference():
|
||||
"""code_operator_structure_dereference (e.g., C++ -> op)"""
|
||||
@@ -0,0 +1,7 @@
|
||||
list: user.code_operators_pointer
|
||||
tag: user.code_operators_pointer
|
||||
-
|
||||
|
||||
dereference: POINTER_INDIRECTION
|
||||
address of: POINTER_ADDRESS_OF
|
||||
arrow: POINTER_STRUCTURE_DEREFERENCE
|
||||
@@ -0,0 +1,5 @@
|
||||
code.language: talonlist
|
||||
-
|
||||
# requires user.talon_populate_lists tag. do not use with dragon
|
||||
list [require] {user.talon_lists}: "list: {talon_lists}"
|
||||
list [require]: "list: "
|
||||
@@ -0,0 +1,140 @@
|
||||
from talon import Context, Module, actions, app, registry
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
mod = Module()
|
||||
ctx_talon = Context()
|
||||
ctx_talon_python = Context()
|
||||
ctx_talon_lists = Context()
|
||||
|
||||
# restrict all the talon_* lists to when the user.talon_populate_lists tag
|
||||
# is active to prevent them from being active in contexts where they are not wanted.
|
||||
# Do not enable this tag with dragon, as it will be unusable.
|
||||
# with conformer, the latency increase may also be unacceptable depending on your cpu
|
||||
# see https://github.com/talonhub/community/issues/600
|
||||
ctx_talon_lists.matches = r"""
|
||||
tag: user.talon_populate_lists
|
||||
"""
|
||||
|
||||
mod.tag("talon_python", "Tag to activate talon-specific python commands")
|
||||
mod.tag(
|
||||
"talon_populate_lists",
|
||||
"Tag to activate talon-specific lists of actions, scopes, modes etcetera. Do not use this tag with dragon",
|
||||
)
|
||||
mod.list("talon_actions")
|
||||
mod.list("talon_lists")
|
||||
mod.list("talon_captures")
|
||||
mod.list("talon_apps")
|
||||
mod.list("talon_tags")
|
||||
mod.list("talon_modes")
|
||||
mod.list("talon_settings")
|
||||
mod.list("talon_scopes")
|
||||
mod.list("talon_modes")
|
||||
|
||||
ctx_talon.matches = r"""
|
||||
code.language: talon
|
||||
"""
|
||||
|
||||
ctx_talon_python.matches = r"""
|
||||
tag: user.talon_python
|
||||
"""
|
||||
|
||||
|
||||
def on_update_decls(decls):
|
||||
# todo modes?
|
||||
for thing in [
|
||||
"actions",
|
||||
"lists",
|
||||
"captures",
|
||||
"tags",
|
||||
"apps",
|
||||
"settings",
|
||||
"scopes",
|
||||
"modes",
|
||||
]:
|
||||
l = getattr(decls, thing)
|
||||
ctx_talon_lists.lists[f"user.talon_{thing}"] = (
|
||||
actions.user.create_spoken_forms_from_list(
|
||||
l.keys(), generate_subsequences=False
|
||||
)
|
||||
)
|
||||
# print(
|
||||
# "List: {} \n {}".format(thing, str(ctx_talon_lists.lists[f"user.talon_{thing}"]))
|
||||
# )
|
||||
|
||||
|
||||
def on_ready():
|
||||
# print("on_ready")
|
||||
on_update_decls(registry.decls)
|
||||
registry.register("update_decls", on_update_decls)
|
||||
|
||||
|
||||
app.register("ready", on_ready)
|
||||
|
||||
|
||||
@mod.action_class
|
||||
class Actions:
|
||||
def talon_code_insert_action_call(text: str, selection: str):
|
||||
"""inserts talon-specific action call"""
|
||||
actions.user.code_insert_function(text, selection)
|
||||
|
||||
def talon_code_enable_tag(tag: str):
|
||||
"""enables tag in either python or talon files"""
|
||||
|
||||
def talon_code_enable_setting(setting: str):
|
||||
"""asserts setting in either python or talon files"""
|
||||
|
||||
|
||||
@ctx_talon.action_class("user")
|
||||
class TalonActions:
|
||||
def talon_code_enable_tag(tag: str):
|
||||
"""enables tag in either python or talon files"""
|
||||
actions.user.paste(f"tag(): {tag}")
|
||||
|
||||
def talon_code_enable_setting(setting: str):
|
||||
"""asserts setting in either python or talon files"""
|
||||
actions.user.paste(f"{setting} = ")
|
||||
|
||||
|
||||
@ctx_talon_python.action_class("user")
|
||||
class TalonPythonActions:
|
||||
def talon_code_insert_action_call(text: str, selection: str):
|
||||
text = f"actions.{text}({selection or ''})"
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
def talon_code_enable_tag(tag: str):
|
||||
"""enables tag in either python or talon files"""
|
||||
actions.user.paste(f'ctx.tags = ["{tag}"]')
|
||||
if not tag:
|
||||
actions.edit.left()
|
||||
actions.edit.left()
|
||||
|
||||
def talon_code_enable_setting(setting: str):
|
||||
"""asserts setting in either python or talon files"""
|
||||
if not setting:
|
||||
actions.user.insert_between('ctx.settings["', '"] = ')
|
||||
else:
|
||||
actions.user.paste(f'ctx.settings["{setting}"] = ')
|
||||
|
||||
|
||||
operators = Operators(
|
||||
MATH_AND=" and ",
|
||||
MATH_OR=" or ",
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_DIVIDE=" / ",
|
||||
ASSIGNMENT=" = ",
|
||||
)
|
||||
|
||||
|
||||
@ctx_talon.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
text += f"({selection or ''})"
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user