From 89069407d27b7b6f5123db1a7d61e44cef597d47 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Nov 2021 22:15:04 +0530 Subject: [PATCH] Make action_alias recursive --- kitty/options/definition.py | 5 +++-- kitty/options/utils.py | 4 ++-- kitty_tests/options.py | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 52eb475ab..255d583f0 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -2876,8 +2876,9 @@ long_text=''' Define aliases to avoid repeating the same options in multiple mappings. Aliases can be defined for the :ref:`launch `, :ref:`kitten ` -and :ref:`action-remote_control` actions. For example, the above alias allows you -to create mappings to launch a new tab without duplication:: +and :ref:`action-remote_control` actions. Aliases are expanded recursively. +For example, the above alias allows you to create mappings to launch a new tab without +duplication:: map f1 launch_tab vim map f2 launch_tab emacs diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 4d7a9166a..cf86b597d 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -849,9 +849,9 @@ def build_action_aliases(raw: Dict[str, List[str]], first_arg_replacement: str = def resolve_aliases_in_action(action: KeyAction, aliases: Dict[str, List[ActionAlias]]) -> KeyAction: for alias in aliases.get(action.func, ()): if alias.second_arg_test is None: - return action._replace(func=alias.func_name, args=alias.args + action.args) + return resolve_aliases_in_action(action._replace(func=alias.func_name, args=alias.args + action.args), aliases) if action.args and alias.second_arg_test(action.args[0]): - return action._replace(func=alias.func_name, args=alias.args + action.args[1:]) + return resolve_aliases_in_action(action._replace(func=alias.func_name, args=alias.args + action.args[1:]), aliases) return action diff --git a/kitty_tests/options.py b/kitty_tests/options.py index c75819c4d..e008679b4 100644 --- a/kitty_tests/options.py +++ b/kitty_tests/options.py @@ -59,6 +59,10 @@ def keys_for_func(opts, name): ka = tuple(opts.keymap.values())[0][0] self.ae(ka.func, 'launch') self.ae(ka.args, ('--moo', 'XXX')) + opts = p('clear_all_shortcuts y', 'action_alias one launch --moo', 'action_alias two one recursive', 'map f1 two XXX') + ka = tuple(opts.keymap.values())[0][0] + self.ae(ka.func, 'launch') + self.ae(ka.args, ('--moo', 'recursive', 'XXX')) opts = p('clear_all_shortcuts y', 'action_alias la launch --moo', 'map f1 combine : new_window : la ') ka = tuple(opts.keymap.values())[0] self.ae((ka[0].func, ka[1].func), ('new_window', 'launch'))