diff --git a/docs/conf.py b/docs/conf.py index 8b8a2b143..2e0825452 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -512,7 +512,7 @@ def write_conf_docs(app: Any, all_kitten_names: Iterable[str]) -> None: generate_default_config(definition, f'kitten-{kitten}') from kitty.actions import as_rst - with open(f'generated/actions.rst', 'w', encoding='utf-8') as f: + with open('generated/actions.rst', 'w', encoding='utf-8') as f: f.write(as_rst()) # }}} diff --git a/kitty/actions.py b/kitty/actions.py index bb9e65fd1..b65a076e1 100644 --- a/kitty/actions.py +++ b/kitty/actions.py @@ -2,12 +2,13 @@ # vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal -from typing import NamedTuple, Dict, List -from .window import Window -from .tabs import Tab -from .boss import Boss -from .types import run_once import inspect +from typing import Dict, List, NamedTuple + +from .boss import Boss +from .tabs import Tab +from .types import run_once +from .window import Window class Action(NamedTuple): @@ -64,9 +65,17 @@ def dump() -> None: def as_rst() -> str: + from .options.definition import definition + from .conf.types import Mapping allg = get_all_actions() lines: List[str] = [] a = lines.append + maps: Dict[str, List[Mapping]] = {} + for m in definition.iter_all_maps(): + if m.documented: + func = m.action_def.split()[0] + maps.setdefault(func, []).append(m) + for group in sorted(allg, key=lambda x: group_title(x).lower()): title = group_title(group) a('') @@ -91,4 +100,9 @@ def as_rst() -> str: a('') if action.long_help: a(action.long_help) + if action.name in maps: + a('') + a('Default shortcuts using this action:') + scs = {f':sc:`kitty.{m.name}`' for m in maps[action.name]} + a(', '.join(sorted(scs))) return '\n'.join(lines) diff --git a/kitty/conf/types.py b/kitty/conf/types.py index 54d53cf59..dbbce825e 100644 --- a/kitty/conf/types.py +++ b/kitty/conf/types.py @@ -566,9 +566,9 @@ class Definition: def iter_all_maps(self, which: str = 'map') -> Iterator[Union[ShortcutMapping, MouseMapping]]: for x in self.iter_all_non_groups(): - if isinstance(x, ShortcutMapping) and which == 'map': + if isinstance(x, ShortcutMapping) and which in ('map', '*'): yield x - elif isinstance(x, MouseMapping) and which == 'mouse_map': + elif isinstance(x, MouseMapping) and which == ('mouse_map', '*'): yield x def parser_func(self, name: str) -> Callable: