Skip to content

Attempt to optimize dfa #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from dataclasses import dataclass
from .homophones import run_homophones_action
from .find import run_find_action
from .call import run_call_action

mod = Module()

Expand All @@ -20,8 +21,8 @@ class MakeshiftAction:


makeshift_actions = [
MakeshiftAction("define", "editor.action.revealDefinition"),
MakeshiftAction("drink cell", "jupyter.insertCellAbove"),
MakeshiftAction("define", "editor.action.revealDefinition"),
MakeshiftAction("hover", "editor.action.showHover"),
MakeshiftAction("inspect", "editor.debug.action.showDebugHover"),
MakeshiftAction("pour cell", "jupyter.insertCellBelow"),
Expand All @@ -41,7 +42,8 @@ class CallbackAction:


callbacks = [
CallbackAction("find", "find", run_find_action),
CallbackAction("call", "call", run_call_action),
CallbackAction("scout", "find", run_find_action),
CallbackAction("phones", "nextHomophone", run_homophones_action),
]

Expand All @@ -56,30 +58,30 @@ class CallbackAction:
"center": "scrollToCenter",
"chuck": "delete",
"clear": "clear",
"clone up": "copyLinesUp",
"clone": "copyLinesDown",
"comment": "commentLines",
"copy": "copy",
"crown": "scrollToTop",
"dedent": "outdentLines",
"drink": "editNewLineAbove",
"drop": "insertEmptyLineAbove",
"clone": "copyLinesDown",
"clone up": "copyLinesUp",
"extract": "extractVariable",
"find all": "findInFiles",
"float": "insertEmptyLineBelow",
"fold": "fold",
"indent": "indentLines",
"paste": "paste",
"paste to": "paste",
"post": "setSelectionAfter",
"pour": "editNewLineBelow",
"pre": "setSelectionBefore",
"puff": "insertEmptyLinesAround",
"reverse": "reverse",
"scout all": "findInFiles",
"sort": "sort",
"take": "setSelection",
"top": "scrollToTop",
"unfold": "unfold",
**{callback.term: callback.action for callback in callbacks},
**{action.term: action.term for action in makeshift_actions},
**{callback.term: callback.action for callback in callbacks},
}


Expand Down
9 changes: 9 additions & 0 deletions src/actions/call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ..primitive_target import STRICT_HERE
from talon import Module, actions

mod = Module()


def run_call_action(target: dict):
targets = [target, STRICT_HERE]
actions.user.cursorless_multiple_target_command("call", targets)
4 changes: 2 additions & 2 deletions src/actions/get_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


