emacs-which-key icon indicating copy to clipboard operation
emacs-which-key copied to clipboard

Search in `which-key` Buffer

Open mangkoran opened this issue 5 years ago • 9 comments

Maybe it sounds a bit dumb but how do I search in which-key buffer? For example here I have which-key-show-full-keymap opened, showing hydra-ivy/keymap keymaps, and I want to search keymaps of toggle... image

mangkoran avatar Apr 20 '21 03:04 mangkoran

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 avatar Apr 22 '21 16:04 justbur

@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

a13 avatar May 14 '21 22:05 a13

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).

a13 avatar May 14 '21 22:05 a13

So you want something like counsel-M-x that is kind of like a command (instead of file) browser that respects keymaps?

justbur avatar Jun 01 '21 02:06 justbur

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).

a13 avatar Nov 01 '21 18:11 a13