From 71477684db6d781a07edda5060a0530da3623d96 Mon Sep 17 00:00:00 2001 From: "Kim F. Storm" Date: Thu, 30 Oct 2014 15:19:49 -0400 Subject: Restore cua-delete-copy-to-register-0 and M-v command. * lisp/delsel.el (delete-selection-save-to-register) (delsel--replace-text-or-position): New vars. (delete-active-region): Use them. (delete-selection-repeat-replace-region): New command, moved from cua-base.el. * lisp/emulation/cua-base.el (cua--repeat-replace-text): Remove var. (cua-repeat-replace-region): Move command to delsel.el. (cua--init-keymaps): Update binding accordingly. (cua-mode): Set delete-selection-save-to-register. Fixes: debbugs:18886 --- lisp/emulation/cua-base.el | 54 +++++++++------------------------------------- 1 file changed, 10 insertions(+), 44 deletions(-) (limited to 'lisp/emulation') diff --git a/lisp/emulation/cua-base.el b/lisp/emulation/cua-base.el index 96c9ba1e095..c57188338ce 100644 --- a/lisp/emulation/cua-base.el +++ b/lisp/emulation/cua-base.el @@ -277,7 +277,7 @@ enabled." (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'." +Also, M-v is mapped to `delete-selection-repeat-replace-region'." :type 'boolean :group 'cua) @@ -350,6 +350,8 @@ interpreted as a register number." :group 'cua) (defcustom cua-delete-copy-to-register-0 t + ;; FIXME: Obey delete-selection-save-to-register rather than hardcoding + ;; register 0. "If non-nil, save last deleted region or rectangle to register 0." :type 'boolean :group 'cua) @@ -958,48 +960,8 @@ See also `exchange-point-and-mark'." (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) - -(defun cua-repeat-replace-region (arg) - "Repeat replacing text of highlighted region with typed text. -Searches for the next stretch of text identical to the region last -replaced by typing text over it and replaces it with the same stretch -of text." - (interactive "P") - (when cua--last-deleted-region-pos - (with-current-buffer (car cua--last-deleted-region-pos) - (save-restriction - (widen) - ;; Find the text that replaced the region via the undo list. - (let ((ul buffer-undo-list) - (elt (cdr cua--last-deleted-region-pos)) - u s e) - (when elt - (while (consp ul) - (setq u (car ul) ul (cdr ul)) - (cond - ((eq u elt) ;; got it - (setq ul nil)) - ((and (consp u) (integerp (car u)) (integerp (cdr u))) - (if (and s (= (cdr u) s)) - (setq s (car u)) - (setq s (car u) e (cdr u))))))) - (cond ((and s e (<= s e) (= s (mark t))) - (setq cua--repeat-replace-text (cua--filter-buffer-noprops s e))) - ((and (null s) (eq u elt)) ;; nothing inserted - (setq cua--repeat-replace-text - "")) - (t - (message "Cannot locate replacement text")))))) - (setq cua--last-deleted-region-pos nil)) - (if (and cua--last-deleted-region-text - cua--repeat-replace-text - (search-forward cua--last-deleted-region-text nil t nil)) - (replace-match cua--repeat-replace-text arg t))) + (if cua--rectangle + (cua--rectangle-corner 0)))))) (defun cua-help-for-region (&optional help) "Show region specific help in echo area." @@ -1333,7 +1295,8 @@ If ARG is the atom `-', scroll upward by nearly full screen." (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 [(meta v)] + 'delete-selection-repeat-replace-region)) (define-key cua--prefix-override-keymap [(control x)] 'cua--prefix-override-handler) (define-key cua--prefix-override-keymap [(control c)] 'cua--prefix-override-handler) @@ -1402,6 +1365,7 @@ If ARG is the atom `-', scroll upward by nearly full screen." ;; delete-selection-mode (defvar cua--saved-state nil) +(defvar delete-selection-save-to-register) ;;;###autoload (define-minor-mode cua-mode @@ -1469,6 +1433,8 @@ the prefix fallback behavior." (if (and (boundp 'delete-selection-mode) delete-selection-mode) (delete-selection-mode -1))) (if cua-highlight-region-shift-only (transient-mark-mode -1)) + (if cua-delete-copy-to-register-0 + (setq delete-selection-save-to-register ?0)) (cua--deactivate)) (cua--saved-state (if (nth 0 cua--saved-state) -- cgit v1.2.1 From 95af181d665ffe7f0361c3f468445ac8e4a7858e Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 31 Oct 2014 11:31:27 -0400 Subject: * lisp/emulation/cua-base.el (cua-delete-region): Use delete-active-region. (cua--last-deleted-region-pos, cua--last-deleted-region-text): Remove. Fixes: debbugs:18886 --- lisp/emulation/cua-base.el | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'lisp/emulation') diff --git a/lisp/emulation/cua-base.el b/lisp/emulation/cua-base.el index c57188338ce..2f321f74b97 100644 --- a/lisp/emulation/cua-base.el +++ b/lisp/emulation/cua-base.el @@ -790,26 +790,12 @@ Repeating prefix key when region is active works as a single prefix key." ;;; Region specific commands -(defvar cua--last-deleted-region-pos nil) -(defvar cua--last-deleted-region-text nil) - (defun cua-delete-region () "Delete the active region. Save a copy in register 0 if `cua-delete-copy-to-register-0' is non-nil." (interactive) - (let ((start (mark)) (end (point))) - (or (<= start end) - (setq start (prog1 end (setq end start)))) - (setq cua--last-deleted-region-text - (funcall region-extract-function t)) - (if cua-delete-copy-to-register-0 - (set-register ?0 cua--last-deleted-region-text)) - (setq cua--last-deleted-region-pos - (cons (current-buffer) - (and (consp buffer-undo-list) - (car buffer-undo-list)))) - (cua--deactivate) - (/= start end))) + (require 'delsel) + (delete-active-region)) (defun cua-copy-region (arg) "Copy the region to the kill ring. @@ -1357,9 +1343,6 @@ 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: ;; delete-selection-mode -- cgit v1.2.1