def get_text(
targets: dict, show_decorations: bool = None, ensure_single_target: bool = None
target: dict, show_decorations: bool = None, ensure_single_target: bool = None
):
"""Get target texts"""
return actions.user.cursorless_single_target_command_get(
"getText",
targets,
target,
{
"showDecorations": show_decorations,
"ensureSingleTarget": ensure_single_target,
Expand Down
31 changes: 2 additions & 29 deletions src/actions/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,8 @@
mod = Module()


@mod.capture(rule="count [from <number_small>]")
def cursorless_count(m) -> str:
try:
start = m.number_small
except AttributeError:
start = 0
return {"start": start}


@mod.capture(rule="[<user.formatters>] <user.text> (and <user.text>)*")
def cursorless_texts(m) -> str:
texts = m.text_list
try:
formatters = m.formatters
texts = list(
map(lambda text: actions.user.formatted_text(text, formatters), texts)
)
except AttributeError:
pass
return texts


@mod.capture(rule="<user.cursorless_texts> | <user.cursorless_count>")
def cursorless_replace_value(m) -> str:
return m[0]


@mod.action_class
class Actions:
def cursorless_replace(targets: dict, texts: list[str] or dict):
def cursorless_replace(target: dict, texts: list[str] or dict):
"""Replaced targets with texts"""
actions.user.cursorless_single_target_command("replace", targets, texts)
actions.user.cursorless_single_target_command("replace", target, texts)
5 changes: 3 additions & 2 deletions src/wrappers.py → src/actions/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
"square": ["[", "]"],
"round": ["(", ")"],
"curly": ["{", "}"],
"angle": ["<", ">"],
"diamond": ["<", ">"],
"twin": ["'", "'"],
"quad": ['"', '"'],
"brick": ["`", "`"],
"escaped twin": ["\\'", "\\'"],
"escaped quad": ['\\"', '\\"'],
"space": [" ", " "]
"space": [" ", " "],
}

mod.list("cursorless_wrapper", desc="Supported wrappers for cursorless wrap action")
ctx.lists["self.cursorless_wrapper"] = wrappers.keys()


@mod.capture(rule=("{user.cursorless_wrapper}"))
def cursorless_wrapper(m) -> list[str]:
return wrappers[m.cursorless_wrapper]
14 changes: 0 additions & 14 deletions src/call.py

This file was deleted.

25 changes: 19 additions & 6 deletions src/compound_targets.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
from .primitive_target import BASE_TARGET
from talon import Module
from talon import Module, Context

mod = Module()
ctx = Context()

ctx.matches = r"""
tag: user.cursorless
"""

range_specifier = {
"past",
"until",
"between",
}

mod.list("cursorless_range_specifier", desc="A symbol that comes in pairs, eg brackets")
ctx.lists["self.cursorless_range_specifier"] = range_specifier


@mod.capture(
rule=(
"<user.cursorless_primitive_target> | "
"(past|until|tween) <user.cursorless_primitive_target> | "
"<user.cursorless_primitive_target> (past|until|tween) <user.cursorless_primitive_target>"
"[{user.cursorless_range_specifier}] <user.cursorless_primitive_target> | "
"<user.cursorless_primitive_target> {user.cursorless_range_specifier} <user.cursorless_primitive_target>"
)
)
def cursorless_range(m) -> str:
Expand All @@ -25,8 +38,8 @@ def cursorless_range(m) -> str:
"type": "range",
"start": start,
"end": m[-1],
"excludeStart": modifier == "tween",
"excludeEnd": modifier in ["tween", "until"],
"excludeStart": modifier == "between",
"excludeEnd": modifier in ["between", "until"],
}


Expand Down
30 changes: 6 additions & 24 deletions src/cursorless.talon
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,20 @@ tag(): user.cursorless
{user.cursorless_simple_action} <user.cursorless_target>:
user.cursorless_simple_action(cursorless_simple_action, cursorless_target)

<user.cursorless_wrapper> wrap <user.cursorless_target>:
user.cursorless_single_target_command_with_arg_list("wrap", cursorless_target, cursorless_wrapper)

wrap <user.cursorless_target> with funk <user.code_functions>:
user.cursorless_single_target_command("wrap", cursorless_target, "{code_functions}(", ")")

replace <user.cursorless_target> with <user.cursorless_replace_value>$:
user.cursorless_replace(cursorless_target, cursorless_replace_value)

reformat <user.cursorless_target> as <user.formatters>:
user.cursorless_reformat(cursorless_target, formatters)

extract <user.cursorless_target> as <user.text>$:
user.cursorless_single_target_command("extractVariable", cursorless_target)
sleep(300ms)
user.code_public_variable_formatter(text)
key(enter)

<user.cursorless_swap>:
user.cursorless_multiple_target_command("swap", cursorless_swap)

{user.cursorless_move_bring_action} <user.cursorless_move_bring_targets>:
user.cursorless_multiple_target_command(cursorless_move_bring_action, cursorless_move_bring_targets)

<user.cursorless_call>:
user.cursorless_multiple_target_command("call", cursorless_call)
<user.cursorless_wrapper> wrap <user.cursorless_target>:
user.cursorless_single_target_command_with_arg_list("wrap", cursorless_target, cursorless_wrapper)

pour cell:
user.vscode("jupyter.insertCellBelow")
format <user.formatters> at <user.cursorless_target>:
user.cursorless_reformat(cursorless_target, formatters)

