]> code.delx.au - gnu-emacs/blobdiff - lisp/emulation/cua-base.el
Add 2010 to copyright years.
[gnu-emacs] / lisp / emulation / cua-base.el
index de2cfe499f0e97fab95e08d34fb26b5421d01988..57ea683a1ff0878492dee630c5aba96a65c77046 100644 (file)
@@ -1,17 +1,17 @@
 ;;; cua-base.el --- emulate CUA key bindings
 
 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Kim F. Storm <storm@cua.dk>
 ;; Keywords: keyboard emulation convenience cua
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 
 ;;; Commentary:
@@ -65,7 +63,7 @@
 ;; - press the prefix key and the following key within 0.2 seconds, or
 ;; - use the SHIFT key with the prefix key, i.e. C-X or C-C
 ;;
-;; This behaviour can be customized via the
+;; This behavior can be customized via the
 ;; cua-prefix-override-inhibit-delay variable.
 
 ;; In addition to using the shifted movement keys, you can also use
@@ -282,6 +280,17 @@ enabled."
                 (other :tag "Enabled" t))
   :group 'cua)
 
+(defcustom cua-remap-control-v t
+  "*If non-nil, C-v binding is used for paste (yank).
+Also, M-v is mapped to `cua-repeat-replace-region'."
+  :type 'boolean
+  :group 'cua)
+
+(defcustom cua-remap-control-z t
+  "*If non-nil, C-z binding is used for undo."
+  :type 'boolean
+  :group 'cua)
+
 (defcustom cua-highlight-region-shift-only nil
   "*If non-nil, only highlight region if marked with S-<move>.
 When this is non-nil, CUA toggles `transient-mark-mode' on when the region
@@ -583,35 +592,37 @@ a cons (TYPE . COLOR), then both properties are affected."
 
 ;;; Rectangle support is in cua-rect.el
 
-(autoload 'cua-set-rectangle-mark "cua-rect" nil t nil)
+(autoload 'cua-set-rectangle-mark "cua-rect"
+  "Start rectangle at mouse click position." t nil)
 
 ;; Stub definitions until it is loaded
-
-(when (not (featurep 'cua-rect))
-  (defvar cua--rectangle)
-  (setq cua--rectangle nil)
-  (defvar cua--last-killed-rectangle)
-  (setq cua--last-killed-rectangle nil))
-
-
+(defvar cua--rectangle)
+(defvar cua--last-killed-rectangle)
+(unless (featurep 'cua-rect)
+  (setq cua--rectangle nil
+        cua--last-killed-rectangle nil))
+
+;; All behind cua--rectangle tests.
+(declare-function cua-copy-rectangle    "cua-rect" (arg))
+(declare-function cua-cut-rectangle     "cua-rect" (arg))
+(declare-function cua--rectangle-left   "cua-rect" (&optional val))
+(declare-function cua--delete-rectangle "cua-rect" ())
+(declare-function cua--insert-rectangle "cua-rect"
+                  (rect &optional below paste-column line-count))
+(declare-function cua--rectangle-corner "cua-rect" (&optional advance))
+(declare-function cua--rectangle-assert "cua-rect" ())
 
 ;;; Global Mark support is in cua-gmrk.el
 
 (autoload 'cua-toggle-global-mark "cua-gmrk" nil t nil)
 
 ;; Stub definitions until cua-gmrk.el is loaded
-
-(when (not (featurep 'cua-gmrk))
-  (defvar cua--global-mark-active)
+(defvar cua--global-mark-active)
+(unless (featurep 'cua-gmrk)
   (setq cua--global-mark-active nil))
 
-
-(provide 'cua-base)
-
-(eval-when-compile
-  (require 'cua-rect)
-  (require 'cua-gmrk)
-  )
+(declare-function cua--insert-at-global-mark    "cua-gmrk" (str &optional msg))
+(declare-function cua--global-mark-post-command "cua-gmrk" ())
 
 
 ;;; Low-level Interface
@@ -874,7 +885,7 @@ With numeric prefix arg, copy to register 0-9 instead."
   (if (fboundp 'cua--cancel-rectangle)
       (cua--cancel-rectangle)))
 
-(declare-function x-clipboard-yank "term/x-win" ())
+(declare-function x-clipboard-yank "../term/x-win" ())
 
 (defun cua-paste (arg)
   "Paste last cut or copied region or rectangle.
@@ -896,7 +907,7 @@ If global mark is active, copy from register or one character."
          (cua--insert-at-global-mark (filter-buffer-substring (point) (+ (point) count)))
          (forward-char count))))
      (buffer-read-only
-      (message "Cannot paste into a read-only buffer"))
+      (error "Cannot paste into a read-only buffer"))
      (t
       ;; Must save register here, since delete may override reg 0.
       (if mark-active
@@ -920,6 +931,7 @@ If global mark is active, copy from register or one character."
       (cond
        (regtxt
        (cond
+        ;; This being a cons implies cua-rect is loaded?
         ((consp regtxt) (cua--insert-rectangle regtxt))
         ((stringp regtxt) (insert-for-yank regtxt))
         (t (message "Unknown data in register %c" cua--register))))
@@ -1139,6 +1151,7 @@ If ARG is the atom `-', scroll downward by nearly full screen."
       (end-of-buffer (goto-char (point-max)))))))
 
 (put 'cua-scroll-up 'CUA 'move)
+(put 'cua-scroll-up 'isearch-scroll t)
 
 (defun cua-scroll-down (&optional arg)
   "Scroll text of current window downward ARG lines; or near full screen if no ARG.
@@ -1159,6 +1172,7 @@ If ARG is the atom `-', scroll upward by nearly full screen."
       (beginning-of-buffer (goto-char (point-min)))))))
 
 (put 'cua-scroll-down 'CUA 'move)
+(put 'cua-scroll-down 'isearch-scroll t)
 
 ;;; Cursor indications
 
@@ -1182,8 +1196,8 @@ If ARG is the atom `-', scroll upward by nearly full screen."
        (set-cursor-color color))
     (if (and type
             (symbolp type)
-            (not (eq type default-cursor-type)))
-       (setq default-cursor-type type))))
+            (not (eq type (default-value 'cursor-type))))
+       (setq-default cursor-type type))))
 
 
 ;;; Pre-command hook
@@ -1429,24 +1443,21 @@ If ARG is the atom `-', scroll upward by nearly full screen."
 
   (define-key cua--cua-keys-keymap [(control x) timeout] 'kill-region)
   (define-key cua--cua-keys-keymap [(control c) timeout] 'copy-region-as-kill)
-  (define-key cua--cua-keys-keymap [(control z)] 'undo)
-  (define-key cua--cua-keys-keymap [(control v)] 'yank)
-  (define-key cua--cua-keys-keymap [(meta v)] 'cua-repeat-replace-region)
+  (when cua-remap-control-z
+    (define-key cua--cua-keys-keymap [(control z)] 'undo))
+  (when cua-remap-control-v
+    (define-key cua--cua-keys-keymap [(control v)] 'yank)
+    (define-key cua--cua-keys-keymap [(meta v)] 'cua-repeat-replace-region))
   (define-key cua--cua-keys-keymap [remap exchange-point-and-mark] 'cua-exchange-point-and-mark)
 
   (define-key cua--prefix-override-keymap [(control x)] 'cua--prefix-override-handler)
   (define-key cua--prefix-override-keymap [(control c)] 'cua--prefix-override-handler)
 
   (define-key cua--prefix-repeat-keymap [(control x) (control x)] 'cua--prefix-repeat-handler)
-  (define-key cua--prefix-repeat-keymap [(control x) up]    'cua--prefix-cut-handler)
-  (define-key cua--prefix-repeat-keymap [(control x) down]  'cua--prefix-cut-handler)
-  (define-key cua--prefix-repeat-keymap [(control x) left]  'cua--prefix-cut-handler)
-  (define-key cua--prefix-repeat-keymap [(control x) right] 'cua--prefix-cut-handler)
   (define-key cua--prefix-repeat-keymap [(control c) (control c)] 'cua--prefix-repeat-handler)
-  (define-key cua--prefix-repeat-keymap [(control c) up]    'cua--prefix-copy-handler)
-  (define-key cua--prefix-repeat-keymap [(control c) down]  'cua--prefix-copy-handler)
-  (define-key cua--prefix-repeat-keymap [(control c) left]  'cua--prefix-copy-handler)
-  (define-key cua--prefix-repeat-keymap [(control c) right] 'cua--prefix-copy-handler)
+  (dolist (key '(up down left right home end next prior))
+    (define-key cua--prefix-repeat-keymap (vector '(control x) key) 'cua--prefix-cut-handler)
+    (define-key cua--prefix-repeat-keymap (vector '(control c) key) 'cua--prefix-copy-handler))
 
   ;; Enable shifted fallbacks for C-x and C-c when region is active
   (define-key cua--region-keymap [(shift control x)] 'cua--shift-control-x-prefix)
@@ -1484,6 +1495,7 @@ If ARG is the atom `-', scroll upward by nearly full screen."
    next-line previous-line
    forward-word backward-word
    end-of-line beginning-of-line
+   end-of-visual-line beginning-of-visual-line
    move-end-of-line move-beginning-of-line
    end-of-buffer beginning-of-buffer
    scroll-up scroll-down
@@ -1492,7 +1504,12 @@ If ARG is the atom `-', scroll upward by nearly full screen."
    forward-sexp backward-sexp
    forward-list backward-list
    forward-sentence backward-sentence
-   forward-paragraph backward-paragraph))
+   forward-paragraph backward-paragraph
+   ;; CC mode motion commands
+   c-forward-conditional c-backward-conditional
+   c-down-conditional c-up-conditional
+   c-down-conditional-with-else c-up-conditional-with-else
+   c-beginning-of-statement c-end-of-statement))
   (put cmd 'CUA 'move))
 
 ;; State prior to enabling cua-mode
@@ -1534,6 +1551,7 @@ shifted movement key, set `cua-highlight-region-shift-only'."
   :global t
   :group 'cua
   :set-after '(cua-enable-modeline-indications
+              cua-remap-control-v cua-remap-control-z
               cua-rectangle-mark-key cua-rectangle-modifier-key)
   :require 'cua-base
   :link '(emacs-commentary-link "cua-base.el")
@@ -1567,12 +1585,14 @@ shifted movement key, set `cua-highlight-region-shift-only'."
          (list
           transient-mark-mode
           (and (boundp 'delete-selection-mode) delete-selection-mode)
-          (and (boundp 'pc-selection-mode) pc-selection-mode)))
+          (and (boundp 'pc-selection-mode) pc-selection-mode)
+          shift-select-mode))
     (if (and (boundp 'delete-selection-mode) delete-selection-mode)
        (delete-selection-mode -1))
     (if (and (boundp 'pc-selection-mode) pc-selection-mode)
        (pc-selection-mode -1))
     (cua--deactivate)
+    (setq shift-select-mode nil)
     (setq transient-mark-mode (and cua-mode
                                   (if cua-highlight-region-shift-only
                                       (not cua--explicit-region-start)
@@ -1583,7 +1603,8 @@ shifted movement key, set `cua-highlight-region-shift-only'."
        (delete-selection-mode 1))
     (if (nth 2 cua--saved-state)
        (pc-selection-mode 1))
-    (if (interactive-p)
+    (setq shift-select-mode (nth 3 cua--saved-state))
+    (if (called-interactively-p 'interactive)
        (message "CUA mode disabled.%s%s%s%s"
                 (if (nth 1 cua--saved-state) " Delete-Selection" "")
                 (if (and (nth 1 cua--saved-state) (nth 2 cua--saved-state)) " and" "")
@@ -1606,7 +1627,7 @@ shifted movement key, set `cua-highlight-region-shift-only'."
   (setq cua--debug (not cua--debug)))
 
 
-(provide 'cua)
+(provide 'cua-base)
 
-;;; arch-tag: 21fb6289-ba25-4fee-bfdc-f9fb351acf05
+;; arch-tag: 21fb6289-ba25-4fee-bfdc-f9fb351acf05
 ;;; cua-base.el ends here