aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2002-05-31 12:19:57 +0000
committerKim F. Storm2002-05-31 12:19:57 +0000
commit5834ac9207ea4856abd41efcf4666adb46dce2ec (patch)
tree7a28f6e7d8193edab25f67349a29cac3b3da33cb
parent6be1e45909403d0549c48a8ad4e2f5632cf80b86 (diff)
downloademacs-5834ac9207ea4856abd41efcf4666adb46dce2ec.tar.gz
emacs-5834ac9207ea4856abd41efcf4666adb46dce2ec.zip
(cua--last-deleted-region-pos)
(cua--last-deleted-region-text): New aux variables. (cua-delete-region): Set them. (cua-repeat-replace-region): Use them to find the replacement text.
-rw-r--r--lisp/emulation/cua-base.el63
1 files changed, 44 insertions, 19 deletions
diff --git a/lisp/emulation/cua-base.el b/lisp/emulation/cua-base.el
index a90ed837012..f7887575521 100644
--- a/lisp/emulation/cua-base.el
+++ b/lisp/emulation/cua-base.el
@@ -676,6 +676,9 @@ Knows about CUA rectangle highlighting in addition to standard undo."
676 676
677;;; Region specific commands 677;;; Region specific commands
678 678
679(defvar cua--last-deleted-region-pos nil)
680(defvar cua--last-deleted-region-text nil)
681
679(defun cua-delete-region () 682(defun cua-delete-region ()
680 "Delete the active region. 683 "Delete the active region.
681Save a copy in register 0 if `cua-delete-copy-to-register-0' is non-nil." 684Save a copy in register 0 if `cua-delete-copy-to-register-0' is non-nil."
@@ -683,17 +686,22 @@ Save a copy in register 0 if `cua-delete-copy-to-register-0' is non-nil."
683 (let ((start (mark)) (end (point))) 686 (let ((start (mark)) (end (point)))
684 (or (<= start end) 687 (or (<= start end)
685 (setq start (prog1 end (setq end start)))) 688 (setq start (prog1 end (setq end start))))
689 (setq cua--last-deleted-region-text (buffer-substring start end))
686 (if cua-delete-copy-to-register-0 690 (if cua-delete-copy-to-register-0
687 (copy-to-register ?0 start end nil)) 691 (set-register ?0 cua--last-deleted-region-text))
688 (delete-region start end) 692 (delete-region start end)
693 (setq cua--last-deleted-region-pos
694 (cons (current-buffer)
695 (and (consp buffer-undo-list)
696 (car buffer-undo-list))))
689 (cua--deactivate))) 697 (cua--deactivate)))
690 698
691(defun cua-replace-region () 699(defun cua-replace-region ()
692 "Replace the active region with the character you type." 700 "Replace the active region with the character you type."
693 (interactive) 701 (interactive)
694 (cua-delete-region) 702 (cua-delete-region)
695 (if (not (eq this-original-command this-command)) 703 (unless (eq this-original-command this-command)
696 (cua--fallback))) 704 (cua--fallback)))
697 705
698(defun cua-copy-region (arg) 706(defun cua-copy-region (arg)
699 "Copy the region to the kill ring. 707 "Copy the region to the kill ring.
@@ -814,23 +822,40 @@ Activates the mark if a prefix argument is given."
814 "Repeat replacing text of highlighted region with typed text. 822 "Repeat replacing text of highlighted region with typed text.
815Searches for the next streach of text identical to the region last 823Searches for the next streach of text identical to the region last
816replaced by typing text over it and replaces it with the same streach 824replaced by typing text over it and replaces it with the same streach
817of text. 825of text."
818Note: Works only when used immediately after typing the last character.
819After that, it can be repeated (fairly) reliable until a buffer is
820modified in any other way than repeating this command."
821 (interactive "P") 826 (interactive "P")
822 (unless (or (eq this-command last-command) 827 (when cua--last-deleted-region-pos
823 (not cua--repeat-replace-text) 828 (save-excursion
824 (not (eq last-command 'self-insert-command))) 829 (save-restriction
825 (setq cua--repeat-replace-text 830 (set-buffer (car cua--last-deleted-region-pos))
826 (and (mark t) 831 (widen)
827 (/= (point) (mark t)) 832 ;; Find the text that replaced the region via the undo list.
828 (buffer-substring-no-properties (point) (mark t))))) 833 (let ((ul buffer-undo-list)
829 (let ((old (get-register ?0))) 834 (elt (cdr cua--last-deleted-region-pos))
830 (if (and old 835 u s e)
831 cua--repeat-replace-text 836 (when elt
832 (search-forward old nil t nil)) 837 (while (consp ul)
833 (replace-match cua--repeat-replace-text arg t)))) 838 (setq u (car ul) ul (cdr ul))
839 (cond
840 ((eq u elt) ;; got it
841 (setq ul nil))
842 ((and (consp u) (integerp (car u)) (integerp (cdr u)))
843 (if (and s (= (cdr u) s))
844 (setq s (car u))
845 (setq s (car u) e (cdr u)))))))
846 (setq cua--repeat-replace-text
847 (cond ((and s e (<= s e) (= s (mark t)))
848 (buffer-substring-no-properties s e))
849 ((and (null s) (eq u elt)) ;; nothing inserted
850 "")
851 (t
852 (message "Cannot locate replacement text")
853 nil))))))
854 (setq cua--last-deleted-region-pos nil))
855 (if (and cua--last-deleted-region-text
856 cua--repeat-replace-text
857 (search-forward cua--last-deleted-region-text nil t nil))
858 (replace-match cua--repeat-replace-text arg t)))
834 859
835(defun cua-help-for-region (&optional help) 860(defun cua-help-for-region (&optional help)
836 "Show region specific help in echo area." 861 "Show region specific help in echo area."