Skip to content
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

Talon v0.4 support: port from resource.open to resource.watch & initial talon-list conversions #1239

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
11 changes: 3 additions & 8 deletions apps/emacs/emacs_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ def emacs_command_short_form(command_name: str) -> Optional[str]:
return emacs_commands.get(command_name, Command(command_name)).short


def load_csv():
filepath = Path(__file__).parents[0] / "emacs_commands.csv"
with resource.open(filepath) as f:
rows = list(csv.reader(f))
@resource.watch("emacs_commands.csv")
def load_commands(f):
rows = list(csv.reader(f))
# Check headers
assert rows[0] == ["Command", " Key binding", " Short form", " Spoken form"]

Expand Down Expand Up @@ -70,7 +69,3 @@ def load_csv():
if c.spoken:
command_list[c.spoken] = c.name
ctx.lists["self.emacs_command"] = command_list


# TODO: register on change to file!
app.register("ready", load_csv)
48 changes: 32 additions & 16 deletions core/create_spoken_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,49 @@
from talon import Module, actions

from .abbreviate.abbreviate import abbreviations_list
from .file_extension.file_extension import file_extensions
from .keys.keys import symbol_key_words
from .numbers.numbers import digits_map, scales, teens, tens
from .user_settings import track_csv_list

mod = Module()


