Share OSX Clipboard With Emacs

Add the following to your .el init files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
;; Use M-w to copy Emacs buffer selection; and Cmd-V to paste outside of Emacs.
;; Use Cmd-C to copy selection from OSX; and C-y to paste in Emacs

(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))

(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))

(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)