]> code.delx.au - gnu-emacs/blobdiff - lisp/emulation/cua-base.el
* cua-base.el, cua-gmrk.el: Fix use of `filter-buffer-substring'.
[gnu-emacs] / lisp / emulation / cua-base.el
index 1f6967888694ef1407d4303e78b11fb498e463c7..d8b36adf730591f06fb8bb79831546808a2ddf1c 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
@@ -898,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
@@ -1031,7 +1040,9 @@ of text."
                  (setq s (car u) e (cdr u)))))))
          (cond ((and s e (<= s e) (= s (mark t)))
                 (setq cua--repeat-replace-text
-                      (filter-buffer-substring s e nil t)))
+                      (filter-buffer-substring s e))
+                (set-text-properties 0 (length cua--repeat-replace-text)
+                                     nil cua--repeat-replace-text))
                ((and (null s) (eq u elt)) ;; nothing inserted
                 (setq cua--repeat-replace-text
                       ""))
@@ -1142,6 +1153,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.
@@ -1162,6 +1174,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
 
@@ -1185,8 +1198,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,27 +1442,26 @@ If ARG is the atom `-', scroll upward by nearly full screen."
   ;; scrolling
   (define-key cua-global-keymap [remap scroll-up]      'cua-scroll-up)
   (define-key cua-global-keymap [remap scroll-down]    'cua-scroll-down)
+  (define-key cua-global-keymap [remap scroll-up-command]   'cua-scroll-up)
+  (define-key cua-global-keymap [remap scroll-down-command] 'cua-scroll-down)
 
   (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)
@@ -1487,15 +1499,22 @@ 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
+   scroll-up-command scroll-down-command
    up-list down-list backward-up-list
    end-of-defun beginning-of-defun
    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
@@ -1537,6 +1556,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")
@@ -1570,12 +1590,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)
@@ -1586,7 +1608,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" "")
@@ -1611,5 +1634,5 @@ shifted movement key, set `cua-highlight-region-shift-only'."
 
 (provide 'cua-base)
 
-;;; arch-tag: 21fb6289-ba25-4fee-bfdc-f9fb351acf05
+;; arch-tag: 21fb6289-ba25-4fee-bfdc-f9fb351acf05
 ;;; cua-base.el ends here