Don't bind missing commands to leader keys

I don't want to litter config/default/+evil-bindings.el with conditions
for every keybind whose module may or may not be enabled. It impacts its
readability and is relatively expensive (due to the internals of map!
and general).

So instead, we no-op keybinds for commands that don't exist (and aren't
autoloaded), so you don't see missing function errors when using these
keys.
This commit is contained in:
Henrik Lissner 2019-04-05 02:52:49 -04:00
parent 038e0196c7
commit d6c9520d93
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -99,11 +99,18 @@ If any hook returns non-nil, all hooks after it are ignored.")
(general--concat t doom-leader-key ,key)
,desc)
wkforms))
(push `(define-key doom-leader-map (general--kbd ,key)
,(if (general--extended-def-p unquoted-def)
(plist-get unquoted-def :def)
def))
forms)))))
;; Don't bind missing functions (so they don't throw errors when
;; used). `fboundp' conveniently returns `t' for autoloaded
;; functions as well as defined ones.
(let* ((fn (if (general--extended-def-p unquoted-def)
(plist-get unquoted-def :def)
def))
(unquoted-fn (doom-unquote fn)))
(when (or (not (symbolp unquoted-fn))
(fboundp unquoted-fn))
(push `(define-key doom-leader-map (general--kbd ,key)
,fn)
forms)))))))
(macroexp-progn
(append (nreverse forms)
(when wkforms