jfritz42
jfritz42

Reputation: 5993

How to combine Emacs primary/clipboard copy and paste behavior on MS Windows?

Emacs 24 changed the way copy/paste behavior works to conform with modern X applications (See this article under "Selection changes"). They have explicitly separated primary selection and middle mouse button paste from clipboard copy/paste.

Unfortunately for me, using native (not cygwin!) Emacs 24.2.1 under MS Windows, this messes up the way I want to work.

Here is what I want:

  1. Highlighting (selecting) text in Emacs automatically copies it to the Windows clipboard. If I paste it (Ctrl-V) in another Windows app it pastes. If I type C-y (yank) in Emacs, it pastes. If I middle-click in Emacs, it pastes.
  2. Killing in Emacs (C-w) copies the data to the clipboard. If I paste it (Ctrl-V) in another Windows app it pastes. If I type C-y (yank) in Emacs, it pastes. If I middle-click in Emacs, it pastes the clipboard contents, not the last selected text.
  3. Anything I copied to the clipboard from another Windows app (e.g. via Ctrl-C), can be pasted in Emacs either by typing C-y (yank) or middle-clicking (right now, middle clicking pastes the last selected text, not the clipboard contents).

To summarize, I think this means removing the distinction between primary selections and the clipboard in Emacs. I want everything to act on the clipboard!

Upvotes: 15

Views: 10070

Answers (3)

JSON
JSON

Reputation: 4606

The following entries from NEWS seem pertinent:

  • mouse-drag-copy-region now defaults to nil.

  • mouse-2 is now bound to mouse-yank-primary.

This pastes from the primary selection, ignoring the kill-ring. Previously, mouse-2 was bound to mouse-yank-at-click.

  • To return to the previous behavior, do the following:

    • Change select-active-regions to nil.
    • Change mouse-drag-copy-region to t.
    • Change x-select-enable-primary to t (on X only).
    • Change x-select-enable-clipboard to nil.
    • Bind mouse-yank-at-click to mouse-2.

I think to get the previous behaviour on Windows, you need to leave both x-select-enable-primary and x-select-enable-clipboard at their current values, and maybe select-active-regions is not related to the change in behaviour you are complaining about here.


Here are the exact lines to put in your .emacs file:

(setq select-active-regions nil)
(setq mouse-drag-copy-region t)
(global-set-key [mouse-2] 'mouse-yank-at-click)

Upvotes: 22

Miserable Variable
Miserable Variable

Reputation: 28761

It seems dragging mouse does not do anything with the clipboard. The following adds that, but I don't know what it does to point and mark:

(defadvice mouse-drag-region (after copy-to-clipboard activate)
  (clipboard-kill-ring-save (region-beginning) (region-end))
  (goto-char st) (push-mark nd nil t)
  )

Upvotes: 1

PascalVKooten
PascalVKooten

Reputation: 21461

  • As far as I can tell, point 2 and 3 already work "out-of-the-box"?
  • Also, I take it that you are not interested in having a history (like a kill-ring) available?
  • Do you mean with highlighting "selecting it" (in emacs known as the region), or actually highlighting it (giving it a color, like say, yellow)?

If you mean selecting it, I think the problem is that Emacs would not know when your selecting ends, and thus has to copy it to clipboard? That's why you would use Meta-W (Alt-Shift-w) which copies it to the kill-ring, accessible outside of Emacs.

(I posted this here since I think the comments are confusing, but I will remove or change this answer later on)

I think you will find all the information you need in mouse.el:

To get there, try: C-hkany mouse button and click on mouse.el to find out where it is defined. If you look for some more "global-set-key" within the file you might find exactly what you are looking for (I'm still not a 100% sure on this)

Upvotes: 0

Related Questions