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