Function: kkp-with-legacy-keys
kkp-with-legacy-keys is a macro defined in kkp.el.
Signature
(kkp-with-legacy-keys &rest BODY)
Documentation
Run BODY with KKP key encoding temporarily disabled in the selected terminal.
While BODY runs in a terminal where KKP is active, the terminal is asked to
revert to the legacy single-byte encoding of control keys, so that C-g
arrives as the raw quit-char byte and can interrupt blocking subprocess
calls such as a synchronous call-process. The previous KKP flags are
restored afterwards, even if BODY exits non-locally.
The flags are toggled with the set command (CSI = flags ; 1 u) rather than
the push/pop stack: we know the exact flags to restore (they are recorded
in the terminal's kkp--state), and the set command restores them
directly on terminals that lack the flag stack (e.g. zellij), where a
stack pop would instead leave KKP disabled for good.
This is a no-op when KKP is not active in the selected terminal, and is not re-applied for nested forms.
Source Code
;; Defined in /nix/store/0igl9q4k4n87vg4h2gnnrlha21kx9biv-emacs-packages-deps/share/emacs/site-lisp/elpa/kkp-20260706.858/kkp.el
(defmacro kkp-with-legacy-keys (&rest body)
"Run BODY with KKP key encoding temporarily disabled in the selected terminal.
While BODY runs in a terminal where KKP is active, the terminal is asked to
revert to the legacy single-byte encoding of control keys, so that `C-g'
arrives as the raw `quit-char' byte and can interrupt blocking subprocess
calls such as a synchronous `call-process'. The previous KKP flags are
restored afterwards, even if BODY exits non-locally.
The flags are toggled with the set command (CSI = flags ; 1 u) rather than
the push/pop stack: we know the exact flags to restore (they are recorded
in the terminal's `kkp--state'), and the set command restores them
directly on terminals that lack the flag stack (e.g. zellij), where a
stack pop would instead leave KKP disabled for good.
This is a no-op when KKP is not active in the selected terminal, and is
not re-applied for nested forms."
(declare (indent 0) (debug t))
(let ((term (make-symbol "terminal"))
(state (make-symbol "state")))
`(let* ((,term (kkp--selected-terminal))
(,state (kkp--terminal-state ,term)))
(if (or (not (and ,state (kkp--state-enhancements ,state))) ; KKP inactive here
(kkp--state-legacy-active ,state)) ; already switched
(progn ,@body)
(setf (kkp--state-legacy-active ,state) t)
(kkp--set-encoding-flags ,term 0)
(unwind-protect
(progn ,@body)
(setf (kkp--state-legacy-active ,state) nil)
;; Restore the flags kkp recorded when it enabled the terminal;
;; the body never changes them, so this value is still current.
(kkp--set-encoding-flags ,term (kkp--state-enhancements ,state)))))))