1 ;;; cua-rect.el --- CUA unified rectangle support
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Kim F. Storm <storm@cua.dk>
7 ;; Keywords: keyboard emulations convenience CUA
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; The rectangle handling and display code borrows from the standard
27 ;; GNU emacs rect.el package and the rect-mark.el package by Rick
28 ;; Sladkey <jrs@world.std.com>.
41 ;; If non-nil, restrict current region to this rectangle.
42 ;; Value is a vector [top bot left right corner ins virt select].
43 ;; CORNER specifies currently active corner 0=t/l 1=t/r 2=b/l 3=b/r.
44 ;; INS specifies whether to insert on left(nil) or right(t) side.
45 ;; If VIRT is non-nil, virtual straight edges are enabled.
46 ;; If SELECT is a regexp, only lines starting with that regexp are affected.")
47 (defvar cua--rectangle nil
)
48 (make-variable-buffer-local 'cua--rectangle
)
50 ;; Most recent rectangle geometry. Note: car is buffer.
51 (defvar cua--last-rectangle nil
)
53 ;; Rectangle restored by undo.
54 (defvar cua--restored-rectangle nil
)
56 ;; Last rectangle copied/killed; nil if last kill was not a rectangle.
57 (defvar cua--last-killed-rectangle nil
)
59 ;; List of overlays used to display current rectangle.
60 (defvar cua--rectangle-overlays nil
)
61 (make-variable-buffer-local 'cua--rectangle-overlays
)
62 (put 'cua--rectangle-overlays
'permanent-local t
)
64 (defvar cua--overlay-keymap
65 (let ((map (make-sparse-keymap)))
66 (define-key map
"\r" 'cua-rotate-rectangle
)))
68 (defvar cua--virtual-edges-debug nil
)
70 ;; Undo rectangle commands.
72 (defvar cua--rect-undo-set-point nil
)
74 (defun cua--rectangle-undo-boundary ()
75 (when (listp buffer-undo-list
)
76 (let ((s (cua--rect-start-position))
77 (e (cua--rect-end-position)))
79 (push (list 'apply
0 s e
80 'cua--rect-undo-handler
81 (copy-sequence cua--rectangle
) t s e
)
84 (defun cua--rect-undo-handler (rect on s e
)
85 (if (setq on
(not on
))
86 (setq cua--rect-undo-set-point s
)
87 (setq cua--restored-rectangle
(copy-sequence rect
))
88 (setq cua--buffer-and-point-before-command nil
))
89 (push (list 'apply
0 s
(if on e s
)
90 'cua--rect-undo-handler rect on s e
)
93 ;;; Rectangle geometry
95 (defun cua--rectangle-top (&optional val
)
96 ;; Top of CUA rectangle (buffer position on first line).
98 (aref cua--rectangle
0)
99 (setq val
(line-beginning-position))
100 (if (<= val
(aref cua--rectangle
1))
101 (aset cua--rectangle
0 val
)
102 (aset cua--rectangle
1 val
)
103 (cua--rectangle-corner 2))))
105 (defun cua--rectangle-bot (&optional val
)
106 ;; Bot of CUA rectangle (buffer position on last line).
108 (aref cua--rectangle
1)
109 (setq val
(line-end-position))
110 (if (>= val
(aref cua--rectangle
0))
111 (aset cua--rectangle
1 val
)
112 (aset cua--rectangle
0 val
)
113 (cua--rectangle-corner 2))))
115 (defun cua--rectangle-left (&optional val
)
116 ;; Left column of CUA rectangle.
118 (if (<= val
(aref cua--rectangle
3))
119 (aset cua--rectangle
2 val
)
120 (aset cua--rectangle
3 val
)
121 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
122 (aref cua--rectangle
2)))
124 (defun cua--rectangle-right (&optional val
)
125 ;; Right column of CUA rectangle.
127 (if (>= val
(aref cua--rectangle
2))
128 (aset cua--rectangle
3 val
)
129 (aset cua--rectangle
2 val
)
130 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
131 (aref cua--rectangle
3)))
133 (defun cua--rectangle-corner (&optional advance
)
134 ;; Currently active corner of rectangle.
135 (let ((c (aref cua--rectangle
4)))
136 (if (not (integerp advance
))
138 (aset cua--rectangle
4
140 (- 3 c
) ; opposite corner
141 (mod (+ c
4 advance
) 4)))
142 (aset cua--rectangle
5 0))))
144 (defun cua--rectangle-right-side (&optional topbot
)
145 ;; t if point is on right side of rectangle.
146 (if (and topbot
(= (cua--rectangle-left) (cua--rectangle-right)))
147 (< (cua--rectangle-corner) 2)
148 (= (mod (cua--rectangle-corner) 2) 1)))
150 (defun cua--rectangle-column ()
151 (if (cua--rectangle-right-side)
152 (cua--rectangle-right)
153 (cua--rectangle-left)))
155 (defun cua--rectangle-insert-col (&optional col
)
156 ;; Currently active corner of rectangle.
158 (aset cua--rectangle
5 col
)
159 (if (cua--rectangle-right-side t
)
160 (if (= (aref cua--rectangle
5) 0)
161 (1+ (cua--rectangle-right))
162 (aref cua--rectangle
5))
163 (cua--rectangle-left))))
165 (defun cua--rectangle-virtual-edges (&optional set val
)
166 ;; Current setting of rectangle virtual-edges
168 (aset cua--rectangle
6 val
))
169 (and ;(not buffer-read-only)
170 (aref cua--rectangle
6)))
172 (defun cua--rectangle-restriction (&optional val bounded negated
)
173 ;; Current rectangle restriction
175 (aset cua--rectangle
7
178 (list val bounded negated
)))
179 (aref cua--rectangle
7)))
181 (defun cua--rectangle-assert ()
182 (message "%S (%d)" cua--rectangle
(point))
183 (if (< (cua--rectangle-right) (cua--rectangle-left))
184 (message "rectangle right < left"))
185 (if (< (cua--rectangle-bot) (cua--rectangle-top))
186 (message "rectangle bot < top")))
188 (defun cua--rectangle-get-corners ()
189 ;; Calculate the rectangular region represented by point and mark,
190 ;; putting start in the upper left corner and end in the
191 ;; bottom right corner.
192 (let ((top (point)) (bot (mark)) r l corner
)
195 (setq l
(current-column))
197 (setq r
(current-column))
199 (setq corner
(if (<= l r
) 0 1))
200 (setq top
(prog1 bot
(setq bot top
)))
201 (setq corner
(if (<= l r
) 2 3)))
205 (setq l
(prog1 r
(setq r l
)))
212 (vector top bot l r corner
0 cua-virtual-rectangle-edges nil
)))
214 (defun cua--rectangle-set-corners ()
215 ;; Set mark and point in opposite corners of current rectangle.
216 (let (pp pc mp mc
(c (cua--rectangle-corner)))
218 ((= c
0) ; top/left -> bot/right
219 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-left)
220 mp
(cua--rectangle-bot) mc
(cua--rectangle-right)))
221 ((= c
1) ; top/right -> bot/left
222 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-right)
223 mp
(cua--rectangle-bot) mc
(cua--rectangle-left)))
224 ((= c
2) ; bot/left -> top/right
225 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-left)
226 mp
(cua--rectangle-top) mc
(cua--rectangle-right)))
227 ((= c
3) ; bot/right -> top/left
228 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-right)
229 mp
(cua--rectangle-top) mc
(cua--rectangle-left))))
234 ;; Move cursor inside rectangle, except if char at rigth edge is a tab.
235 (if (and (if (cua--rectangle-right-side)
236 (and (= (move-to-column pc
) (- pc tab-width
))
238 (> (move-to-column pc
) pc
))
243 (defun cua--rect-start-position ()
244 ;; Return point of top left corner
246 (goto-char (cua--rectangle-top))
247 (and (> (move-to-column (cua--rectangle-left))
248 (cua--rectangle-left))
253 (defun cua--rect-end-position ()
254 ;; Return point of bottom right cornet
256 (goto-char (cua--rectangle-bot))
257 (and (= (move-to-column (cua--rectangle-right))
258 (- (cua--rectangle-right) tab-width
))
264 ;;; Rectangle resizing
266 (defun cua--forward-line (n)
267 ;; Move forward/backward one line. Returns t if movement.
269 (and (= (forward-line n
) 0)
270 ;; Deal with end of buffer
274 (defun cua--rectangle-resized ()
275 ;; Refresh state after resizing rectangle
276 (setq cua--buffer-and-point-before-command nil
)
277 (cua--rectangle-insert-col 0)
278 (cua--rectangle-set-corners)
281 (defun cua-resize-rectangle-right (n)
282 "Resize rectangle to the right."
284 (let ((resized (> n
0)))
288 ((cua--rectangle-right-side)
289 (cua--rectangle-right (1+ (cua--rectangle-right)))
290 (move-to-column (cua--rectangle-right)))
292 (cua--rectangle-left (1+ (cua--rectangle-left)))
293 (move-to-column (cua--rectangle-right)))))
295 (cua--rectangle-resized))))
297 (defun cua-resize-rectangle-left (n)
298 "Resize rectangle to the left."
303 (if (or (= (cua--rectangle-right) 0)
304 (and (not (cua--rectangle-right-side)) (= (cua--rectangle-left) 0)))
307 ((cua--rectangle-right-side)
308 (cua--rectangle-right (1- (cua--rectangle-right)))
309 (move-to-column (cua--rectangle-right)))
311 (cua--rectangle-left (1- (cua--rectangle-left)))
312 (move-to-column (cua--rectangle-right))))
315 (cua--rectangle-resized))))
317 (defun cua-resize-rectangle-down (n)
318 "Resize rectangle downwards."
324 ((>= (cua--rectangle-corner) 2)
325 (goto-char (cua--rectangle-bot))
326 (when (cua--forward-line 1)
327 (move-to-column (cua--rectangle-column))
328 (cua--rectangle-bot t
)
331 (goto-char (cua--rectangle-top))
332 (when (cua--forward-line 1)
333 (move-to-column (cua--rectangle-column))
334 (cua--rectangle-top t
)
337 (cua--rectangle-resized))))
339 (defun cua-resize-rectangle-up (n)
340 "Resize rectangle upwards."
346 ((>= (cua--rectangle-corner) 2)
347 (goto-char (cua--rectangle-bot))
348 (when (cua--forward-line -
1)
349 (move-to-column (cua--rectangle-column))
350 (cua--rectangle-bot t
)
353 (goto-char (cua--rectangle-top))
354 (when (cua--forward-line -
1)
355 (move-to-column (cua--rectangle-column))
356 (cua--rectangle-top t
)
359 (cua--rectangle-resized))))
361 (defun cua-resize-rectangle-eol ()
362 "Resize rectangle to end of line."
366 (if (> (current-column) (cua--rectangle-right))
367 (cua--rectangle-right (current-column)))
368 (if (not (cua--rectangle-right-side))
369 (cua--rectangle-corner 1))
370 (cua--rectangle-resized)))
372 (defun cua-resize-rectangle-bol ()
373 "Resize rectangle to beginning of line."
377 (cua--rectangle-left (current-column))
378 (if (cua--rectangle-right-side)
379 (cua--rectangle-corner -
1))
380 (cua--rectangle-resized)))
382 (defun cua-resize-rectangle-bot ()
383 "Resize rectangle to bottom of buffer."
385 (goto-char (point-max))
386 (move-to-column (cua--rectangle-column))
387 (cua--rectangle-bot t
)
388 (cua--rectangle-resized))
390 (defun cua-resize-rectangle-top ()
391 "Resize rectangle to top of buffer."
393 (goto-char (point-min))
394 (move-to-column (cua--rectangle-column))
395 (cua--rectangle-top t
)
396 (cua--rectangle-resized))
398 (defun cua-resize-rectangle-page-up ()
399 "Resize rectangle upwards by one scroll page."
402 (move-to-column (cua--rectangle-column))
403 (if (>= (cua--rectangle-corner) 2)
404 (cua--rectangle-bot t
)
405 (cua--rectangle-top t
))
406 (cua--rectangle-resized))
408 (defun cua-resize-rectangle-page-down ()
409 "Resize rectangle downwards by one scroll page."
412 (move-to-column (cua--rectangle-column))
413 (if (>= (cua--rectangle-corner) 2)
414 (cua--rectangle-bot t
)
415 (cua--rectangle-top t
))
416 (cua--rectangle-resized))
420 ;; This is pretty simplistic, but it does the job...
422 (defun cua-mouse-resize-rectangle (event)
423 "Set rectangle corner at mouse click position."
425 (mouse-set-point event
)
426 ;; FIX ME -- need to calculate virtual column.
427 (if (cua--rectangle-virtual-edges)
428 (move-to-column (car (posn-col-row (event-end event
))) t
))
429 (if (cua--rectangle-right-side)
430 (cua--rectangle-right (current-column))
431 (cua--rectangle-left (current-column)))
432 (if (>= (cua--rectangle-corner) 2)
433 (cua--rectangle-bot t
)
434 (cua--rectangle-top t
))
435 (cua--rectangle-resized))
437 (defvar cua--mouse-last-pos nil
)
439 (defun cua-mouse-set-rectangle-mark (event)
440 "Start rectangle at mouse click position."
443 (cua--deactivate-rectangle)
445 (setq cua--last-rectangle nil
)
446 (mouse-set-point event
)
447 ;; FIX ME -- need to calculate virtual column.
448 (cua-set-rectangle-mark)
449 (setq cua--buffer-and-point-before-command nil
)
450 (setq cua--mouse-last-pos nil
))
452 (defun cua-mouse-save-then-kill-rectangle (event arg
)
453 "Expand rectangle to mouse click position and copy rectangle.
454 If command is repeated at same position, delete the rectangle."
456 (if (and (eq this-command last-command
)
457 (eq (point) (car-safe cua--mouse-last-pos
))
458 (eq cua--last-killed-rectangle
(cdr-safe cua--mouse-last-pos
)))
460 (unless buffer-read-only
461 (cua--delete-rectangle))
463 (cua-mouse-resize-rectangle event
)
464 (let ((cua-keep-region-after-copy t
))
465 (cua-copy-rectangle arg
)
466 (setq cua--mouse-last-pos
(cons (point) cua--last-killed-rectangle
)))))
468 (defun cua--mouse-ignore (event)
470 (setq this-command last-command
))
472 (defun cua--rectangle-move (dir)
474 (top (cua--rectangle-top))
475 (bot (cua--rectangle-bot))
476 (l (cua--rectangle-left))
477 (r (cua--rectangle-right)))
481 (when (cua--forward-line -
1)
482 (cua--rectangle-top t
)
485 (cua--rectangle-bot t
)))
488 (when (cua--forward-line 1)
489 (cua--rectangle-bot t
)
491 (cua--forward-line 1)
492 (cua--rectangle-top t
)))
495 (cua--rectangle-left (1- l
))
496 (cua--rectangle-right (1- r
))))
498 (cua--rectangle-right (1+ r
))
499 (cua--rectangle-left (1+ l
)))
503 (setq cua--buffer-and-point-before-command nil
)
504 (cua--rectangle-set-corners)
505 (cua--keep-active))))
508 ;;; Operations on current rectangle
510 (defun cua--tabify-start (start end
)
511 ;; Return position where auto-tabify should start (or nil if not required).
515 (and (not buffer-read-only
)
516 cua-auto-tabify-rectangles
517 (if (or (not (integerp cua-auto-tabify-rectangles
))
518 (= (point-min) (point-max))
520 (goto-char (max (point-min)
521 (- start cua-auto-tabify-rectangles
)))
522 (search-forward "\t" (min (point-max)
523 (+ end cua-auto-tabify-rectangles
)) t
)))
526 (defun cua--rectangle-operation (keep-clear visible undo pad tabify
&optional fct post-fct
)
527 ;; Call FCT for each line of region with 4 parameters:
528 ;; Region start, end, left-col, right-col
529 ;; Point is at start when FCT is called
530 ;; Call fct with (s,e) = whole lines if VISIBLE non-nil.
531 ;; Only call fct for visible lines if VISIBLE==t.
532 ;; Set undo boundary if UNDO is non-nil.
533 ;; Rectangle is padded if PAD = t or numeric and (cua--rectangle-virtual-edges)
534 ;; Perform auto-tabify after operation if TABIFY is non-nil.
535 ;; Mark is kept if keep-clear is 'keep and cleared if keep-clear is 'clear.
536 (let* ((inhibit-field-text-motion t
)
537 (start (cua--rectangle-top))
538 (end (cua--rectangle-bot))
539 (l (cua--rectangle-left))
540 (r (1+ (cua--rectangle-right)))
542 (tabpad (and (integerp pad
) (= pad
2)))
543 (sel (cua--rectangle-restriction))
544 (tabify-start (and tabify
(cua--tabify-start start end
))))
546 (cua--rectangle-undo-boundary))
548 (setq pad
(cua--rectangle-virtual-edges)))
552 (when (> (cua--rectangle-corner) 1)
554 (and (bolp) (not (eolp)) (not (eobp))
555 (setq end
(1+ end
))))
557 (setq start
(max (window-start) start
))
558 (setq end
(min (window-end) end
)))
560 (setq end
(line-end-position))
561 (if (and visible
(bolp) (not (eobp)))
564 (setq start
(line-beginning-position))
565 (narrow-to-region start end
)
566 (goto-char (point-min))
567 (while (< (point) (point-max))
568 (move-to-column r pad
)
569 (and (not pad
) (not visible
) (> (current-column) r
)
571 (if (and tabpad
(not pad
) (looking-at "\t"))
573 (set-marker m
(point))
574 (move-to-column l pad
)
575 (if (and fct
(or visible
(and (>= (current-column) l
) (<= (current-column) r
))))
576 (let ((v t
) (p (point)))
579 (setq v
(looking-at (car sel
)))
580 (setq v
(re-search-forward (car sel
) m t
))
582 (if (car (cdr (cdr sel
)))
585 (funcall fct p m l r v
)
587 (funcall fct p m l r
)))))
591 (cua--rectangle-bot t
))
593 (funcall post-fct l r
))
595 (tabify tabify-start
(point)))))
597 ((eq keep-clear
'keep
)
599 ((eq keep-clear
'clear
)
601 ((eq keep-clear
'corners
)
602 (cua--rectangle-set-corners)
604 (setq cua--buffer-and-point-before-command nil
)))
606 (put 'cua--rectangle-operation
'lisp-indent-function
4)
608 (defun cua--delete-rectangle ()
610 (if (not (cua--rectangle-virtual-edges))
611 (cua--rectangle-operation nil nil t
2 t
613 (setq lines
(1+ lines
))
614 (if (and (> e s
) (<= e
(point-max)))
615 (delete-region s e
))))
616 (cua--rectangle-operation nil
1 t nil t
618 (setq lines
(1+ lines
))
619 (when (and (> e s
) (<= e
(point-max)))
620 (delete-region s e
)))))
623 (defun cua--extract-rectangle ()
625 (if (not (cua--rectangle-virtual-edges))
626 (cua--rectangle-operation nil nil nil nil nil
; do not tabify
628 (setq rect
(cons (cua--filter-buffer-noprops s e
) rect
))))
629 (cua--rectangle-operation nil
1 nil nil nil
; do not tabify
631 (let ((copy t
) (bs 0) (as 0) row
)
632 (if (= s e
) (setq e
(1+ e
)))
635 (if (= (point) (line-end-position))
638 (skip-chars-forward "\s\t" e
)
639 (setq bs
(- (min r
(current-column)) l
)
642 (skip-chars-backward "\s\t" s
)
643 (setq as
(- r
(max (current-column) l
))
645 (setq row
(if (and copy
(> e s
))
646 (cua--filter-buffer-noprops s e
)
649 (setq row
(concat (make-string bs ?\s
) row
)))
651 (setq row
(concat row
(make-string as ?\s
))))
652 (setq rect
(cons row rect
))))))
655 (defun cua--insert-rectangle (rect &optional below paste-column line-count
)
656 ;; Insert rectangle as insert-rectangle, but don't set mark and exit with
657 ;; point at either next to top right or below bottom left corner
658 ;; Notice: In overwrite mode, the rectangle is inserted as separate text lines.
660 (setq below
(and (bolp)
661 (or (eolp) (eobp) (= (1+ (point)) (point-max))))))
663 (setq paste-column
(current-column)))
666 (tabify-start (cua--tabify-start (point) (point)))
669 (while (or lines below
)
674 (or (bolp) (insert ?
\n))))
675 (unless overwrite-mode
676 (move-to-column paste-column t
))
679 (insert-for-yank (car lines
))
681 (setq last-column
(current-column)))
682 (setq lines
(cdr lines
))
683 (and first
(not below
)
686 (if (and line-count
(= (setq line-count
(1- line-count
)) 0))
688 (when (and line-count last-column
(not overwrite-mode
))
689 (while (> line-count
0)
691 (or (bolp) (insert ?
\n))
692 (move-to-column paste-column t
)
693 (insert-char ?\s
(- last-column paste-column -
1))
694 (setq line-count
(1- line-count
))))
695 (when (and tabify-start
696 (not overwrite-mode
))
697 (tabify tabify-start
(point)))
698 (and p
(not overwrite-mode
)
701 (defun cua--copy-rectangle-as-kill (&optional ring
)
703 (set-register cua--register
(cua--extract-rectangle))
704 (setq killed-rectangle
(cua--extract-rectangle))
705 (setq cua--last-killed-rectangle
(cons (and kill-ring
(car kill-ring
)) killed-rectangle
))
708 (function (lambda (row) (concat row
"\n")))
709 killed-rectangle
"")))))
711 (defun cua--activate-rectangle ()
712 ;; Turn on rectangular marking mode by disabling transient mark mode
713 ;; and manually handling highlighting from a post command hook.
714 ;; Be careful if we are already marking a rectangle.
716 (if (and cua--last-rectangle
717 (eq (car cua--last-rectangle
) (current-buffer))
718 (eq (car (cdr cua--last-rectangle
)) (point)))
719 (cdr (cdr cua--last-rectangle
))
720 (cua--rectangle-get-corners))
721 cua--status-string
(if (cua--rectangle-virtual-edges) " [R]" "")
722 cua--last-rectangle nil
))
724 ;; (defvar cua-save-point nil)
726 (defun cua--deactivate-rectangle ()
727 ;; This is used to clean up after `cua--activate-rectangle'.
728 (mapc (function delete-overlay
) cua--rectangle-overlays
)
729 (setq cua--last-rectangle
(cons (current-buffer)
730 (cons (point) ;; cua-save-point
733 cua--rectangle-overlays nil
734 cua--status-string nil
735 cua--mouse-last-pos nil
))
737 (defun cua--highlight-rectangle ()
738 ;; This function is used to highlight the rectangular region.
739 ;; We do this by putting an overlay on each line within the rectangle.
740 ;; Each overlay extends across all the columns of the rectangle.
741 ;; We try to reuse overlays where possible because this is more efficient
742 ;; and results in less flicker.
743 ;; If cua--rectangle-virtual-edges is nil and the buffer contains tabs or short lines,
744 ;; the higlighted region may not be perfectly rectangular.
745 (let ((deactivate-mark deactivate-mark
)
746 (old cua--rectangle-overlays
)
748 (left (cua--rectangle-left))
749 (right (1+ (cua--rectangle-right))))
750 (when (/= left right
)
751 (sit-for 0) ; make window top/bottom reliable
752 (cua--rectangle-operation nil t nil nil nil
; do not tabify
754 (let ((rface (if v
'cua-rectangle
'cua-rectangle-noselect
))
756 (when (cua--rectangle-virtual-edges)
757 (let ((lb (line-beginning-position))
758 (le (line-end-position))
761 (setq cl
(move-to-column l
)
763 (setq cr
(move-to-column r
)
768 (setq cl0
(current-column)))
772 (setq cr0
(current-column)))
773 (unless (and (= cl l
) (= cr r
))
777 (- l cl0
(if (and (= le pl
) (/= le lb
)) 1 0))
778 (if cua--virtual-edges-debug ?. ?\s
))
779 'face
(or (get-text-property (1- s
) 'face
) 'default
)))
786 (or bs
(/= cr0
(- cr tab-width
)))
787 (/= (mod cr tab-width
) 0))
793 (if cua--virtual-edges-debug ?
, ?\s
))
795 (if (cua--rectangle-right-side)
796 (put-text-property (1- (length ms
)) (length ms
) 'cursor
2 ms
)
797 (put-text-property 0 1 'cursor
2 ms
))
798 (setq bs
(concat bs ms
))
803 (- r cr0
(if (= le pr
) 1 0))
804 (if cua--virtual-edges-debug ?~ ?\s
))
806 (if (cua--rectangle-right-side)
807 (put-text-property (1- (length as
)) (length as
) 'cursor
2 as
)
808 (put-text-property 0 1 'cursor
2 as
))
810 (setq e
(1- e
))))))))
811 ;; Trim old leading overlays.
813 (setq overlay
(car old
))
814 (< (overlay-start overlay
) s
)
815 (/= (overlay-end overlay
) e
))
816 (delete-overlay overlay
)
817 (setq old
(cdr old
)))
818 ;; Reuse an overlay if possible, otherwise create one.
820 (setq overlay
(car old
))
821 (or (= (overlay-start overlay
) s
)
822 (= (overlay-end overlay
) e
)))
824 (move-overlay overlay s e
)
825 (setq old
(cdr old
)))
826 (setq overlay
(make-overlay s e
)))
827 (overlay-put overlay
'before-string bs
)
828 (overlay-put overlay
'after-string as
)
829 (overlay-put overlay
'face rface
)
830 (overlay-put overlay
'keymap cua--overlay-keymap
)
831 (overlay-put overlay
'window
(selected-window))
832 (setq new
(cons overlay new
))))))
833 ;; Trim old trailing overlays.
834 (mapc (function delete-overlay
) old
)
835 (setq cua--rectangle-overlays
(nreverse new
))))
837 (defun cua--indent-rectangle (&optional ch to-col clear
)
838 ;; Indent current rectangle.
839 (let ((col (cua--rectangle-insert-col))
840 (pad (cua--rectangle-virtual-edges))
842 (cua--rectangle-operation (if clear
'clear
'corners
) nil t pad nil
844 (move-to-column col pad
)
846 (< (current-column) col
))
847 (move-to-column col t
))
849 (to-col (indent-to to-col
))
850 ((and ch
(not (eq ch ?
\t))) (insert ch
))
851 (t (tab-to-tab-stop)))
852 (if (cua--rectangle-right-side t
)
853 (cua--rectangle-insert-col (current-column))
854 (setq indent
(- (current-column) l
))))
856 (when (and indent
(> indent
0))
857 (aset cua--rectangle
2 (+ l indent
))
858 (aset cua--rectangle
3 (+ r indent -
1)))))))
861 ;; rectangle functions / actions
864 (defvar cua--rectangle-initialized nil
)
866 (defun cua-set-rectangle-mark (&optional reopen
)
867 "Set mark and start in CUA rectangle mode.
868 With prefix argument, activate previous rectangle if possible."
870 (unless cua--rectangle-initialized
871 (cua--init-rectangles))
872 (when (not cua--rectangle
)
875 (eq (car cua--last-rectangle
) (current-buffer)))
876 (goto-char (car (cdr cua--last-rectangle
)))
877 (if (not mark-active
)
878 (push-mark nil nil t
)))
879 (cua--activate-rectangle)
880 (cua--rectangle-set-corners)
882 cua--explicit-region-start t
)
883 (if cua-enable-rectangle-auto-help
884 (cua-help-for-rectangle t
))))
886 (defun cua-clear-rectangle-mark ()
887 "Cancel current rectangle."
890 (setq mark-active nil
891 cua--explicit-region-start nil
)
892 (cua--deactivate-rectangle)))
894 (defun cua-toggle-rectangle-mark ()
897 (cua--deactivate-rectangle)
898 (unless cua--rectangle-initialized
899 (cua--init-rectangles))
900 (cua--activate-rectangle))
902 (if cua-enable-rectangle-auto-help
903 (cua-help-for-rectangle t
))
904 (if cua-enable-region-auto-help
905 (cua-help-for-region t
))))
907 (defun cua-restrict-regexp-rectangle (arg)
908 "Restrict rectangle to lines (not) matching REGEXP.
909 With prefix argument, the toggle restriction."
911 (let ((r (cua--rectangle-restriction)) regexp
)
912 (if (and r
(null (car (cdr r
))))
914 (cua--rectangle-restriction (car r
) nil
(not (car (cdr (cdr r
)))))
915 (cua--rectangle-restriction "" nil nil
))
916 (cua--rectangle-restriction
917 (read-from-minibuffer "Restrict rectangle (regexp): "
918 nil nil nil nil
) nil arg
))))
920 (defun cua-restrict-prefix-rectangle (arg)
921 "Restrict rectangle to lines (not) starting with CHAR.
922 With prefix argument, the toggle restriction."
924 (let ((r (cua--rectangle-restriction)) regexp
)
925 (if (and r
(car (cdr r
)))
927 (cua--rectangle-restriction (car r
) t
(not (car (cdr (cdr r
)))))
928 (cua--rectangle-restriction "" nil nil
))
929 (cua--rectangle-restriction
931 (read-char "Restrictive rectangle (char): ")) t arg
))))
933 (defun cua-move-rectangle-up ()
935 (cua--rectangle-move 'up
))
937 (defun cua-move-rectangle-down ()
939 (cua--rectangle-move 'down
))
941 (defun cua-move-rectangle-left ()
943 (cua--rectangle-move 'left
))
945 (defun cua-move-rectangle-right ()
947 (cua--rectangle-move 'right
))
949 (defun cua-copy-rectangle (arg)
951 (setq arg
(cua--prefix-arg arg
))
952 (cua--copy-rectangle-as-kill arg
)
953 (if cua-keep-region-after-copy
957 (defun cua-cut-rectangle (arg)
960 (cua-copy-rectangle arg
)
961 (setq arg
(cua--prefix-arg arg
))
962 (goto-char (min (mark) (point)))
963 (cua--copy-rectangle-as-kill arg
)
964 (cua--delete-rectangle))
967 (defun cua-delete-rectangle ()
969 (goto-char (min (point) (mark)))
970 (if cua-delete-copy-to-register-0
971 (set-register ?
0 (cua--extract-rectangle)))
972 (cua--delete-rectangle)
975 (defun cua-rotate-rectangle ()
977 (cua--rectangle-corner (if (= (cua--rectangle-left) (cua--rectangle-right)) 0 1))
978 (cua--rectangle-set-corners)
979 (if (cua--rectangle-virtual-edges)
980 (setq cua--buffer-and-point-before-command nil
)))
982 (defun cua-toggle-rectangle-virtual-edges ()
984 (cua--rectangle-virtual-edges t
(not (cua--rectangle-virtual-edges)))
985 (cua--rectangle-set-corners)
986 (setq cua--status-string
(and (cua--rectangle-virtual-edges) " [R]"))
989 (defun cua-do-rectangle-padding ()
992 (message "Cannot do padding in read-only buffer")
993 (cua--rectangle-operation nil nil t t t
)
994 (cua--rectangle-set-corners))
997 (defun cua-open-rectangle ()
998 "Blank out CUA rectangle, shifting text right.
999 The text previously in the region is not overwritten by the blanks,
1000 but instead winds up to the right of the rectangle."
1002 (cua--rectangle-operation 'corners nil t
1 nil
1004 (skip-chars-forward " \t")
1005 (let ((ws (- (current-column) l
))
1007 (skip-chars-backward " \t")
1008 (delete-region (point) p
)
1009 (indent-to (+ r ws
))))))
1011 (defun cua-close-rectangle (arg)
1012 "Delete all whitespace starting at left edge of CUA rectangle.
1013 On each line in the rectangle, all continuous whitespace starting
1014 at that column is deleted.
1015 With prefix arg, also delete whitespace to the left of that column."
1017 (cua--rectangle-operation 'clear nil t
1 nil
1020 (skip-syntax-backward " " (line-beginning-position))
1022 (skip-syntax-forward " " (line-end-position))
1023 (delete-region s
(point)))))
1025 (defun cua-blank-rectangle ()
1026 "Blank out CUA rectangle.
1027 The text previously in the rectangle is overwritten by the blanks."
1029 (cua--rectangle-operation 'keep nil nil
1 nil
1032 (skip-syntax-forward " " (line-end-position))
1034 (let ((column (current-column)))
1036 (skip-syntax-backward " " (line-beginning-position))
1037 (delete-region (point) e
)
1038 (indent-to column
)))))
1040 (defun cua-align-rectangle ()
1041 "Align rectangle lines to left column."
1044 (cua--rectangle-operation 'clear nil t t nil
1046 (let ((b (line-beginning-position)))
1047 (skip-syntax-backward "^ " b
)
1048 (skip-syntax-backward " " b
)
1050 (skip-syntax-forward " " (line-end-position))
1051 (delete-region s
(point))
1055 ;; (setq cua-save-point (point))
1058 (declare-function cua--cut-rectangle-to-global-mark
"cua-gmrk" (as-text))
1059 (declare-function cua--copy-rectangle-to-global-mark
"cua-gmrk" (as-text))
1061 (defun cua-copy-rectangle-as-text (&optional arg delete
)
1062 "Copy rectangle, but store as normal text."
1064 (if cua--global-mark-active
1066 (cua--cut-rectangle-to-global-mark t
)
1067 (cua--copy-rectangle-to-global-mark t
))
1068 (let* ((rect (cua--extract-rectangle))
1070 (function (lambda (row) (concat row
"\n")))
1072 (setq arg
(cua--prefix-arg arg
))
1074 (set-register cua--register text
)
1077 (cua--delete-rectangle))
1080 (defun cua-cut-rectangle-as-text (arg)
1081 "Kill rectangle, but store as normal text."
1083 (cua-copy-rectangle-as-text arg
(not buffer-read-only
)))
1085 (defun cua-string-rectangle (string)
1086 "Replace CUA rectangle contents with STRING on each line.
1087 The length of STRING need not be the same as the rectangle width."
1088 (interactive "sString rectangle: ")
1089 (cua--rectangle-operation 'keep nil t t nil
1092 (skip-chars-forward " \t")
1093 (let ((ws (- (current-column) l
)))
1094 (delete-region s
(point))
1096 (indent-to (+ (current-column) ws
))))
1097 (unless (cua--rectangle-restriction)
1099 (cua--rectangle-right (max l
(+ l
(length string
) -
1)))))))
1101 (defun cua-fill-char-rectangle (character)
1102 "Replace CUA rectangle contents with CHARACTER."
1103 (interactive "cFill rectangle with character: ")
1104 (cua--rectangle-operation 'clear nil t
1 nil
1107 (move-to-column l t
)
1108 (insert-char character
(- r l
)))))
1110 (defun cua-replace-in-rectangle (regexp newtext
)
1111 "Replace REGEXP with NEWTEXT in each line of CUA rectangle."
1112 (interactive "sReplace regexp: \nsNew text: ")
1113 (if buffer-read-only
1114 (message "Cannot replace in read-only buffer")
1115 (cua--rectangle-operation 'keep nil t
1 nil
1117 (if (re-search-forward regexp e t
)
1118 (replace-match newtext nil nil
))))))
1120 (defun cua-incr-rectangle (increment)
1121 "Increment each line of CUA rectangle by prefix amount."
1123 (cua--rectangle-operation 'keep nil t
1 nil
1126 ((re-search-forward "0x\\([0-9a-fA-F]+\\)" e t
)
1127 (let* ((txt (cua--filter-buffer-noprops (match-beginning 1) (match-end 1)))
1128 (n (string-to-number txt
16))
1129 (fmt (format "0x%%0%dx" (length txt
))))
1130 (replace-match (format fmt
(+ n increment
)))))
1131 ((re-search-forward "\\( *-?[0-9]+\\)" e t
)
1132 (let* ((txt (cua--filter-buffer-noprops (match-beginning 1) (match-end 1)))
1133 (prefix (if (= (aref txt
0) ?
0) "0" ""))
1134 (n (string-to-number txt
10))
1135 (fmt (format "%%%s%dd" prefix
(length txt
))))
1136 (replace-match (format fmt
(+ n increment
)))))
1139 (defvar cua--rectangle-seq-format
"%d"
1140 "Last format used by `cua-sequence-rectangle'.")
1142 (defun cua-sequence-rectangle (first incr format
)
1143 "Resequence each line of CUA rectangle starting from FIRST.
1144 The numbers are formatted according to the FORMAT string."
1146 (list (if current-prefix-arg
1147 (prefix-numeric-value current-prefix-arg
)
1149 (read-string "Start value: (0) " nil nil
"0")))
1151 (read-string "Increment: (1) " nil nil
"1"))
1152 (read-string (concat "Format: (" cua--rectangle-seq-format
") "))))
1153 (if (= (length format
) 0)
1154 (setq format cua--rectangle-seq-format
)
1155 (setq cua--rectangle-seq-format format
))
1156 (cua--rectangle-operation 'clear nil t
1 nil
1159 (insert (format format first
))
1160 (setq first
(+ first incr
)))))
1162 (defmacro cua--convert-rectangle-as
(command tabify
)
1163 `(cua--rectangle-operation 'clear nil nil nil
,tabify
1167 (defun cua-upcase-rectangle ()
1168 "Convert the rectangle to upper case."
1170 (cua--convert-rectangle-as upcase-region nil
))
1172 (defun cua-downcase-rectangle ()
1173 "Convert the rectangle to lower case."
1175 (cua--convert-rectangle-as downcase-region nil
))
1177 (defun cua-upcase-initials-rectangle ()
1178 "Convert the rectangle initials to upper case."
1180 (cua--convert-rectangle-as upcase-initials-region nil
))
1182 (defun cua-capitalize-rectangle ()
1183 "Convert the rectangle to proper case."
1185 (cua--convert-rectangle-as capitalize-region nil
))
1188 ;;; Replace/rearrange text in current rectangle
1190 (defun cua--rectangle-aux-replace (width adjust keep replace pad format-fct
&optional setup-fct
)
1191 ;; Process text inserted by calling SETUP-FCT or current rectangle if nil.
1192 ;; Then call FORMAT-FCT on text (if non-nil); takes two args: start and end.
1193 ;; Fill to WIDTH characters if > 0 or fill to current width if == 0.
1194 ;; Don't fill if WIDTH < 0.
1195 ;; Replace current rectangle by filled text if REPLACE is non-nil
1196 (let ((auxbuf (get-buffer-create "*CUA temp*"))
1197 (w (if (> width
1) width
1198 (- (cua--rectangle-right) (cua--rectangle-left) -
1)))
1199 (r (or setup-fct
(cua--extract-rectangle)))
1201 (with-current-buffer auxbuf
1205 (cua--insert-rectangle r
))
1207 (let ((fill-column w
))
1208 (funcall format-fct
(point-min) (point-max))))
1210 (goto-char (point-min))
1212 (setq z
(cons (filter-buffer-substring (point) (line-end-position)) z
))
1214 (if (not cua--debug
)
1215 (kill-buffer auxbuf
))
1217 (setq z
(reverse z
))
1220 (cua--rectangle-operation nil nil t pad nil
1224 (skip-chars-forward " \t")
1225 (setq cc
(current-column))
1227 (print (list cc s e
) auxbuf
))
1228 (delete-region s
(point))
1231 (move-to-column l t
)
1233 (when (> (current-column) (+ l w
))
1235 (move-to-column (+ l w
) t
)
1236 (delete-region (point) y
)
1240 (print (list (current-column) cc
) auxbuf
))
1244 (message "Warning: Truncated %d row%s" tr
(if (> tr
1) "s" "")))
1246 (cua--rectangle-right (+ (cua--rectangle-left) w -
1)))
1248 (cua--rectangle-resized)))))
1250 (put 'cua--rectangle-aux-replace
'lisp-indent-function
4)
1252 (defun cua--left-fill-rectangle (start end
)
1254 (while (< (point) (point-max))
1255 (delete-horizontal-space nil
)
1257 (fill-region-as-paragraph (point-min) (point-max) 'left nil
)
1258 (untabify (point-min) (point-max)))
1260 (defun cua-text-fill-rectangle (width text
)
1261 "Replace rectagle with filled TEXT read from minibuffer.
1262 A numeric prefix argument is used a new width for the filled rectangle."
1264 (prefix-numeric-value current-prefix-arg
)
1265 (read-from-minibuffer "Enter text: "
1267 (cua--rectangle-aux-replace width t t t
1
1268 'cua--left-fill-rectangle
1269 '(lambda () (insert text
))))
1271 (defun cua-refill-rectangle (width)
1272 "Fill contents of current rectagle.
1273 A numeric prefix argument is used as new width for the filled rectangle."
1275 (cua--rectangle-aux-replace
1276 (if width
(prefix-numeric-value width
) 0)
1277 t t t
1 'cua--left-fill-rectangle
))
1279 (defun cua-shell-command-on-rectangle (replace command
)
1280 "Run shell command on rectangle like `shell-command-on-region'.
1281 With prefix arg, replace rectangle with output from command."
1284 (read-from-minibuffer "Shell command on rectangle: "
1286 'shell-command-history
)))
1287 (cua--rectangle-aux-replace -
1 t t replace
1
1289 (shell-command-on-region s e command
1290 replace replace nil
))))
1292 (defun cua-reverse-rectangle ()
1293 "Reverse the lines of the rectangle."
1295 (cua--rectangle-aux-replace 0 t t t t
'reverse-region
))
1297 (defun cua-scroll-rectangle-up ()
1298 "Remove the first line of the rectangle and scroll remaining lines up."
1300 (cua--rectangle-aux-replace 0 t t t t
1302 (if (= (forward-line 1) 0)
1303 (delete-region s
(point))))))
1305 (defun cua-scroll-rectangle-down ()
1306 "Insert a blank line at the first line of the rectangle.
1307 The remaining lines are scrolled down, losing the last line."
1309 (cua--rectangle-aux-replace 0 t t t t
1315 ;;; Insert/delete text to left or right of rectangle
1317 (defun cua-insert-char-rectangle (&optional ch
)
1319 (if buffer-read-only
1321 (cua--indent-rectangle (or ch
(aref (this-single-command-keys) 0)))
1325 (defun cua-indent-rectangle (column)
1326 "Indent rectangle to next tab stop.
1327 With prefix arg, indent to that column."
1330 (cua-insert-char-rectangle ?
\t)
1331 (cua--indent-rectangle nil
(prefix-numeric-value column
))))
1333 (defun cua-delete-char-rectangle ()
1334 "Delete char to left or right of rectangle."
1336 (let ((col (cua--rectangle-insert-col))
1337 (pad (cua--rectangle-virtual-edges))
1339 (cua--rectangle-operation 'corners nil t pad nil
1342 (if (cua--rectangle-right-side t
)
1347 (delete-backward-char 1)
1348 (if (cua--rectangle-right-side t
)
1349 (cua--rectangle-insert-col (current-column))
1350 (setq indent
(- l
(current-column))))))
1352 (when (and indent
(> indent
0))
1353 (aset cua--rectangle
2 (- l indent
))
1354 (aset cua--rectangle
3 (- r indent
1)))))))
1356 (defun cua-help-for-rectangle (&optional help
)
1358 (let ((M (cond ((eq cua--rectangle-modifier-key
'hyper
) " H-")
1359 ((eq cua--rectangle-modifier-key
'super
) " s-")
1360 ((eq cua--rectangle-modifier-key
'alt
) " A-")
1363 (concat (if help
"C-?:help" "")
1364 M
"p:pad" M
"o:open" M
"c:close" M
"b:blank"
1365 M
"s:string" M
"f:fill" M
"i:incr" M
"n:seq"))))
1368 ;;; CUA-like cut & paste for rectangles
1370 (defun cua--cancel-rectangle ()
1373 (cua--deactivate-rectangle))
1374 (setq cua--last-rectangle nil
))
1376 (defun cua--rectangle-post-command ()
1377 (if cua--restored-rectangle
1379 (setq cua--rectangle cua--restored-rectangle
1380 cua--restored-rectangle nil
1382 deactivate-mark nil
)
1383 (cua--rectangle-set-corners))
1384 (when (and cua--rectangle cua--buffer-and-point-before-command
1385 (equal (car cua--buffer-and-point-before-command
) (current-buffer))
1386 (not (= (cdr cua--buffer-and-point-before-command
) (point))))
1387 (if (cua--rectangle-right-side)
1388 (cua--rectangle-right (current-column))
1389 (cua--rectangle-left (current-column)))
1390 (if (>= (cua--rectangle-corner) 2)
1391 (cua--rectangle-bot t
)
1392 (cua--rectangle-top t
))))
1394 (if (and mark-active
1395 (not deactivate-mark
))
1396 (cua--highlight-rectangle)
1397 (cua--deactivate-rectangle))
1398 (when cua--rectangle-overlays
1399 ;; clean-up after revert-buffer
1400 (mapc (function delete-overlay
) cua--rectangle-overlays
)
1401 (setq cua--rectangle-overlays nil
)
1402 (setq deactivate-mark t
)))
1403 (when cua--rect-undo-set-point
1404 (goto-char cua--rect-undo-set-point
)
1405 (setq cua--rect-undo-set-point nil
)))
1409 (defun cua--rect-M/H-key
(key cmd
)
1410 (cua--M/H-key cua--rectangle-keymap key cmd
))
1412 (defun cua--init-rectangles ()
1413 (define-key cua--rectangle-keymap cua-rectangle-mark-key
'cua-clear-rectangle-mark
)
1414 (define-key cua--region-keymap cua-rectangle-mark-key
'cua-toggle-rectangle-mark
)
1415 (unless (eq cua--rectangle-modifier-key
'meta
)
1416 (cua--rect-M/H-key ?\s
'cua-clear-rectangle-mark
)
1417 (cua--M/H-key cua--region-keymap ?\s
'cua-toggle-rectangle-mark
))
1419 (define-key cua--rectangle-keymap
[remap copy-region-as-kill
] 'cua-copy-rectangle
)
1420 (define-key cua--rectangle-keymap
[remap kill-ring-save
] 'cua-copy-rectangle
)
1421 (define-key cua--rectangle-keymap
[remap kill-region
] 'cua-cut-rectangle
)
1422 (define-key cua--rectangle-keymap
[remap delete-char
] 'cua-delete-rectangle
)
1423 (define-key cua--rectangle-keymap
[remap set-mark-command
] 'cua-toggle-rectangle-mark
)
1425 (define-key cua--rectangle-keymap
[remap forward-char
] 'cua-resize-rectangle-right
)
1426 (define-key cua--rectangle-keymap
[remap backward-char
] 'cua-resize-rectangle-left
)
1427 (define-key cua--rectangle-keymap
[remap next-line
] 'cua-resize-rectangle-down
)
1428 (define-key cua--rectangle-keymap
[remap previous-line
] 'cua-resize-rectangle-up
)
1429 (define-key cua--rectangle-keymap
[remap end-of-line
] 'cua-resize-rectangle-eol
)
1430 (define-key cua--rectangle-keymap
[remap beginning-of-line
] 'cua-resize-rectangle-bol
)
1431 (define-key cua--rectangle-keymap
[remap end-of-buffer
] 'cua-resize-rectangle-bot
)
1432 (define-key cua--rectangle-keymap
[remap beginning-of-buffer
] 'cua-resize-rectangle-top
)
1433 (define-key cua--rectangle-keymap
[remap scroll-down
] 'cua-resize-rectangle-page-up
)
1434 (define-key cua--rectangle-keymap
[remap scroll-up
] 'cua-resize-rectangle-page-down
)
1435 (define-key cua--rectangle-keymap
[remap scroll-down-command
] 'cua-resize-rectangle-page-up
)
1436 (define-key cua--rectangle-keymap
[remap scroll-up-command
] 'cua-resize-rectangle-page-down
)
1438 (define-key cua--rectangle-keymap
[remap delete-backward-char
] 'cua-delete-char-rectangle
)
1439 (define-key cua--rectangle-keymap
[remap backward-delete-char
] 'cua-delete-char-rectangle
)
1440 (define-key cua--rectangle-keymap
[remap backward-delete-char-untabify
] 'cua-delete-char-rectangle
)
1441 (define-key cua--rectangle-keymap
[remap self-insert-command
] 'cua-insert-char-rectangle
)
1442 (define-key cua--rectangle-keymap
[remap self-insert-iso
] 'cua-insert-char-rectangle
)
1444 ;; Catch self-inserting characters which are "stolen" by other modes
1445 (define-key cua--rectangle-keymap
[t]
1446 '(menu-item "sic" cua-insert-char-rectangle :filter cua--self-insert-char-p))
1448 (define-key cua--rectangle-keymap "\r" 'cua-rotate-rectangle)
1449 (define-key cua--rectangle-keymap "\t" 'cua-indent-rectangle)
1451 (define-key cua--rectangle-keymap [(control ??)] 'cua-help-for-rectangle)
1453 (define-key cua--rectangle-keymap [mouse-1] 'cua-mouse-set-rectangle-mark)
1454 (define-key cua--rectangle-keymap [down-mouse-1] 'cua--mouse-ignore)
1455 (define-key cua--rectangle-keymap [drag-mouse-1] 'cua--mouse-ignore)
1456 (define-key cua--rectangle-keymap [mouse-3] 'cua-mouse-save-then-kill-rectangle)
1457 (define-key cua--rectangle-keymap [down-mouse-3] 'cua--mouse-ignore)
1458 (define-key cua--rectangle-keymap [drag-mouse-3] 'cua--mouse-ignore)
1460 (cua--rect-M/H-key 'up 'cua-move-rectangle-up)
1461 (cua--rect-M/H-key 'down 'cua-move-rectangle-down)
1462 (cua--rect-M/H-key 'left 'cua-move-rectangle-left)
1463 (cua--rect-M/H-key 'right 'cua-move-rectangle-right)
1465 (cua--rect-M/H-key '(control up) 'cua-scroll-rectangle-up)
1466 (cua--rect-M/H-key '(control down) 'cua-scroll-rectangle-down)
1468 (cua--rect-M/H-key ?a 'cua-align-rectangle)
1469 (cua--rect-M/H-key ?b 'cua-blank-rectangle)
1470 (cua--rect-M/H-key ?c 'cua-close-rectangle)
1471 (cua--rect-M/H-key ?f 'cua-fill-char-rectangle)
1472 (cua--rect-M/H-key ?i 'cua-incr-rectangle)
1473 (cua--rect-M/H-key ?k 'cua-cut-rectangle-as-text)
1474 (cua--rect-M/H-key ?l 'cua-downcase-rectangle)
1475 (cua--rect-M/H-key ?m 'cua-copy-rectangle-as-text)
1476 (cua--rect-M/H-key ?n 'cua-sequence-rectangle)
1477 (cua--rect-M/H-key ?o 'cua-open-rectangle)
1478 (cua--rect-M/H-key ?p 'cua-toggle-rectangle-virtual-edges)
1479 (cua--rect-M/H-key ?P 'cua-do-rectangle-padding)
1480 (cua--rect-M/H-key ?q 'cua-refill-rectangle)
1481 (cua--rect-M/H-key ?r 'cua-replace-in-rectangle)
1482 (cua--rect-M/H-key ?R 'cua-reverse-rectangle)
1483 (cua--rect-M/H-key ?s 'cua-string-rectangle)
1484 (cua--rect-M/H-key ?t 'cua-text-fill-rectangle)
1485 (cua--rect-M/H-key ?u 'cua-upcase-rectangle)
1486 (cua--rect-M/H-key ?| 'cua-shell-command-on-rectangle)
1487 (cua--rect-M/H-key ?' 'cua-restrict-prefix-rectangle)
1488 (cua--rect-M/H-key ?/ 'cua-restrict-regexp-rectangle)
1490 (setq cua--rectangle-initialized t))
1494 ;; arch-tag: b730df53-17b9-4a89-bd63-4a71ec196731
1495 ;;; cua-rect.el ends here