diff options
| author | Kim F. Storm | 2014-10-30 15:19:49 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2014-10-30 15:19:49 -0400 |
| commit | 71477684db6d781a07edda5060a0530da3623d96 (patch) | |
| tree | 96592d49b85f67dffcd6f90522e3d8e01152365d | |
| parent | c465f1c27f538c0ef2afa01f179e1f472bd9f097 (diff) | |
| download | emacs-71477684db6d781a07edda5060a0530da3623d96.tar.gz emacs-71477684db6d781a07edda5060a0530da3623d96.zip | |
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
| -rw-r--r-- | lisp/ChangeLog | 14 | ||||
| -rw-r--r-- | lisp/delsel.el | 76 | ||||
| -rw-r--r-- | lisp/emulation/cua-base.el | 54 |
3 files changed, 94 insertions, 50 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 33e0b1c757a..bed0928f68f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,17 @@ | |||
| 1 | 2014-10-30 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2014-10-30 Kim F. Storm <storm@cua.dk> |
| 2 | |||
| 3 | Restore cua-delete-copy-to-register-0 and M-v command (bug#18886). | ||
| 4 | * delsel.el (delete-selection-save-to-register) | ||
| 5 | (delsel--replace-text-or-position): New vars. | ||
| 6 | (delete-active-region): Use them. | ||
| 7 | (delete-selection-repeat-replace-region): New command, moved from | ||
| 8 | cua-base.el. | ||
| 9 | * emulation/cua-base.el (cua--repeat-replace-text): Remove var. | ||
| 10 | (cua-repeat-replace-region): Move command to delsel.el. | ||
| 11 | (cua--init-keymaps): Update binding accordingly. | ||
| 12 | (cua-mode): Set delete-selection-save-to-register. | ||
| 2 | 13 | ||
| 14 | 2014-10-30 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 3 | 15 | ||
| 4 | * progmodes/cc-defs.el (c--macroexpand-all): New function (bug#18845). | 16 | * progmodes/cc-defs.el (c--macroexpand-all): New function (bug#18845). |
| 5 | (c-lang-defconst): | 17 | (c-lang-defconst): |
diff --git a/lisp/delsel.el b/lisp/delsel.el index 1ada02705fe..96794fce7aa 100644 --- a/lisp/delsel.el +++ b/lisp/delsel.el | |||
| @@ -54,6 +54,10 @@ | |||
| 54 | 54 | ||
| 55 | ;;; Code: | 55 | ;;; Code: |
| 56 | 56 | ||
| 57 | (defvar delete-selection-save-to-register nil | ||
| 58 | "If non-nil, deleted region text is stored in this register. | ||
| 59 | Value must be the register (key) to use.") | ||
| 60 | |||
| 57 | ;;;###autoload | 61 | ;;;###autoload |
| 58 | (defalias 'pending-delete-mode 'delete-selection-mode) | 62 | (defalias 'pending-delete-mode 'delete-selection-mode) |
| 59 | 63 | ||
| @@ -72,16 +76,78 @@ point regardless of any selection." | |||
| 72 | (remove-hook 'pre-command-hook 'delete-selection-pre-hook) | 76 | (remove-hook 'pre-command-hook 'delete-selection-pre-hook) |
| 73 | (add-hook 'pre-command-hook 'delete-selection-pre-hook))) | 77 | (add-hook 'pre-command-hook 'delete-selection-pre-hook))) |
| 74 | 78 | ||
| 79 | (defvar delsel--replace-text-or-position nil) | ||
| 80 | |||
| 75 | (defun delete-active-region (&optional killp) | 81 | (defun delete-active-region (&optional killp) |
| 76 | "Delete the active region. | 82 | "Delete the active region. |
| 77 | If KILLP in not-nil, the active region is killed instead of deleted." | 83 | If KILLP in not-nil, the active region is killed instead of deleted." |
| 78 | (if killp | 84 | (cond |
| 79 | ;; Don't allow `kill-region' to change the value of `this-command'. | 85 | (killp |
| 80 | (let (this-command) | 86 | ;; Don't allow `kill-region' to change the value of `this-command'. |
| 81 | (kill-region (point) (mark) t)) | 87 | (let (this-command) |
| 82 | (funcall region-extract-function 'delete-only)) | 88 | (kill-region (point) (mark) t))) |
| 89 | (delete-selection-save-to-register | ||
| 90 | (set-register delete-selection-save-to-register | ||
| 91 | (funcall region-extract-function t)) | ||
| 92 | (setq delsel--replace-text-or-position | ||
| 93 | (cons (current-buffer) | ||
| 94 | (and (consp buffer-undo-list) (car buffer-undo-list))))) | ||
| 95 | (t | ||
| 96 | (funcall region-extract-function 'delete-only))) | ||
| 83 | t) | 97 | t) |
| 84 | 98 | ||
| 99 | (defun delete-selection-repeat-replace-region (arg) | ||
| 100 | "Repeat replacing text of highlighted region with typed text. | ||
| 101 | Search for the next stretch of text identical to the region last replaced | ||
| 102 | by typing text over it and replaces it with the same stretch of text. | ||
| 103 | With ARG, repeat that many times. `C-u' means until end of buffer." | ||
| 104 | (interactive "P") | ||
| 105 | (let ((old-text (and delete-selection-save-to-register | ||
| 106 | (get-register delete-selection-save-to-register))) | ||
| 107 | (count (if (consp arg) (point-max) | ||
| 108 | (prefix-numeric-value current-prefix-arg)))) | ||
| 109 | (if (not (and old-text | ||
| 110 | (> (length old-text) 0) | ||
| 111 | (or (stringp delsel--replace-text-or-position) | ||
| 112 | (buffer-live-p (car delsel--replace-text-or-position))))) | ||
| 113 | (message "No known previous replacement") | ||
| 114 | ;; If this is the first use after overwriting regions, | ||
| 115 | ;; find the replacement text by looking at the undo list. | ||
| 116 | (when (consp delsel--replace-text-or-position) | ||
| 117 | (let ((buffer (car delsel--replace-text-or-position)) | ||
| 118 | (elt (cdr delsel--replace-text-or-position))) | ||
| 119 | (setq delsel--replace-text-or-position nil) | ||
| 120 | (with-current-buffer buffer | ||
| 121 | (save-restriction | ||
| 122 | (widen) | ||
| 123 | ;; Find the text that replaced the region via the undo list. | ||
| 124 | (let ((ul buffer-undo-list) u s e) | ||
| 125 | (when elt | ||
| 126 | (while (consp ul) | ||
| 127 | (setq u (car ul) ul (cdr ul)) | ||
| 128 | (cond | ||
| 129 | ((eq u elt) ;; got it | ||
| 130 | (setq ul nil)) | ||
| 131 | ((and (consp u) (integerp (car u)) (integerp (cdr u))) | ||
| 132 | (if (and s (= (cdr u) s)) | ||
| 133 | (setq s (car u)) | ||
| 134 | (setq s (car u) e (cdr u))))))) | ||
| 135 | (cond ((and s e (<= s e) (= s (mark t))) | ||
| 136 | (setq delsel--replace-text-or-position | ||
| 137 | (filter-buffer-substring s e)) | ||
| 138 | (set-text-properties | ||
| 139 | 0 (length delsel--replace-text-or-position) | ||
| 140 | nil delsel--replace-text-or-position)) | ||
| 141 | ((and (null s) (eq u elt)) ;; Nothing inserted. | ||
| 142 | (setq delsel--replace-text-or-position "")) | ||
| 143 | (t | ||
| 144 | (message "Cannot locate replacement text")))))))) | ||
| 145 | (while (and (> count 0) | ||
| 146 | delsel--replace-text-or-position | ||
| 147 | (search-forward old-text nil t)) | ||
| 148 | (replace-match delsel--replace-text-or-position nil t) | ||
| 149 | (setq count (1- count)))))) | ||
| 150 | |||
| 85 | (defun delete-selection-helper (type) | 151 | (defun delete-selection-helper (type) |
| 86 | "Delete selection according to TYPE: | 152 | "Delete selection according to TYPE: |
| 87 | `yank' | 153 | `yank' |
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." | |||
| 277 | 277 | ||
| 278 | (defcustom cua-remap-control-v t | 278 | (defcustom cua-remap-control-v t |
| 279 | "If non-nil, C-v binding is used for paste (yank). | 279 | "If non-nil, C-v binding is used for paste (yank). |
| 280 | Also, M-v is mapped to `cua-repeat-replace-region'." | 280 | Also, M-v is mapped to `delete-selection-repeat-replace-region'." |
| 281 | :type 'boolean | 281 | :type 'boolean |
| 282 | :group 'cua) | 282 | :group 'cua) |
| 283 | 283 | ||
| @@ -350,6 +350,8 @@ interpreted as a register number." | |||
| 350 | :group 'cua) | 350 | :group 'cua) |
| 351 | 351 | ||
| 352 | (defcustom cua-delete-copy-to-register-0 t | 352 | (defcustom cua-delete-copy-to-register-0 t |
| 353 | ;; FIXME: Obey delete-selection-save-to-register rather than hardcoding | ||
| 354 | ;; register 0. | ||
| 353 | "If non-nil, save last deleted region or rectangle to register 0." | 355 | "If non-nil, save last deleted region or rectangle to register 0." |
| 354 | :type 'boolean | 356 | :type 'boolean |
| 355 | :group 'cua) | 357 | :group 'cua) |
| @@ -958,48 +960,8 @@ See also `exchange-point-and-mark'." | |||
| 958 | (t | 960 | (t |
| 959 | (let (mark-active) | 961 | (let (mark-active) |
| 960 | (exchange-point-and-mark) | 962 | (exchange-point-and-mark) |
| 961 | (if cua--rectangle | 963 | (if cua--rectangle |
| 962 | (cua--rectangle-corner 0)))))) | 964 | (cua--rectangle-corner 0)))))) |
| 963 | |||
| 964 | ;; Typed text that replaced the highlighted region. | ||
| 965 | (defvar cua--repeat-replace-text nil) | ||
| 966 | |||
| 967 | (defun cua-repeat-replace-region (arg) | ||
| 968 | "Repeat replacing text of highlighted region with typed text. | ||
| 969 | Searches for the next stretch of text identical to the region last | ||
| 970 | replaced by typing text over it and replaces it with the same stretch | ||
| 971 | of text." | ||
| 972 | (interactive "P") | ||
| 973 | (when cua--last-deleted-region-pos | ||
| 974 | (with-current-buffer (car cua--last-deleted-region-pos) | ||
| 975 | (save-restriction | ||
| 976 | (widen) | ||
| 977 | ;; Find the text that replaced the region via the undo list. | ||
| 978 | (let ((ul buffer-undo-list) | ||
| 979 | (elt (cdr cua--last-deleted-region-pos)) | ||
| 980 | u s e) | ||
| 981 | (when elt | ||
| 982 | (while (consp ul) | ||
| 983 | (setq u (car ul) ul (cdr ul)) | ||
| 984 | (cond | ||
| 985 | ((eq u elt) ;; got it | ||
| 986 | (setq ul nil)) | ||
| 987 | ((and (consp u) (integerp (car u)) (integerp (cdr u))) | ||
| 988 | (if (and s (= (cdr u) s)) | ||
| 989 | (setq s (car u)) | ||
| 990 | (setq s (car u) e (cdr u))))))) | ||
| 991 | (cond ((and s e (<= s e) (= s (mark t))) | ||
| 992 | (setq cua--repeat-replace-text (cua--filter-buffer-noprops s e))) | ||
| 993 | ((and (null s) (eq u elt)) ;; nothing inserted | ||
| 994 | (setq cua--repeat-replace-text | ||
| 995 | "")) | ||
| 996 | (t | ||
| 997 | (message "Cannot locate replacement text")))))) | ||
| 998 | (setq cua--last-deleted-region-pos nil)) | ||
| 999 | (if (and cua--last-deleted-region-text | ||
| 1000 | cua--repeat-replace-text | ||
| 1001 | (search-forward cua--last-deleted-region-text nil t nil)) | ||
| 1002 | (replace-match cua--repeat-replace-text arg t))) | ||
| 1003 | 965 | ||
| 1004 | (defun cua-help-for-region (&optional help) | 966 | (defun cua-help-for-region (&optional help) |
| 1005 | "Show region specific help in echo area." | 967 | "Show region specific help in echo area." |
| @@ -1333,7 +1295,8 @@ If ARG is the atom `-', scroll upward by nearly full screen." | |||
| 1333 | (define-key cua--cua-keys-keymap [(control z)] 'undo)) | 1295 | (define-key cua--cua-keys-keymap [(control z)] 'undo)) |
| 1334 | (when cua-remap-control-v | 1296 | (when cua-remap-control-v |
| 1335 | (define-key cua--cua-keys-keymap [(control v)] 'yank) | 1297 | (define-key cua--cua-keys-keymap [(control v)] 'yank) |
| 1336 | (define-key cua--cua-keys-keymap [(meta v)] 'cua-repeat-replace-region)) | 1298 | (define-key cua--cua-keys-keymap [(meta v)] |
| 1299 | 'delete-selection-repeat-replace-region)) | ||
| 1337 | 1300 | ||
| 1338 | (define-key cua--prefix-override-keymap [(control x)] 'cua--prefix-override-handler) | 1301 | (define-key cua--prefix-override-keymap [(control x)] 'cua--prefix-override-handler) |
| 1339 | (define-key cua--prefix-override-keymap [(control c)] 'cua--prefix-override-handler) | 1302 | (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." | |||
| 1402 | ;; delete-selection-mode | 1365 | ;; delete-selection-mode |
| 1403 | 1366 | ||
| 1404 | (defvar cua--saved-state nil) | 1367 | (defvar cua--saved-state nil) |
| 1368 | (defvar delete-selection-save-to-register) | ||
| 1405 | 1369 | ||
| 1406 | ;;;###autoload | 1370 | ;;;###autoload |
| 1407 | (define-minor-mode cua-mode | 1371 | (define-minor-mode cua-mode |
| @@ -1469,6 +1433,8 @@ the prefix fallback behavior." | |||
| 1469 | (if (and (boundp 'delete-selection-mode) delete-selection-mode) | 1433 | (if (and (boundp 'delete-selection-mode) delete-selection-mode) |
| 1470 | (delete-selection-mode -1))) | 1434 | (delete-selection-mode -1))) |
| 1471 | (if cua-highlight-region-shift-only (transient-mark-mode -1)) | 1435 | (if cua-highlight-region-shift-only (transient-mark-mode -1)) |
| 1436 | (if cua-delete-copy-to-register-0 | ||
| 1437 | (setq delete-selection-save-to-register ?0)) | ||
| 1472 | (cua--deactivate)) | 1438 | (cua--deactivate)) |
| 1473 | (cua--saved-state | 1439 | (cua--saved-state |
| 1474 | (if (nth 0 cua--saved-state) | 1440 | (if (nth 0 cua--saved-state) |