Skip to content

Commit

Permalink
Added glyph scope (#2050)
Browse files Browse the repository at this point in the history
`chuck glyph dollar red air`

Fixes #54

## Checklist

- [x] I have added
[tests](https://www.cursorless.org/docs/contributing/test-case-recorder/)
- [x] I have updated the
[docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and
[cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)
- [x] I have not broken the cheatsheet

---------

Co-authored-by: Pokey Rule <[email protected]>
  • Loading branch information
2 people authored and cursorless-bot committed Dec 11, 2023
1 parent 5db7e7f commit f5df6dc
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 15 deletions.
27 changes: 20 additions & 7 deletions src/cheatsheet/sections/scopes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
from ..get_list import get_lists
from ..get_list import get_lists, get_raw_list


def get_scopes():
return get_lists(
["scope_type"],
"scopeType",
complex_scopes = get_raw_list("glyph_scope_type")
return [
*get_lists(
["scope_type"],
"scopeType",
{
"argumentOrParameter": "Argument",
"boundedNonWhitespaceSequence": "Non whitespace sequence stopped by surrounding pair delimeters",
},
),
{
"argumentOrParameter": "Argument",
"boundedNonWhitespaceSequence": "Non whitespace sequence stopped by surrounding pair delimeters",
"id": "glyph",
"type": "scopeType",
"variations": [
{
"spokenForm": f"{complex_scopes['glyph']} <character>",
"description": "Instance of single character <character>",
},
],
},
)
]
30 changes: 30 additions & 0 deletions src/modifiers/glyph_scope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from talon import Module

mod = Module()

mod.list(
"cursorless_glyph_scope_type",
desc="Cursorless glyph scope type",
)
mod.list(
"cursorless_glyph_scope_type_plural",
desc="Plural version of Cursorless glyph scope type",
)


@mod.capture(rule="{user.cursorless_glyph_scope_type} <user.any_alphanumeric_key>")
def cursorless_glyph_scope_type(m) -> dict[str, str]:
return {
"type": "glyph",
"character": m.any_alphanumeric_key,
}


@mod.capture(
rule="{user.cursorless_glyph_scope_type_plural} <user.any_alphanumeric_key>"
)
def cursorless_glyph_scope_type_plural(m) -> dict[str, str]:
return {
"type": "glyph",
"character": m.any_alphanumeric_key,
}
28 changes: 21 additions & 7 deletions src/modifiers/scopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,39 @@


@mod.capture(
rule="{user.cursorless_scope_type} | {user.cursorless_custom_regex_scope_type}"
rule="{user.cursorless_scope_type} | <user.cursorless_glyph_scope_type> | {user.cursorless_custom_regex_scope_type}"
)
def cursorless_scope_type(m) -> dict[str, str]:
"""Cursorless scope type singular"""
try:
return {"type": m.cursorless_scope_type}
except AttributeError:
return {"type": "customRegex", "regex": m.cursorless_custom_regex_scope_type}
pass

try:
return m.cursorless_glyph_scope_type
except AttributeError:
pass

return {"type": "customRegex", "regex": m.cursorless_custom_regex_scope_type}


@mod.capture(
rule="{user.cursorless_scope_type_plural} | {user.cursorless_custom_regex_scope_type_plural}"
rule="{user.cursorless_scope_type_plural} | <user.cursorless_glyph_scope_type_plural> | {user.cursorless_custom_regex_scope_type_plural}"
)
def cursorless_scope_type_plural(m) -> dict[str, str]:
"""Cursorless scope type plural"""
try:
return {"type": m.cursorless_scope_type_plural}
except AttributeError:
return {
"type": "customRegex",
"regex": m.cursorless_custom_regex_scope_type_plural,
}
pass

try:
return m.cursorless_glyph_scope_type_plural
except AttributeError:
pass

return {
"type": "customRegex",
"regex": m.cursorless_custom_regex_scope_type_plural,
}
3 changes: 3 additions & 0 deletions src/spoken_forms.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
},
"surrounding_pair_scope_type": {
"string": "string"
},
"glyph_scope_type": {
"glyph": "glyph"
}
},
"paired_delimiters.csv": {
Expand Down
3 changes: 2 additions & 1 deletion src/spoken_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def ret(filename: str, *args: P.args, **kwargs: P.kwargs) -> R:
"wrapper_only_paired_delimiter": "pairedDelimiter",
"surrounding_pair_scope_type": "pairedDelimiter",
"scope_type": "simpleScopeTypeType",
"glyph_scope_type": "complexScopeTypeType",
"custom_regex_scope_type": "customRegex",
}

Expand Down Expand Up @@ -125,7 +126,7 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
handle_csv("experimental/miscellaneous.csv"),
handle_csv(
"modifier_scope_types.csv",
pluralize_lists=["scope_type"],
pluralize_lists=["scope_type", "glyph_scope_type"],
extra_allowed_values=[
"private.fieldAccess",
"private.switchStatementSubject",
Expand Down

0 comments on commit f5df6dc

Please sign in to comment.