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

Does paging work for `<escape>-` key sequences? #371

Open deen1 opened 4 months ago

deen1 commented 4 months ago

Apologies if this has been raised before, but I couldn't quite find an issue that addressed this head on. I found this Stack Exchange post, which had a couple of answers (but the question is focused on Spacemacs, which I don't use), and this possibly related issue, #223.

When hitting <escape> in a number of contexts, which-key pops up in a side-window with a number of options – see first screenshot below (which was made via emacs -Q, so hopefully should be reproducible). But it is not possible to page them, as <escape> C-h is bound to something else (I think it's (mark-defun)) and the side-window is killed.

2024-04-12-153833_295x929_scrot

Following the paging section in the README, I tried running emacs -Q, loading which-key and using the following config:

(which-key-side-window-right)
(which-key-mode)
(setq which-key-use-C-h-commands t)

(define-key which-key-mode-map (kbd "<escape> <f5>") 'which-key-C-h-dispatch)

Unfortunately, hitting <escape> no longer offers all the previous command descriptions, just the <f5> for paging (see second screenshot).

Is this simply an unavoidable issue with <escape>, or is there some way around it?

2024-04-12-154011_320x78_scrot

justbur commented 4 months ago

I believe emacs will intercept the sequence <escape> C-h before which-key can handle it. The problem is that emacs translates that sequence to C-M-h. I can't find the reference for it right now, but essentially <escape> x, where x could be any key, translates immediately to M-x, so you're unintentionally invoking C-M-h instead of something + C-h, if that makes sense.

This behavior is something particular to <escape> and would be difficult if not impossible to circumvent unfortunately.

deen1 commented 4 months ago

I believe emacs will intercept the sequence C-h before which-key can handle it. The problem is that emacs translates that sequence to C-M-h.

This is what I understood, but I had hoped that by adding e.g. <f5> as the paging key (as far as I can tell, <escape>-<f5> is not bound to anything) we could circumvent C-M-h binding.

But I guess you're saying that Emacs basically tries to reserve any key combination beginning with <escape>, which may be why (define-key which-key-mode-map (kbd "<escape> <f5>") 'which-key-C-h-dispatch) doesn't work as intended.

That's a shame, but I can live with it. Thanks for your input on this!