I am using emacs 23.3 on Ubuntu 12.04 LTS. I am having problems trying to copy text from another application (most of the time, Firefox) to emacs. Sometimes it works and sometimes it doesn't. Any way to fix this?
Thanks
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityI am using emacs 23.3 on Ubuntu 12.04 LTS. I am having problems trying to copy text from another application (most of the time, Firefox) to emacs. Sometimes it works and sometimes it doesn't. Any way to fix this?
Thanks
This should use the system clipboard:
(defun copy-from-ubuntu (text &optional push)
(interactive)
(if (display-graphic-p)
(progn
(message "Yanked region to x-clipboard!")
(call-interactively 'clipboard-kill-ring-save)
)
(if (region-active-p)
(progn
(shell-command-on-region (region-beginning) (region-end) "xsel -i -b")
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
)
(defun paste-to-ubuntu ()
(interactive)
(if (display-graphic-p)
(progn
(clipboard-yank)
(message "graphics active")
)
(insert (shell-command-to-string "xsel -o -b"))
)
)
And then finally add:
(setq interprogram-cut-function 'copy-from-ubuntu)
(setq interprogram-paste-function 'paste-to-ubuntu)
You will also need to install xsel
$ sudo apt-get install xsel
I have that in my configuration :
(setq select-enable-primary nil)
(setq select-enable-clipboard t)
on my side it works for gnome-shell (I didn't try with unity)
C-c
copies andC-v
pastes, but in Emacs it'sM-w
andC-y
respectively. – user12563 Apr 21 '17 at 22:28