From d6c9520d93bfb8bb56c8efbaffce51f0967914bf Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Apr 2019 02:52:49 -0400 Subject: [PATCH] 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. --- core/core-keybinds.el | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/core-keybinds.el b/core/core-keybinds.el index a676a1bac..d8264246f 100644 --- a/core/core-keybinds.el +++ b/core/core-keybinds.el @@ -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