;;; locate-key-binding.el --- Utility for finding in which map a key is bound -*- lexical-binding: t; -*- ;; Copyright (C) 2015 Chris Barrett ;; Author: Chris Barrett ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;; From the following SO post: ;; ;; http://emacs.stackexchange.com/questions/653/how-can-i-find-out-in-which-keymap-a-key-is-bound ;;; Code: (defun key-binding-at-point (key) (mapcar (lambda (keymap) (when (keymapp keymap) (lookup-key keymap key))) (list ;; More likely (get-text-property (point) 'keymap) (mapcar (lambda (overlay) (overlay-get overlay 'keymap)) (overlays-at (point))) ;; Less likely (get-text-property (point) 'local-map) (mapcar (lambda (overlay) (overlay-get overlay 'local-map)) (overlays-at (point)))))) ;;;###autoload (defun locate-key-binding (key) "Determine in which keymap KEY is defined." (interactive "kPress key: ") (let ((ret (list (key-binding-at-point key) (minor-mode-key-binding key) (local-key-binding key) (global-key-binding key)))) (when (called-interactively-p 'any) (message "At Point: %s\nMinor-mode: %s\nLocal: %s\nGlobal: %s" (or (nth 0 ret) "") (or (mapconcat (lambda (x) (format "%s: %s" (car x) (cdr x))) (nth 1 ret) "\n ") "") (or (nth 2 ret) "") (or (nth 3 ret) ""))) ret)) (provide 'locate-key-binding) ;;; locate-key-binding.el ends here