;;; cua-base.el --- emulate CUA key bindings
;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008 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
;; 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:
;; - 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
(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
(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
(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
""))
(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.
(beginning-of-buffer (goto-char (point-min)))))))
(put 'cua-scroll-down 'CUA 'move)
+(put 'cua-scroll-down 'isearch-scroll t)
;;; Cursor indications
(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
;; 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)
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
: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")
(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)
(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" "")
(provide 'cua-base)
-;;; arch-tag: 21fb6289-ba25-4fee-bfdc-f9fb351acf05
+;; arch-tag: 21fb6289-ba25-4fee-bfdc-f9fb351acf05
;;; cua-base.el ends here