Skip to content

Instantly share code, notes, and snippets.

@mmarshall540
Last active August 31, 2025 17:10
Show Gist options
  • Select an option

  • Save mmarshall540/b51fcfb7813c99578e18406572c5c669 to your computer and use it in GitHub Desktop.

Select an option

Save mmarshall540/b51fcfb7813c99578e18406572c5c669 to your computer and use it in GitHub Desktop.
An abbreviator for which-key descriptions
(defun my/wk-abbrev (prefixstr &optional prefixabbrev)
"Remove PREFIXSTR from which-key descriptions.
Or, with PREFIXABBREV, replace it."
(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)))))))))))
@mmarshall540
Copy link
Author

Updated and simplified for maintainability.

@mmarshall540
Copy link
Author

mmarshall540 commented Aug 30, 2025

Updated the short description, since it's no longer a macro.

Updated the docstring.

Updated the example usage in first comment with more abbreviations for Gnus. Also modified to remove the implication that Gnus would need to be loaded first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment