Function: evil-esc

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

Signature

(evil-esc MAP)

Documentation

Translate \e to escape if no further event arrives.

This function is used to translate a \e event either to escape or to the standard ESC prefix translation map. If \e arrives, this function waits for evil-esc-delay seconds for another event. If no other event arrives, the event is translated to escape, otherwise it is translated to the standard ESC prefix map stored in input-decode-map. If evil-inhibit-esc is non-nil or if evil is in emacs state, the event is always translated to the ESC prefix.

The translation to escape happens only if the current command has indeed been triggered by \e. In other words, this will only happen when the keymap is accessed from read-key-sequence. In particular, if it is access from define-key the returned mapping will always be the ESC prefix map.

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-core.el
(defun evil-esc (map)
  "Translate \\e to `escape' if no further event arrives.
This function is used to translate a \\e event either to `escape'
or to the standard ESC prefix translation map. If \\e arrives,
this function waits for `evil-esc-delay' seconds for another
event. If no other event arrives, the event is translated to
`escape', otherwise it is translated to the standard ESC prefix
map stored in `input-decode-map'. If `evil-inhibit-esc' is
non-nil or if evil is in emacs state, the event is always
translated to the ESC prefix.

The translation to `escape' happens only if the current command
has indeed been triggered by \\e. In other words, this will only
happen when the keymap is accessed from `read-key-sequence'. In
particular, if it is access from `define-key' the returned
mapping will always be the ESC prefix map."
  (if (and (not evil-inhibit-esc)
           (or evil-local-mode (evil-ex-p)
               (active-minibuffer-window))
           (not (evil-emacs-state-p))
           (let ((keys (this-single-command-keys)))
             (and (> (length keys) 0)
                  (= (aref keys (1- (length keys))) ?\e)))
           (sit-for evil-esc-delay))
      (prog1 [escape]
        (when defining-kbd-macro
          (end-kbd-macro)
          (setq last-kbd-macro (vconcat last-kbd-macro [escape]))
          (start-kbd-macro t t)))
    map))