1 ;;; cua-rect.el --- CUA unified rectangle support
3 ;; Copyright (C) 1997-2002, 2004 Free Software Foundation, Inc.
5 ;; Author: Kim F. Storm <storm@cua.dk>
6 ;; Keywords: keyboard emulations convenience CUA
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; The rectangle handling and display code borrows from the standard
28 ;; GNU emacs rect.el package and the rect-mark.el package by Rick
29 ;; Sladkey <jrs@world.std.com>.
46 ;; If non-nil, restrict current region to this rectangle.
47 ;; Value is a vector [top bot left right corner ins virt select].
48 ;; CORNER specifies currently active corner 0=t/l 1=t/r 2=b/l 3=b/r.
49 ;; INS specifies whether to insert on left(nil) or right(t) side.
50 ;; If VIRT is non-nil, virtual straight edges are enabled.
51 ;; If SELECT is a regexp, only lines starting with that regexp are affected.")
52 (defvar cua--rectangle nil)
53 (make-variable-buffer-local 'cua--rectangle)
55 ;; Most recent rectangle geometry. Note: car is buffer.
56 (defvar cua--last-rectangle nil)
58 ;; Rectangle restored by undo.
59 (defvar cua--restored-rectangle nil)
61 ;; Last rectangle copied/killed; nil if last kill was not a rectangle.
62 (defvar cua--last-killed-rectangle nil)
64 ;; List of overlays used to display current rectangle.
65 (defvar cua--rectangle-overlays nil)
66 (make-variable-buffer-local 'cua--rectangle-overlays)
68 (defvar cua--overlay-keymap
69 (let ((map (make-sparse-keymap)))
70 (define-key map "\r" 'cua-rotate-rectangle)))
72 (defvar cua--virtual-edges-debug nil)
74 ;; Per-buffer CUA mode undo list.
75 (defvar cua--undo-list nil)
76 (make-variable-buffer-local 'cua--undo-list)
78 ;; Record undo boundary for rectangle undo.
79 (defun cua--rectangle-undo-boundary ()
80 (when (listp buffer-undo-list)
81 (if (> (length cua--undo-list) cua-undo-max)
82 (setcdr (nthcdr (1- cua-undo-max) cua--undo-list) nil))
85 (cons (cons (cdr buffer-undo-list) (copy-sequence cua--rectangle)) cua--undo-list))))
87 (defun cua--rectangle-undo (&optional arg)
88 "Undo some previous changes.
89 Knows about CUA rectangle highlighting in addition to standard undo."
92 (cua--rectangle-undo-boundary))
94 (let ((l cua--undo-list))
96 (if (eq (car (car l)) pending-undo-list)
97 (setq cua--restored-rectangle
98 (and (vectorp (cdr (car l))) (cdr (car l)))
101 (setq cua--buffer-and-point-before-command nil))
103 (defvar cua--tidy-undo-counter 0
104 "Number of times `cua--tidy-undo-lists' have run successfully.")
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.
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))
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)))))
124 (if (setq bul (memq cc bul))
126 cc (and (cdr cul) (car (car (cdr cul)))))))
129 (setq cc (length (cdr cul))))
130 (if (eq (cdr cul) cua--undo-list)
131 (setq cua--undo-list nil)
133 (setq cua--tidy-undo-counter (1+ cua--tidy-undo-counter))
135 (message "Clean undo list in %s (%d)"
136 (buffer-name) cc)))))))
137 (setq buffers (cdr buffers)))
138 (/= cnt cua--tidy-undo-counter)))
140 ;;; Rectangle geometry
142 (defun cua--rectangle-top (&optional val)
143 ;; Top of CUA rectangle (buffer position on first line).
145 (aref cua--rectangle 0)
146 (setq val (line-beginning-position))
147 (if (<= val (aref cua--rectangle 1))
148 (aset cua--rectangle 0 val)
149 (aset cua--rectangle 1 val)
150 (cua--rectangle-corner 2))))
152 (defun cua--rectangle-bot (&optional val)
153 ;; Bot of CUA rectangle (buffer position on last line).
155 (aref cua--rectangle 1)
156 (setq val (line-end-position))
157 (if (>= val (aref cua--rectangle 0))
158 (aset cua--rectangle 1 val)
159 (aset cua--rectangle 0 val)
160 (cua--rectangle-corner 2))))
162 (defun cua--rectangle-left (&optional val)
163 ;; Left column of CUA rectangle.
165 (if (<= val (aref cua--rectangle 3))
166 (aset cua--rectangle 2 val)
167 (aset cua--rectangle 3 val)
168 (cua--rectangle-corner (if (cua--rectangle-right-side) -1 1)))
169 (aref cua--rectangle 2)))
171 (defun cua--rectangle-right (&optional val)
172 ;; Right column of CUA rectangle.
174 (if (>= val (aref cua--rectangle 2))
175 (aset cua--rectangle 3 val)
176 (aset cua--rectangle 2 val)
177 (cua--rectangle-corner (if (cua--rectangle-right-side) -1 1)))
178 (aref cua--rectangle 3)))
180 (defun cua--rectangle-corner (&optional advance)
181 ;; Currently active corner of rectangle.
182 (let ((c (aref cua--rectangle 4)))
183 (if (not (integerp advance))
185 (aset cua--rectangle 4
187 (- 3 c) ; opposite corner
188 (mod (+ c 4 advance) 4)))
189 (aset cua--rectangle 5 0))))
191 (defun cua--rectangle-right-side (&optional topbot)
192 ;; t if point is on right side of rectangle.
193 (if (and topbot (= (cua--rectangle-left) (cua--rectangle-right)))
194 (< (cua--rectangle-corner) 2)
195 (= (mod (cua--rectangle-corner) 2) 1)))
197 (defun cua--rectangle-column ()
198 (if (cua--rectangle-right-side)
199 (cua--rectangle-right)
200 (cua--rectangle-left)))
202 (defun cua--rectangle-insert-col (&optional col)
203 ;; Currently active corner of rectangle.
205 (aset cua--rectangle 5 col)
206 (if (cua--rectangle-right-side t)
207 (if (= (aref cua--rectangle 5) 0)
208 (1+ (cua--rectangle-right))
209 (aref cua--rectangle 5))
210 (cua--rectangle-left))))
212 (defun cua--rectangle-virtual-edges (&optional set val)
213 ;; Current setting of rectangle virtual-edges
215 (aset cua--rectangle 6 val))
216 (and ;(not buffer-read-only)
217 (aref cua--rectangle 6)))
219 (defun cua--rectangle-restriction (&optional val bounded negated)
220 ;; Current rectangle restriction
222 (aset cua--rectangle 7
225 (list val bounded negated)))
226 (aref cua--rectangle 7)))
228 (defun cua--rectangle-assert ()
229 (message "%S (%d)" cua--rectangle (point))
230 (if (< (cua--rectangle-right) (cua--rectangle-left))
231 (message "rectangle right < left"))
232 (if (< (cua--rectangle-bot) (cua--rectangle-top))
233 (message "rectangle bot < top")))
235 (defun cua--rectangle-get-corners ()
236 ;; Calculate the rectangular region represented by point and mark,
237 ;; putting start in the upper left corner and end in the
238 ;; bottom right corner.
239 (let ((top (point)) (bot (mark)) r l corner)
242 (setq l (current-column))
244 (setq r (current-column))
246 (setq corner (if (<= l r) 0 1))
247 (setq top (prog1 bot (setq bot top)))
248 (setq corner (if (<= l r) 2 3)))
252 (setq l (prog1 r (setq r l)))
259 (vector top bot l r corner 0 cua-virtual-rectangle-edges nil)))
261 (defun cua--rectangle-set-corners ()
262 ;; Set mark and point in opposite corners of current rectangle.
263 (let (pp pc mp mc (c (cua--rectangle-corner)))
265 ((= c 0) ; top/left -> bot/right
266 (setq pp (cua--rectangle-top) pc (cua--rectangle-left)
267 mp (cua--rectangle-bot) mc (cua--rectangle-right)))
268 ((= c 1) ; top/right -> bot/left
269 (setq pp (cua--rectangle-top) pc (cua--rectangle-right)
270 mp (cua--rectangle-bot) mc (cua--rectangle-left)))
271 ((= c 2) ; bot/left -> top/right
272 (setq pp (cua--rectangle-bot) pc (cua--rectangle-left)
273 mp (cua--rectangle-top) mc (cua--rectangle-right)))
274 ((= c 3) ; bot/right -> top/left
275 (setq pp (cua--rectangle-bot) pc (cua--rectangle-right)
276 mp (cua--rectangle-top) mc (cua--rectangle-left))))
281 ;; Move cursor inside rectangle, except if char at rigth edge is a tab.
282 (if (and (if (cua--rectangle-right-side)
283 (and (= (move-to-column pc) (- pc tab-width))
285 (> (move-to-column pc) pc))
290 ;;; Rectangle resizing
292 (defun cua--forward-line (n)
293 ;; Move forward/backward one line. Returns t if movement.
295 (and (= (forward-line n) 0)
296 ;; Deal with end of buffer
300 (defun cua--rectangle-resized ()
301 ;; Refresh state after resizing rectangle
302 (setq cua--buffer-and-point-before-command nil)
303 (cua--rectangle-insert-col 0)
304 (cua--rectangle-set-corners)
307 (defun cua-resize-rectangle-right (n)
308 "Resize rectangle to the right."
310 (let ((resized (> n 0)))
314 ((cua--rectangle-right-side)
315 (cua--rectangle-right (1+ (cua--rectangle-right)))
316 (move-to-column (cua--rectangle-right)))
318 (cua--rectangle-left (1+ (cua--rectangle-left)))
319 (move-to-column (cua--rectangle-right)))))
321 (cua--rectangle-resized))))
323 (defun cua-resize-rectangle-left (n)
324 "Resize rectangle to the left."
329 (if (or (= (cua--rectangle-right) 0)
330 (and (not (cua--rectangle-right-side)) (= (cua--rectangle-left) 0)))
333 ((cua--rectangle-right-side)
334 (cua--rectangle-right (1- (cua--rectangle-right)))
335 (move-to-column (cua--rectangle-right)))
337 (cua--rectangle-left (1- (cua--rectangle-left)))
338 (move-to-column (cua--rectangle-right))))
341 (cua--rectangle-resized))))
343 (defun cua-resize-rectangle-down (n)
344 "Resize rectangle downwards."
350 ((>= (cua--rectangle-corner) 2)
351 (goto-char (cua--rectangle-bot))
352 (when (cua--forward-line 1)
353 (move-to-column (cua--rectangle-column))
354 (cua--rectangle-bot t)
357 (goto-char (cua--rectangle-top))
358 (when (cua--forward-line 1)
359 (move-to-column (cua--rectangle-column))
360 (cua--rectangle-top t)
363 (cua--rectangle-resized))))
365 (defun cua-resize-rectangle-up (n)
366 "Resize rectangle upwards."
372 ((>= (cua--rectangle-corner) 2)
373 (goto-char (cua--rectangle-bot))
374 (when (cua--forward-line -1)
375 (move-to-column (cua--rectangle-column))
376 (cua--rectangle-bot t)
379 (goto-char (cua--rectangle-top))
380 (when (cua--forward-line -1)
381 (move-to-column (cua--rectangle-column))
382 (cua--rectangle-top t)
385 (cua--rectangle-resized))))
387 (defun cua-resize-rectangle-eol ()
388 "Resize rectangle to end of line."
392 (if (> (current-column) (cua--rectangle-right))
393 (cua--rectangle-right (current-column)))
394 (if (not (cua--rectangle-right-side))
395 (cua--rectangle-corner 1))
396 (cua--rectangle-resized)))
398 (defun cua-resize-rectangle-bol ()
399 "Resize rectangle to beginning of line."
403 (cua--rectangle-left (current-column))
404 (if (cua--rectangle-right-side)
405 (cua--rectangle-corner -1))
406 (cua--rectangle-resized)))
408 (defun cua-resize-rectangle-bot ()
409 "Resize rectangle to bottom of buffer."
411 (goto-char (point-max))
412 (move-to-column (cua--rectangle-column))
413 (cua--rectangle-bot t)
414 (cua--rectangle-resized))
416 (defun cua-resize-rectangle-top ()
417 "Resize rectangle to top of buffer."
419 (goto-char (point-min))
420 (move-to-column (cua--rectangle-column))
421 (cua--rectangle-top t)
422 (cua--rectangle-resized))
424 (defun cua-resize-rectangle-page-up ()
425 "Resize rectangle upwards by one scroll page."
428 (move-to-column (cua--rectangle-column))
429 (if (>= (cua--rectangle-corner) 2)
430 (cua--rectangle-bot t)
431 (cua--rectangle-top t))
432 (cua--rectangle-resized))
434 (defun cua-resize-rectangle-page-down ()
435 "Resize rectangle downwards by one scroll page."
438 (move-to-column (cua--rectangle-column))
439 (if (>= (cua--rectangle-corner) 2)
440 (cua--rectangle-bot t)
441 (cua--rectangle-top t))
442 (cua--rectangle-resized))
446 ;; This is pretty simplistic, but it does the job...
448 (defun cua-mouse-resize-rectangle (event)
449 "Set rectangle corner at mouse click position."
451 (mouse-set-point event)
452 ;; FIX ME -- need to calculate virtual column.
453 (if (cua--rectangle-virtual-edges)
454 (move-to-column (car (posn-col-row (event-end event))) t))
455 (if (cua--rectangle-right-side)
456 (cua--rectangle-right (current-column))
457 (cua--rectangle-left (current-column)))
458 (if (>= (cua--rectangle-corner) 2)
459 (cua--rectangle-bot t)
460 (cua--rectangle-top t))
461 (cua--rectangle-resized))
463 (defvar cua--mouse-last-pos nil)
465 (defun cua-mouse-set-rectangle-mark (event)
466 "Start rectangle at mouse click position."
469 (cua--deactivate-rectangle)
471 (setq cua--last-rectangle nil)
472 (mouse-set-point event)
473 ;; FIX ME -- need to calculate virtual column.
474 (cua-set-rectangle-mark)
475 (setq cua--buffer-and-point-before-command nil)
476 (setq cua--mouse-last-pos nil))
478 (defun cua-mouse-save-then-kill-rectangle (event arg)
479 "Expand rectangle to mouse click position and copy rectangle.
480 If command is repeated at same position, delete the rectangle."
482 (if (and (eq this-command last-command)
483 (eq (point) (car-safe cua--mouse-last-pos))
484 (eq cua--last-killed-rectangle (cdr-safe cua--mouse-last-pos)))
486 (unless buffer-read-only
487 (cua--delete-rectangle))
489 (cua-mouse-resize-rectangle event)
490 (let ((cua-keep-region-after-copy t))
491 (cua-copy-rectangle arg)
492 (setq cua--mouse-last-pos (cons (point) cua--last-killed-rectangle)))))
494 (defun cua--mouse-ignore (event)
496 (setq this-command last-command))
498 (defun cua--rectangle-move (dir)
500 (top (cua--rectangle-top))
501 (bot (cua--rectangle-bot))
502 (l (cua--rectangle-left))
503 (r (cua--rectangle-right)))
507 (when (cua--forward-line -1)
508 (cua--rectangle-top t)
511 (cua--rectangle-bot t)))
514 (when (cua--forward-line 1)
515 (cua--rectangle-bot t)
517 (cua--forward-line 1)
518 (cua--rectangle-top t)))
521 (cua--rectangle-left (1- l))
522 (cua--rectangle-right (1- r))))
524 (cua--rectangle-right (1+ r))
525 (cua--rectangle-left (1+ l)))
529 (setq cua--buffer-and-point-before-command nil)
530 (cua--rectangle-set-corners)
531 (cua--keep-active))))
534 ;;; Operations on current rectangle
536 (defun cua--tabify-start (start end)
537 ;; Return position where auto-tabify should start (or nil if not required).
541 (and (not buffer-read-only)
542 cua-auto-tabify-rectangles
543 (if (or (not (integerp cua-auto-tabify-rectangles))
544 (= (point-min) (point-max))
546 (goto-char (max (point-min)
547 (- start cua-auto-tabify-rectangles)))
548 (search-forward "\t" (min (point-max)
549 (+ end cua-auto-tabify-rectangles)) t)))
552 (defun cua--rectangle-operation (keep-clear visible undo pad tabify &optional fct post-fct)
553 ;; Call FCT for each line of region with 4 parameters:
554 ;; Region start, end, left-col, right-col
555 ;; Point is at start when FCT is called
556 ;; Call fct with (s,e) = whole lines if VISIBLE non-nil.
557 ;; Only call fct for visible lines if VISIBLE==t.
558 ;; Set undo boundary if UNDO is non-nil.
559 ;; Rectangle is padded if PAD = t or numeric and (cua--rectangle-virtual-edges)
560 ;; Perform auto-tabify after operation if TABIFY is non-nil.
561 ;; Mark is kept if keep-clear is 'keep and cleared if keep-clear is 'clear.
562 (let* ((inhibit-field-text-motion t)
563 (start (cua--rectangle-top))
564 (end (cua--rectangle-bot))
565 (l (cua--rectangle-left))
566 (r (1+ (cua--rectangle-right)))
568 (tabpad (and (integerp pad) (= pad 2)))
569 (sel (cua--rectangle-restriction))
570 (tabify-start (and tabify (cua--tabify-start start end))))
572 (cua--rectangle-undo-boundary))
574 (setq pad (cua--rectangle-virtual-edges)))
578 (when (> (cua--rectangle-corner) 1)
580 (and (bolp) (not (eolp)) (not (eobp))
581 (setq end (1+ end))))
583 (setq start (max (window-start) start))
584 (setq end (min (window-end) end)))
586 (setq end (line-end-position))
587 (if (and visible (bolp) (not (eobp)))
590 (setq start (line-beginning-position))
591 (narrow-to-region start end)
592 (goto-char (point-min))
593 (while (< (point) (point-max))
594 (move-to-column r pad)
595 (and (not pad) (not visible) (> (current-column) r)
597 (if (and tabpad (not pad) (looking-at "\t"))
599 (set-marker m (point))
600 (move-to-column l pad)
601 (if (and fct (or visible (and (>= (current-column) l) (<= (current-column) r))))
602 (let ((v t) (p (point)))
605 (setq v (looking-at (car sel)))
606 (setq v (re-search-forward (car sel) m t))
608 (if (car (cdr (cdr sel)))
611 (funcall fct p m l r v)
613 (funcall fct p m l r)))))
617 (cua--rectangle-bot t))
619 (funcall post-fct l r))
621 (tabify tabify-start (point)))))
623 ((eq keep-clear 'keep)
625 ((eq keep-clear 'clear)
627 ((eq keep-clear 'corners)
628 (cua--rectangle-set-corners)
630 (setq cua--buffer-and-point-before-command nil)))
632 (put 'cua--rectangle-operation 'lisp-indent-function 4)
634 (defun cua--delete-rectangle ()
636 (if (not (cua--rectangle-virtual-edges))
637 (cua--rectangle-operation nil nil t 2 t
639 (setq lines (1+ lines))
640 (if (and (> e s) (<= e (point-max)))
641 (delete-region s e))))
642 (cua--rectangle-operation nil 1 t nil t
644 (setq lines (1+ lines))
645 (when (and (> e s) (<= e (point-max)))
646 (delete-region s e)))))
649 (defun cua--extract-rectangle ()
651 (if (not (cua--rectangle-virtual-edges))
652 (cua--rectangle-operation nil nil nil nil nil ; do not tabify
654 (setq rect (cons (buffer-substring-no-properties s e) rect))))
655 (cua--rectangle-operation nil 1 nil nil nil ; do not tabify
657 (let ((copy t) (bs 0) (as 0) row)
658 (if (= s e) (setq e (1+ e)))
661 (if (= (point) (line-end-position))
664 (skip-chars-forward "\s\t" e)
665 (setq bs (- (min r (current-column)) l)
668 (skip-chars-backward "\s\t" s)
669 (setq as (- r (max (current-column) l))
671 (setq row (if (and copy (> e s))
672 (buffer-substring-no-properties s e)
675 (setq row (concat (make-string bs ?\s) row)))
677 (setq row (concat row (make-string as ?\s))))
678 (setq rect (cons row rect))))))
681 (defun cua--insert-rectangle (rect &optional below paste-column line-count)
682 ;; Insert rectangle as insert-rectangle, but don't set mark and exit with
683 ;; point at either next to top right or below bottom left corner
684 ;; Notice: In overwrite mode, the rectangle is inserted as separate text lines.
686 (setq below (and (bolp)
687 (or (eolp) (eobp) (= (1+ (point)) (point-max))))))
689 (setq paste-column (current-column)))
692 (tabify-start (cua--tabify-start (point) (point)))
695 (while (or lines below)
700 (or (bolp) (insert ?\n))))
701 (unless overwrite-mode
702 (move-to-column paste-column t))
705 (insert-for-yank (car lines))
707 (setq last-column (current-column)))
708 (setq lines (cdr lines))
709 (and first (not below)
712 (if (and line-count (= (setq line-count (1- line-count)) 0))
714 (when (and line-count last-column (not overwrite-mode))
715 (while (> line-count 0)
717 (or (bolp) (insert ?\n))
718 (move-to-column paste-column t)
719 (insert-char ?\s (- last-column paste-column -1))
720 (setq line-count (1- line-count))))
721 (when (and tabify-start
722 (not overwrite-mode))
723 (tabify tabify-start (point)))
724 (and p (not overwrite-mode)
727 (defun cua--copy-rectangle-as-kill (&optional ring)
729 (set-register cua--register (cua--extract-rectangle))
730 (setq killed-rectangle (cua--extract-rectangle))
731 (setq cua--last-killed-rectangle (cons (and kill-ring (car kill-ring)) killed-rectangle))
734 (function (lambda (row) (concat row "\n")))
735 killed-rectangle "")))))
737 (defun cua--activate-rectangle ()
738 ;; Turn on rectangular marking mode by disabling transient mark mode
739 ;; and manually handling highlighting from a post command hook.
740 ;; Be careful if we are already marking a rectangle.
742 (if (and cua--last-rectangle
743 (eq (car cua--last-rectangle) (current-buffer))
744 (eq (car (cdr cua--last-rectangle)) (point)))
745 (cdr (cdr cua--last-rectangle))
746 (cua--rectangle-get-corners))
747 cua--status-string (if (cua--rectangle-virtual-edges) " [R]" "")
748 cua--last-rectangle nil))
750 ;; (defvar cua-save-point nil)
752 (defun cua--deactivate-rectangle ()
753 ;; This is used to clean up after `cua--activate-rectangle'.
754 (mapcar (function delete-overlay) cua--rectangle-overlays)
755 (setq cua--last-rectangle (cons (current-buffer)
756 (cons (point) ;; cua-save-point
759 cua--rectangle-overlays nil
760 cua--status-string nil
761 cua--mouse-last-pos nil))
763 (defun cua--highlight-rectangle ()
764 ;; This function is used to highlight the rectangular region.
765 ;; We do this by putting an overlay on each line within the rectangle.
766 ;; Each overlay extends across all the columns of the rectangle.
767 ;; We try to reuse overlays where possible because this is more efficient
768 ;; and results in less flicker.
769 ;; If cua--rectangle-virtual-edges is nil and the buffer contains tabs or short lines,
770 ;; the higlighted region may not be perfectly rectangular.
771 (let ((deactivate-mark deactivate-mark)
772 (old cua--rectangle-overlays)
774 (left (cua--rectangle-left))
775 (right (1+ (cua--rectangle-right))))
776 (when (/= left right)
777 (sit-for 0) ; make window top/bottom reliable
778 (cua--rectangle-operation nil t nil nil nil ; do not tabify
780 (let ((rface (if v 'cua-rectangle-face 'cua-rectangle-noselect-face))
782 (when (cua--rectangle-virtual-edges)
783 (let ((lb (line-beginning-position))
784 (le (line-end-position))
787 (setq cl (move-to-column l)
789 (setq cr (move-to-column r)
794 (setq cl0 (current-column)))
798 (setq cr0 (current-column)))
799 (unless (and (= cl l) (= cr r))
803 (- l cl0 (if (and (= le pl) (/= le lb)) 1 0))
804 (if cua--virtual-edges-debug ?. ?\s))
812 (or bs (/= cr0 (- cr tab-width)))
813 (/= (mod cr tab-width) 0))
819 (if cua--virtual-edges-debug ?, ?\s))
821 (if (cua--rectangle-right-side)
822 (put-text-property (1- (length ms)) (length ms) 'cursor t ms)
823 (put-text-property 0 1 'cursor t ms))
824 (setq bs (concat bs ms))
829 (- r cr0 (if (= le pr) 1 0))
830 (if cua--virtual-edges-debug ?~ ?\s))
832 (if (cua--rectangle-right-side)
833 (put-text-property (1- (length as)) (length as) 'cursor t as)
834 (put-text-property 0 1 'cursor t as))
836 (setq e (1- e))))))))
837 ;; Trim old leading overlays.
839 (setq overlay (car old))
840 (< (overlay-start overlay) s)
841 (/= (overlay-end overlay) e))
842 (delete-overlay overlay)
843 (setq old (cdr old)))
844 ;; Reuse an overlay if possible, otherwise create one.
846 (setq overlay (car old))
847 (or (= (overlay-start overlay) s)
848 (= (overlay-end overlay) e)))
850 (move-overlay overlay s e)
851 (setq old (cdr old)))
852 (setq overlay (make-overlay s e)))
853 (overlay-put overlay 'before-string bs)
854 (overlay-put overlay 'after-string as)
855 (overlay-put overlay 'face rface)
856 (overlay-put overlay 'keymap cua--overlay-keymap)
857 (setq new (cons overlay new))))))
858 ;; Trim old trailing overlays.
859 (mapcar (function delete-overlay) old)
860 (setq cua--rectangle-overlays (nreverse new))))
862 (defun cua--indent-rectangle (&optional ch to-col clear)
863 ;; Indent current rectangle.
864 (let ((col (cua--rectangle-insert-col))
865 (pad (cua--rectangle-virtual-edges))
867 (cua--rectangle-operation (if clear 'clear 'corners) nil t pad nil
869 (move-to-column col pad)
871 (< (current-column) col))
872 (move-to-column col t))
874 (to-col (indent-to to-col))
876 (t (tab-to-tab-stop)))
877 (if (cua--rectangle-right-side t)
878 (cua--rectangle-insert-col (current-column))
879 (setq indent (- (current-column) l))))
881 (when (and indent (> indent 0))
882 (aset cua--rectangle 2 (+ l indent))
883 (aset cua--rectangle 3 (+ r indent -1)))))))
886 ;; rectangle functions / actions
889 (defvar cua--rectangle-initialized nil)
891 (defun cua-set-rectangle-mark (&optional reopen)
892 "Set mark and start in CUA rectangle mode.
893 With prefix argument, activate previous rectangle if possible."
895 (unless cua--rectangle-initialized
896 (cua--init-rectangles))
897 (when (not cua--rectangle)
900 (eq (car cua--last-rectangle) (current-buffer)))
901 (goto-char (car (cdr cua--last-rectangle)))
902 (if (not mark-active)
903 (push-mark nil nil t)))
904 (cua--activate-rectangle)
905 (cua--rectangle-set-corners)
907 cua--explicit-region-start t)
908 (if cua-enable-rectangle-auto-help
909 (cua-help-for-rectangle t))))
911 (defun cua-clear-rectangle-mark ()
912 "Cancel current rectangle."
915 (setq mark-active nil
916 cua--explicit-region-start nil)
917 (cua--deactivate-rectangle)))
919 (defun cua-toggle-rectangle-mark ()
922 (cua--deactivate-rectangle)
923 (unless cua--rectangle-initialized
924 (cua--init-rectangles))
925 (cua--activate-rectangle))
927 (if cua-enable-rectangle-auto-help
928 (cua-help-for-rectangle t))
929 (if cua-enable-region-auto-help
930 (cua-help-for-region t))))
932 (defun cua-restrict-regexp-rectangle (arg)
933 "Restrict rectangle to lines (not) matching REGEXP.
934 With prefix argument, the toggle restriction."
936 (let ((r (cua--rectangle-restriction)) regexp)
937 (if (and r (null (car (cdr r))))
939 (cua--rectangle-restriction (car r) nil (not (car (cdr (cdr r)))))
940 (cua--rectangle-restriction "" nil nil))
941 (cua--rectangle-restriction
942 (read-from-minibuffer "Restrict rectangle (regexp): "
943 nil nil nil nil) nil arg))))
945 (defun cua-restrict-prefix-rectangle (arg)
946 "Restrict rectangle to lines (not) starting with CHAR.
947 With prefix argument, the toggle restriction."
949 (let ((r (cua--rectangle-restriction)) regexp)
950 (if (and r (car (cdr r)))
952 (cua--rectangle-restriction (car r) t (not (car (cdr (cdr r)))))
953 (cua--rectangle-restriction "" nil nil))
954 (cua--rectangle-restriction
956 (read-char "Restrictive rectangle (char): ")) t arg))))
958 (defun cua-move-rectangle-up ()
960 (cua--rectangle-move 'up))
962 (defun cua-move-rectangle-down ()
964 (cua--rectangle-move 'down))
966 (defun cua-move-rectangle-left ()
968 (cua--rectangle-move 'left))
970 (defun cua-move-rectangle-right ()
972 (cua--rectangle-move 'right))
974 (defun cua-copy-rectangle (arg)
976 (setq arg (cua--prefix-arg arg))
977 (cua--copy-rectangle-as-kill arg)
978 (if cua-keep-region-after-copy
982 (defun cua-cut-rectangle (arg)
985 (cua-copy-rectangle arg)
986 (setq arg (cua--prefix-arg arg))
987 (goto-char (min (mark) (point)))
988 (cua--copy-rectangle-as-kill arg)
989 (cua--delete-rectangle))
992 (defun cua-delete-rectangle ()
994 (goto-char (min (point) (mark)))
995 (if cua-delete-copy-to-register-0
996 (set-register ?0 (cua--extract-rectangle)))
997 (cua--delete-rectangle)
1000 (defun cua-rotate-rectangle ()
1002 (cua--rectangle-corner (if (= (cua--rectangle-left) (cua--rectangle-right)) 0 1))
1003 (cua--rectangle-set-corners)
1004 (if (cua--rectangle-virtual-edges)
1005 (setq cua--buffer-and-point-before-command nil)))
1007 (defun cua-toggle-rectangle-virtual-edges ()
1009 (cua--rectangle-virtual-edges t (not (cua--rectangle-virtual-edges)))
1010 (cua--rectangle-set-corners)
1011 (setq cua--status-string (and (cua--rectangle-virtual-edges) " [R]"))
1014 (defun cua-do-rectangle-padding ()
1016 (if buffer-read-only
1017 (message "Cannot do padding in read-only buffer.")
1018 (cua--rectangle-operation nil nil t t t)
1019 (cua--rectangle-set-corners))
1022 (defun cua-open-rectangle ()
1023 "Blank out CUA rectangle, shifting text right.
1024 The text previously in the region is not overwritten by the blanks,
1025 but instead winds up to the right of the rectangle."
1027 (cua--rectangle-operation 'corners nil t 1 nil
1029 (skip-chars-forward " \t")
1030 (let ((ws (- (current-column) l))
1032 (skip-chars-backward " \t")
1033 (delete-region (point) p)
1034 (indent-to (+ r ws))))))
1036 (defun cua-close-rectangle (arg)
1037 "Delete all whitespace starting at left edge of CUA rectangle.
1038 On each line in the rectangle, all continuous whitespace starting
1039 at that column is deleted.
1040 With prefix arg, also delete whitespace to the left of that column."
1042 (cua--rectangle-operation 'clear nil t 1 nil
1045 (skip-syntax-backward " " (line-beginning-position))
1047 (skip-syntax-forward " " (line-end-position))
1048 (delete-region s (point)))))
1050 (defun cua-blank-rectangle ()
1051 "Blank out CUA rectangle.
1052 The text previously in the rectangle is overwritten by the blanks."
1054 (cua--rectangle-operation 'keep nil nil 1 nil
1057 (skip-syntax-forward " " (line-end-position))
1059 (let ((column (current-column)))
1061 (skip-syntax-backward " " (line-beginning-position))
1062 (delete-region (point) e)
1063 (indent-to column)))))
1065 (defun cua-align-rectangle ()
1066 "Align rectangle lines to left column."
1069 (cua--rectangle-operation 'clear nil t t nil
1071 (let ((b (line-beginning-position)))
1072 (skip-syntax-backward "^ " b)
1073 (skip-syntax-backward " " b)
1075 (skip-syntax-forward " " (line-end-position))
1076 (delete-region s (point))
1080 ;; (setq cua-save-point (point))
1083 (defun cua-copy-rectangle-as-text (&optional arg delete)
1084 "Copy rectangle, but store as normal text."
1086 (if cua--global-mark-active
1088 (cua--cut-rectangle-to-global-mark t)
1089 (cua--copy-rectangle-to-global-mark t))
1090 (let* ((rect (cua--extract-rectangle))
1092 (function (lambda (row) (concat row "\n")))
1094 (setq arg (cua--prefix-arg arg))
1096 (set-register cua--register text)
1099 (cua--delete-rectangle))
1102 (defun cua-cut-rectangle-as-text (arg)
1103 "Kill rectangle, but store as normal text."
1105 (cua-copy-rectangle-as-text arg (not buffer-read-only)))
1107 (defun cua-string-rectangle (string)
1108 "Replace CUA rectangle contents with STRING on each line.
1109 The length of STRING need not be the same as the rectangle width."
1110 (interactive "sString rectangle: ")
1111 (cua--rectangle-operation 'keep nil t t nil
1114 (skip-chars-forward " \t")
1115 (let ((ws (- (current-column) l)))
1116 (delete-region s (point))
1118 (indent-to (+ (current-column) ws))))
1119 (unless (cua--rectangle-restriction)
1121 (cua--rectangle-right (max l (+ l (length string) -1)))))))
1123 (defun cua-fill-char-rectangle (ch)
1124 "Replace CUA rectangle contents with CHARACTER."
1125 (interactive "cFill rectangle with character: ")
1126 (cua--rectangle-operation 'clear nil t 1 nil
1129 (move-to-column l t)
1130 (insert-char ch (- r l)))))
1132 (defun cua-replace-in-rectangle (regexp newtext)
1133 "Replace REGEXP with NEWTEXT in each line of CUA rectangle."
1134 (interactive "sReplace regexp: \nsNew text: ")
1135 (if buffer-read-only
1136 (message "Cannot replace in read-only buffer")
1137 (cua--rectangle-operation 'keep nil t 1 nil
1139 (if (re-search-forward regexp e t)
1140 (replace-match newtext nil nil))))))
1142 (defun cua-incr-rectangle (increment)
1143 "Increment each line of CUA rectangle by prefix amount."
1145 (cua--rectangle-operation 'keep nil t 1 nil
1148 ((re-search-forward "0x\\([0-9a-fA-F]+\\)" e t)
1149 (let* ((txt (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
1150 (n (string-to-number txt 16))
1151 (fmt (format "0x%%0%dx" (length txt))))
1152 (replace-match (format fmt (+ n increment)))))
1153 ((re-search-forward "\\( *-?[0-9]+\\)" e t)
1154 (let* ((txt (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
1155 (prefix (if (= (aref txt 0) ?0) "0" ""))
1156 (n (string-to-number txt 10))
1157 (fmt (format "%%%s%dd" prefix (length txt))))
1158 (replace-match (format fmt (+ n increment)))))
1161 (defvar cua--rectangle-seq-format "%d"
1162 "Last format used by cua-sequence-rectangle.")
1164 (defun cua-sequence-rectangle (first incr fmt)
1165 "Resequence each line of CUA rectangle starting from FIRST.
1166 The numbers are formatted according to the FORMAT string."
1168 (list (if current-prefix-arg
1169 (prefix-numeric-value current-prefix-arg)
1171 (read-string "Start value: (0) " nil nil "0")))
1173 (read-string "Increment: (1) " nil nil "1"))
1174 (read-string (concat "Format: (" cua--rectangle-seq-format ") "))))
1175 (if (= (length fmt) 0)
1176 (setq fmt cua--rectangle-seq-format)
1177 (setq cua--rectangle-seq-format fmt))
1178 (cua--rectangle-operation 'clear nil t 1 nil
1181 (insert (format fmt first))
1182 (setq first (+ first incr)))))
1184 (defmacro cua--convert-rectangle-as (command tabify)
1185 `(cua--rectangle-operation 'clear nil nil nil ,tabify
1189 (defun cua-upcase-rectangle ()
1190 "Convert the rectangle to upper case."
1192 (cua--convert-rectangle-as upcase-region nil))
1194 (defun cua-downcase-rectangle ()
1195 "Convert the rectangle to lower case."
1197 (cua--convert-rectangle-as downcase-region nil))
1199 (defun cua-upcase-initials-rectangle ()
1200 "Convert the rectangle initials to upper case."
1202 (cua--convert-rectangle-as upcase-initials-region nil))
1204 (defun cua-capitalize-rectangle ()
1205 "Convert the rectangle to proper case."
1207 (cua--convert-rectangle-as capitalize-region nil))
1210 ;;; Replace/rearrange text in current rectangle
1212 (defun cua--rectangle-aux-replace (width adjust keep replace pad format-fct &optional setup-fct)
1213 ;; Process text inserted by calling SETUP-FCT or current rectangle if nil.
1214 ;; Then call FORMAT-FCT on text (if non-nil); takes two args: start and end.
1215 ;; Fill to WIDTH characters if > 0 or fill to current width if == 0.
1216 ;; Don't fill if WIDTH < 0.
1217 ;; Replace current rectangle by filled text if REPLACE is non-nil
1218 (let ((auxbuf (get-buffer-create "*CUA temp*"))
1219 (w (if (> width 1) width
1220 (- (cua--rectangle-right) (cua--rectangle-left) -1)))
1221 (r (or setup-fct (cua--extract-rectangle)))
1228 (cua--insert-rectangle r))
1230 (let ((fill-column w))
1231 (funcall format-fct (point-min) (point-max))))
1233 (goto-char (point-min))
1235 (setq z (cons (buffer-substring (point) (line-end-position)) z))
1237 (if (not cua--debug)
1238 (kill-buffer auxbuf))
1240 (setq z (reverse z))
1243 (cua--rectangle-operation nil nil t pad nil
1247 (skip-chars-forward " \t")
1248 (setq cc (current-column))
1250 (print (list cc s e) auxbuf))
1251 (delete-region s (point))
1254 (move-to-column l t)
1256 (when (> (current-column) (+ l w))
1258 (move-to-column (+ l w) t)
1259 (delete-region (point) y)
1263 (print (list (current-column) cc) auxbuf))
1266 (message "Warning: Truncated %d row%s" tr (if (> tr 1) "s" "")))
1268 (cua--rectangle-right (+ (cua--rectangle-left) w -1)))
1270 (cua--rectangle-resized)))))
1272 (put 'cua--rectangle-aux-replace 'lisp-indent-function 4)
1274 (defun cua--left-fill-rectangle (start end)
1276 (while (< (point) (point-max))
1277 (delete-horizontal-space nil)
1279 (fill-region-as-paragraph (point-min) (point-max) 'left nil)
1280 (untabify (point-min) (point-max)))
1282 (defun cua-text-fill-rectangle (width text)
1283 "Replace rectagle with filled TEXT read from minibuffer.
1284 A numeric prefix argument is used a new width for the filled rectangle."
1286 (prefix-numeric-value current-prefix-arg)
1287 (read-from-minibuffer "Enter text: "
1289 (cua--rectangle-aux-replace width t t t 1
1290 'cua--left-fill-rectangle
1291 '(lambda () (insert text))))
1293 (defun cua-refill-rectangle (width)
1294 "Fill contents of current rectagle.
1295 A numeric prefix argument is used as new width for the filled rectangle."
1297 (cua--rectangle-aux-replace
1298 (if width (prefix-numeric-value width) 0)
1299 t t t 1 'cua--left-fill-rectangle))
1301 (defun cua-shell-command-on-rectangle (replace command)
1302 "Run shell command on rectangle like `shell-command-on-region'.
1303 With prefix arg, replace rectangle with output from command."
1306 (read-from-minibuffer "Shell command on rectangle: "
1308 'shell-command-history)))
1309 (cua--rectangle-aux-replace -1 t t replace 1
1311 (shell-command-on-region s e command
1312 replace replace nil))))
1314 (defun cua-reverse-rectangle ()
1315 "Reverse the lines of the rectangle."
1317 (cua--rectangle-aux-replace 0 t t t t 'reverse-region))
1319 (defun cua-scroll-rectangle-up ()
1320 "Remove the first line of the rectangle and scroll remaining lines up."
1322 (cua--rectangle-aux-replace 0 t t t t
1324 (if (= (forward-line 1) 0)
1325 (delete-region s (point))))))
1327 (defun cua-scroll-rectangle-down ()
1328 "Insert a blank line at the first line of the rectangle.
1329 The remaining lines are scrolled down, losing the last line."
1331 (cua--rectangle-aux-replace 0 t t t t
1337 ;;; Insert/delete text to left or right of rectangle
1339 (defun cua-insert-char-rectangle (&optional ch)
1341 (if buffer-read-only
1343 (cua--indent-rectangle (or ch (aref (this-single-command-keys) 0)))
1347 (defun cua-indent-rectangle (column)
1348 "Indent rectangle to next tab stop.
1349 With prefix arg, indent to that column."
1352 (cua-insert-char-rectangle ?\t)
1353 (cua--indent-rectangle nil (prefix-numeric-value column))))
1355 (defun cua-delete-char-rectangle ()
1356 "Delete char to left or right of rectangle."
1358 (let ((col (cua--rectangle-insert-col))
1359 (pad (cua--rectangle-virtual-edges))
1361 (cua--rectangle-operation 'corners nil t pad nil
1364 (if (cua--rectangle-right-side t)
1369 (delete-backward-char 1)
1370 (if (cua--rectangle-right-side t)
1371 (cua--rectangle-insert-col (current-column))
1372 (setq indent (- l (current-column))))))
1374 (when (and indent (> indent 0))
1375 (aset cua--rectangle 2 (- l indent))
1376 (aset cua--rectangle 3 (- r indent 1)))))))
1378 (defun cua-help-for-rectangle (&optional help)
1380 (let ((M (if cua-use-hyper-key " H-" " M-")))
1382 (concat (if help "C-?:help" "")
1383 M "p:pad" M "o:open" M "c:close" M "b:blank"
1384 M "s:string" M "f:fill" M "i:incr" M "n:seq"))))
1387 ;;; CUA-like cut & paste for rectangles
1389 (defun cua--cancel-rectangle ()
1392 (cua--deactivate-rectangle))
1393 (setq cua--last-rectangle nil))
1395 (defun cua--rectangle-post-command ()
1396 (if cua--restored-rectangle
1397 (setq cua--rectangle cua--restored-rectangle
1398 cua--restored-rectangle nil
1400 deactivate-mark nil)
1401 (when (and cua--rectangle cua--buffer-and-point-before-command
1402 (equal (car cua--buffer-and-point-before-command) (current-buffer))
1403 (not (= (cdr cua--buffer-and-point-before-command) (point))))
1404 (if (cua--rectangle-right-side)
1405 (cua--rectangle-right (current-column))
1406 (cua--rectangle-left (current-column)))
1407 (if (>= (cua--rectangle-corner) 2)
1408 (cua--rectangle-bot t)
1409 (cua--rectangle-top t))))
1411 (if (and mark-active
1412 (not deactivate-mark))
1413 (cua--highlight-rectangle)
1414 (cua--deactivate-rectangle))))
1419 (defun cua--rect-M/H-key (key cmd)
1420 (cua--M/H-key cua--rectangle-keymap key cmd))
1422 (defun cua--rectangle-on-off (on)
1423 (cancel-function-timers 'cua--tidy-undo-lists)
1425 (run-with-idle-timer 10 t 'cua--tidy-undo-lists)
1426 (cua--tidy-undo-lists t)))
1428 (defun cua--init-rectangles ()
1429 (unless (face-background 'cua-rectangle-face)
1430 (copy-face 'region 'cua-rectangle-face)
1431 (set-face-background 'cua-rectangle-face "maroon")
1432 (set-face-foreground 'cua-rectangle-face "white"))
1434 (unless (face-background 'cua-rectangle-noselect-face)
1435 (copy-face 'region 'cua-rectangle-noselect-face)
1436 (set-face-background 'cua-rectangle-noselect-face "dimgray")
1437 (set-face-foreground 'cua-rectangle-noselect-face "white"))
1439 (unless (eq cua-use-hyper-key 'only)
1440 (define-key cua--rectangle-keymap [(shift return)] 'cua-clear-rectangle-mark)
1441 (define-key cua--region-keymap [(shift return)] 'cua-toggle-rectangle-mark))
1442 (when cua-use-hyper-key
1443 (cua--rect-M/H-key 'space 'cua-clear-rectangle-mark)
1444 (cua--M/H-key cua--region-keymap 'space 'cua-toggle-rectangle-mark))
1446 (define-key cua--rectangle-keymap [remap copy-region-as-kill] 'cua-copy-rectangle)
1447 (define-key cua--rectangle-keymap [remap kill-ring-save] 'cua-copy-rectangle)
1448 (define-key cua--rectangle-keymap [remap kill-region] 'cua-cut-rectangle)
1449 (define-key cua--rectangle-keymap [remap delete-char] 'cua-delete-rectangle)
1450 (define-key cua--rectangle-keymap [remap set-mark-command] 'cua-toggle-rectangle-mark)
1452 (define-key cua--rectangle-keymap [remap forward-char] 'cua-resize-rectangle-right)
1453 (define-key cua--rectangle-keymap [remap backward-char] 'cua-resize-rectangle-left)
1454 (define-key cua--rectangle-keymap [remap next-line] 'cua-resize-rectangle-down)
1455 (define-key cua--rectangle-keymap [remap previous-line] 'cua-resize-rectangle-up)
1456 (define-key cua--rectangle-keymap [remap end-of-line] 'cua-resize-rectangle-eol)
1457 (define-key cua--rectangle-keymap [remap beginning-of-line] 'cua-resize-rectangle-bol)
1458 (define-key cua--rectangle-keymap [remap end-of-buffer] 'cua-resize-rectangle-bot)
1459 (define-key cua--rectangle-keymap [remap beginning-of-buffer] 'cua-resize-rectangle-top)
1460 (define-key cua--rectangle-keymap [remap scroll-down] 'cua-resize-rectangle-page-up)
1461 (define-key cua--rectangle-keymap [remap scroll-up] 'cua-resize-rectangle-page-down)
1463 (define-key cua--rectangle-keymap [remap delete-backward-char] 'cua-delete-char-rectangle)
1464 (define-key cua--rectangle-keymap [remap backward-delete-char] 'cua-delete-char-rectangle)
1465 (define-key cua--rectangle-keymap [remap backward-delete-char-untabify] 'cua-delete-char-rectangle)
1466 (define-key cua--rectangle-keymap [remap self-insert-command] 'cua-insert-char-rectangle)
1467 (define-key cua--rectangle-keymap [remap self-insert-iso] 'cua-insert-char-rectangle)
1469 ;; Catch self-inserting characters which are "stolen" by other modes
1470 (define-key cua--rectangle-keymap [t]
1471 '(menu-item "sic" cua-insert-char-rectangle :filter cua--self-insert-char-p))
1473 (define-key cua--rectangle-keymap "\r" 'cua-rotate-rectangle)
1474 (define-key cua--rectangle-keymap "\t" 'cua-indent-rectangle)
1476 (define-key cua--rectangle-keymap [(control ??)] 'cua-help-for-rectangle)
1478 (define-key cua--rectangle-keymap [mouse-1] 'cua-mouse-set-rectangle-mark)
1479 (define-key cua--rectangle-keymap [down-mouse-1] 'cua--mouse-ignore)
1480 (define-key cua--rectangle-keymap [drag-mouse-1] 'cua--mouse-ignore)
1481 (define-key cua--rectangle-keymap [mouse-3] 'cua-mouse-save-then-kill-rectangle)
1482 (define-key cua--rectangle-keymap [down-mouse-3] 'cua--mouse-ignore)
1483 (define-key cua--rectangle-keymap [drag-mouse-3] 'cua--mouse-ignore)
1485 (cua--rect-M/H-key 'up 'cua-move-rectangle-up)
1486 (cua--rect-M/H-key 'down 'cua-move-rectangle-down)
1487 (cua--rect-M/H-key 'left 'cua-move-rectangle-left)
1488 (cua--rect-M/H-key 'right 'cua-move-rectangle-right)
1490 (cua--rect-M/H-key '(control up) 'cua-scroll-rectangle-up)
1491 (cua--rect-M/H-key '(control down) 'cua-scroll-rectangle-down)
1493 (cua--rect-M/H-key ?a 'cua-align-rectangle)
1494 (cua--rect-M/H-key ?b 'cua-blank-rectangle)
1495 (cua--rect-M/H-key ?c 'cua-close-rectangle)
1496 (cua--rect-M/H-key ?f 'cua-fill-char-rectangle)
1497 (cua--rect-M/H-key ?i 'cua-incr-rectangle)
1498 (cua--rect-M/H-key ?k 'cua-cut-rectangle-as-text)
1499 (cua--rect-M/H-key ?l 'cua-downcase-rectangle)
1500 (cua--rect-M/H-key ?m 'cua-copy-rectangle-as-text)
1501 (cua--rect-M/H-key ?n 'cua-sequence-rectangle)
1502 (cua--rect-M/H-key ?o 'cua-open-rectangle)
1503 (cua--rect-M/H-key ?p 'cua-toggle-rectangle-virtual-edges)
1504 (cua--rect-M/H-key ?P 'cua-do-rectangle-padding)
1505 (cua--rect-M/H-key ?q 'cua-refill-rectangle)
1506 (cua--rect-M/H-key ?r 'cua-replace-in-rectangle)
1507 (cua--rect-M/H-key ?R 'cua-reverse-rectangle)
1508 (cua--rect-M/H-key ?s 'cua-string-rectangle)
1509 (cua--rect-M/H-key ?t 'cua-text-fill-rectangle)
1510 (cua--rect-M/H-key ?u 'cua-upcase-rectangle)
1511 (cua--rect-M/H-key ?| 'cua-shell-command-on-rectangle)
1512 (cua--rect-M/H-key ?' 'cua-restrict-prefix-rectangle)
1513 (cua--rect-M/H-key ?/ 'cua-restrict-regexp-rectangle)
1515 (setq cua--rectangle-initialized t))
1517 ;;; arch-tag: b730df53-17b9-4a89-bd63-4a71ec196731
1518 ;;; cua-rect.el ends here