Skip to content

Commit

Permalink
fix: make leader key descriptions in the keymap
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LemonBreezes committed Aug 6, 2023
1 parent 90b1b22 commit 6cf64d9
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lisp/doom-keybinds.el
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@ all hooks after it are ignored.")
forms))
(when-let (desc (cadr (memq :which-key udef)))
(prependq!
wkforms `((which-key-add-key-based-replacements
(general--concat t doom-leader-alt-key ,key)
,desc)
(which-key-add-key-based-replacements
(general--concat t doom-leader-key ,key)
wkforms `((which-key-add-keymap-based-replacements doom-leader-map
,key
,desc))))))))
(macroexp-progn
(append (and wkforms `((after! which-key ,@(nreverse wkforms))))
Expand Down Expand Up @@ -195,7 +192,7 @@ localleader prefix."
;; :prefix/:non-normal-prefix properties because general is incredibly slow
;; binding keys en mass with them in conjunction with :states -- an effective
;; 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)

;; Bind `doom-leader-key' and `doom-leader-alt-key' as late as possible to give
Expand All @@ -210,9 +207,9 @@ localleader prefix."
(set-keymap-parent doom-leader-map mode-specific-map))
((equal doom-leader-alt-key "C-x")
(set-keymap-parent doom-leader-map ctl-x-map)))
(define-key map (kbd doom-leader-alt-key) 'doom/leader))
(evil-define-key* '(normal visual motion) map (kbd doom-leader-key) 'doom/leader)
(evil-define-key* '(emacs insert) 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-map)
(evil-define-key* '(emacs insert) map (kbd doom-leader-alt-key) #'doom-leader-map))
(general-override-mode +1))))


Expand Down Expand Up @@ -317,6 +314,8 @@ For example, :nvi will map to (list 'normal 'visual 'insert). See
:prefix prefix)
rest))
(push `(defvar ,keymap (make-sparse-keymap))
doom--map-forms)
(push `(define-prefix-command ',keymap)
doom--map-forms))))
(:prefix
(cl-destructuring-bind (prefix . desc)
Expand Down

0 comments on commit 6cf64d9

Please sign in to comment.