help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find bindings for all modes


From: John Mastro
Subject: Re: Find bindings for all modes
Date: Tue, 28 Oct 2014 14:53:22 -0700

Tim Johnson <tim@akwebsoft.com> wrote:
> Is there a way to find out all mode - specific bindings for a given
> key sequence?

I think it depends on what your intended use is. For instance, you could
do something like this:

    (defun bindings-for (key)
      (let ((seen nil)
            (bindings nil))
        (dolist (buffer (buffer-list))
          (with-current-buffer buffer
            (unless (memq major-mode seen)
              (push major-mode seen)
              (push (cons major-mode (key-binding key))
                    bindings))))
        bindings))

    (pp (bindings-for (kbd "C-j")))

This will show you an alist mapping major mode names to the command
bound to C-j in some active buffer of that mode.

Unfortunately, this is far from perfect. The binding could well be
associated with a minor mode rather than a major mode, but it shows the
major mode's name anyway. And different `foo-mode' buffers could have
different bindings for the same key, but it assumes they're all the
same.

I don't know a way to get a really definitive look at "what's bound
where by whom", but hopefully someone else will chime in.

-- 
john



reply via email to

[Prev in Thread] Current Thread [Next in Thread]