From 6acb3ffb6f3e17351cdc56ca638e3592ca724d68 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Thu, 2 Dec 2021 18:56:06 +0100 Subject: [PATCH] Added identity modifier. Added head tail modifier to csv (#115) * Added identity modifier. Added head tail modifier to csv * Update src/modifiers/identity.py Co-authored-by: Pokey Rule * Update src/modifiers/modifiers.py Co-authored-by: Pokey Rule * Changed identifier on head tail * Update src/modifiers/identity.py Co-authored-by: Pokey Rule --- src/modifiers/head_tail.py | 28 ++++++++++++++++++++++------ src/modifiers/identity.py | 14 ++++++++++++++ src/modifiers/modifiers.py | 4 ++++ src/primitive_target.py | 1 + 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/modifiers/identity.py diff --git a/src/modifiers/head_tail.py b/src/modifiers/head_tail.py index 159a7d6f..37d14812 100644 --- a/src/modifiers/head_tail.py +++ b/src/modifiers/head_tail.py @@ -1,13 +1,29 @@ -from talon import Context, Module +from talon import Module +from dataclasses import dataclass mod = Module() -ctx = Context() +mod.list("cursorless_head_tail", desc="Cursorless modifier for head or tail of line") -mod.list("cursorless_head_tail", desc="Cursorless modifier for head or tail of line") -ctx.lists["self.cursorless_head_tail"] = {"head", "tail"} +@dataclass +class HeadTail: + defaultSpokenForm: str + cursorlessIdentifier: str + type: str + + +head_tail_list = [ + HeadTail("head", "extendThroughStartOf", "head"), + HeadTail("tail", "extendThroughEndOf", "tail"), +] +head_tail_map = {i.cursorlessIdentifier: i.type for i in head_tail_list} +head_tail = {i.defaultSpokenForm: i.cursorlessIdentifier for i in head_tail_list} @mod.capture(rule="{user.cursorless_head_tail}") -def cursorless_head_tail(m) -> str: - return {"modifier": {"type": m.cursorless_head_tail}} +def cursorless_head_tail(m) -> dict: + return { + "modifier": { + "type": head_tail_map[m.cursorless_head_tail], + } + } diff --git a/src/modifiers/identity.py b/src/modifiers/identity.py new file mode 100644 index 00000000..44d2fcaa --- /dev/null +++ b/src/modifiers/identity.py @@ -0,0 +1,14 @@ +from talon import Module + +mod = Module() + + +mod.list( + "cursorless_identity", + desc="Cursorless modifier for identity. Use to break inference chain.", +) + + +@mod.capture(rule="{user.cursorless_identity}") +def cursorless_identity(m) -> dict: + return {"modifier": {"type": "identity"}} diff --git a/src/modifiers/modifiers.py b/src/modifiers/modifiers.py index 1b474a75..48e57c26 100644 --- a/src/modifiers/modifiers.py +++ b/src/modifiers/modifiers.py @@ -1,5 +1,6 @@ from talon import app from ..csv_overrides import init_csv_and_watch_changes +from .head_tail import head_tail # NOTE: Please do not change these dicts. Use the CSVs for customization. # See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md @@ -7,6 +8,7 @@ "inside": "interiorOnly", "bound": "excludeInterior", } +identity = {"just": "identity"} def on_ready(): @@ -14,6 +16,8 @@ def on_ready(): "modifiers", { "delimiter_inclusion": delimiter_inclusions, + "head_tail": head_tail, + "identity": identity, }, ) diff --git a/src/primitive_target.py b/src/primitive_target.py index a436e6c2..8cd4007e 100644 --- a/src/primitive_target.py +++ b/src/primitive_target.py @@ -21,6 +21,7 @@ "", # funk, state, class "", # first past second word "", # matching/pair [curly, round] + "", # just # "", # matching ]