Mac – Configure emacs to cut and copy text to Mac OS X clipboard

copy/pasteemacs

Can I configure emacs, so that I could copy/cut text from emacs (default Terminal version) and paste it somewhere else (into X Window program)?

Best Answer

To copy the current region to the OS X clipboard, you can use

(shell-command-on-region (region-beginning) (region-end) "pbcopy")

The inverse, copying the OS X paste buffer to the Emacs kill ring, is not recommended. Kill rings and clipboards are very different structures and there's no good answer to what, exactly, pushing a clipboard into a kill ring should do. Still, you can run pbpaste manually to get the current clipboard contents.