DEFAULT_MINIMUM_TERM_LENGTH = 2
EXPLODE_MAX_LEN = 3
FANCY_REGULAR_EXPRESSION = r"[A-Z]?[a-z]+|[A-Z]+(?![a-z])|[0-9]+"
FILE_EXTENSIONS_REGEX = "|".join(
re.escape(file_extension.strip()) + "$"
for file_extension in file_extensions.values()
)
SYMBOLS_REGEX = "|".join(re.escape(symbol) for symbol in set(symbol_key_words.values()))
REGEX_NO_SYMBOLS = re.compile(
"|".join(
[
FANCY_REGULAR_EXPRESSION,
FILE_EXTENSIONS_REGEX,
]
FILE_EXTENSIONS_REGEX = r"^\b$"
file_extensions = {}


def update_regex():
global REGEX_NO_SYMBOLS
global REGEX_WITH_SYMBOLS
REGEX_NO_SYMBOLS = re.compile(
"|".join(
[
FANCY_REGULAR_EXPRESSION,
FILE_EXTENSIONS_REGEX,
]
)
)
REGEX_WITH_SYMBOLS = re.compile(
"|".join([FANCY_REGULAR_EXPRESSION, FILE_EXTENSIONS_REGEX, SYMBOLS_REGEX])
)


update_regex()


@track_csv_list("file_extensions.csv", headers=("File extension", "Name"))
def on_extensions(values):
global FILE_EXTENSIONS_REGEX
global file_extensions
file_extensions = values
FILE_EXTENSIONS_REGEX = "|".join(
re.escape(file_extension.strip()) + "$" for file_extension in values.values()
)
)
update_regex()

REGEX_WITH_SYMBOLS = re.compile(
"|".join([FANCY_REGULAR_EXPRESSION, FILE_EXTENSIONS_REGEX, SYMBOLS_REGEX])
)

REVERSE_PRONUNCIATION_MAP = {
**{str(value): key for key, value in digits_map.items()},
Expand Down
12 changes: 7 additions & 5 deletions core/file_extension/file_extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from talon import Context, Module

from ..user_settings import get_list_from_csv
from ..user_settings import track_csv_list

mod = Module()
mod.list("file_extension", desc="A file extension, such as .py")
Expand Down Expand Up @@ -55,11 +55,13 @@
"dot log": ".log",
}

file_extensions = get_list_from_csv(
ctx = Context()


@track_csv_list(
"file_extensions.csv",
headers=("File extension", "Name"),
default=_file_extensions_defaults,
)

ctx = Context()
ctx.lists["self.file_extension"] = file_extensions
def on_update(values):
ctx.lists["self.file_extension"] = values
6 changes: 6 additions & 0 deletions core/keys/arrow_key.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
list: user.arrow_key
-
down: down
left: left
right: right
up: up
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do up instead of up: up in all of these identity mapped lists. With up: up it's actually kind of confusing which side to edit too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's arguably a bit more convenient for those that may customize to keep up: up though.

This is a similar problem to eg https://github.com/talonhub/community/blob/7b09a4a789ed1dc380865d2840a5abda9f65af25/core/windows_and_tabs/window_snap_positions.talon-list

where we may be better off with something more obviously not a spoken form on the right side.

Copy link
Collaborator

@lunixbochs lunixbochs Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think up: up is not more convenient at all, because it's not obvious which side to edit when the sides are symmetrical. I think using a non spoken form on the right hand side is also bad (in the case of key mappings), because the right hand side is a key name. You shouldn't map those to something else.

up on a line by itself should be fine. It's easy enough to teach people how to work with these files I think. We're still much better off than the "simple key names" in Python where you had to move the key to a different list if you wanted to remap it.

If the file contains:

list: user.arrow_key
-
up
down
left
right

I want to remove "up" and add "shoop" mapped to up. I need to know what the existing lines in the .talon-list mean, and I need to know how to add a line. I need to know this regardless of whether the file contains up: up or just up.

-up
+shoop: up

Anyway. Don't do up: up. Not worth bike shedding.

26 changes: 26 additions & 0 deletions core/keys/function_key.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
list: user.function_key
-
f one: f1
f two: f2
f three: f3
f four: f4
f five: f5
f six: f6
f seven: f7
f eight: f8
f nine: f9
f ten: f10
f eleven: f11
f twelve: f12
f thirteen: f13
f fourteen: f14
f fifteen: f15
f sixteen: f16
f seventeen: f17
f eighteen: f18
f nineteen: f19
f twenty: f20
f twenty one: f21
f twenty two: f22
f twenty three: f23
f twenty four: f24
knausj85 marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions core/keys/keypad_key.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
list: user.keypad_key
-
key pad zero: keypad_0
key pad one: keypad_1
key pad two: keypad_2
key pad three: keypad_3
key pad four: keypad_4
key pad five: keypad_5
key pad six: keypad_6
key pad seven: keypad_7
key pad eight: keypad_8
key pad nine: keypad_9
key pad dot: keypad_decimal
key pad plus: keypad_plus
key pad minus: keypad_minus
key pad plex: keypad_multiply
key pad slash: keypad_divide
key pad equals: keypad_equals
key pad clear: keypad_clear
31 changes: 13 additions & 18 deletions core/keys/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,17 @@

from ..user_settings import get_list_from_csv


def setup_default_alphabet():
"""set up common default alphabet.

no need to modify this here, change your alphabet using alphabet.csv"""
initial_default_alphabet = "air bat cap drum each fine gust harp sit jury crunch look made near odd pit quench red sun trap urge vest whale plex yank zip".split()
initial_letters_string = "abcdefghijklmnopqrstuvwxyz"
initial_default_alphabet_dict = dict(
zip(initial_default_alphabet, initial_letters_string)
)

return initial_default_alphabet_dict


alphabet_list = get_list_from_csv(
"alphabet.csv", ("Letter", "Spoken Form"), setup_default_alphabet()
default_digits = "zero one two three four five six seven eight nine".split(" ")
numbers = [str(i) for i in range(10)]
default_f_digits = (
"one two three four five six seven eight nine ten eleven twelve".split(" ")
Comment on lines +5 to +8
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge error, can be removed.

)

# used for number keys & function keys respectively
digits = "zero one two three four five six seven eight nine".split()
f_digits = "one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty".split()


mod = Module()
mod.list("letter", desc="The spoken phonetic alphabet")
mod.list("symbol_key", desc="All symbols from the keyboard")
Expand All @@ -32,6 +21,7 @@ def setup_default_alphabet():
mod.list("modifier_key", desc="All modifier keys")
mod.list("function_key", desc="All function keys")
mod.list("special_key", desc="All special keys")
mod.list("keypad_key", desc="all keypad keys")
mod.list("punctuation", desc="words for inserting punctuation into text")


Expand Down Expand Up @@ -59,6 +49,12 @@ def number_key(m) -> str:
return m.number_key


@mod.capture(rule="{self.keypad_key}")
def keypad_key(m) -> str:
"One keypad key"
return m.keypad_key


@mod.capture(rule="{self.letter}")
def letter(m) -> str:
"One letter key"
Expand Down Expand Up @@ -91,7 +87,7 @@ def any_alphanumeric_key(m) -> str:

@mod.capture(
rule="( <self.letter> | <self.number_key> | <self.symbol_key> "
"| <self.arrow_key> | <self.function_key> | <self.special_key> )"
"| <self.arrow_key> | <self.function_key> | <self.special_key> | <self.keypad_key>)"
)
def unmodified_key(m) -> str:
"A single key with no modifiers"
Expand Down Expand Up @@ -132,7 +128,6 @@ def letters(m) -> str:
modifier_keys["command"] = "cmd"
modifier_keys["option"] = "alt"
ctx.lists["self.modifier_key"] = modifier_keys
ctx.lists["self.letter"] = alphabet_list

# `punctuation_words` is for words you want available BOTH in dictation and as key names in command mode.
# `symbol_key_words` is for key names that should be available in command mode, but NOT during dictation.
Expand Down
28 changes: 28 additions & 0 deletions core/keys/letter.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
list: user.letter
-
air: a
bat: b
cap: c
drum: d
each: e
fine: f
gust: g
harp: h
sit: i
jury: j
crunch: k
look: l
made: m
near: n
odd: o
pit: p
quench: q
red: r
sun: s
trap: t
urge: u
vest: v
whale: w
plex: x
yank: y
zip: z
9 changes: 9 additions & 0 deletions core/keys/mac/modifier_key.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
list: user.modifier_key
os: mac
-
alt: alt
control: ctrl
shift: shift
super: super
command: cmd
option: alt
17 changes: 17 additions & 0 deletions core/keys/mac/special_key.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
list: user.special_key
os: mac
-
end: end
enter: enter
escape: escape
home: home
insert: insert
pagedown: pagedown
pageup: pageup
space: space
tab: tab
wipe: backspace
delete: backspace
forward delete: delete
page up: pageup
page down: pagedown
12 changes: 12 additions & 0 deletions core/keys/number_key.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
list: user.number_key
-
zero: 0
one: 1
two: 2
three: 3
four: 4
five: 5
six: 6
seven: 7
eight: 8
nine: 9
29 changes: 29 additions & 0 deletions core/keys/punctuation.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
list: user.punctuation
-
`: `
Comment on lines +2 to +3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved to a dragon specific punctuation list.

,: ,
back tick: `
comma: ,
coma: ,
period: .
full stop: .
semicolon: ;
colon: :
forward slash: /
question mark: ?
exclamation mark: !
exclamation point: !
asterisk: *
hash sign: #
number sign: #
percent sign: %
at sign: @
and sign: &
ampersand: &
dollar sign: $
pound sign: £
hyphen: -
L paren: (
left paren: (
R paren: )
right paren: )
8 changes: 8 additions & 0 deletions core/keys/win/modifier_key.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
list: user.modifier_key
os: windows
os: linux
-
alt: alt
control: ctrl
shift: shift
super: super
20 changes: 20 additions & 0 deletions core/keys/win/special_key.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
list: user.special_key
os: windows
os: linux
-
end: end
enter: enter
escape: escape
home: home
insert: insert
pagedown: pagedown
pageup: pageup
space: space
tab: tab
wipe: backspace
delete: backspace
forward delete: delete
page up: pageup
page down: pagedown
menu key: menu
print screen: printscr
24 changes: 24 additions & 0 deletions core/modes/dictation/punctuation.talon-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
list: user.punctuation
mode: dictation
-
back tick: `
comma: ,
# Workaround for issue with conformer b-series; see #946
coma: ,
period: .
full stop: .
semicolon: ;
colon: :
forward slash: /
question mark: ?
exclamation mark: !
exclamation point: !
asterisk: *
number sign: #
percent sign: %
at sign: @
and sign: &
ampersand: &
# Currencies
dollar sign: $
pound sign: £
Loading
Loading