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 <noreply@anthropic.com>