Skip to content

Commit f5df6dc

Browse files
AndreasArvidssonpokey
authored andcommitted
Added glyph scope (#2050)
`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]>
1 parent 5db7e7f commit f5df6dc

File tree

5 files changed

+76
-15
lines changed

5 files changed

+76
-15
lines changed

src/cheatsheet/sections/scopes.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
from ..get_list import get_lists
1+
from ..get_list import get_lists, get_raw_list
22

33

44
def get_scopes():
5-
return get_lists(
6-
["scope_type"],
7-
"scopeType",
5+
complex_scopes = get_raw_list("glyph_scope_type")
6+
return [
7+
*get_lists(
8+
["scope_type"],
9+
"scopeType",
10+
{
11+
"argumentOrParameter": "Argument",
12+
"boundedNonWhitespaceSequence": "Non whitespace sequence stopped by surrounding pair delimeters",
13+
},
14+
),
815
{
9-
"argumentOrParameter": "Argument",
10-
"boundedNonWhitespaceSequence": "Non whitespace sequence stopped by surrounding pair delimeters",
16+
"id": "glyph",
17+
"type": "scopeType",
18+
"variations": [
19+
{
20+
"spokenForm": f"{complex_scopes['glyph']} <character>",
21+
"description": "Instance of single character <character>",
22+
},
23+
],
1124
},
12-
)
25+
]

src/modifiers/glyph_scope.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from talon import Module
2+
3+
mod = Module()
4+
5+
mod.list(
6+
"cursorless_glyph_scope_type",
7+
desc="Cursorless glyph scope type",
8+
)
9+
mod.list(
10+
"cursorless_glyph_scope_type_plural",
11+
desc="Plural version of Cursorless glyph scope type",
12+
)
13+
14+
15+
@mod.capture(rule="{user.cursorless_glyph_scope_type} <user.any_alphanumeric_key>")
16+
def cursorless_glyph_scope_type(m) -> dict[str, str]:
17+
return {
18+
"type": "glyph",
19+
"character": m.any_alphanumeric_key,
20+
}
21+
22+
23+
@mod.capture(
24+
rule="{user.cursorless_glyph_scope_type_plural} <user.any_alphanumeric_key>"
25+
)
26+
def cursorless_glyph_scope_type_plural(m) -> dict[str, str]:
27+
return {
28+
"type": "glyph",
29+
"character": m.any_alphanumeric_key,
30+
}

src/modifiers/scopes.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,39 @@
1515

1616

1717
@mod.capture(
18-
rule="{user.cursorless_scope_type} | {user.cursorless_custom_regex_scope_type}"
18+
rule="{user.cursorless_scope_type} | <user.cursorless_glyph_scope_type> | {user.cursorless_custom_regex_scope_type}"
1919
)
2020
def cursorless_scope_type(m) -> dict[str, str]:
2121
"""Cursorless scope type singular"""
2222
try:
2323
return {"type": m.cursorless_scope_type}
2424
except AttributeError:
25-
return {"type": "customRegex", "regex": m.cursorless_custom_regex_scope_type}
25+
pass
26+
27+
try:
28+
return m.cursorless_glyph_scope_type
29+
except AttributeError:
30+
pass
31+
32+
return {"type": "customRegex", "regex": m.cursorless_custom_regex_scope_type}
2633

2734

2835
@mod.capture(
29-
rule="{user.cursorless_scope_type_plural} | {user.cursorless_custom_regex_scope_type_plural}"
36+
rule="{user.cursorless_scope_type_plural} | <user.cursorless_glyph_scope_type_plural> | {user.cursorless_custom_regex_scope_type_plural}"
3037
)
3138
def cursorless_scope_type_plural(m) -> dict[str, str]:
3239
"""Cursorless scope type plural"""
3340
try:
3441
return {"type": m.cursorless_scope_type_plural}
3542
except AttributeError:
36-
return {
37-
"type": "customRegex",
38-
"regex": m.cursorless_custom_regex_scope_type_plural,
39-
}
43+
pass
44+
45+
try:
46+
return m.cursorless_glyph_scope_type_plural
47+
except AttributeError:
48+
pass
49+
50+
return {
51+
"type": "customRegex",
52+
"regex": m.cursorless_custom_regex_scope_type_plural,
53+
}

src/spoken_forms.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@
171171
},
172172
"surrounding_pair_scope_type": {
173173
"string": "string"
174+
},
175+
"glyph_scope_type": {
176+
"glyph": "glyph"
174177
}
175178
},
176179
"paired_delimiters.csv": {

src/spoken_forms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def ret(filename: str, *args: P.args, **kwargs: P.kwargs) -> R:
6868
"wrapper_only_paired_delimiter": "pairedDelimiter",
6969
"surrounding_pair_scope_type": "pairedDelimiter",
7070
"scope_type": "simpleScopeTypeType",
71+
"glyph_scope_type": "complexScopeTypeType",
7172
"custom_regex_scope_type": "customRegex",
7273
}
7374

@@ -125,7 +126,7 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
125126
handle_csv("experimental/miscellaneous.csv"),
126127
handle_csv(
127128
"modifier_scope_types.csv",
128-
pluralize_lists=["scope_type"],
129+
pluralize_lists=["scope_type", "glyph_scope_type"],
129130
extra_allowed_values=[
130131
"private.fieldAccess",
131132
"private.switchStatementSubject",

0 commit comments

Comments
 (0)