diff options
| author | Kim F. Storm | 2006-12-02 00:30:00 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2006-12-02 00:30:00 +0000 |
| commit | c64a6023b9c59b61091f6e542ee6901eefaad1ef (patch) | |
| tree | 901dfcd5be826274a5cbe3099024cb790edc61d4 | |
| parent | 85e3d48f01d40bb0be049e66d69eb95034e05480 (diff) | |
| download | emacs-c64a6023b9c59b61091f6e542ee6901eefaad1ef.tar.gz emacs-c64a6023b9c59b61091f6e542ee6901eefaad1ef.zip | |
(cua-toggle-set-mark): Doc fix.
(cua-repeat-replace-region): Make M-v more robust.
(cua-paste-pop-rotate-temporarily): New defcustom.
(cua-paste-pop): Use it.
(cua-auto-mark-last-change): New defcustom.
(cua-pop-to-last-change): New helper function.
(cua-set-mark): Use them.
| -rw-r--r-- | lisp/emulation/cua-base.el | 119 |
1 files changed, 100 insertions, 19 deletions
diff --git a/lisp/emulation/cua-base.el b/lisp/emulation/cua-base.el index 2fbd09600bd..6eabed45d4e 100644 --- a/lisp/emulation/cua-base.el +++ b/lisp/emulation/cua-base.el | |||
| @@ -317,11 +317,19 @@ If the value is nil, use a shifted prefix key to inhibit the override." | |||
| 317 | :group 'cua) | 317 | :group 'cua) |
| 318 | 318 | ||
| 319 | (defcustom cua-toggle-set-mark t | 319 | (defcustom cua-toggle-set-mark t |
| 320 | "*In non-nil, the `cua-set-mark' command toggles the mark." | 320 | "*If non-nil, the `cua-set-mark' command toggles the mark." |
| 321 | :type '(choice (const :tag "Disabled" nil) | 321 | :type '(choice (const :tag "Disabled" nil) |
| 322 | (other :tag "Enabled" t)) | 322 | (other :tag "Enabled" t)) |
| 323 | :group 'cua) | 323 | :group 'cua) |
| 324 | 324 | ||
| 325 | (defcustom cua-auto-mark-last-change nil | ||
| 326 | "*If non-nil, set implicit mark at position of last buffer change. | ||
| 327 | This means that \\[universal-argument] \\[cua-set-mark] will jump to the position | ||
| 328 | of the last buffer change before jumping to the explicit marks on the mark ring. | ||
| 329 | See `cua-set-mark' for details." | ||
| 330 | :type 'boolean | ||
| 331 | :group 'cua) | ||
| 332 | |||
| 325 | (defcustom cua-enable-register-prefix 'not-ctrl-u | 333 | (defcustom cua-enable-register-prefix 'not-ctrl-u |
| 326 | "*If non-nil, registers are supported via numeric prefix arg. | 334 | "*If non-nil, registers are supported via numeric prefix arg. |
| 327 | If the value is t, any numeric prefix arg in the range 0 to 9 will be | 335 | If the value is t, any numeric prefix arg in the range 0 to 9 will be |
| @@ -358,6 +366,15 @@ managers, so try setting this to nil, if prefix override doesn't work." | |||
| 358 | :type 'boolean | 366 | :type 'boolean |
| 359 | :group 'cua) | 367 | :group 'cua) |
| 360 | 368 | ||
| 369 | (defcustom cua-paste-pop-rotate-temporarily nil | ||
| 370 | "*If non-nil, \\[cua-paste-pop] only rotates the kill-ring temporarily. | ||
| 371 | This means that \\[cua-paste] always inserts the most recent kill, while one or | ||
| 372 | more \\[cua-paste-pop]'s immediately following it will replace the previous text | ||
| 373 | with the next older element on the `kill-ring'. If \\[cua-paste-pop] is used after | ||
| 374 | any other command, it will insert the same element from the `kill-ring' as last | ||
| 375 | time it was used." | ||
| 376 | :type 'boolean | ||
| 377 | :group 'cua) | ||
| 361 | 378 | ||
| 362 | ;;; Rectangle Customization | 379 | ;;; Rectangle Customization |
| 363 | 380 | ||
| @@ -912,15 +929,52 @@ If global mark is active, copy from register or one character." | |||
| 912 | (clipboard-yank)) | 929 | (clipboard-yank)) |
| 913 | (t (yank arg))))))) | 930 | (t (yank arg))))))) |
| 914 | 931 | ||
| 932 | |||
| 933 | ;; cua-paste-pop-rotate-temporarily == t mechanism: | ||
| 934 | ;; | ||
| 935 | ;; C-y M-y M-y => only rotates kill ring temporarily, | ||
| 936 | ;; so next C-y yanks what previous C-y yanked, | ||
| 937 | ;; | ||
| 938 | ;; But: After another command, M-y remembers the temporary | ||
| 939 | ;; kill-ring position, so | ||
| 940 | ;; M-y => yanks what the last M-y yanked | ||
| 941 | ;; | ||
| 942 | |||
| 943 | (defvar cua-paste-pop-count nil) | ||
| 944 | |||
| 915 | (defun cua-paste-pop (arg) | 945 | (defun cua-paste-pop (arg) |
| 916 | "Replace a just-pasted text or rectangle with a different text. | 946 | "Replace a just-pasted text or rectangle with a different text. |
| 917 | See `yank-pop' for details." | 947 | See `yank-pop' for details about the default behaviour. For an alternative |
| 948 | behaviour, see `cua-paste-pop-rotate-temporarily'." | ||
| 918 | (interactive "P") | 949 | (interactive "P") |
| 919 | (if (eq last-command 'cua--paste-rectangle) | 950 | (cond |
| 920 | (progn | 951 | ((eq last-command 'cua--paste-rectangle) |
| 921 | (undo) | 952 | (undo) |
| 922 | (yank arg)) | 953 | (yank arg)) |
| 923 | (yank-pop (prefix-numeric-value arg)))) | 954 | ((not cua-paste-pop-rotate-temporarily) |
| 955 | (yank-pop (prefix-numeric-value arg))) | ||
| 956 | (t | ||
| 957 | (let ((rotate (if (consp arg) 1 (prefix-numeric-value arg)))) | ||
| 958 | (cond | ||
| 959 | ((or (null cua-paste-pop-count) | ||
| 960 | (eq last-command 'yank) | ||
| 961 | (eq last-command 'cua-paste)) | ||
| 962 | (setq cua-paste-pop-count rotate) | ||
| 963 | (setq last-command 'yank) | ||
| 964 | (yank-pop cua-paste-pop-count)) | ||
| 965 | ((eq last-command 'cua-paste-pop) | ||
| 966 | (unless (consp arg) | ||
| 967 | (setq cua-paste-pop-count (+ cua-paste-pop-count rotate))) | ||
| 968 | (setq last-command 'yank) | ||
| 969 | (yank-pop cua-paste-pop-count)) | ||
| 970 | (t | ||
| 971 | (setq cua-paste-pop-count (+ cua-paste-pop-count rotate -1)) | ||
| 972 | (yank (1+ cua-paste-pop-count))))) | ||
| 973 | ;; Undo rotating the kill-ring, so next C-y will | ||
| 974 | ;; yank the original head. | ||
| 975 | (unless (consp arg) | ||
| 976 | (setq kill-ring-yank-pointer kill-ring)) | ||
| 977 | (setq this-command 'cua-paste-pop)))) | ||
| 924 | 978 | ||
| 925 | (defun cua-exchange-point-and-mark (arg) | 979 | (defun cua-exchange-point-and-mark (arg) |
| 926 | "Exchanges point and mark, but don't activate the mark. | 980 | "Exchanges point and mark, but don't activate the mark. |
| @@ -961,14 +1015,14 @@ of text." | |||
| 961 | (if (and s (= (cdr u) s)) | 1015 | (if (and s (= (cdr u) s)) |
| 962 | (setq s (car u)) | 1016 | (setq s (car u)) |
| 963 | (setq s (car u) e (cdr u))))))) | 1017 | (setq s (car u) e (cdr u))))))) |
| 964 | (setq cua--repeat-replace-text | 1018 | (cond ((and s e (<= s e) (= s (mark t))) |
| 965 | (cond ((and s e (<= s e) (= s (mark t))) | 1019 | (setq cua--repeat-replace-text |
| 966 | (filter-buffer-substring s e nil t)) | 1020 | (filter-buffer-substring s e nil t))) |
| 967 | ((and (null s) (eq u elt)) ;; nothing inserted | 1021 | ((and (null s) (eq u elt)) ;; nothing inserted |
| 968 | "") | 1022 | (setq cua--repeat-replace-text |
| 969 | (t | 1023 | "")) |
| 970 | (message "Cannot locate replacement text") | 1024 | (t |
| 971 | nil)))))) | 1025 | (message "Cannot locate replacement text")))))) |
| 972 | (setq cua--last-deleted-region-pos nil)) | 1026 | (setq cua--last-deleted-region-pos nil)) |
| 973 | (if (and cua--last-deleted-region-text | 1027 | (if (and cua--last-deleted-region-text |
| 974 | cua--repeat-replace-text | 1028 | cua--repeat-replace-text |
| @@ -985,6 +1039,28 @@ of text." | |||
| 985 | 1039 | ||
| 986 | ;;; Shift activated / extended region | 1040 | ;;; Shift activated / extended region |
| 987 | 1041 | ||
| 1042 | (defun cua-pop-to-last-change () | ||
| 1043 | (let ((undo-list buffer-undo-list) | ||
| 1044 | pos elt) | ||
| 1045 | (while (and (not pos) | ||
| 1046 | (consp undo-list)) | ||
| 1047 | (setq elt (car undo-list) | ||
| 1048 | undo-list (cdr undo-list)) | ||
| 1049 | (cond | ||
| 1050 | ((integerp elt) | ||
| 1051 | (setq pos elt)) | ||
| 1052 | ((not (consp elt))) | ||
| 1053 | ((and (integerp (cdr elt)) | ||
| 1054 | (or (integerp (car elt)) (stringp (car elt)))) | ||
| 1055 | (setq pos (cdr elt))) | ||
| 1056 | ((and (eq (car elt) 'apply) (consp (cdr elt)) (integerp (cadr elt))) | ||
| 1057 | (setq pos (nth 3 elt))))) | ||
| 1058 | (when (and pos | ||
| 1059 | (/= pos (point)) | ||
| 1060 | (>= pos (point-min)) (<= pos (point-max))) | ||
| 1061 | (goto-char pos) | ||
| 1062 | t))) | ||
| 1063 | |||
| 988 | (defun cua-set-mark (&optional arg) | 1064 | (defun cua-set-mark (&optional arg) |
| 989 | "Set mark at where point is, clear mark, or jump to mark. | 1065 | "Set mark at where point is, clear mark, or jump to mark. |
| 990 | 1066 | ||
| @@ -993,12 +1069,15 @@ mark, and push old mark position on local mark ring; also push mark on | |||
| 993 | global mark ring if last mark was set in another buffer. | 1069 | global mark ring if last mark was set in another buffer. |
| 994 | 1070 | ||
| 995 | With argument, jump to mark, and pop a new position for mark off | 1071 | With argument, jump to mark, and pop a new position for mark off |
| 996 | the local mark ring \(this does not affect the global mark ring\). | 1072 | the local mark ring (this does not affect the global mark ring). |
| 997 | Use \\[pop-global-mark] to jump to a mark off the global mark ring | 1073 | Use \\[pop-global-mark] to jump to a mark off the global mark ring |
| 998 | \(see `pop-global-mark'\). | 1074 | \(see `pop-global-mark'). |
| 1075 | |||
| 1076 | If `cua-auto-mark-last-change' is non-nil, this command behaves as if there | ||
| 1077 | was an implicit mark at the position of the last buffer change. | ||
| 999 | 1078 | ||
| 1000 | Repeating the command without the prefix jumps to the next position | 1079 | Repeating the command without the prefix jumps to the next position |
| 1001 | off the local \(or global\) mark ring. | 1080 | off the local (or global) mark ring. |
| 1002 | 1081 | ||
| 1003 | With a double \\[universal-argument] prefix argument, unconditionally set mark." | 1082 | With a double \\[universal-argument] prefix argument, unconditionally set mark." |
| 1004 | (interactive "P") | 1083 | (interactive "P") |
| @@ -1013,7 +1092,9 @@ With a double \\[universal-argument] prefix argument, unconditionally set mark." | |||
| 1013 | (pop-global-mark)) | 1092 | (pop-global-mark)) |
| 1014 | (arg | 1093 | (arg |
| 1015 | (setq this-command 'pop-to-mark-command) | 1094 | (setq this-command 'pop-to-mark-command) |
| 1016 | (pop-to-mark-command)) | 1095 | (or (and cua-auto-mark-last-change |
| 1096 | (cua-pop-to-last-change)) | ||
| 1097 | (pop-to-mark-command))) | ||
| 1017 | ((and cua-toggle-set-mark mark-active) | 1098 | ((and cua-toggle-set-mark mark-active) |
| 1018 | (cua--deactivate) | 1099 | (cua--deactivate) |
| 1019 | (message "Mark Cleared")) | 1100 | (message "Mark Cleared")) |