diff --git a/lisp/doom-keybinds.el b/lisp/doom-keybinds.el index 69d5250d9..9c797eaf8 100644 --- a/lisp/doom-keybinds.el +++ b/lisp/doom-keybinds.el @@ -50,27 +50,23 @@ and Emacs states, and for non-evil users.") (setq w32-lwindow-modifier 'super w32-rwindow-modifier 'super))) -;; HACK: Emacs cannot distinguish between C-i from TAB. This is largely a -;; byproduct of its history in the terminal, which can't distinguish them -;; either, however, when GUIs came about Emacs created separate input events -;; for more contentious keys like TAB and RET. Therefore [return] != RET, -;; [tab] != TAB, and [backspace] != DEL. -;; -;; In the same vein, this keybind adds a [C-i] event, so users can bind to it -;; independently of TAB. Otherwise, it falls back to keys bound to C-i. -(define-key key-translation-map [?\C-i] - (cmd! (if (let ((keys (this-single-command-raw-keys))) - (and keys - (not (cl-position 'tab keys)) - (not (cl-position 'kp-tab keys)) - (display-graphic-p) - ;; Fall back if no keybind can be found, otherwise - ;; we've broken all pre-existing C-i keybinds. - (let ((key - (doom-lookup-key - (vconcat (cl-subseq keys 0 -1) [C-i])))) - (not (or (numberp key) (null key)))))) - [C-i] [?\C-i]))) +;; HACK: Emacs can't distinguish C-i from TAB in either GUI or TTY frames. This +;; is a byproduct of its history with the terminal, which can't distinguish +;; them either, however, Emacs has separate input events for many contentious +;; keys like TAB and RET (like [tab] and [return], aka "" and +;; ""), 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 +;; workaround for that though. +(define-key input-decode-map + [?\C-i] (cmd! (if (when-let ((keys (this-single-command-raw-keys))) + (and (display-graphic-p) + (not (cl-position 'tab keys)) + (not (cl-position 'kp-tab keys)) + ;; Fall back if no keybind can be found, + ;; otherwise we've broken all pre-existing C-i + ;; keybinds. + (key-binding (vconcat (cl-subseq keys 0 -1) [C-i]) nil t))) + [C-i] [?\C-i]))) ;; diff --git a/modules/os/tty/config.el b/modules/os/tty/config.el index 8acc88848..36a69a188 100644 --- a/modules/os/tty/config.el +++ b/modules/os/tty/config.el @@ -57,4 +57,14 @@ [M-return] (kbd "M-RET") [M-tab] (kbd "M-TAB") [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]))))