4

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

4
  • Please try to isolate when you can copy text successfully, and when you cannot.
    – Dan
    Apr 12, 2017 at 21:00
  • How do you usually try to copy and paste..? Are you using a keyboard shortcut? Do you highlight + Middle-click paste? Are you pasting into a terminal?
    – Archenoth
    Apr 21, 2017 at 16:08
  • 1
    From my experience, GUI Emacs just works with the clipboard without any configuration. I think I've tried it on Ubuntu too. Just make sure you're using the correct keyboard shortcuts. In most programs C-c copies and C-v pastes, but in Emacs it's M-w and C-yrespectively.
    – user12563
    Apr 21, 2017 at 22:28
  • I would like to mention that currently there is no solution to this problem. Jan 18, 2021 at 9:16

2 Answers 2

1

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)

2
  • I guess I neglected to mention that I am completely new to both emacs and linux. Do I have to add this code to the .emacs file? Apr 18, 2017 at 22:00
  • yes you should had the code in the .emacs file but I just realize that this variables are obsolete since emacs 25.1, I updated the previous comment in consequence
    – slemaguer
    Apr 21, 2017 at 15:41
0

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
2
  • I guess I neglected to mention that I am completely new to both emacs and linux. Do I have to add this code to the .emacs file? Apr 18, 2017 at 22:01
  • Yes, just add the two defuns and two setq to your .emacs (or init.el) file. The "sudo apt-get install xsel" command you must run in the terminal application. Apr 20, 2017 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.