Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I copy from emacs and paste into another instance of emacs or else where?

If I do C-space, M-w, and then C-y, I can only paste in the open instance of Emacs. If I navigate to another Emacs window or outside of Emacs, Crtl + v does nothing or paste something I copied that wasn't in Emacs.

I am looking for a solution the updates the init lisp script (~/.emacs). I don't want to switch programs. As of now, I have this in my .emacs but it doesn't seem to do the trick.

;; Copy and paste between Emac instances                                          
(setq x-select-enable-clipboard t)
(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
share|improve this question

4 Answers 4

up vote 3 down vote accepted

If you aren't running emacs in X mode, then it doesn't have access to the X clipboard, so you can't copy/paste with other X apps. You will have to use the copy/paste function of your xterm instead.

To copy/paste between different emacs sessions, the emacs way is to not run multiple sessions. Instead you can open frames on different terminals that are all bound to the same session, so they share the same kill ring. You do this by using M-x server-start in the main instance, then use emacsclient -t to open a new frame in another terminal.

share|improve this answer
    
can I set the server start in the ~/.eacs? –  dustin Apr 16 '13 at 14:28
    
@dustin, yes.... –  psusi Apr 16 '13 at 14:31
    
Do you know the lisp command for it? –  dustin Apr 16 '13 at 14:35
2  
@dustin, (server-start) of course. –  psusi Apr 16 '13 at 14:38
    
this may be a long shot but is there a way to setup an alias for emacs ~/path/to/file so it is recognized as emacsclient - t? Maybe something like alias emacs='emacsclient -t' but then that would override my alias emacs='emacs -nw' –  dustin Apr 16 '13 at 14:44

You can use the Edit tab to use the mouse for it (at least in XEmacs, haven't used GNU Emaccs in quite a while).

share|improve this answer
1  
I do all my programming and tex from the terminal so that won't work for me. –  dustin Apr 16 '13 at 11:48
    
Use X... I'm no GUI guy, it is just a convenient way of having a lot of terminals around, and have a preview on LaTeX nearby.. –  vonbrand Apr 16 '13 at 11:57
1  
I don't plan on switching I am looking for a solution for emacs. –  dustin Apr 16 '13 at 13:41
    
No, you don't want to use the mouse, and it is not the Emacs kill ring anyway. –  Emanuel Berg Apr 16 '13 at 23:07

I'm not an emacs user, but if you work outside of a GUI environment you can use the general purpose mouse (gpm) daemon on linux and I would guess some other *nixes. Most distros have it available as a package, so all you need to do is install it and start the service.

You can cut and paste in a VC this way with a mouse (I think button 1 is select, button 2 is paste -- there is no popup menu; this takes a bit of getting used to). You can, in fact, copy and paste across VC's. It works with complex ncurses apps akin to emacs such as vim.

share|improve this answer
    
My take is that 99% of the "outside of a GUI" people will not wish to use the mouse. –  Emanuel Berg Apr 16 '13 at 23:04
    
There is no other option if you want to copy/paste between applications, because without gpm there is no buffer to use. Judging from the OP's selected answer though, what s/he really wanted was to just share selections between emacs instances. –  goldilocks Apr 17 '13 at 10:45
    
Check out this question on GNU readline, and especially the answer by @jordanm - what we need is a global kill ring, for all the Linux VTs; for xterm, urxvt, etc., launched in X; and for Emacs. –  Emanuel Berg Apr 18 '13 at 14:42

To get access to the actual Emacs kill ring, I don't know, but if you find out, please tell us, and I'd be very appreciative. But there are some other things I know of that might help you.

It is not true that you can't access the X clipboard in the Linux VT/tty/console.

Check out those aliases, as they are shown when I use where in zsh:

xi: aliased to xclip -d ":0" -selection clipboard
xo: aliased to xclip -d ":0" -selection clipboard -o

I also put the xo part into a script (called pst), so as to paste from X to Emacs.

#!/bin/zsh

CLIP=`xclip -d ":0" -o -selection clipboard`
CLIP_LEN=`echo -n $CLIP | wc -c`
echo "(set-variable '*clip-len* $CLIP_LEN)" > ~/.clip_len
echo -n $CLIP

Then, in Emacs:

;; clipboard
(setq *clip-len* 0)

(defun pst ()
  "Inserts the X clipboard (xclip -d ':0' -o -selection clipboard)
at point. `M-1' (the '(1)) to insert in the current buffer."
  (interactive)
  (shell-command "/home/user_name/scripts/pst" '(1))
  (load-file "/home/user_name/.clip_len")
  (forward-char *clip-len*) )

Now, to get Emacs-Emacs communication (and I agree several instances is not optimal), if they share access to a file, how about using it by setting up functions like:

(defun write-to-file-clipboard ()
  "Write the region to `~/.fclipboard.txt'"
  (interactive)
  (write-region (region-beginning) (region-end) "~/.fclipboard.txt") )

Then, do a similar for append-to-file, insert-file, etc., and then setup shortcuts and/or (Emacs) aliases for fast access.

This is of course not the Emacs kill ring but at least I found them very useful as a "next best" thing.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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