Function: kkp--handle-u-or-tilde-terminators
kkp--handle-u-or-tilde-terminators is a natively compiled function
defined in kkp.el.
Signature
(kkp--handle-u-or-tilde-terminators TERMINATOR TERMINAL-INPUT)
Documentation
Handle input sequences ending with ?u or ?~ terminators.
TERMINATOR is the last character in the TERMINAL-INPUT sequence,
indicating the end of the sequence. TERMINAL-INPUT is a list of
characters representing the terminal input sequence. This function
contains the specific logic for processing sequences terminated by ?u or
?~.
Source Code
;; Defined in /nix/store/0igl9q4k4n87vg4h2gnnrlha21kx9biv-emacs-packages-deps/share/emacs/site-lisp/elpa/kkp-20260706.858/kkp.el
(defun kkp--handle-u-or-tilde-terminators (terminator terminal-input)
"Handle input sequences ending with ?u or ?~ terminators.
TERMINATOR is the last character in the TERMINAL-INPUT sequence,
indicating the end of the sequence. TERMINAL-INPUT is a list of
characters representing the terminal input sequence. This function
contains the specific logic for processing sequences terminated by ?u or
?~."
(let* ((terminator-alist (pcase terminator
(?u kkp--non-printable-keys-with-u-terminator)
(?~ kkp--non-printable-keys-with-tilde-terminator)))
(input-string (mapconcat 'char-to-string (remq terminator terminal-input) ""))
(input-parts (split-string input-string ";"))
(keycode-parts (split-string (cl-first input-parts) ":")) ;; get keycodes from sequence
(primary-keycode (cl-first keycode-parts))
(secondary-keycode-str (cl-second keycode-parts))
(secondary-keycode (and (stringp secondary-keycode-str)
(not (string-empty-p secondary-keycode-str))
secondary-keycode-str))
(modifier-parts (split-string (or (cl-second input-parts) "") ":")) ;; list of modifiers and event types
(modifier-string (cl-first modifier-parts))
(modifier-num (if (not (string-empty-p modifier-string))
(1- (string-to-number modifier-string))
0))
(has-shift (/= 0 (logand modifier-num (kkp--mod-bits 'shift))))
(has-ctrl (/= 0 (logand modifier-num (kkp--mod-bits 'control))))
(is-ascii-letter (member (string-to-number primary-keycode) kkp--printable-ascii-letters))
;; -------------------------------------------------------------
;; Shift-collapse rule:
;; • Shift present
;; • secondary code available
;; • no Control *when key is an ASCII letter*
;; -------------------------------------------------------------
(use-secondary (and secondary-keycode
has-shift
(or (not is-ascii-letter)
(not has-ctrl))))
(final-key-code (if use-secondary secondary-keycode primary-keycode)))
;; if we use the secondary keycode, remove shift from modifier number
(when use-secondary
(setq modifier-num (logand modifier-num (lognot 1))))
;; create keybinding by concatenating the modifier string with the key-name
(let
((modifier-str (kkp--create-modifiers-string modifier-num))
(key-name (kkp--get-keycode-representation (string-to-number final-key-code)
terminator-alist)))
(kbd (concat modifier-str key-name)))))