Skip to content

embark-prefix-help-command shallow preview if keys are bound to keymaps with replacements (which-key) #771

@Mateus-Carmo31

Description

@Mateus-Carmo31

I have recently started making use of embark, and especially embark-prefix-help-command. I quite like being able to press C-h and, at a glance, view and filter through all the keybinds I have under my main leader keymap.

However, I have experienced some strange issues using embark-prefix-help-command with which-key. if I define a key that triggers another keymap in my main map and then make use of which-key's which-key-add-keymap-based-replacements to give the binding a name, embark's help command becomes unable to give me binds within those sub keymaps. Below is a reproducible test keymap:

(defvar test-prefix-buffer-map (make-sparse-keymap))

(define-key test-prefix-buffer-map "s" #'save-buffer)
(define-key test-prefix-buffer-map "w" #'write-file)
(define-key test-prefix-buffer-map "p" #'previous-buffer)
(define-key test-prefix-buffer-map "n" #'next-buffer)

(defalias 'test-prefix-buffer test-prefix-buffer-map)

(defvar test-prefix-mode-map (make-sparse-keymap))

(define-key test-prefix-mode-map "l" #'display-line-numbers-mode)
(define-key test-prefix-mode-map "h" #'hl-line-mode)

(defalias 'test-prefix-mode test-prefix-mode-map)

(defvar test-prefix-map
  (let ((map (make-keymap)))
    (define-key map "b" 'test-prefix-buffer)
    (define-key map "m" 'test-prefix-mode)
    (define-key map "f" #'find-file)
    (define-key map "d" #'dired)
    map)
  "Prefix map.")
(keymap-lookup global-map "SPC w")

;; v Issue!
(which-key-add-keymap-based-replacements test-prefix-map
  "b" `("Buffer" . ,test-prefix-buffer-map)
  "m" `("Testing" . ,test-prefix-mode-map))

(keymap-set global-map "<f2>" test-prefix-map)

If that issue section is commented out, embark-prefix-help-command is able to show the keybinds b b, b m, etc. when <f2> C-h is pressed, but if it's active, then the underlying keybinds are replaced with just Buffer and Testing entries in the help display. To make matters worse, selecting these shallow options results in an error (Wrong type argument: commandp, (keymap <keymap definition>). Is there a way to avoid this? Is this a problem with which-key, or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions