summaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorRavi R Kiran <aine.marina@gmail.com>2021-11-03 03:37:47 (GMT)
committerRavi R Kiran <aine.marina@gmail.com>2021-11-03 03:37:47 (GMT)
commit62745280cf6311884616cd69fdcce30808077f7f (patch)
tree1bf53590002eb822785cc72bd729d4e78c332682 /lisp
parent9622a1faec8f94eb31fc51b87dcb0e0155cce689 (diff)
downloaddotemacs-62745280cf6311884616cd69fdcce30808077f7f.zip
dotemacs-62745280cf6311884616cd69fdcce30808077f7f.tar.gz
dotemacs-62745280cf6311884616cd69fdcce30808077f7f.tar.bz2
Use OSC 52 to send text to clipboard
Diffstat (limited to 'lisp')
-rw-r--r--lisp/kitty-remote-control.el27
1 files changed, 27 insertions, 0 deletions
diff --git a/lisp/kitty-remote-control.el b/lisp/kitty-remote-control.el
index a5c988a..6fe7d31 100644
--- a/lisp/kitty-remote-control.el
+++ b/lisp/kitty-remote-control.el
@@ -84,5 +84,32 @@
`(("type" . "background")
("args" . ,cmd))))
+;; Clipboard handling: could be generalized
+(defvar kitty-rc-clipboard-max-length 10000
+ "Maximum length of characters copied to clipboard")
+(defun kitty-rc-copy-to-clipboard (string &optional append use-primary)
+ "Copy STRING to clipboard"
+ (if-let* ((out-len (+ (* (length string) 3) 2))
+ (allowed (< out-len kitty-rc-clipboard-max-length))
+ (out-str (base64-encode-string (encode-coding-string string 'binary)))
+ (pfx (concat "\e]52;" (if use-primary "p" "c") ";"))
+ (sfx "\e\\"))
+ (progn
+ (unless append
+ (send-string-to-terminal (concat pfx "!" sfx)))
+ (send-string-to-terminal (concat pfx out-str sfx))
+ (sit-for 0.1))
+ (message "Selection too long to send to terminal")))
+
+(defun kitty-rc-interprogram-cut-function (text)
+ (when select-enable-primary
+ (kitty-rc-copy-to-clipboard text nil t))
+ (when select-enable-clipboard
+ (kitty-rc-copy-to-clipboard text nil nil)))
+
+(defun kitty-rc-set-interprogram-cut-function ()
+ (interactive)
+ (setq interprogram-cut-function #'kitty-rc-interprogram-cut-function))
+
(provide 'kitty-remote-control)
;;; kitty-remote-control.el ends here