justbur / emacs-which-key

Emacs package that displays available keybindings in popup
GNU General Public License v3.0
1.73k stars 87 forks source link

Which-key shows wrong labels from inactive keymaps #360

Closed ay4 closed 6 months ago

ay4 commented 6 months ago

Hi,

I was looking at other issues and on Reddit, and saw that which-key doesn't always play well with general. That said, I'm not certain that this particular issue has been reported.

My goal in this minimal example is to construct a nested menu that works as follows:

  1. Outside of org-mode: press s-o, see 's→+system', press s, see 'c→open config'
  2. Inside org-mode: press press s-o, see 's→+system i→+insert', press i, see 's→source code', press s, see 's→shell'

What actually happens:

  1. Outside of org-mode: press s-o, see 's→shell', press s, see 'c→open config'. In other words, what the menu does is correct, but the label is incorrect: it shows shell instead of system.
  2. Inside org-mode: press press s-o, see 's→+shell i→+insert', press i, see 's→shell', press s, see 's→shell'. So, each time we see an s, the logic is correct but the label always chooses a certain keymap that, as I understand, shouldn't be even active (admittedly I don't exactly understand how keymaps work down to the last detail).

Here's the code that produces the above:

  (defconst ayleader "s-o")

  (general-define-key
  :prefix ayleader
  "s" '(:prefix-command aysystem-map :which-key "system")
)

(general-define-key
:keymaps 'aysystem-map
:wk-full-keys nil
"c" '((lambda()(interactive)(find-file "~/.emacs.d/README.org")) :which-key "open config")
)

(general-define-key
:prefix ayleader
:wk-full-keys nil
:keymaps 'org-mode-map
"i" '(:prefix-command ayorg-insert-map :which-key "insert")
)

(general-define-key
:keymaps 'ayorg-insert-map
:wk-full-keys nil
"s" '(:prefix-command ayorg-insert-source-map :which-key "source code")
)

(general-define-key
:keymaps 'ayorg-insert-source-map
:wk-full-keys nil
"s" '((lambda()(interactive)(insert "#+begin_src sh")) :which-key "shell")
) 
ay4 commented 6 months ago

So sorry, I posted it to the wrong repo! Really really sorry, meant to post it to general.el but had a brain twitch