Function: evil-normalize-keymaps

evil-normalize-keymaps is a byte-compiled function defined in evil-core.el.

Signature

(evil-normalize-keymaps &optional STATE)

Documentation

Create a buffer-local value for evil-mode-map-alist.

This is a keymap alist, determined by the current state
(or by STATE if specified).

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-core.el
(defun evil-normalize-keymaps (&optional state)
  "Create a buffer-local value for `evil-mode-map-alist'.
This is a keymap alist, determined by the current state
\(or by STATE if specified)."
  (let ((state (or state evil-state))
        (excluded '(nil t))
        map mode temp)
    ;; initialize buffer-local keymaps as necessary
    (evil-initialize-local-keymaps)
    ;; deactivate keymaps of previous state
    (dolist (entry evil-mode-map-alist)
      (setq mode (car entry)
            map (cdr entry))
      ;; don't deactivate overriding keymaps;
      ;; they are toggled by their associated mode
      (if (or (memq mode excluded)
              (evil-intercept-keymap-p map)
              (evil-overriding-keymap-p map)
              (evil-auxiliary-keymap-p map)
              (evil-minor-mode-keymap-p map))
          (push mode excluded)
        (and (fboundp mode) (symbol-value mode) (funcall mode -1))
        (set mode nil)))
    (setq evil-mode-map-alist nil)
    ;; activate keymaps of current state
    (when state
      (setq temp (evil-state-keymaps state))
      (dolist (entry temp)
        (setq mode (car entry)
              map (cdr entry))
        (unless (or (and (boundp mode) (symbol-value mode))
                    ;; the minor-mode keymaps include modes that are not
                    ;; necessarily active
                    (evil-minor-mode-keymap-p map))
          (when (fboundp mode)
            (funcall mode 1))
          (set mode t))
        ;; refresh the keymap in case it has changed
        ;; (e.g., `evil-operator-shortcut-map' is
        ;; reset on toggling)
        (if (or (memq mode excluded)
                (evil-intercept-keymap-p map)
                (evil-overriding-keymap-p map)
                (evil-auxiliary-keymap-p map)
                (evil-minor-mode-keymap-p map))
            (push mode excluded)
          (setcdr entry (or (evil-keymap-for-mode mode) map))))
      ;; update `evil-mode-map-alist'
      (setq evil-mode-map-alist temp))))