Emacs as an X Clipboard Manager, take 2

I am no longer using any of the solutions from my first Emacs as an X Clipboard Manager post. I am now using an automatic, event-driven solution that is just a simple shell script. This makes the Emacs kill-ring an X clipboard manager without requiring the user to run some yank operation to pull content from the X clipboard. The shell script depends on clipnotify.

#!/bin/sh

id=$(id -u)

while clipnotify; do
  if pgrep -q -u "$id" -f 'emacs --daemon'; then
    emacsclient -n -e "(current-kill 0)"
  fi
done

If you want to save the kill ring between Emacs sessions, add kill-ring to savehist-additional-variables.

Here is some configuration for ~/.tmux.conf, so tmux can exchange text with the X clipboard. It depends on xclip.

bind < run "xclip -sel clip -o|tmux load-buffer -;tmux paste-buffer"      #[1]

## Copy mode keybindings
bind -Tcopy-mode M-w send -X copy-pipe-and-cancel 'xclip -sel clip -i'    #[2]
bind -Tcopy-mode M-W send -X copy-pipe            'xclip -sel clip -i'    #[2]

# [1] Copy the X clipboard contents into the tmux paste buffer and insert them
#     into the current pane.

# [2] Copy the selection into the tmux paste buffer and the X clipboard.

Posted 2021-05-10 16:40 | Comments

Recent posts

Monthly Archives

Yearly Archives


RSS