For a key KEY, the following searchs (define-key _KEYMAP KEY CMD)
expression in files where KEYMAP and CMD are defined.
;; -*- lexical-binding: t; -*-
(defun jump-to-binding (key)
(interactive "kJump to binding of key: ")
(let* ((cmd (key-binding key))
(cmd-file (find-library-name (symbol-file cmd)))
(keymap (help--binding-locus key nil))
(keymap-file (find-library-name (symbol-file keymap)))
(search-files (seq-uniq
(delq nil
(list cmd-file keymap-file)))))
(require 'el-search-x)
(el-search-setup-search
(list '\` (list 'define-key ',_ (list '\, `(keys ,key)) `',cmd))
(lambda () (stream search-files)))))
el-search is used for searching, you can get the package from GNU ELPA. The command can
work for some keys such as C-s
(isearch-forward
) and C-l
(recenter-top-bottom
).
You can improve the command in many ways, for example,
- Search
bindings.el
, many Emacs key bindings is created there
- Search your init file if you want to
- Support
global-set-key
, bind-key
etc
- Support prefix keymap, for example,
C-x h
should be able to find
(define-key ctl-x-map "h" 'mark-whole-buffer)
M-x find-variable RET my-mode-map RET
will get you to where you want to be most of the time, but not always since the bindings may be added with a major-mode hook or wrapped in aneval-after-load
statement. Another idea would be to grep for'my-func
or'my-func)
[using the appropriate backslashes if a regexp search] which may turn up a lot of hits, but then you can isearch fordefine-key
in the grep results.find-variable
combined with an appropriate grep seems to come pretty close to this.