Make action_alias recursive

This commit is contained in:
Kovid Goyal 2021-11-22 22:15:04 +05:30
parent 495b29bf21
commit 89069407d2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 9 additions and 4 deletions

View File

@ -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 <action-launch>`, :ref:`kitten <action-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

View File

@ -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

View File

@ -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'))