Last active
August 10, 2025 01:24
-
-
Save mmarshall540/b51fcfb7813c99578e18406572c5c669 to your computer and use it in GitHub Desktop.
A macro for shortening which-key descriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my/wk-abbrev (prefixstr &optional prefixabbrev) | |
"Remove PREFIXSTR from which-key descriptions. | |
Or, with PREFIXABBREV, replace it. Optionally, condition replacement on | |
the value of MODE. An `eval-after-load' is included, to ensure that | |
which-key will have loaded before adding to | |
`which-key-replacement-alist'." | |
(let ((wkabbfuncsym (intern | |
(concat "my-wk-" prefixstr "-abbreviator"))) | |
(rx (concat prefixstr "-"))) | |
(setq which-key-replacement-alist | |
(append | |
which-key-replacement-alist | |
(list | |
(cons (cons nil rx) | |
(fset wkabbfuncsym | |
(lambda (wkcons) | |
(let ((inkey (car wkcons)) | |
(indesc (cdr wkcons))) | |
(cons | |
inkey | |
(replace-regexp-in-string | |
rx (if prefixabbrev | |
(concat "\\1" | |
prefixabbrev "-") | |
"\\1") | |
indesc))))))))))) |
Updated and simplified for maintainability.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: