diff options
| author | Ravi R Kiran <aine.marina@gmail.com> | 2021-05-10 00:27:16 (GMT) |
|---|---|---|
| committer | Ravi R Kiran <aine.marina@gmail.com> | 2021-05-10 00:27:16 (GMT) |
| commit | cc0fe1d30b5b9da44f003f9658fccf52e52b4a8c (patch) | |
| tree | b4d6d91d6ab7e8f31980c46d0167e1bc07f9e69d | |
| parent | 606af070a7914315670561a876b2d8d64ed96434 (diff) | |
| download | dotemacs-cc0fe1d30b5b9da44f003f9658fccf52e52b4a8c.zip dotemacs-cc0fe1d30b5b9da44f003f9658fccf52e52b4a8c.tar.gz dotemacs-cc0fe1d30b5b9da44f003f9658fccf52e52b4a8c.tar.bz2 | |
Make xterm-kitty into a real terminal initialization handler
| -rw-r--r-- | init.el | 26 | ||||
| -rw-r--r-- | lisp/term/xterm-kitty.el (renamed from lisp/xterm-kitty.el) | 71 |
2 files changed, 54 insertions, 43 deletions
@@ -82,22 +82,20 @@ (use-package s) (use-package dash) -(use-package xterm-kitty +(use-package term/xterm-kitty :init (setq xterm-kitty-modifiers-alist '((1 . shift) (2 . alt) (4 . control) (32 . super) (16 . hyper) (8 . meta))) - :config - (xterm-kitty-add) - (when xterm-kitty-in-use - (defun ravi/get-rid-of-xterm-key-translations () - (mapcar (lambda (k) (define-key local-function-key-map (vector k) nil)) - '(tab delete return escape)) - ;; Manually disambiguate between DEL=backspace and delete keys - (bind-key "C-DEL" #'backward-kill-word) - (bind-key "C-<delete>" #'kill-word) - (bind-key "<delete>" #'delete-forward-char)) - (add-hook 'terminal-init-xterm-hook 'ravi/get-rid-of-xterm-key-translations)) - :ensure nil - :load-path (lambda () (ravi/emacs-file "lisp"))) + (defun ravi/get-rid-of-xterm-key-translations () + (message "Getting rid of xterm key translations") + (mapcar (lambda (k) (define-key local-function-key-map (vector k) nil)) + '(tab delete return escape)) + ;; Manually disambiguate between DEL=backspace and delete keys + (define-key local-function-key-map (kbd "C-DEL") #'backward-kill-word) + (define-key local-function-key-map (kbd "C-<delete>") #'kill-word) + (define-key local-function-key-map (kbd "<delete>") #'delete-forward-char)) + (add-hook 'terminal-init-xterm-kitty-hook #'ravi/get-rid-of-xterm-key-translations) + ;; Don't defer since we will use xterm-kitty-make-binding-sequence elsewhere + :ensure nil) (require 's) (require 'ravi-ergodox-mode) diff --git a/lisp/xterm-kitty.el b/lisp/term/xterm-kitty.el index 906c032..9706fbb 100644 --- a/lisp/xterm-kitty.el +++ b/lisp/term/xterm-kitty.el @@ -21,19 +21,19 @@ ;;; Commentary: ;; Work-in-progress to support kitty terminal with all modifiers -;; - not ready yet to be moved into term/xterm-kitty.el ;; - still need to ;; + ensure proper 24-bit color support -;; + reduce/formalize dependencies on xterm.el -;; + provide init-terminal-xterm-kitty +;; + add all keys specified in private unicode space +;; + figure out a way to split keybindings between kitty and non-kitty +;; frames ;;; Code: (require 'term/xterm) -(defvar xterm-kitty-in-use - (and (string-match "^xterm-kitty" (getenv-internal "TERM" initial-environment)) t) - "Currently running under xterm-kitty.") +(defun xterm-kitty-in-use (&optional frame) + "Check whether FRAME is running under kitty terminal." + (terminal-parameter frame 'kitty-window-id)) (defvar xterm-kitty-modifiers-alist '((1 . shift) (2 . alt) (4 . control) (8 . super) (16 . hyper) (32 . meta)) @@ -360,7 +360,7 @@ off shift modifiers for alphabetic characters. The only way to avoid it is to provide the key vector itself to 'define-key', which this function explicitly creates. In that sense, this function is almost equivalent to 'event-convert-list'." - (if xterm-kitty-in-use + (if (xterm-kitty-in-use) (vector (xterm-kitty--add-modifier-list modifiers key)) default)) @@ -374,7 +374,7 @@ function is almost equivalent to 'event-convert-list'." (defun xterm-kitty-apply-keyboard (&optional keymap alternate-keymap) "Apply keyboard defintion; optionally to KEYMAP and ALTERNATE-KEYMAP." (let* ((kmap (or keymap - (and xterm-kitty-in-use input-decode-map))) + (and (xterm-kitty-in-use) input-decode-map))) (alternate-kmap (or alternate-keymap (and kmap (not keymap) @@ -391,14 +391,6 @@ function is almost equivalent to 'event-convert-list'." (when (and alternate-kmap) (xterm-kitty--setup-legacy-control-maps alternate-kmap)))) -(defun xterm-kitty-add () - "This one should be replaced by init-terminal-xterm-kitty; just a hack for now." - (when xterm-kitty-in-use - (setq xterm-extra-capabilities '(reportBackground getSelection setSelection)) - (add-hook 'terminal-init-xterm-hook 'xterm-kitty-apply-keyboard) - (add-hook 'terminal-init-xterm-hook 'xterm-kitty-save-window-id) - (xterm-kitty-add-select-frame-set-input-focus-advice))) - (defun xterm-kitty-window-id (&optional terminal) ; public API (terminal-parameter terminal 'kitty-window-id)) @@ -438,9 +430,8 @@ function is almost equivalent to 'event-convert-list'." (defun xterm-kitty-save-window-id () "Save kitty window ID of current terminal" - (when xterm-kitty-in-use - (xterm--query "\eP@kitty-cmd{\"cmd\":\"ls\",\"version\":[0,19,3]}\e\\" - '(("\eP@kitty-cmd" . xterm-kitty--save-kitty-window-id))))) + (xterm--query "\eP@kitty-cmd{\"cmd\":\"ls\",\"version\":[0,19,3]}\e\\" + '(("\eP@kitty-cmd" . xterm-kitty--save-kitty-window-id)))) (defvar xterm-kitty--focus-window-command-string "\eP@kitty-cmd{\"cmd\":\"focus-window\",\"version\":[0,19,3],\"no_response\":true,\"payload\":{\"match\":\"id:%d\"}}\e\\" @@ -449,21 +440,20 @@ function is almost equivalent to 'event-convert-list'." "Set focus to terminal containing FRAME-OR-WINDOW FRAME-OR-WINDOW can be a terminal, a frame, or a window" - (let* ((frame (if (windowp frame-or-window) - (window-frame frame-or-window) - frame-or-window)) - (kitty-window-id (and xterm-kitty-in-use (xterm-kitty-window-id (frame-terminal frame))))) + (let* ((frame (if (windowp frame-or-window) (window-frame frame-or-window) frame-or-window)) + (kitty-window-id (xterm-kitty-window-id (frame-terminal frame)))) ;; (message "Window id %d for %s" kitty-window-id frame) - (when kitty-window-id - (send-string-to-terminal (format xterm-kitty--focus-window-command-string kitty-window-id))))) + (if kitty-window-id + (send-string-to-terminal (format xterm-kitty--focus-window-command-string kitty-window-id)) + (message "%s is not a kitty window" frame-or-window)))) (defun xterm-kitty-select-frame-set-input-focus-advice (old-function frame &optional no-record) - (or (when xterm-kitty-in-use + (or (when (xterm-kitty-in-use frame) ;; (message "Switching to frame: %s" frame) (xterm-kitty-focus frame) (select-frame frame no-record)) (funcall old-function frame no-record))) (defun xterm-kitty-visible-window-advice (old-function &optional window minibuf all-frames) - (when xterm-kitty-in-use + (when (xterm-kitty-in-use) ;; Terminal emacs thinks that only one frame is ever visible (funcall old-function window minibuf (if (eql all-frames 'visible) t all-frames)))) (defun xterm-kitty-add-select-frame-set-input-focus-advice () @@ -479,8 +469,31 @@ function is almost equivalent to 'event-convert-list'." (defun xterm-kitty-new-os-window () "Open new xterm-kitty os window" (interactive) - (when xterm-kitty-in-use + (when (xterm-kitty-in-use) (send-string-to-terminal xterm-kitty--new-os-window-command-string))) -(provide 'xterm-kitty) +(defun terminal-init-xterm-kitty () + "Terminal initialization function for kitty" + ;; Order is important here: window id must be saved prior to any + ;; other xterm-kitty function calls in this function. + (xterm-kitty-save-window-id) + (xterm-kitty-apply-keyboard) + + ;; Standard xterm-like initialization + (xterm-register-default-colors xterm-standard-colors) + (tty-set-up-initial-frame-faces) + + ;; Steal private functions from term/xterm that kitty supports + (xterm--query "\e]11;?\e\\" + '(("\e]11;" . xterm--report-background-handler))) + (xterm--init-activate-get-selection) + (xterm--init-activate-set-selection) + (when xterm-set-window-title + (xterm--init-frame-title)) + (xterm--init-bracketed-paste-mode) + (xterm--init-focus-tracking) + + (run-hooks 'terminal-init-xterm-kitty-hook)) + +(provide 'term/xterm-kitty) ;;; xterm-kitty.el ends here |
