Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paging hint suggests C-h even when it's bound under given prefix and won't work #368

Open
crzcrz opened this issue Mar 30, 2024 · 1 comment · May be fixed by #370
Open

Paging hint suggests C-h even when it's bound under given prefix and won't work #368

crzcrz opened this issue Mar 30, 2024 · 1 comment · May be fixed by #370

Comments

@crzcrz
Copy link

crzcrz commented Mar 30, 2024

I believe the current implementation of which-key--next-page-hint could be improved. There are two issues with it.

  1. If help-char (C-h) is bound under the current prefix, then pressing C-h will invoke the binding and not which-key-C-h-dispatch, while the hint still reads [C-h paging/help],
  2. no hint is displayed for C-h- prefix at all, even if we have manually bound some key to which-key-C-h-dispatch there.

I've made a crude prototype that attempts to display a hint with keys that would actually work under the given prefix.

(defun which-key--next-page-hint (prefix-keys)
  "Return string for next page hint."
  (when which-key-use-C-h-commands
    (let* ((user-paging-key (concat prefix-keys " " which-key-paging-key))
           (paging-key (concat prefix-keys " " (help-key)))
           (help-prefix (equal (vector help-char)
                               (vconcat (kbd prefix-keys))))
           (keys '()))
      (when (eq 'which-key-C-h-dispatch
                (key-binding (kbd user-paging-key)))
        (push which-key-paging-key keys))
      (unless help-prefix
        (push "?" keys)
        (push "<f1>" keys)
        (unless (key-binding (kbd paging-key))
          (push (help-key) keys)))
      (when keys
        (which-key--propertize (format "[%s%spaging/help]"
                                       (string-join keys " or ")
                                       which-key-separator)
                               'face 'which-key-note-face)))))

Now we get nice hints:

  • C-x- -> [C-h or <f1> or ? -> paging/help] as C-h is not bound under this prefix in our configuration,
  • C-w--> [<f1> or ? -> paging/help] as C-h is bound under this prefix in our configuration,
  • C-h- -> [<f5> -> paging/help] as we have bound C-h <f5> to which-key-C-h-dispatch in our configuration.

One remaining issue with my prototype is that a hint will be still displayed for evil prefixes while it shouldn't, as it is not possible to make any binding to which-key-C-h-dispatch there.

@justbur
Copy link
Owner

justbur commented Apr 9, 2024

Hi, I'm happy to consider a PR for this. I think it makes sense.

@crzcrz crzcrz linked a pull request Apr 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants