Copying to clipboard doesn't work on Emacs Terminal mode
I was faced with the problem which is similar as Mac OS Lion へ Emacs 24.3 をインストール - Shammerism at Emacs 24.3 on Mac OS X Mavericks.
The step is ...
- Launch terminal
- emacs -nw
- Mark
- move cursor
- Try to copy by Ctrl-CC
In my environment, Ctrl-CC is defined as original function.
(defun copy-to-clipboard (p1 p2) (interactive "r*") (ns-set-pasteboard (buffer-substring p1 p2)) (message "Copied selection to clipboard"))
But try this command, the following message will be echoed in mini-buffer.
openstep is not in use or not initialized
I have seen this message ever before, that is described in 2013/03/16 my blog. I thought that this is caused by the ns-function-shortage at that time, but this is not correct. Because in my environment, following elisp code returns t, but this message will be output.
(fboundp 'ns-get-pasteboard) t (fboundp 'ns-set-pasteboard) t
I have no idea about the root cause, but using "simpleclip.el" can avoid this issue and this is happened only terminal mode. So I have changed my init file like below.
... (cond ((and (fboundp 'ns-set-pasteboard) (fboundp 'ns-get-pasteboard) (window-system)) ; cocoa-emacs. ;;; Windows mode only... (setq interprogram-cut-function nil) (setq interprogram-paste-function nil) (defun paste-from-clipboard () (interactive) (and mark-active (filter-buffer-substring (region-beginning) (region-end) t)) (insert (ns-get-pasteboard))) (defun copy-to-clipboard (p1 p2) (interactive "r*") (ns-set-pasteboard (buffer-substring p1 p2)) (message "Copied selection to clipboard")) (defun cut-to-clipboard (p1 p2) (interactive "r*") (ns-set-pasteboard (filter-buffer-substring p1 p2 t))) (global-set-key "\C-cx" 'cut-to-clipboard);[f5]"\C-cx" (global-set-key "\C-cc" 'copy-to-clipboard);[f6]"\C-cc" (global-set-key "\C-cv" 'paste-from-clipboard));[f7]"\C-cv") (t ; The emacs installed by port (progn (require 'simpleclip) (simpleclip-mode 1) (global-set-key "\C-cx" 'simpleclip-cut) (global-set-key "\C-cc" 'simpleclip-copy) (global-set-key "\C-cv" 'simpleclip-paste)))) ...
This is required "simpleclip.el".