Last Updated: May 04, 2019
·
1.15K
· gongo

Cooperation with the clipboard and emacs (window/no window)

1. (when window-system ...)

(setq x-select-enable-clipboard t)

2. (unless window-system ...)

2.1 (when (eq system-type 'darwin) ...)

(defun my-cut-function (text &optional rest)
  (let ((process-connection-type nil))
    (let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
      (process-send-string proc text)
      (process-send-eof proc))))

(defun my-paste-function ()
  (shell-command-to-string "pbpaste"))

(setq interprogram-cut-function 'my-cut-function)
(setq interprogram-paste-function 'my-paste-function)

2.2 (when (eq system-type 'gnu/linux) ...)

(defun my-cut-function (text &optional rest)
  (let ((process-connection-type nil))
    (let ((proc (start-process "xclip" "*Messages*" "xclip")))
      (process-send-string proc text)
      (process-send-eof proc))))

(defun my-paste-function ()
  (shell-command-to-string "xclip -o"))

(setq interprogram-cut-function 'my-cut-function)
(setq interprogram-paste-function 'my-paste-function)

2.3 Other system-type

I don't need it