fix: C-i in KKP supported terminals

"C-i" and "TAB" are equivalent to Emacs. In GUI Emacs, we can bind to
[tab] instead of "TAB", permitted users to treat the two keys
differently. However, [tab] is unavailable in TTY frames, so there was
no avoiding sacrificing C-i keybinds there. With KKP support, though,
that's no longer the case.
This commit is contained in:
Henrik Lissner 2024-08-30 21:35:15 -04:00
parent 0a38eeef4c
commit 538ddf5e66
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 28 additions and 22 deletions

View file

@ -50,26 +50,22 @@ and Emacs states, and for non-evil users.")
(setq w32-lwindow-modifier 'super (setq w32-lwindow-modifier 'super
w32-rwindow-modifier 'super))) w32-rwindow-modifier 'super)))
;; HACK: Emacs cannot distinguish between C-i from TAB. This is largely a ;; HACK: Emacs can't distinguish C-i from TAB in either GUI or TTY frames. This
;; byproduct of its history in the terminal, which can't distinguish them ;; is a byproduct of its history with the terminal, which can't distinguish
;; either, however, when GUIs came about Emacs created separate input events ;; them either, however, Emacs has separate input events for many contentious
;; for more contentious keys like TAB and RET. Therefore [return] != RET, ;; keys like TAB and RET (like [tab] and [return], aka "<tab>" and
;; [tab] != TAB, and [backspace] != DEL. ;; "<return>"), which are only triggered in GUI frames, so here, I create one
;; ;; for C-i. Won't work in TTY frames, though. Doom's :os tty module has a
;; In the same vein, this keybind adds a [C-i] event, so users can bind to it ;; workaround for that though.
;; independently of TAB. Otherwise, it falls back to keys bound to C-i. (define-key input-decode-map
(define-key key-translation-map [?\C-i] [?\C-i] (cmd! (if (when-let ((keys (this-single-command-raw-keys)))
(cmd! (if (let ((keys (this-single-command-raw-keys))) (and (display-graphic-p)
(and keys
(not (cl-position 'tab keys)) (not (cl-position 'tab keys))
(not (cl-position 'kp-tab keys)) (not (cl-position 'kp-tab keys))
(display-graphic-p) ;; Fall back if no <C-i> keybind can be found,
;; Fall back if no <C-i> keybind can be found, otherwise ;; otherwise we've broken all pre-existing C-i
;; we've broken all pre-existing C-i keybinds. ;; keybinds.
(let ((key (key-binding (vconcat (cl-subseq keys 0 -1) [C-i]) nil t)))
(doom-lookup-key
(vconcat (cl-subseq keys 0 -1) [C-i]))))
(not (or (numberp key) (null key))))))
[C-i] [?\C-i]))) [C-i] [?\C-i])))

View file

@ -57,4 +57,14 @@
[M-return] (kbd "M-RET") [M-return] (kbd "M-RET")
[M-tab] (kbd "M-TAB") [M-tab] (kbd "M-TAB")
[M-backspace] (kbd "M-DEL") [M-backspace] (kbd "M-DEL")
[M-delete] (kbd "M-DEL"))) [M-delete] (kbd "M-DEL"))
;; HACK: Allow C-i to function independently of TAB in KKP-supported
;; terminals. Requires the `input-decode-map' entry in
;; lisp/doom-keybinds.el.
(define-key! key-translation-map
[?\C-i] (cmd! (if-let (((kkp--terminal-has-active-kkp-p))
(keys (this-single-command-raw-keys))
((> (length keys) 2))
((equal (cl-subseq keys -3) [27 91 49])))
[C-i] [?\C-i]))))