Help with cut and paste in emacs

Discussion of programming Lisps using Emacs, including SLIME and other tools
Post Reply
joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Help with cut and paste in emacs

Post by joeish80829 » Tue Nov 12, 2013 10:33 am

Im on Ubuntu Saucy. In emacs when i select text then copy with C-c (added (cua-mode t) to .emacs) it saves what i copied to the clipboard so when i press C-v (again (cua-mode t)) to paste it, it pastes what i copied correctly....but after copying with C-c if i press the paste toolbar button it pastes the last thing i copied with the copy toolbar button instead of what i just selected and copied with C-c. How do i change this so no matter how i paste, C-v or paste toolbar button , the last thing i copied, using either C-c or the copy toolbar button gets pasted. Thx in advance for any guidance on this :)

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Help with cut and paste in emacs

Post by Goheeca » Tue Nov 12, 2013 1:09 pm

Which version have you used? It works for me regardless if cua-mode is turned on or off.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Re: Help with cut and paste in emacs

Post by joeish80829 » Tue Nov 12, 2013 1:24 pm

i use GNU Emacs 23.4.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.18) on Ubuntu Saucy with SLIME/SBCL/QUICKLISP
thanks for getting back to me btw

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Help with cut and paste in emacs

Post by edgar-rft » Sat Nov 16, 2013 5:00 am

Add the following line to your .emacs file and try if it works:

Code: Select all

(setq x-select-enable-clipboard t)
C-h v x-select-enable-clipboard wrote:x-select-enable-clipboard is a variable defined in `x-win.el'.

Non-nil means cutting and pasting uses the clipboard.
This is in addition to, but in preference to, the primary selection.
The toolbar buttons by default use the Emacs kill-ring, while cua-mode by default uses the X clipboard to store text. Setting x-select-enable-clipboard to a non-NIL value should make both using the X clipboard.
  • Text in the X clipboard can be exchanged with other applications (if you copy text from Firefox you can paste it into an Emacs buffer), but the X clipboard can hold only one text item at a time.
  • The Emacs kill-ring can hold an arbitrary number of text items (that's why it is called a "ring"), but the text from the Emacs kill-ring cannot be exchanged with other applications. The Emacs kill-ring is always available via Ctrl-w (cut), Alt-w (copy), and Ctrl-y (paste). Ctrl-w (cut) and Alt-w (copy) both add text items to the kill ring. You can choose which text item to insert by pressing Alt-y after the first Ctrl-y (paste).
  • If you mark some text while pressing the left mouse button, the text gets highlighted, and if you then release the left moust button, the text is automatically stored in the primary X selection (another text buffer of the X window system). You can paste the text from the primary X selection by pressing the middle mouse button. The primary X selection can hold only one text item at a time.
- edgar

joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Re: Help with cut and paste in emacs

Post by joeish80829 » Sun Nov 17, 2013 8:00 am

Thank you very very much your suggestion worked, pressing C-h-v to access the variable you suggested, and change it made my emacs setup even easier to use.....You are very kind to take the time to teach me that=)

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Help with cut and paste in emacs

Post by edgar-rft » Sun Nov 17, 2013 11:29 am

Copying and pasting text from one window into another under Linux is a mess. The full story can be found in Wikipedia under X Window selection. Today it's only important to know that there are two ways to copy text. Most programs today use the clipboard, but if that doesn't work, try copying the text with the mouse buttons.

If you type in Emacs one of these:
  • C-h a clipboard
  • M-x apropos RET clipboard
Then a buffer pops-up with all clipboard-related functions and variables. If you click in that buffer on a function or variable name with the left mouse button, then another buffer pops up with the documentation. That's how I found the x-select-enable-clipboard variable.

- edgar
Last edited by edgar-rft on Sun Nov 17, 2013 11:45 am, edited 1 time in total.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Help with cut and paste in emacs

Post by Goheeca » Sun Nov 17, 2013 11:43 am

The cua-mode uses the X clipboard, that's good to know. I didn't even assume this option. I'd already had installed script for joining emacs' kill-ring and the X clipboard so I couldn't replicate the situation.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Help with cut and paste in emacs

Post by edgar-rft » Sun Nov 17, 2013 12:00 pm

Goheeca wrote:The cua-mode uses the X clipboard, that's good to know...
That's no so easy to find out because Emacs' C-h k (describe-key) doesn't recognize cua's C-c as a valid stand-alone key sequence. Emacs' describe-key insisted me to type another letter because it thought that C-c was a prefix key. I had to read the cua-base.el code to see where C-c (cua-copy-region) stores the text.

And it was even worse: I have replaced most of the buttons in my Emacs toolbar with my own custom buttons, so I do not even have "copy" and "paste" buttons anymore. This then was another round of reading the toolbar.el code.

I think I was obviously bored...

- edgar

findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: Help with cut and paste in emacs

Post by findinglisp » Thu Nov 28, 2013 9:52 am

IMO, if you're going to use Emacs a lot, get used to the native command bindings and avoid CUA mode. Unfortunately, CUA mode conflicts with C-x and C-c which are the two major prefix keys. You couldn't pick two worse key bindings to conflict with if you tried. While CUA mode might be able to manage some of this, you'll always have other modes trying to bind things to one or other of those and virtually every piece of documentation will have to be reinterpreted. In short, don't make it hard on yourself; learn to use the native cut/copy/paste (C-w, M-w, C-y) keys and save yourself the hassle. That said, if you're on a Mac, you can use the Mac's native command key with Command-X, Command-C, and Command-V, without rebinding C-c/C-x. If you're on a PC platform (e.g., Windows or Linux), you're going to be stuck, though.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Post Reply