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)?
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.
Add this to
(defun pbcopy () (interactive) (call-process-region (point) (mark) "pbcopy") (setq deactivate-mark t)) (defun pbpaste () (interactive) (call-process-region (point) (if mark-active (mark) (point)) "pbpaste" t t)) (defun pbcut () (interactive) (pbcopy) (delete-region (region-beginning) (region-end))) (global-set-key (kbd "C-c c") 'pbcopy) (global-set-key (kbd "C-c v") 'pbpaste) (global-set-key (kbd "C-c x") 'pbcut)
If you use Emacs in iTerm 2, you can also remap key combinations in the preferences:
Then add something like this to
(global-set-key (kbd "<f13> c") 'pbcopy) (global-set-key (kbd "<f13> v") 'pbpaste) (global-set-key (kbd "<f13> x") 'pbcut)
Here's a solution to integrate OS X Clipboard to Emacs' kill-ring by Daniel Nelson: https://github.com/wesen/emacs/blob/master/pbcopy.el
Enables the kill-ring to interact with the clipboard when running Emacs from a Mac OSX terminal (without losing full kill-ring functionality). All I did was modify
xclip.elto work with
pbpaste. The real thanks go to Leo Shidai Liu, the author of xclip.el.
The following just works, got it from here :)
(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))
The version of emacs that is included with OS X is too old to provide this functionality.
Fortunately you can update emacs to a version that is integrated with your clipboard here: http://emacsformacosx.com
I believe that you use Ctrl+Y to paste in emacs, after the update.
I found this post really useful (defining 2 functions and assigning shortcuts to them in your ~/.emacs file).
After adding those lines to your .emacs file, you won't have access to those shortcuts until you open a new shell session (tab/window). Let the changes be applied.
You can get such interaction with the clipboard transparently while running Emacs in the text terminal by enabling the
xclip-mode provided by the
xclip package which you can install from GNU ELPA (i.e. via
M-x package-list-packages RET).
See also https://emacs.stackexchange.com/questions/10900/ for a similar question&answers.