From b15939174917bdabcf4e2e2ba0e5e392b84aecf2 Mon Sep 17 00:00:00 2001 From: David Florness Date: Sat, 18 Jul 2026 15:58:32 -0400 Subject: [PATCH] clipboard: give terminal frames system-clipboard access via xclip Terminal frames (emacsclient -t) have no window-system connection, so Emacs' native gui-backend selection path is a no-op there: killing and yanking never touch the host clipboard. GUI frames already reach the Wayland/macOS selection natively, so this gap only affects the terminal frames that the recent Kitty Keyboard Protocol work (16a7459, edaf9d9) made usable in the first place. xclip closes that gap by shelling out to the platform's real clipboard tool -- wl-copy on Wayland, pbcopy on macOS, xclip/xsel on X11 -- auto-detected per machine via `xclip-method', so one config works everywhere without branching. It is bidirectional, so both C-w/M-w and C-y see the system clipboard. It is safe under this daemon, which serves both GUI and terminal frames: on Emacs >= 25 xclip registers its gui-backend-get/set-selection methods specialized on `(window-system nil)', so they dispatch only in terminal frames while GUI frames keep their native clipboard. It also overrides term/xterm.el's built-in (poorly supported) OSC 52 method so the two don't fight. Preferred over an OSC 52 solution (e.g. clipetty) because OSC 52 is copy-only in practice and rides the terminal stream (needing tmux set-clipboard passthrough, with a per-message size cap); shelling to the native tool avoids all of that for a local daemon. OSC 52 would only win for Emacs running on a remote host over SSH, which isn't the use case. Co-Authored-By: Claude Opus 4.8 --- lisp/keys.el | 9 +++++++++ straight/versions/default.el | 1 + 2 files changed, 10 insertions(+) diff --git a/lisp/keys.el b/lisp/keys.el index 2541eb3..c68ca91 100644 --- a/lisp/keys.el +++ b/lisp/keys.el @@ -143,3 +143,12 @@ ;; protocol; check `kkp-status' in a given frame to confirm. (use-package kkp :hook (tty-setup . global-kkp-mode)) + +;; Give terminal frames (emacsclient -t) access to the system clipboard by +;; shelling out to the platform's clipboard tool (wl-copy on Wayland, pbcopy on +;; macOS, xclip/xsel on X11 -- auto-detected via `xclip-method'). On Emacs >= 25 +;; xclip dispatches only for terminal frames (its gui-backend-* methods are +;; specialized on `(window-system nil)'), so GUI frames keep their native +;; clipboard. Bidirectional: both kill and yank reach the system clipboard. +(use-package xclip + :config (xclip-mode 1)) diff --git a/straight/versions/default.el b/straight/versions/default.el index 964d3d1..d441f03 100644 --- a/straight/versions/default.el +++ b/straight/versions/default.el @@ -128,6 +128,7 @@ ("use-package" . "4b3484b550431f74ab9cda060a8dc983fe482131") ("web-mode" . "aeee2d4c82a791ff69657c1413873bf9265544df") ("with-editor" . "45bfc6084f03e3aa7f4f8db20836d559186c5957") + ("xclip" . "9ab22517f3f2044e1c8c19be263da9803fbca26a") ("xref" . "bd31f9ac86a105c01631b29e6f442049500e9928") ("xterm-color" . "ffdad85e584dfc0857f2a1fb970f5ef0f5d31ba3") ("yaml-mode" . "96ef0201101a7cd591febd5886633154dae8834c") -- 2.38.4