                (pcase key
                  (:leader
                   (doom--map-commit)
-                  (setq doom--map-fn 'define-leader-key!))
+                  (setq doom--map-fn 'doom--define-leader-key))
                  (:localleader
                   (doom--map-commit)
                   (setq doom--map-fn 'define-localleader-key!))

        (if (keywordp key)
            (when (memq key '(:prefix :infix))
              (setq prefix def))
          (let ((unquoted-def (cdr-safe (doom-unquote def))))
            (when prefix
              (setq key `(general--concat t ,prefix ,key)))
            (when-let* ((desc (plist-get unquoted-def :which-key)))
              (push `(which-key-add-key-based-replacements
                       (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)))))
    (macroexp-progn
     (append (nreverse forms)
             (when wkforms
               `((eval-after-load 'which-key
                   (lambda () ,@(nreverse wkforms)))))))))

(general-create-definer define-localleader-key!
  :major-modes t
  :prefix doom-localleader-alt-key)

;; :non-normal-prefix doesn't apply to non-evil sessions (only evil's emacs
;; state), so we must redefine `define-localleader-key!' to behave differently
;; where evil is present.
(after! evil
  (general-create-definer define-localleader-key!
    :states '(normal visual motion emacs)
    :major-modes t
    :prefix doom-localleader-key
    :non-normal-prefix doom-localleader-alt-key))

;; We use a prefix commands instead of general's :prefix/:non-normal-prefix
;; properties because general is incredibly slow binding keys en mass with them

(defalias 'define-key! #'general-def)
(defalias 'unmap! #'general-unbind)

;; `map!' uses this instead of `define-leader-key!' because it consumes 20-30%
;; more startup time, so we reimplement it ourselves.
(defmacro doom--define-leader-key (&rest keys)
  (let (prefix forms wkforms)
    (while keys
      (let ((key (pop keys))
