;;; cua-base.el --- emulate CUA key bindings
-;; Copyright (C) 1997-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1997-2012 Free Software Foundation, Inc.
;; Author: Kim F. Storm <storm@cua.dk>
;; Keywords: keyboard emulations convenience cua
;; If you have just replaced a highlighted region with typed text,
;; you can repeat the replace with M-v. This will search forward
-;; for a streach of text identical to the previous contents of the
+;; for a stretch of text identical to the previous contents of the
;; region (i.e. the contents of register 0) and replace it with the
;; text you typed to replace the original region. Repeating M-v will
;; replace the next matching region and so on.
;; CUA register support
;; --------------------
-;; Emacs' standard register support is also based on a separate set of
+;; Emacs's standard register support is also based on a separate set of
;; "register commands".
;;
;; CUA's register support is activated by providing a numeric
;; CUA rectangle support
;; ---------------------
-;; Emacs' normal rectangle support is based on interpreting the region
+;; Emacs's normal rectangle support is based on interpreting the region
;; between the mark and point as a "virtual rectangle", and using a
;; completely separate set of "rectangle commands" [C-x r ...] on the
;; region to copy, kill, fill a.s.o. the virtual rectangle.
(defcustom cua-check-pending-input t
"If non-nil, don't override prefix key if input pending.
-It is rumoured that `input-pending-p' is unreliable under some window
+It is rumored that `input-pending-p' is unreliable under some window
managers, so try setting this to nil, if prefix override doesn't work."
:type 'boolean
:group 'cua)
(defface cua-global-mark
'((((min-colors 88)(class color)) :foreground "black" :background "yellow1")
(((class color)) :foreground "black" :background "yellow")
- (t :bold t))
+ (t :weight bold))
"Font used by CUA for highlighting the global mark."
:group 'cua)
(setq this-command 'cua-paste-pop))))
(defun cua-exchange-point-and-mark (arg)
- "Exchanges point and mark, but don't activate the mark.
-Activates the mark if a prefix argument is given."
+ "Exchange point and mark.
+Don't activate the mark if `cua-enable-cua-keys' is non-nil.
+Otherwise, just activate the mark if a prefix ARG is given.
+
+See also `exchange-point-and-mark'."
(interactive "P")
- (if arg
- (setq mark-active t)
- (let (mark-active)
- (exchange-point-and-mark)
- (if cua--rectangle
- (cua--rectangle-corner 0)))))
+ (cond ((null cua-enable-cua-keys)
+ (exchange-point-and-mark arg))
+ (arg
+ (setq mark-active t))
+ (t
+ (let (mark-active)
+ (exchange-point-and-mark)
+ (if cua--rectangle
+ (cua--rectangle-corner 0))))))
;; Typed text that replaced the highlighted region.
(defvar cua--repeat-replace-text nil)
(pop-to-mark-command)))
((and cua-toggle-set-mark mark-active)
(cua--deactivate)
- (message "Mark Cleared"))
+ (message "Mark cleared"))
(t
(push-mark-command nil nil)
(setq cua--explicit-region-start t)
;; Handle shifted cursor keys and other movement commands.
;; If region is not active, region is activated if key is shifted.
- ;; If region is active, region is cancelled if key is unshifted
+ ;; If region is active, region is canceled if key is unshifted
;; (and region not started with C-SPC).
;; If rectangle is active, expand rectangle in specified direction and
;; ignore the movement.
- ((if window-system
- ;; Shortcut for window-system, assuming that input-decode-map is empty.
- (memq 'shift (event-modifiers
- (aref (this-single-command-raw-keys) 0)))
- (or
- ;; Check if the final key-sequence was shifted.
- (memq 'shift (event-modifiers
- (aref (this-single-command-keys) 0)))
- ;; If not, maybe the raw key-sequence was mapped by input-decode-map
- ;; to a shifted key (and then mapped down to its unshifted form).
- (let* ((keys (this-single-command-raw-keys))
- (ev (lookup-key input-decode-map keys)))
- (or (and (vector ev) (memq 'shift (event-modifiers (aref ev 0))))
- ;; Or maybe, the raw key-sequence was not an escape sequence
- ;; and was shifted (and then mapped down to its unshifted form).
- (memq 'shift (event-modifiers (aref keys 0)))))))
+ (this-command-keys-shift-translated
(unless mark-active
(push-mark-command nil t))
(setq cua--last-region-shifted t)
(define-key cua--region-keymap [remap backward-delete-char] 'cua-delete-region)
(define-key cua--region-keymap [remap backward-delete-char-untabify] 'cua-delete-region)
(define-key cua--region-keymap [remap delete-char] 'cua-delete-region)
+ (define-key cua--region-keymap [remap delete-forward-char] 'cua-delete-region)
;; kill region
(define-key cua--region-keymap [remap kill-region] 'cua-cut-region)
(define-key cua--region-keymap [remap clipboard-kill-region] 'cua-cut-region)
c-beginning-of-statement c-end-of-statement))
(put cmd 'CUA 'move))
+;; Only called if pc-selection-mode is t, which means pc-select is loaded.
+(declare-function pc-selection-mode "pc-select" (&optional arg))
+
;; State prior to enabling cua-mode
;; Value is a list with the following elements:
;; transient-mark-mode
;;;###autoload
(define-minor-mode cua-mode
- "Toggle CUA key-binding mode.
-When enabled, using shifted movement keys will activate the
-region (and highlight the region using `transient-mark-mode'),
-and typed text replaces the active selection.
-
-Also when enabled, you can use C-z, C-x, C-c, and C-v to undo,
-cut, copy, and paste in addition to the normal Emacs bindings.
-The C-x and C-c keys only do cut and copy when the region is
-active, so in most cases, they do not conflict with the normal
-function of these prefix keys.
+ "Toggle Common User Access style editing (CUA mode).
+With a prefix argument ARG, enable CUA mode if ARG is positive,
+and disable it otherwise. If called from Lisp, enable the mode
+if ARG is omitted or nil.
+
+CUA mode is a global minor mode. When enabled, typed text
+replaces the active selection, and you can use C-z, C-x, C-c, and
+C-v to undo, cut, copy, and paste in addition to the normal Emacs
+bindings. The C-x and C-c keys only do cut and copy when the
+region is active, so in most cases, they do not conflict with the
+normal function of these prefix keys.
If you really need to perform a command which starts with one of
the prefix keys even when the region is active, you have three
"Enable CUA selection mode without the C-z/C-x/C-c/C-v bindings."
(interactive "P")
(setq-default cua-enable-cua-keys nil)
- (cua-mode arg))
+ (if (not (called-interactively-p 'any))
+ (cua-mode arg)
+ ;; Use call-interactive to turn a nil prefix arg into `toggle'.
+ (call-interactively 'cua-mode)
+ (customize-mark-as-set 'cua-enable-cua-keys)))
(defun cua-debug ()