Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ $ head xcompose.compose
* `DefaultKeyBinding.dict` map doesn't work in some popular programs:
- JetBrain editors such as PyCharm, see: https://youtrack.jetbrains.com/issue/IDEA-127470
- QT apps such as Qutebrowser, see (and vote): https://bugreports.qt.io/browse/QTBUG-393

* UTF character codes like `\UF703` (the right arrow key) are kept as is. This will break any key combinations starting with `\U`.


#### Related Resources
Expand Down
15 changes: 13 additions & 2 deletions gencompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,26 @@ def merge(source, destination):
def read_paths(data):
"""
Unpack first key of a dictionary as nested dictionary path
Do not split utf character codes.

>>> read_paths({'cat': '>-.-<'})
{'c': {'a': {'t': '>-.-<'}}}
"""
utf_pattern = re.compile(r'\\U[0-9A-Fa-f]{4,6}')

parsed = {}
for k, v in data.items():
parsed = merge(parsed, key_nest(list(k) + [v]))
# If the key matches the utf pattern, split it into individual utf codes and nest them
if utf_pattern.search(k):
utf_codes = utf_pattern.findall(k)
nested_data = v
for code in reversed(utf_codes):
nested_data = {code: nested_data}
parsed = merge(parsed, nested_data)
else:
parsed = merge(parsed, key_nest(list(k) + [v]))
return parsed


def data_to_mac_dict(data):
"""
converts dictionary data to macos keymap.dict format
Expand All @@ -133,6 +143,7 @@ def data_to_mac_dict(data):
text = re.sub('"INSERT:(.+)",*', repl, text)
text = re.sub('},*', '};', text)
text = re.sub('": ', '" = ', text)
text = re.sub(r'\\\\U([0-9A-Fa-f]{4,6})', r'\\U\1', text)
return text


Expand Down