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

Fix paging with God mode

Open darth10 opened this issue 4 years ago • 8 comments

Paging in which-key is not working when C-h(help-char) is entered in God mode. This bug has been reported recently (emacsorphanage/god-mode#114), but it's been an issue for a while.

Current behaviour: which-key god-mode orig-issue

This PR attempts to fix this issue. The changes can be summarised as follows:

  • Use nadvice.el instead of advice.el.
  • Fix paging with God mode using an :around advice for god-mode-lookup-key-sequence.

Behaviour with these changes: which-key god-mode fixed

Known issues:

  • There's currently an issue when which-key-undo-key is invoked from the help menu. From what I can tell, this is caused by which-key--update or which-key--hide-popup being invoked through a timer. I've tried calling which-key--stop-timer in the new advice function appropriately, but then the paging of which-key-undo-key has the same issue. Also, I'm not sure this is the best way to fix the problem. Here's what the behaviour looks like with the possible fix using which-key--stop-timer (ebcc4e6):

    which-key god-mode issue 1

    It would be great if I could get some clues on how to fix this issue. However, if it's still complicated, this issue could be tracked separately and fixed later on.

Any feedback is more than welcome!

darth10 avatar May 29 '20 09:05 darth10

@justbur It would be really helpful if you could provide any feedback on this PR.

darth10 avatar Jun 08 '20 03:06 darth10

I'm not very familiar with god-mode to start with, but after some basic testing it looks like god-mode breaks the basic emacs mechanism of using help-char to get help in the middle of an incomplete key sequence. In vanilla emacs, after say C-x emacs waits for you to complete the key sequence. If in an incomplete sequence you type help-char, which is C-h by default you get the command stored in prefix-help-command, which is describe-prefix-bindings by default. which-key takes over this functionality to do paging.

I can't trigger describe-prefix-bindings in god-mode in vanilla emacs (meaning with nothing else enabled) which points to a basic problem with how god-mode works. Neither x h nor x C-h works.

It seems to me that fixing this aspect of god-mode without worrying about which-key should be the first approach. If that is impossible for some reason, we can explore using the advice mechanism in which-key.

justbur avatar Jun 13 '20 01:06 justbur

I'll try modifying God mode to call prefix-help-command on entering help-char and follow up soon. I've converted this PR to a draft for now.

darth10 avatar Jun 13 '20 21:06 darth10

Great, thanks for your work.

justbur avatar Jun 13 '20 23:06 justbur

@justbur I've managed to fix God mode's handling of help-char. This was done in commit emacsorphanage/god-mode@e80b6e6 as part of emacsorphanage/god-mode#115.

With the way God mode uses the command loop, this was possible only with the use of unread-command-events to add key sequences to the command loop. Even with this change, help-char somehow fails to call which-key-C-h-dispatch when which-key-mode is enabled. I'm open to suggestions for making the implementation in God mode better in any way.

That being said, as emacsorphanage/god-mode@e80b6e6 adds the god-mode-help-char-dispatch function to handle help-char, adding advice functions to call which-key-C-h-dispatch for paging becomes a bit easier. I've updated this PR to do just that.

However, the timer issue with which-key-undo-key I described earlier is still present. Any feedback to help fix this issue is more than welcome. Alternatively, this particular issue can also be tracked and fixed separately.

darth10 avatar Jun 15 '20 09:06 darth10

@justbur Have you had a chance to review my fix in God mode and the changes in this PR?

darth10 avatar Jul 11 '20 00:07 darth10

I asked a couple of questions about the changes a while ago and was waiting to hear back

justbur avatar Jul 16 '20 17:07 justbur

Please refer to this comment.

I've managed to fix God mode's handling of help-char. This was done in commit emacsorphanage/god-mode@e80b6e6 as part of emacsorphanage/god-mode#115.

With the way God mode uses the command loop, this was possible only with the use of unread-command-events to add key sequences to the command loop. Even with this change, help-char somehow fails to call which-key-C-h-dispatch when which-key-mode is enabled. I'm open to suggestions for making the implementation in God mode better in any way.

So, help-char now calls prefix-help-command in God mode, but the issue with which-key is not resolved. I've updated this PR with simpler advice functions, which was possible due to the help-char fix in God mode.

darth10 avatar Jul 16 '20 21:07 darth10