Function: ghostel--tty-esc-init

ghostel--tty-esc-init is a natively compiled function defined in ghostel.el.

Signature

(ghostel--tty-esc-init &optional FRAME)

Documentation

Install the lone-ESC to escape filter on FRAME's terminal.

Only acts on text terminals; re-wraps if another package later replaced the entry. The wrapped entry may itself be another package's filter (e.g. evil's) — nested filters compose, with at most one translation delay paid per key. The filter is inert outside ghostel terminal-input buffers, so no uninstall is needed.

Source Code

;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel.el
(defun ghostel--tty-esc-init (&optional frame)
  "Install the lone-ESC to `escape' filter on FRAME's terminal.
Only acts on text terminals; re-wraps if another package later
replaced the entry.  The wrapped entry may itself be another
package's filter (e.g. evil's) — nested filters compose, with at
most one translation delay paid per key.  The filter is inert
outside ghostel terminal-input buffers, so no uninstall is needed."
  (let ((term (frame-terminal frame)))
    (when (eq (terminal-live-p term) t)
      ;; `input-decode-map' is terminal-local; select the frame to
      ;; read and modify the right terminal's map.
      (with-selected-frame (or frame (selected-frame))
        ;; `lookup-key' resolves menu-item filters to the wrapped map,
        ;; dropping another package's wrapper — read the entry
        ;; structurally.
        (let* ((cell (assq ?\e (cdr input-decode-map)))
               (raw (if cell (cdr cell)
                      (lookup-key input-decode-map [?\e]))))
          ;; Recognize our wrapper by its :filter tag; `define-key'
          ;; copies the menu-item list, so object identity won't do.
          (unless (if cell
                      (and (eq (car-safe raw) 'menu-item)
                           (eq (cadr (memq :filter raw)) 'ghostel--tty-esc))
                    (terminal-parameter term 'ghostel--tty-esc-map))
            (set-terminal-parameter term 'ghostel--tty-esc-map (or raw t))
            ;; package-lint's reserved-key check matches literal
            ;; vectors only; a translation-map entry is not a
            ;; reserved binding.
            (define-key input-decode-map (vector ?\e)
              `(menu-item "" ,raw :filter ghostel--tty-esc))))))))