Wednesday, September 30, 2009

Sharing the Mac Clipboard with Emacs

From Doug: original post

Add the following lines to your .emacs or .emacs.d/init.el file to share the OS X clipboard with emacs.
From emacs inside the terminal in a “no window” mode. You can use M-w to copy something from emacs and then Cmd-V it in another Terminal window or likewise Cmd-C something in Terminal and then paste it into emacs with C-y.

(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)

No comments:

Post a Comment