;;; cua-base.el --- emulate CUA key bindings
;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006 Free Software Foundation, Inc.
+;; 2005, 2006, 2007 Free Software Foundation, Inc.
;; Author: Kim F. Storm <storm@cua.dk>
;; Keywords: keyboard emulation convenience cua
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
(defcustom cua-paste-pop-rotate-temporarily nil
"*If non-nil, \\[cua-paste-pop] only rotates the kill-ring temporarily.
-This means that \\[cua-paste] always inserts the most recent kill, while one or
-more \\[cua-paste-pop]'s immediately following it will replace the previous text
-with the next older element on the `kill-ring'. If \\[cua-paste-pop] is used after
-any other command, it will insert the same element from the `kill-ring' as last
-time it was used."
+This means that both \\[yank] and the first \\[yank-pop] in a sequence always insert
+the most recently killed text. Each immediately following \\[cua-paste-pop] replaces
+the previous text with the next older element on the `kill-ring'.
+With prefix arg, \\[universal-argument] \\[yank-pop] inserts the same text as the most
+recent \\[yank-pop] (or \\[yank]) command."
:type 'boolean
:group 'cua)
(other :tag "Enabled" t))
:group 'cua)
+(defvar cua-global-keymap) ; forward
+(defvar cua--region-keymap) ; forward
+
(defcustom cua-rectangle-mark-key [(control return)]
"Global key used to toggle the cua rectangle mark."
:set #'(lambda (symbol value)
(t
;; Must save register here, since delete may override reg 0.
(if mark-active
- ;; Before a yank command, make sure we don't yank
- ;; the same region that we are going to delete.
- ;; That would make yank a no-op.
(if cua--rectangle
(progn
(goto-char (min (mark) (point)))
(setq paste-lines (cua--delete-rectangle))
(if (= paste-lines 1)
(setq paste-lines nil))) ;; paste all
- (if (string= (filter-buffer-substring (point) (mark))
- (car kill-ring))
+ ;; Before a yank command, make sure we don't yank the
+ ;; head of the kill-ring that really comes from the
+ ;; currently active region we are going to delete
+ ;; (when last-command is one that uses copy-region-as-kill
+ ;; or kill-new). That would make yank a no-op.
+ (if (and (string= (filter-buffer-substring (point) (mark))
+ (car kill-ring))
+ (memq last-command
+ '(mouse-set-region mouse-drag-region
+ mouse-save-then-kill mouse-secondary-save-then-kill)))
(current-kill 1))
(cua-delete-region)))
(cond
(if arg (goto-char pt))))
((eq this-original-command 'clipboard-yank)
(clipboard-yank))
+ ((eq this-original-command 'x-clipboard-yank)
+ (x-clipboard-yank))
(t (yank arg)))))))
;; C-y M-y M-y => only rotates kill ring temporarily,
;; so next C-y yanks what previous C-y yanked,
;;
-;; But: After another command, M-y remembers the temporary
+;; M-y M-y M-y => equivalent to C-y M-y M-y
+;;
+;; But: After another command, C-u M-y remembers the temporary
;; kill-ring position, so
-;; M-y => yanks what the last M-y yanked
+;; C-u M-y => yanks what the last M-y yanked
;;
(defvar cua-paste-pop-count nil)
(setq cua-paste-pop-count rotate)
(setq last-command 'yank)
(yank-pop cua-paste-pop-count))
- ((eq last-command 'cua-paste-pop)
- (unless (consp arg)
- (setq cua-paste-pop-count (+ cua-paste-pop-count rotate)))
+ ((and (eq last-command 'cua-paste-pop) (not (consp arg)))
+ (setq cua-paste-pop-count (+ cua-paste-pop-count rotate))
(setq last-command 'yank)
(yank-pop cua-paste-pop-count))
(t
- (setq cua-paste-pop-count (+ cua-paste-pop-count rotate -1))
+ (setq cua-paste-pop-count
+ (if (consp arg) (+ cua-paste-pop-count rotate -1) 1))
(yank (1+ cua-paste-pop-count)))))
;; Undo rotating the kill-ring, so next C-y will
;; yank the original head.
- (unless (consp arg)
- (setq kill-ring-yank-pointer kill-ring))
+ (setq kill-ring-yank-pointer kill-ring)
(setq this-command 'cua-paste-pop))))
(defun cua-exchange-point-and-mark (arg)
(memq 'shift (event-modifiers
(aref (this-single-command-keys) 0)))
;; See if raw escape sequence maps to a shifted event, e.g. S-up or C-S-home.
- (and (boundp 'function-key-map)
- function-key-map
- (let ((ev (lookup-key function-key-map
+ (and (boundp 'local-function-key-map)
+ local-function-key-map
+ (let ((ev (lookup-key local-function-key-map
(this-single-command-raw-keys))))
(and (vector ev)
(symbolp (setq ev (aref ev 0)))
;; replace region with rectangle or element on kill ring
(define-key cua-global-keymap [remap yank] 'cua-paste)
(define-key cua-global-keymap [remap clipboard-yank] 'cua-paste)
+ (define-key cua-global-keymap [remap x-clipboard-yank] 'cua-paste)
;; replace current yank with previous kill ring element
(define-key cua-global-keymap [remap yank-pop] 'cua-paste-pop)
;; set mark