aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2005-02-07 11:44:57 +0000
committerKim F. Storm2005-02-07 11:44:57 +0000
commite4907bbe3bc5fa4a32eeaa753304981d868c7cb5 (patch)
treebc29e0fbca292eb58be18171cfbfb2e3ba362fb9
parent4905133fd709e6d349d2c1fa331a6015a134520b (diff)
downloademacs-e4907bbe3bc5fa4a32eeaa753304981d868c7cb5.tar.gz
emacs-e4907bbe3bc5fa4a32eeaa753304981d868c7cb5.zip
(cua--undo-list, cua--tidy-undo-counter)
(cua--rect-undo, cua--tidy-undo-lists, cua--rectangle-on-off): Remove. (cua--rect-undo-set-point): New var. (cua--rectangle-undo-boundary): Setup undo apply entry. (cua--rect-undo-handler): New function for rectangle undo. (cua--rect-start-position, cua--rect-end-position): Add. (cua--rectangle-post-command): Call cua--rectangle-set-corners for restored rectangle. Set point if cua--rect-undo-set-point.
-rw-r--r--lisp/emulation/cua-rect.el126
1 files changed, 51 insertions, 75 deletions
diff --git a/lisp/emulation/cua-rect.el b/lisp/emulation/cua-rect.el
index 742ae2033be..bfb51694db4 100644
--- a/lisp/emulation/cua-rect.el
+++ b/lisp/emulation/cua-rect.el
@@ -1,6 +1,6 @@
1;;; cua-rect.el --- CUA unified rectangle support 1;;; cua-rect.el --- CUA unified rectangle support
2 2
3;; Copyright (C) 1997-2002, 2004 Free Software Foundation, Inc. 3;; Copyright (C) 1997-2002, 2004, 2005 Free Software Foundation, Inc.
4 4
5;; Author: Kim F. Storm <storm@cua.dk> 5;; Author: Kim F. Storm <storm@cua.dk>
6;; Keywords: keyboard emulations convenience CUA 6;; Keywords: keyboard emulations convenience CUA
@@ -71,71 +71,28 @@
71 71
72(defvar cua--virtual-edges-debug nil) 72(defvar cua--virtual-edges-debug nil)
73 73
74;; Per-buffer CUA mode undo list. 74;; Undo rectangle commands.
75(defvar cua--undo-list nil) 75
76(make-variable-buffer-local 'cua--undo-list) 76(defvar cua--rect-undo-set-point nil)
77 77
78;; Record undo boundary for rectangle undo.
79(defun cua--rectangle-undo-boundary () 78(defun cua--rectangle-undo-boundary ()
80 (when (listp buffer-undo-list) 79 (when (listp buffer-undo-list)
81 (if (> (length cua--undo-list) cua-undo-max) 80 (let ((s (cua--rect-start-position))
82 (setcdr (nthcdr (1- cua-undo-max) cua--undo-list) nil)) 81 (e (cua--rect-end-position)))
83 (undo-boundary) 82 (undo-boundary)
84 (setq cua--undo-list 83 (push (list 'apply 0 s e
85 (cons (cons (cdr buffer-undo-list) (copy-sequence cua--rectangle)) cua--undo-list)))) 84 'cua--rect-undo-handler
86 85 (copy-sequence cua--rectangle) t s e)
87(defun cua--rectangle-undo (&optional arg) 86 buffer-undo-list))))
88 "Undo some previous changes. 87
89Knows about CUA rectangle highlighting in addition to standard undo." 88(defun cua--rect-undo-handler (rect on s e)
90 (interactive "*P") 89 (if (setq on (not on))
91 (if cua--rectangle 90 (setq cua--rect-undo-set-point s)
92 (cua--rectangle-undo-boundary)) 91 (setq cua--restored-rectangle (copy-sequence rect))
93 (undo arg) 92 (setq cua--buffer-and-point-before-command nil))
94 (let ((l cua--undo-list)) 93 (push (list 'apply 0 s (if on e s)
95 (while l 94 'cua--rect-undo-handler rect on s e)
96 (if (eq (car (car l)) pending-undo-list) 95 buffer-undo-list))
97 (setq cua--restored-rectangle
98 (and (vectorp (cdr (car l))) (cdr (car l)))
99 l nil)
100 (setq l (cdr l)))))
101 (setq cua--buffer-and-point-before-command nil))
102
103(defvar cua--tidy-undo-counter 0
104 "Number of times `cua--tidy-undo-lists' have run successfully.")
105
106;; Clean out dangling entries from cua's undo list.
107;; Since this list contains pointers into the standard undo list,
108;; such references are only meningful as undo information if the
109;; corresponding entry is still on the standard undo list.
110
111(defun cua--tidy-undo-lists (&optional clean)
112 (let ((buffers (buffer-list)) (cnt cua--tidy-undo-counter))
113 (while (and buffers (or clean (not (input-pending-p))))
114 (with-current-buffer (car buffers)
115 (when (local-variable-p 'cua--undo-list)
116 (if (or clean (null cua--undo-list) (eq buffer-undo-list t))
117 (progn
118 (kill-local-variable 'cua--undo-list)
119 (setq cua--tidy-undo-counter (1+ cua--tidy-undo-counter)))
120 (let* ((bul buffer-undo-list)
121 (cul (cons nil cua--undo-list))
122 (cc (car (car (cdr cul)))))
123 (while (and bul cc)
124 (if (setq bul (memq cc bul))
125 (setq cul (cdr cul)
126 cc (and (cdr cul) (car (car (cdr cul)))))))
127 (when cc
128 (if cua--debug
129 (setq cc (length (cdr cul))))
130 (if (eq (cdr cul) cua--undo-list)
131 (setq cua--undo-list nil)
132 (setcdr cul nil))
133 (setq cua--tidy-undo-counter (1+ cua--tidy-undo-counter))
134 (if cua--debug
135 (message "Clean undo list in %s (%d)"
136 (buffer-name) cc)))))))
137 (setq buffers (cdr buffers)))
138 (/= cnt cua--tidy-undo-counter)))
139 96
140;;; Rectangle geometry 97;;; Rectangle geometry
141 98
@@ -287,6 +244,27 @@ Knows about CUA rectangle highlighting in addition to standard undo."
287 (backward-char 1)) 244 (backward-char 1))
288 )) 245 ))
289 246
247(defun cua--rect-start-position ()
248 ;; Return point of top left corner
249 (save-excursion
250 (goto-char (cua--rectangle-top))
251 (and (> (move-to-column (cua--rectangle-left))
252 (cua--rectangle-left))
253 (not (bolp))
254 (backward-char 1))
255 (point)))
256
257(defun cua--rect-end-position ()
258 ;; Return point of bottom right cornet
259 (save-excursion
260 (goto-char (cua--rectangle-bot))
261 (and (= (move-to-column (cua--rectangle-right))
262 (- (cua--rectangle-right) tab-width))
263 (not (eolp))
264 (not (bolp))
265 (backward-char 1))
266 (point)))
267
290;;; Rectangle resizing 268;;; Rectangle resizing
291 269
292(defun cua--forward-line (n) 270(defun cua--forward-line (n)
@@ -1394,10 +1372,12 @@ With prefix arg, indent to that column."
1394 1372
1395(defun cua--rectangle-post-command () 1373(defun cua--rectangle-post-command ()
1396 (if cua--restored-rectangle 1374 (if cua--restored-rectangle
1397 (setq cua--rectangle cua--restored-rectangle 1375 (progn
1398 cua--restored-rectangle nil 1376 (setq cua--rectangle cua--restored-rectangle
1399 mark-active t 1377 cua--restored-rectangle nil
1400 deactivate-mark nil) 1378 mark-active t
1379 deactivate-mark nil)
1380 (cua--rectangle-set-corners))
1401 (when (and cua--rectangle cua--buffer-and-point-before-command 1381 (when (and cua--rectangle cua--buffer-and-point-before-command
1402 (equal (car cua--buffer-and-point-before-command) (current-buffer)) 1382 (equal (car cua--buffer-and-point-before-command) (current-buffer))
1403 (not (= (cdr cua--buffer-and-point-before-command) (point)))) 1383 (not (= (cdr cua--buffer-and-point-before-command) (point))))
@@ -1411,20 +1391,16 @@ With prefix arg, indent to that column."
1411 (if (and mark-active 1391 (if (and mark-active
1412 (not deactivate-mark)) 1392 (not deactivate-mark))
1413 (cua--highlight-rectangle) 1393 (cua--highlight-rectangle)
1414 (cua--deactivate-rectangle)))) 1394 (cua--deactivate-rectangle)))
1415 1395 (when cua--rect-undo-set-point
1396 (goto-char cua--rect-undo-set-point)
1397 (setq cua--rect-undo-set-point nil)))
1416 1398
1417;;; Initialization 1399;;; Initialization
1418 1400
1419(defun cua--rect-M/H-key (key cmd) 1401(defun cua--rect-M/H-key (key cmd)
1420 (cua--M/H-key cua--rectangle-keymap key cmd)) 1402 (cua--M/H-key cua--rectangle-keymap key cmd))
1421 1403
1422(defun cua--rectangle-on-off (on)
1423 (cancel-function-timers 'cua--tidy-undo-lists)
1424 (if on
1425 (run-with-idle-timer 10 t 'cua--tidy-undo-lists)
1426 (cua--tidy-undo-lists t)))
1427
1428(defun cua--init-rectangles () 1404(defun cua--init-rectangles ()
1429 (unless (face-background 'cua-rectangle-face) 1405 (unless (face-background 'cua-rectangle-face)
1430 (copy-face 'region 'cua-rectangle-face) 1406 (copy-face 'region 'cua-rectangle-face)