diff options
| author | Eivind Fonn <evfonn@gmail.com> | 2019-12-31 16:15:18 +0100 |
|---|---|---|
| committer | Eivind Fonn <evfonn@gmail.com> | 2019-12-31 16:22:26 +0100 |
| commit | ef4f345b8bfa45f61448cb6dc747496d3b561dcc (patch) | |
| tree | bd9920ce2b57c3f8465c328e9b22346cc48ec366 /doc/source | |
| parent | 30e951fd41ae408fab7fc19004f88c31205c0e4a (diff) | |
Docs: fix use of \\[...] to display key sequences
Diffstat (limited to 'doc/source')
| -rw-r--r-- | doc/source/_ext/elisp.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/doc/source/_ext/elisp.py b/doc/source/_ext/elisp.py index ea7f7bd..924d026 100644 --- a/doc/source/_ext/elisp.py +++ b/doc/source/_ext/elisp.py @@ -21,12 +21,12 @@ with open(path.join(path.dirname(__file__), '..', '..', 'docstringdb.json')) as re_evilcode = re.compile(r"`(evil-[^']*)'") re_code = re.compile(r"`([^:][^ ']*)'") re_kwd = re.compile(r"`(:[^']*)'") -re_kbd = re.compile(r"\\\[([^\]]*)\]") re_item = re.compile(r"([^\n])\n- ") re_sexp = re.compile(r"\([A-Z \-\.'`\[\]]+\)|[A-Z\-]+") re_capitals = re.compile(r"[A-Z\-]+") re_nonspace = re.compile(r"[^ ]") re_signature = re.compile(r'\(fn (.*)\)') +re_keymap_or_kbd = re.compile(r"\\[\[<]([^\]>]*)[\]>]") emphasis = [ 'thing-at-point', @@ -73,8 +73,20 @@ def process_docstring(docstring, capitals=None): # Substitute `:alpha' with ``alpha`` docstring = re_kwd.sub(r'``\1``', docstring) - # Substitute \[C-z] with :kbd:`C-z` - docstring = re_kbd.sub(r':kbd:`\1`', docstring) + # Translate key bindings + keymap = None + def substitute_binding(match): + nonlocal keymap + if match.group(0)[1] == '<': + keymap = match.group(1) + return '' + if keymap is None: + print(docstring) + assert False + return '???' + key = DATA[keymap]['keymap-inv'][match.group(1)] + return f':kbd:`{key}`' + docstring = re_keymap_or_kbd.sub(substitute_binding, docstring) # Add empty line between list items docstring = re_item.sub(r'\1\n\n- ', docstring) |
