From f63e6d04893e3f5026fd33f69b5cadebda7c549a Mon Sep 17 00:00:00 2001 From: Mountain Man <43313373+MountainMan1312@users.noreply.github.com> Date: Mon, 29 May 2023 23:47:23 -0400 Subject: Add function and keybinds to list all bindings for KEY --- init.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'init.el') diff --git a/init.el b/init.el index b2b0bf8..5f5fdfb 100644 --- a/init.el +++ b/init.el @@ -1001,6 +1001,25 @@ ;; minibuffer or a popup window. ;; --------------------------------- +;; Define function and keybind to list all bindings of a certain key +(defun mm/print-all-bindings-for-key (key) + "Output all bindings for KEY in *MESSAGES*." + (interactive "kEnter key sequence: ") + (mapc (lambda (pair) + (when (cdr pair) + (message "%S: %S" (car pair) (cdr pair)))) + (mapcar (lambda (keymap) + (cons keymap + (let ((binding (lookup-key (eval keymap) key))) + (and (not (numberp binding)) binding)))) + (let (atoms) + (mapatoms (lambda (a) + (when (keymapp (and (boundp a) (eval a))) + (push a atoms)))) + atoms)))) +(global-set-key (kbd "C-h C-u k") 'mm/print-all-bindings-for-key) + + ;; Define fixed version of `keyboard-escape-quit' which does not close ;; windows or change their layout. (defun mm/keyboard-escape-quit-keep-windows () -- cgit v1.2.3