drink cell:
user.vscode("jupyter.insertCellAbove")
pour cell: user.vscode("jupyter.insertCellBelow")
drink cell: user.vscode("jupyter.insertCellAbove")

cursorless help: user.cursorless_cheat_sheet_toggle()
cursorless instructions: user.cursorless_open_instructions()
39 changes: 12 additions & 27 deletions src/modifiers/containing_scope.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from talon import Context, Module
import copy

mod = Module()
ctx = Context()
Expand All @@ -8,16 +7,19 @@
tag: user.cursorless
"""

containing_scope_type_map = {

mod.list("cursorless_scope_type", desc="Supported scope types")
ctx.lists["self.cursorless_scope_type"] = {
"arg": "argumentOrParameter",
"arrow": "arrowFunction",
"attribute": "attribute",
"call": "functionCall",
"class name": "className",
"class": "class",
"comment": "comment",
"funk name": "functionName",
"funk": "namedFunction",
"if": "ifStatement",
"if state": "ifStatement",
"item": "collectionItem",
"key": "collectionKey",
"lambda": "arrowFunction",
Expand All @@ -30,37 +32,20 @@
"type": "type",
"value": "value",
# XML, JSX
"attribute": "xmlAttribute",
"element": "xmlElement",
"tags": "xmlBothTags",
"start tag": "xmlStartTag",
"end tag": "xmlEndTag",
}

containing_scope_types = {
term: {

@mod.capture(rule="[every] {user.cursorless_scope_type}")
def cursorless_containing_scope(m) -> str:
"""Expand to containing scope"""
return {
"modifier": {
"type": "containingScope",
"scopeType": containing_scope_type,
"scopeType": m.cursorless_scope_type,
"includeSiblings": m[0] == "every",
}
}
for term, containing_scope_type in containing_scope_type_map.items()
}

mod.list("cursorless_containing_scope_type", desc="Supported containing scope types")
ctx.lists["self.cursorless_containing_scope_type"] = containing_scope_types.keys()


@mod.capture(rule="{user.cursorless_containing_scope_type}")
def cursorless_containing_scope_type(m) -> str:
return containing_scope_types[m.cursorless_containing_scope_type]


@mod.capture(rule=("[every] <user.cursorless_containing_scope_type>"))
def cursorless_containing_scope(m) -> str:
"""Supported containing scope types"""
if m[0] == "every":
current_target = copy.deepcopy(m.cursorless_containing_scope_type)
current_target["modifier"]["includeSiblings"] = True
return current_target
return m.cursorless_containing_scope_type
14 changes: 11 additions & 3 deletions src/modifiers/head_tail.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from talon import Module
from talon import Context, Module

mod = Module()
ctx = Context()

ctx.matches = r"""
tag: user.cursorless
"""

@mod.capture(rule="head | tail")
mod.list("cursorless_head_tail", desc="Cursorless modifier for head or tail of line")
ctx.lists["self.cursorless_head_tail"] = {"head", "tail"}


@mod.capture(rule="{user.cursorless_head_tail}")
def cursorless_head_tail(m) -> str:
return {"modifier": {"type": m[0]}}
return {"modifier": {"type": m.cursorless_head_tail}}
21 changes: 0 additions & 21 deletions src/modifiers/inside_outside.py

This file was deleted.

8 changes: 1 addition & 7 deletions src/modifiers/matching_pair_symbol.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from talon import Context, Module
from dataclasses import dataclass
from talon import Module

mod = Module()
ctx = Context()

ctx.matches = r"""
tag: user.cursorless
"""


@mod.capture(rule="matching")
Expand Down
2 changes: 1 addition & 1 deletion src/modifiers/position.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from talon import Context, Module
from .selection_type import LINE

mod = Module()
ctx = Context()
Expand All @@ -22,6 +21,7 @@
mod.list("cursorless_position", desc="Types of positions")
ctx.lists["self.cursorless_position"] = positions.keys()


@mod.capture(rule="{user.cursorless_position}")
def cursorless_position(m) -> str:
return positions[m.cursorless_position]
Loading