]> code.delx.au - gnu-emacs/blobdiff - lisp/emulation/cua-base.el
* lisp/url/url-http.el (url-http-create-request): Use url-http-proxy to
[gnu-emacs] / lisp / emulation / cua-base.el
index 08f667b8254e9d1ab02110f546c1cc059117ec50..6b9ae35141cc6287cc3959065e122743fb31266f 100644 (file)
@@ -1,7 +1,6 @@
 ;;; cua-base.el --- emulate CUA key bindings
 
-;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008, 2009, 2010, 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
@@ -85,7 +84,7 @@
 
 ;; 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.
 ;; [C-d] Moves (i.e. deletes and inserts) a single character to the
 ;;       global mark.
 ;; [backspace] deletes the character before the global mark, while
-;; [delete] deltes the character after the global mark.
+;; [delete] deletes the character after the global mark.
 
 ;; [S-C-space] Jumps to and cancels the global mark.
 ;; [C-u S-C-space] Cancels the global mark (stays in current buffer).
@@ -369,7 +368,7 @@ interpreted as a register number."
 
 (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)
@@ -464,7 +463,7 @@ Must be set prior to enabling 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)
 
@@ -1003,15 +1002,21 @@ behavior, see `cua-paste-pop-rotate-temporarily'."
     (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)
@@ -1122,7 +1127,7 @@ With a double \\[universal-argument] prefix argument, unconditionally set mark."
        (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)
@@ -1243,26 +1248,11 @@ If ARG is the atom `-', scroll upward by nearly full screen."
 
    ;; 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)
@@ -1479,6 +1469,7 @@ If ARG is the atom `-', scroll upward by nearly full screen."
   (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)
@@ -1519,6 +1510,9 @@ If ARG is the atom `-', scroll upward by nearly full screen."
    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
@@ -1529,16 +1523,17 @@ If ARG is the atom `-', scroll upward by nearly full screen."
 
 ;;;###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
@@ -1625,7 +1620,11 @@ shifted movement key, set `cua-highlight-region-shift-only'."
   "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 ()