Skip to content

Commit

Permalink
Added identity modifier. Added head tail modifier to csv (#115)
Browse files Browse the repository at this point in the history
* Added identity modifier. Added head tail modifier to csv

* Update src/modifiers/identity.py

Co-authored-by: Pokey Rule <pokey.rule@gmail.com>

* Update src/modifiers/modifiers.py

Co-authored-by: Pokey Rule <pokey.rule@gmail.com>

* Changed identifier on head tail

* Update src/modifiers/identity.py

Co-authored-by: Pokey Rule <pokey.rule@gmail.com>
  • Loading branch information
AndreasArvidsson and pokey committed Dec 13, 2021
1 parent 1b739d6 commit 0cb8367
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/modifiers/head_tail.py
Original file line number Diff line number Diff line change
@@ -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],
}
}
14 changes: 14 additions & 0 deletions src/modifiers/identity.py
Original file line number Diff line number Diff line change
@@ -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"}}
4 changes: 4 additions & 0 deletions src/modifiers/modifiers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
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
delimiter_inclusions = {
"inside": "interiorOnly",
"bound": "excludeInterior",
}
identity = {"just": "identity"}


def on_ready():
init_csv_and_watch_changes(
"modifiers",
{
"delimiter_inclusion": delimiter_inclusions,
"head_tail": head_tail,
"identity": identity,
},
)

Expand Down
1 change: 1 addition & 0 deletions src/primitive_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"<user.cursorless_containing_scope>", # funk, state, class
"<user.cursorless_subtoken_scope>", # first past second word
"<user.cursorless_surrounding_pair>", # matching/pair [curly, round]
"<user.cursorless_identity>", # just
# "<user.cursorless_matching_paired_delimiter>", # matching
]

Expand Down

0 comments on commit 0cb8367

Please sign in to comment.