0

This question has been edited thanks to dalanicolai.

I want to change some of the default which-key key binds used to turn the pages.

In which-key.el they are set like so:

(defvar which-key-C-h-map
  (let ((map (make-sparse-keymap)))
    (dolist (bind `(("\C-a" . which-key-abort)
                    ;;abbreviated...
                    ("n" . which-key-show-next-page-cycle)
                    ("p" . which-key-show-previous-page-cycle)
                    ;;abbreviated...
      (define-key map (car bind) (cdr bind)))
    map)
  "Keymap for C-h commands.")

when I do :

(define-key which-key-C-h-map (kbd "z") 'which-key-show-next-page-cycle)

I can turn the pages ok.

but when I want to use PgUp/PgDown and do :

(define-key which-key-C-h-map (kbd "<next>") 'which-key-show-next-page-cycle)

I get: which-key-C-h-dispatch: Wrong type argument: characterp, next

Why can't I use those two keys?

John Doe
  • 169
  • 6
  • How to achieve this for an individual prefix is explained in the whichk-key README. Unfortunately, at first sight (I did not look into it), it seems that it is not designed to set it for all prefixes at once. – dalanicolai Nov 14 '21 at 16:16
  • Consider reporting a bug (or enhancement request) to the maintainer of which-key.el. – Drew Nov 14 '21 at 18:20

1 Answers1

1

EDIT

To briefly answer your edited question also, this happens because read-key in which-key-C-h-dispatch returns a number for some characters (like 'z') and a symbol for others (like 'next'). A solution for your question is to replace the 'value' for the lexical variable key by

(let ((k (read-key prompt)))
  (if (numberp k)
      (string k)
    (vector k)))

You can open an issue for it at which-key, where it would probably be handy to point/refer to this answer/solution.

END EDIT

Here follows an answer, following your last comment.

What you are trying works like expected. However, you should enter the keybinding correctly and use an existing command. Try

(define-key help-map (kbd "<next>") 'which-key-show-next-page-cycle)

However, this only binds [next] in the help-map, if you would like a similar thing in the C-x which-key-mode-map, you could do

(define-key which-key-mode-map (kbd "C-x <next>") 'which-key-show-next-page-cycle)
dalanicolai
  • 7,795
  • 8
  • 24
  • I do agree that it would be nice if this configuration option for paging got documented in the README. Maybe you are willing to add it to the README and create a PR (you can edit the README right on github). – dalanicolai Nov 17 '21 at 16:08
  • Right, thank you for the correct command syntax, there's indeed an error on the README about it.

    Second command is not what i would like: i want to press C-x WAIT help-char <next>, not C-x WAIT help-char C-x <next>.

    When i bind (define-key which-key-mode-map (kbd "<next>") 'which-key-show-next-page-cycle) it does not work.

    – John Doe Nov 18 '21 at 16:38
  • What is help-char? I am not sure what you mean, but what the code does is to provide paging using <next> after you have pressed C-x (to open which key). So I would say it is just C-x <next>, no wait and no help-char (or at least no help-char, depending on what you mean with wait)... – dalanicolai Nov 19 '21 at 08:55
  • Help char = C-h, is called that way in the manual : http://www.gnu.org/software/emacs/manual/html_node/elisp/Help-Functions.html. What I meant by WAIT is that which key has a delay before showing up. I try again like you describe and it indeed works. But this way I must set up a new bind for each prefix in which I want to turn the pages. I edit the question to be clearer. – John Doe Nov 20 '21 at 17:26
  • 1
    Maybe you did not get updated, but I have edited the answer... – dalanicolai Nov 22 '21 at 16:23
  • Thank you for notification, indeed I missed it. Is that supposed to go here https://github.com/justbur/emacs-which-key/blob/master/which-key.el#L2364 ? – John Doe Nov 23 '21 at 18:48
  • 1
    Exactly... replace the (string (read-key prompt)) with the code in the answer... – dalanicolai Nov 23 '21 at 21:00