Open mangkoran opened 3 years ago
While technically something like this is possible, it is probably better handled through a separate interface, since which-key is meant to be a temporary display.
For something simple along these lines, I have this function in my personal configuration
(defun simple-describe-map (map)
(interactive (list (which-key--read-keymap)))
(let ((file-name (find-lisp-object-file-name map 'defvar)))
(with-help-window "*simple-map*"
(princ
(substitute-command-keys
(format "%s is defined in `%s' and has the bindings:\n\n\\{%s}"
(symbol-name map) (file-name-nondirectory file-name)
(symbol-name map))))
(with-current-buffer standard-output
(save-excursion
(re-search-backward (substitute-command-keys
"`\\([^`']+\\)'")
nil t)
(help-xref-button 1 'help-variable-def
map file-name))))))
You could also look at counsel-descbinds
from counsel.el which is another approach.
@justbur
counsel-descbinds
is fine, but it could be great to limit the candidate list only by the current keymap
For example: we press a binding, which-key shows us a first screen, and C-h
instead of paging calls something like counsel-M-x
but only for the active keymap's commands
there's counsel--M-x-externs
, which returns a list of candidates for counsel-M-x
, btw. Sadly, there's no variable to force this function to return the candidates we want.
We can hack amx-cache
and smex-ido-cache
, but I don't think it's a good idea, so It looks like some work from counsel side has to be done (like adding a local binding for the fallback).
So you want something like counsel-M-x
that is kind of like a command (instead of file) browser that respects keymaps?
So you want something like counsel-M-x that is kind of like a command (instead of file) browser
I've been using it since 2017 or something, it's already there. I just wanted some kind of narrowing functionality to show only command candidates which are in the current keymap (as shown by which-key).
This would be an amazing feature. I often find myself with multiple pages of options and I'm just longing for a fuzzy search. Going back out to another menu isn't something I'm going to do at that point as I already know it is in the list on my screen, I just have to scan though all the options. Being able to just type something like /
to invoke a fuzzy search against those options would make which-key twice the gem it current is.
Hm, I guess we could add a keybinding like C-h x
that drops into an M-x
like interface that is filtered to the keybindings currently shown. Do you include the commands hiding under prefixes or not?
wow, I'm glad the thread is alive!
Here's what I think would be a straightforward way to accomplish this:
When which-key is showing C-h C-h
has always triggered the built-in describe-bindings
, which by default just prints the bindings to a buffer, but there are packages that provide a replacement for describe-bindings
that is interactively searchable. I remember that the counsel package did this for example. To try it, install that package and use
(advice-add 'describe-bindings :override 'counsel-descbinds)
Then C-h C-h
should do what you want.
If counsel is not the right interface for you, an equivalent command would need to exist. It makes for sense to me for this command to come from an alternative package rather than which-key itself.
Maybe it sounds a bit dumb but how do I search in
which-key
buffer? For example here I havewhich-key-show-full-keymap
opened, showinghydra-ivy/keymap
keymaps, and I want to search keymaps oftoggle..
.