[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Change behaviour of Copy/Cut/Paste from the menu bar.
From: |
Jan D. |
Subject: |
Change behaviour of Copy/Cut/Paste from the menu bar. |
Date: |
Tue, 20 Jan 2004 16:11:19 +0100 (CET) |
Hello
As has been pointed out, Emacs does not "behave" w.r.t. the CLIPBOARD
and other newer X applications. Basically, the guideline in
http://freedesktop.org/Standards/clipboards-spec/clipboards.txt says:
When selecting with the mouse -> Save to PRIMARY (Emacs does that).
When using keys/menus (which in Emacs case would be just menus):
Copy -> Save to CLIPBOARD
Cut -> Save to CLIPBOARD
Paste -> Paste from CLIPBOARD
Now, if menu-bar-enable-clipboard is called we are almost there,
except for the Paste thing. Emacs always pastes from the kill ring,
even if there is a CLIPBOARD selection. So I suggest that we modify
lisp/term/x-term.el as below. My question is if this is OK, and how
does the other ports (W32, Mac) handle Paste from the menu? Is it
always from the clipboard, or from the kill-ring?
Thanks,
Jan D.
Index: lisp/term/x-win.el
*** lisp/term/x-win.el.~1.166.~ 2003-09-01 17:45:36.000000000 +0200
--- lisp/term/x-win.el 2004-01-20 16:05:17.000000000 +0100
***************
*** 2385,2396 ****
;; generated from FONT.
(create-fontset-from-ascii-font font resolved-name "startup"))))
- ;; Sun expects the menu bar cut and paste commands to use the clipboard.
- ;; This has ,? to match both on Sunos and on Solaris.
- (if (string-match "Sun Microsystems,? Inc\\."
- (x-server-vendor))
- (menu-bar-enable-clipboard))
-
;; Apply a geometry resource to the initial frame. Put it at the end
;; of the alist, so that anything specified on the command line takes
;; precedence.
--- 2385,2390 ----
***************
*** 2456,2460 ****
--- 2450,2470 ----
;; Turn on support for mouse wheels.
(mouse-wheel-mode 1)
+ ;; Enable CLIPBOARD copy/paste through menu bar commands.
+ (menu-bar-enable-clipboard)
+
+ ;; Override Paste so it looks at CLIPBOARD first.
+ (defun x-clipboard-yank ()
+ "Insert the clipboard contents, or the last stretch of killed text."
+ (interactive)
+ (let ((clipboard-text (x-get-selection 'CLIPBOARD))
+ (x-select-enable-clipboard t))
+ (if (and clipboard-text (> (length clipboard-text) 0))
+ (kill-new clipboard-text))
+ (yank)))
+
+ (define-key menu-bar-edit-menu [paste]
+ (cons "Paste" (cons "Paste text from clipboard" 'x-clipboard-yank)))
+
;;; arch-tag: f1501302-db8b-4d95-88e3-116697d89f78
;;; x-win.el ends here
- Change behaviour of Copy/Cut/Paste from the menu bar.,
Jan D. <=