fix: make leader key descriptions in the keymap

This commit moves leader key descriptions from
`which-key-replacement-alist` to the keymap itself. This helps with
performance because that way, which-key does not have to calculate every
single leader key description for each keypress. Furthermore, this fixes
issues like #1413 where relocating leader keymaps resulted in which-key
not showing the correct leader key descriptions.

I also made the leader prefix maps have their own prefix commands by
populating the function slot of the keymap variables. This is an Emacs
convention. I made `doom-leader-map` follow this convention as well.
This commit is contained in:
StrawberryTea 2023-08-06 16:12:05 -04:00
parent 7a75030458
commit 93680af5c7

View file

@ -145,11 +145,8 @@ all hooks after it are ignored.")
forms)) forms))
(when-let (desc (cadr (memq :which-key udef))) (when-let (desc (cadr (memq :which-key udef)))
(prependq! (prependq!
wkforms `((which-key-add-key-based-replacements wkforms `((which-key-add-keymap-based-replacements doom-leader-map
(general--concat t doom-leader-alt-key ,key) ,key
,desc)
(which-key-add-key-based-replacements
(general--concat t doom-leader-key ,key)
,desc)))))))) ,desc))))))))
(macroexp-progn (macroexp-progn
(append (and wkforms `((after! which-key ,@(nreverse wkforms)))) (append (and wkforms `((after! which-key ,@(nreverse wkforms))))
@ -195,7 +192,7 @@ localleader prefix."
;; :prefix/:non-normal-prefix properties because general is incredibly slow ;; :prefix/:non-normal-prefix properties because general is incredibly slow
;; binding keys en mass with them in conjunction with :states -- an effective ;; binding keys en mass with them in conjunction with :states -- an effective
;; doubling of Doom's startup time! ;; doubling of Doom's startup time!
(define-prefix-command 'doom/leader 'doom-leader-map) (define-prefix-command 'doom-leader-map)
(define-key doom-leader-map [override-state] 'all) (define-key doom-leader-map [override-state] 'all)
;; Bind `doom-leader-key' and `doom-leader-alt-key' as late as possible to give ;; Bind `doom-leader-key' and `doom-leader-alt-key' as late as possible to give
@ -210,9 +207,9 @@ localleader prefix."
(set-keymap-parent doom-leader-map mode-specific-map)) (set-keymap-parent doom-leader-map mode-specific-map))
((equal doom-leader-alt-key "C-x") ((equal doom-leader-alt-key "C-x")
(set-keymap-parent doom-leader-map ctl-x-map))) (set-keymap-parent doom-leader-map ctl-x-map)))
(define-key map (kbd doom-leader-alt-key) 'doom/leader)) (define-key map (kbd doom-leader-alt-key) #'doom-leader-map))
(evil-define-key* '(normal visual motion) map (kbd doom-leader-key) 'doom/leader) (evil-define-key* '(normal visual motion) map (kbd doom-leader-key) #'doom-leader-map)
(evil-define-key* '(emacs insert) map (kbd doom-leader-alt-key) 'doom/leader)) (evil-define-key* '(emacs insert) map (kbd doom-leader-alt-key) #'doom-leader-map))
(general-override-mode +1)))) (general-override-mode +1))))
@ -317,6 +314,8 @@ For example, :nvi will map to (list 'normal 'visual 'insert). See
:prefix prefix) :prefix prefix)
rest)) rest))
(push `(defvar ,keymap (make-sparse-keymap)) (push `(defvar ,keymap (make-sparse-keymap))
doom--map-forms)
(push `(define-prefix-command ',keymap)
doom--map-forms)))) doom--map-forms))))
(:prefix (:prefix
(cl-destructuring-bind (prefix . desc) (cl-destructuring-bind (prefix . desc)