init commit
This commit is contained in:
@@ -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")
|
||||
Reference in New Issue
Block a user