Pasting with mouse-select in GNU Emacs

860 Views Asked by At

There is an functionality in XEmacs that if the user selects a region with the mouse while holding Ctrl, the selected region will be automatically pasted at the current cursor position.

In other words, if you need to quickly copy a short block of text from some open buffer to a new spot, you put the cursor there, and then do Ctrl-mouse-select and it works.

Unfortunately, I recently had to switch from XEmacs to GNU Emacs, and I'm looking to see if there is similar functionality there, or perhaps I could provide it with a custom module (I am very bad at Lisp, unfortunately).

3

There are 3 best solutions below

3
On BEST ANSWER

You sure can, the functionality is bound to mouse button 3 if I'm not mistaken. I assume so, because clicking my mousewheel yanks what I've copied at the cursor.

And Mousewheel == mouse button 3 in most cases.

  1. Select using your mouse
  2. With your mouse button down, hit control
  3. Release your mouse button
  4. Hit mouse button 3
  5. Profit - selection yanked at your cursor

edit:

I found this on http://www.gnu.org/software/emacs/manual/html_node/emacs/Mouse-Commands.html

  • Mouse-1

    Move point to where you click (mouse-set-point).

  • Drag-Mouse-1

    Activate the region around the text selected by dragging, and copy it to the kill ring (mouse-set-region).

  • Mouse-2

    Yank the last killed text at the click position (mouse-yank-at-click).

  • Mouse-3

    If the region is active, move the nearer end of the region to the click position; otherwise, set mark at the current value of point and point at the click position. Save the resulting region in the kill ring; on a second click, kill it (mouse-save-then-kill).

2
On

You might want to use mouse-copy.el which comes with Emacs.

1
On

Put the following in your init file (.emacs):

(require 'mouse-copy)
(global-set-key [C-down-mouse-1] 'mouse-drag-secondary-pasting)

Once you restart Emacs, it should work just like you're used to in XEmacs--hold down Ctrl and the left mouse button, select your text, and when you release the mouse the text will be inserted at your current cursor position.