1

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

  • Please try to isolate when you can copy text successfully, and when you cannot. – Dan Apr 12 '17 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 '17 at 16:08
  • 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. – DoMiNeLa10 Apr 21 '17 at 22:28
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)

  • 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? – Nirjhar Alam Apr 18 '17 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 '17 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
  • 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? – Nirjhar Alam Apr 18 '17 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. – Darryl Hebbes Apr 20 '17 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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