1 ;;; cua-rect.el --- CUA unified rectangle support
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 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, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; The rectangle handling and display code borrows from the standard
29 ;; GNU emacs rect.el package and the rect-mark.el package by Rick
30 ;; Sladkey <jrs@world.std.com>.
43 ;; If non-nil, restrict current region to this rectangle.
44 ;; Value is a vector [top bot left right corner ins virt select].
45 ;; CORNER specifies currently active corner 0=t/l 1=t/r 2=b/l 3=b/r.
46 ;; INS specifies whether to insert on left(nil) or right(t) side.
47 ;; If VIRT is non-nil, virtual straight edges are enabled.
48 ;; If SELECT is a regexp, only lines starting with that regexp are affected.")
49 (defvar cua--rectangle nil
)
50 (make-variable-buffer-local 'cua--rectangle
)
52 ;; Most recent rectangle geometry. Note: car is buffer.
53 (defvar cua--last-rectangle nil
)
55 ;; Rectangle restored by undo.
56 (defvar cua--restored-rectangle nil
)
58 ;; Last rectangle copied/killed; nil if last kill was not a rectangle.
59 (defvar cua--last-killed-rectangle nil
)
61 ;; List of overlays used to display current rectangle.
62 (defvar cua--rectangle-overlays nil
)
63 (make-variable-buffer-local 'cua--rectangle-overlays
)
64 (put 'cua--rectangle-overlays
'permanent-local t
)
66 (defvar cua--overlay-keymap
67 (let ((map (make-sparse-keymap)))
68 (define-key map
"\r" 'cua-rotate-rectangle
)))
70 (defvar cua--virtual-edges-debug nil
)
72 ;; Undo rectangle commands.
74 (defvar cua--rect-undo-set-point nil
)
76 (defun cua--rectangle-undo-boundary ()
77 (when (listp buffer-undo-list
)
78 (let ((s (cua--rect-start-position))
79 (e (cua--rect-end-position)))
81 (push (list 'apply
0 s e
82 'cua--rect-undo-handler
83 (copy-sequence cua--rectangle
) t s e
)
86 (defun cua--rect-undo-handler (rect on s e
)
87 (if (setq on
(not on
))
88 (setq cua--rect-undo-set-point s
)
89 (setq cua--restored-rectangle
(copy-sequence rect
))
90 (setq cua--buffer-and-point-before-command nil
))
91 (push (list 'apply
0 s
(if on e s
)
92 'cua--rect-undo-handler rect on s e
)
95 ;;; Rectangle geometry
97 (defun cua--rectangle-top (&optional val
)
98 ;; Top of CUA rectangle (buffer position on first line).
100 (aref cua--rectangle
0)
101 (setq val
(line-beginning-position))
102 (if (<= val
(aref cua--rectangle
1))
103 (aset cua--rectangle
0 val
)
104 (aset cua--rectangle
1 val
)
105 (cua--rectangle-corner 2))))
107 (defun cua--rectangle-bot (&optional val
)
108 ;; Bot of CUA rectangle (buffer position on last line).
110 (aref cua--rectangle
1)
111 (setq val
(line-end-position))
112 (if (>= val
(aref cua--rectangle
0))
113 (aset cua--rectangle
1 val
)
114 (aset cua--rectangle
0 val
)
115 (cua--rectangle-corner 2))))
117 (defun cua--rectangle-left (&optional val
)
118 ;; Left column of CUA rectangle.
120 (if (<= val
(aref cua--rectangle
3))
121 (aset cua--rectangle
2 val
)
122 (aset cua--rectangle
3 val
)
123 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
124 (aref cua--rectangle
2)))
126 (defun cua--rectangle-right (&optional val
)
127 ;; Right column of CUA rectangle.
129 (if (>= val
(aref cua--rectangle
2))
130 (aset cua--rectangle
3 val
)
131 (aset cua--rectangle
2 val
)
132 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
133 (aref cua--rectangle
3)))
135 (defun cua--rectangle-corner (&optional advance
)
136 ;; Currently active corner of rectangle.
137 (let ((c (aref cua--rectangle
4)))
138 (if (not (integerp advance
))
140 (aset cua--rectangle
4
142 (- 3 c
) ; opposite corner
143 (mod (+ c
4 advance
) 4)))
144 (aset cua--rectangle
5 0))))
146 (defun cua--rectangle-right-side (&optional topbot
)
147 ;; t if point is on right side of rectangle.
148 (if (and topbot
(= (cua--rectangle-left) (cua--rectangle-right)))
149 (< (cua--rectangle-corner) 2)
150 (= (mod (cua--rectangle-corner) 2) 1)))
152 (defun cua--rectangle-column ()
153 (if (cua--rectangle-right-side)
154 (cua--rectangle-right)
155 (cua--rectangle-left)))
157 (defun cua--rectangle-insert-col (&optional col
)
158 ;; Currently active corner of rectangle.
160 (aset cua--rectangle
5 col
)
161 (if (cua--rectangle-right-side t
)
162 (if (= (aref cua--rectangle
5) 0)
163 (1+ (cua--rectangle-right))
164 (aref cua--rectangle
5))
165 (cua--rectangle-left))))
167 (defun cua--rectangle-virtual-edges (&optional set val
)
168 ;; Current setting of rectangle virtual-edges
170 (aset cua--rectangle
6 val
))
171 (and ;(not buffer-read-only)
172 (aref cua--rectangle
6)))
174 (defun cua--rectangle-restriction (&optional val bounded negated
)
175 ;; Current rectangle restriction
177 (aset cua--rectangle
7
180 (list val bounded negated
)))
181 (aref cua--rectangle
7)))
183 (defun cua--rectangle-assert ()
184 (message "%S (%d)" cua--rectangle
(point))
185 (if (< (cua--rectangle-right) (cua--rectangle-left))
186 (message "rectangle right < left"))
187 (if (< (cua--rectangle-bot) (cua--rectangle-top))
188 (message "rectangle bot < top")))
190 (defun cua--rectangle-get-corners ()
191 ;; Calculate the rectangular region represented by point and mark,
192 ;; putting start in the upper left corner and end in the
193 ;; bottom right corner.
194 (let ((top (point)) (bot (mark)) r l corner
)
197 (setq l
(current-column))
199 (setq r
(current-column))
201 (setq corner
(if (<= l r
) 0 1))
202 (setq top
(prog1 bot
(setq bot top
)))
203 (setq corner
(if (<= l r
) 2 3)))
207 (setq l
(prog1 r
(setq r l
)))
214 (vector top bot l r corner
0 cua-virtual-rectangle-edges nil
)))
216 (defun cua--rectangle-set-corners ()
217 ;; Set mark and point in opposite corners of current rectangle.
218 (let (pp pc mp mc
(c (cua--rectangle-corner)))
220 ((= c
0) ; top/left -> bot/right
221 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-left)
222 mp
(cua--rectangle-bot) mc
(cua--rectangle-right)))
223 ((= c
1) ; top/right -> bot/left
224 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-right)
225 mp
(cua--rectangle-bot) mc
(cua--rectangle-left)))
226 ((= c
2) ; bot/left -> top/right
227 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-left)
228 mp
(cua--rectangle-top) mc
(cua--rectangle-right)))
229 ((= c
3) ; bot/right -> top/left
230 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-right)
231 mp
(cua--rectangle-top) mc
(cua--rectangle-left))))
236 ;; Move cursor inside rectangle, except if char at rigth edge is a tab.
237 (if (and (if (cua--rectangle-right-side)
238 (and (= (move-to-column pc
) (- pc tab-width
))
240 (> (move-to-column pc
) pc
))
245 (defun cua--rect-start-position ()
246 ;; Return point of top left corner
248 (goto-char (cua--rectangle-top))
249 (and (> (move-to-column (cua--rectangle-left))
250 (cua--rectangle-left))
255 (defun cua--rect-end-position ()
256 ;; Return point of bottom right cornet
258 (goto-char (cua--rectangle-bot))
259 (and (= (move-to-column (cua--rectangle-right))
260 (- (cua--rectangle-right) tab-width
))
266 ;;; Rectangle resizing
268 (defun cua--forward-line (n)
269 ;; Move forward/backward one line. Returns t if movement.
271 (and (= (forward-line n
) 0)
272 ;; Deal with end of buffer
276 (defun cua--rectangle-resized ()
277 ;; Refresh state after resizing rectangle
278 (setq cua--buffer-and-point-before-command nil
)
279 (cua--rectangle-insert-col 0)
280 (cua--rectangle-set-corners)
283 (defun cua-resize-rectangle-right (n)
284 "Resize rectangle to the right."
286 (let ((resized (> n
0)))
290 ((cua--rectangle-right-side)
291 (cua--rectangle-right (1+ (cua--rectangle-right)))
292 (move-to-column (cua--rectangle-right)))
294 (cua--rectangle-left (1+ (cua--rectangle-left)))
295 (move-to-column (cua--rectangle-right)))))
297 (cua--rectangle-resized))))
299 (defun cua-resize-rectangle-left (n)
300 "Resize rectangle to the left."
305 (if (or (= (cua--rectangle-right) 0)
306 (and (not (cua--rectangle-right-side)) (= (cua--rectangle-left) 0)))
309 ((cua--rectangle-right-side)
310 (cua--rectangle-right (1- (cua--rectangle-right)))
311 (move-to-column (cua--rectangle-right)))
313 (cua--rectangle-left (1- (cua--rectangle-left)))
314 (move-to-column (cua--rectangle-right))))
317 (cua--rectangle-resized))))
319 (defun cua-resize-rectangle-down (n)
320 "Resize rectangle downwards."
326 ((>= (cua--rectangle-corner) 2)
327 (goto-char (cua--rectangle-bot))
328 (when (cua--forward-line 1)
329 (move-to-column (cua--rectangle-column))
330 (cua--rectangle-bot t
)
333 (goto-char (cua--rectangle-top))
334 (when (cua--forward-line 1)
335 (move-to-column (cua--rectangle-column))
336 (cua--rectangle-top t
)
339 (cua--rectangle-resized))))
341 (defun cua-resize-rectangle-up (n)
342 "Resize rectangle upwards."
348 ((>= (cua--rectangle-corner) 2)
349 (goto-char (cua--rectangle-bot))
350 (when (cua--forward-line -
1)
351 (move-to-column (cua--rectangle-column))
352 (cua--rectangle-bot t
)
355 (goto-char (cua--rectangle-top))
356 (when (cua--forward-line -
1)
357 (move-to-column (cua--rectangle-column))
358 (cua--rectangle-top t
)
361 (cua--rectangle-resized))))
363 (defun cua-resize-rectangle-eol ()
364 "Resize rectangle to end of line."
368 (if (> (current-column) (cua--rectangle-right))
369 (cua--rectangle-right (current-column)))
370 (if (not (cua--rectangle-right-side))
371 (cua--rectangle-corner 1))
372 (cua--rectangle-resized)))
374 (defun cua-resize-rectangle-bol ()
375 "Resize rectangle to beginning of line."
379 (cua--rectangle-left (current-column))
380 (if (cua--rectangle-right-side)
381 (cua--rectangle-corner -
1))
382 (cua--rectangle-resized)))
384 (defun cua-resize-rectangle-bot ()
385 "Resize rectangle to bottom of buffer."
387 (goto-char (point-max))
388 (move-to-column (cua--rectangle-column))
389 (cua--rectangle-bot t
)
390 (cua--rectangle-resized))
392 (defun cua-resize-rectangle-top ()
393 "Resize rectangle to top of buffer."
395 (goto-char (point-min))
396 (move-to-column (cua--rectangle-column))
397 (cua--rectangle-top t
)
398 (cua--rectangle-resized))
400 (defun cua-resize-rectangle-page-up ()
401 "Resize rectangle upwards by one scroll page."
404 (move-to-column (cua--rectangle-column))
405 (if (>= (cua--rectangle-corner) 2)
406 (cua--rectangle-bot t
)
407 (cua--rectangle-top t
))
408 (cua--rectangle-resized))
410 (defun cua-resize-rectangle-page-down ()
411 "Resize rectangle downwards by one scroll page."
414 (move-to-column (cua--rectangle-column))
415 (if (>= (cua--rectangle-corner) 2)
416 (cua--rectangle-bot t
)
417 (cua--rectangle-top t
))
418 (cua--rectangle-resized))
422 ;; This is pretty simplistic, but it does the job...
424 (defun cua-mouse-resize-rectangle (event)
425 "Set rectangle corner at mouse click position."
427 (mouse-set-point event
)
428 ;; FIX ME -- need to calculate virtual column.
429 (if (cua--rectangle-virtual-edges)
430 (move-to-column (car (posn-col-row (event-end event
))) t
))
431 (if (cua--rectangle-right-side)
432 (cua--rectangle-right (current-column))
433 (cua--rectangle-left (current-column)))
434 (if (>= (cua--rectangle-corner) 2)
435 (cua--rectangle-bot t
)
436 (cua--rectangle-top t
))
437 (cua--rectangle-resized))
439 (defvar cua--mouse-last-pos nil
)
441 (defun cua-mouse-set-rectangle-mark (event)
442 "Start rectangle at mouse click position."
445 (cua--deactivate-rectangle)
447 (setq cua--last-rectangle nil
)
448 (mouse-set-point event
)
449 ;; FIX ME -- need to calculate virtual column.
450 (cua-set-rectangle-mark)
451 (setq cua--buffer-and-point-before-command nil
)
452 (setq cua--mouse-last-pos nil
))
454 (defun cua-mouse-save-then-kill-rectangle (event arg
)
455 "Expand rectangle to mouse click position and copy rectangle.
456 If command is repeated at same position, delete the rectangle."
458 (if (and (eq this-command last-command
)
459 (eq (point) (car-safe cua--mouse-last-pos
))
460 (eq cua--last-killed-rectangle
(cdr-safe cua--mouse-last-pos
)))
462 (unless buffer-read-only
463 (cua--delete-rectangle))
465 (cua-mouse-resize-rectangle event
)
466 (let ((cua-keep-region-after-copy t
))
467 (cua-copy-rectangle arg
)
468 (setq cua--mouse-last-pos
(cons (point) cua--last-killed-rectangle
)))))
470 (defun cua--mouse-ignore (event)
472 (setq this-command last-command
))
474 (defun cua--rectangle-move (dir)
476 (top (cua--rectangle-top))
477 (bot (cua--rectangle-bot))
478 (l (cua--rectangle-left))
479 (r (cua--rectangle-right)))
483 (when (cua--forward-line -
1)
484 (cua--rectangle-top t
)
487 (cua--rectangle-bot t
)))
490 (when (cua--forward-line 1)
491 (cua--rectangle-bot t
)
493 (cua--forward-line 1)
494 (cua--rectangle-top t
)))
497 (cua--rectangle-left (1- l
))
498 (cua--rectangle-right (1- r
))))
500 (cua--rectangle-right (1+ r
))
501 (cua--rectangle-left (1+ l
)))
505 (setq cua--buffer-and-point-before-command nil
)
506 (cua--rectangle-set-corners)
507 (cua--keep-active))))
510 ;;; Operations on current rectangle
512 (defun cua--tabify-start (start end
)
513 ;; Return position where auto-tabify should start (or nil if not required).
517 (and (not buffer-read-only
)
518 cua-auto-tabify-rectangles
519 (if (or (not (integerp cua-auto-tabify-rectangles
))
520 (= (point-min) (point-max))
522 (goto-char (max (point-min)
523 (- start cua-auto-tabify-rectangles
)))
524 (search-forward "\t" (min (point-max)
525 (+ end cua-auto-tabify-rectangles
)) t
)))
528 (defun cua--rectangle-operation (keep-clear visible undo pad tabify
&optional fct post-fct
)
529 ;; Call FCT for each line of region with 4 parameters:
530 ;; Region start, end, left-col, right-col
531 ;; Point is at start when FCT is called
532 ;; Call fct with (s,e) = whole lines if VISIBLE non-nil.
533 ;; Only call fct for visible lines if VISIBLE==t.
534 ;; Set undo boundary if UNDO is non-nil.
535 ;; Rectangle is padded if PAD = t or numeric and (cua--rectangle-virtual-edges)
536 ;; Perform auto-tabify after operation if TABIFY is non-nil.
537 ;; Mark is kept if keep-clear is 'keep and cleared if keep-clear is 'clear.
538 (let* ((inhibit-field-text-motion t
)
539 (start (cua--rectangle-top))
540 (end (cua--rectangle-bot))
541 (l (cua--rectangle-left))
542 (r (1+ (cua--rectangle-right)))
544 (tabpad (and (integerp pad
) (= pad
2)))
545 (sel (cua--rectangle-restriction))
546 (tabify-start (and tabify
(cua--tabify-start start end
))))
548 (cua--rectangle-undo-boundary))
550 (setq pad
(cua--rectangle-virtual-edges)))
554 (when (> (cua--rectangle-corner) 1)
556 (and (bolp) (not (eolp)) (not (eobp))
557 (setq end
(1+ end
))))
559 (setq start
(max (window-start) start
))
560 (setq end
(min (window-end) end
)))
562 (setq end
(line-end-position))
563 (if (and visible
(bolp) (not (eobp)))
566 (setq start
(line-beginning-position))
567 (narrow-to-region start end
)
568 (goto-char (point-min))
569 (while (< (point) (point-max))
570 (move-to-column r pad
)
571 (and (not pad
) (not visible
) (> (current-column) r
)
573 (if (and tabpad
(not pad
) (looking-at "\t"))
575 (set-marker m
(point))
576 (move-to-column l pad
)
577 (if (and fct
(or visible
(and (>= (current-column) l
) (<= (current-column) r
))))
578 (let ((v t
) (p (point)))
581 (setq v
(looking-at (car sel
)))
582 (setq v
(re-search-forward (car sel
) m t
))
584 (if (car (cdr (cdr sel
)))
587 (funcall fct p m l r v
)
589 (funcall fct p m l r
)))))
593 (cua--rectangle-bot t
))
595 (funcall post-fct l r
))
597 (tabify tabify-start
(point)))))
599 ((eq keep-clear
'keep
)
601 ((eq keep-clear
'clear
)
603 ((eq keep-clear
'corners
)
604 (cua--rectangle-set-corners)
606 (setq cua--buffer-and-point-before-command nil
)))
608 (put 'cua--rectangle-operation
'lisp-indent-function
4)
610 (defun cua--delete-rectangle ()
612 (if (not (cua--rectangle-virtual-edges))
613 (cua--rectangle-operation nil nil t
2 t
615 (setq lines
(1+ lines
))
616 (if (and (> e s
) (<= e
(point-max)))
617 (delete-region s e
))))
618 (cua--rectangle-operation nil
1 t nil t
620 (setq lines
(1+ lines
))
621 (when (and (> e s
) (<= e
(point-max)))
622 (delete-region s e
)))))
625 (defun cua--extract-rectangle ()
627 (if (not (cua--rectangle-virtual-edges))
628 (cua--rectangle-operation nil nil nil nil nil
; do not tabify
630 (setq rect
(cons (filter-buffer-substring s e nil t
) rect
))))
631 (cua--rectangle-operation nil
1 nil nil nil
; do not tabify
633 (let ((copy t
) (bs 0) (as 0) row
)
634 (if (= s e
) (setq e
(1+ e
)))
637 (if (= (point) (line-end-position))
640 (skip-chars-forward "\s\t" e
)
641 (setq bs
(- (min r
(current-column)) l
)
644 (skip-chars-backward "\s\t" s
)
645 (setq as
(- r
(max (current-column) l
))
647 (setq row
(if (and copy
(> e s
))
648 (filter-buffer-substring s e nil t
)
651 (setq row
(concat (make-string bs ?\s
) row
)))
653 (setq row
(concat row
(make-string as ?\s
))))
654 (setq rect
(cons row rect
))))))
657 (defun cua--insert-rectangle (rect &optional below paste-column line-count
)
658 ;; Insert rectangle as insert-rectangle, but don't set mark and exit with
659 ;; point at either next to top right or below bottom left corner
660 ;; Notice: In overwrite mode, the rectangle is inserted as separate text lines.
662 (setq below
(and (bolp)
663 (or (eolp) (eobp) (= (1+ (point)) (point-max))))))
665 (setq paste-column
(current-column)))
668 (tabify-start (cua--tabify-start (point) (point)))
671 (while (or lines below
)
676 (or (bolp) (insert ?
\n))))
677 (unless overwrite-mode
678 (move-to-column paste-column t
))
681 (insert-for-yank (car lines
))
683 (setq last-column
(current-column)))
684 (setq lines
(cdr lines
))
685 (and first
(not below
)
688 (if (and line-count
(= (setq line-count
(1- line-count
)) 0))
690 (when (and line-count last-column
(not overwrite-mode
))
691 (while (> line-count
0)
693 (or (bolp) (insert ?
\n))
694 (move-to-column paste-column t
)
695 (insert-char ?\s
(- last-column paste-column -
1))
696 (setq line-count
(1- line-count
))))
697 (when (and tabify-start
698 (not overwrite-mode
))
699 (tabify tabify-start
(point)))
700 (and p
(not overwrite-mode
)
703 (defun cua--copy-rectangle-as-kill (&optional ring
)
705 (set-register cua--register
(cua--extract-rectangle))
706 (setq killed-rectangle
(cua--extract-rectangle))
707 (setq cua--last-killed-rectangle
(cons (and kill-ring
(car kill-ring
)) killed-rectangle
))
710 (function (lambda (row) (concat row
"\n")))
711 killed-rectangle
"")))))
713 (defun cua--activate-rectangle ()
714 ;; Turn on rectangular marking mode by disabling transient mark mode
715 ;; and manually handling highlighting from a post command hook.
716 ;; Be careful if we are already marking a rectangle.
718 (if (and cua--last-rectangle
719 (eq (car cua--last-rectangle
) (current-buffer))
720 (eq (car (cdr cua--last-rectangle
)) (point)))
721 (cdr (cdr cua--last-rectangle
))
722 (cua--rectangle-get-corners))
723 cua--status-string
(if (cua--rectangle-virtual-edges) " [R]" "")
724 cua--last-rectangle nil
))
726 ;; (defvar cua-save-point nil)
728 (defun cua--deactivate-rectangle ()
729 ;; This is used to clean up after `cua--activate-rectangle'.
730 (mapc (function delete-overlay
) cua--rectangle-overlays
)
731 (setq cua--last-rectangle
(cons (current-buffer)
732 (cons (point) ;; cua-save-point
735 cua--rectangle-overlays nil
736 cua--status-string nil
737 cua--mouse-last-pos nil
))
739 (defun cua--highlight-rectangle ()
740 ;; This function is used to highlight the rectangular region.
741 ;; We do this by putting an overlay on each line within the rectangle.
742 ;; Each overlay extends across all the columns of the rectangle.
743 ;; We try to reuse overlays where possible because this is more efficient
744 ;; and results in less flicker.
745 ;; If cua--rectangle-virtual-edges is nil and the buffer contains tabs or short lines,
746 ;; the higlighted region may not be perfectly rectangular.
747 (let ((deactivate-mark deactivate-mark
)
748 (old cua--rectangle-overlays
)
750 (left (cua--rectangle-left))
751 (right (1+ (cua--rectangle-right))))
752 (when (/= left right
)
753 (sit-for 0) ; make window top/bottom reliable
754 (cua--rectangle-operation nil t nil nil nil
; do not tabify
756 (let ((rface (if v
'cua-rectangle
'cua-rectangle-noselect
))
758 (when (cua--rectangle-virtual-edges)
759 (let ((lb (line-beginning-position))
760 (le (line-end-position))
763 (setq cl
(move-to-column l
)
765 (setq cr
(move-to-column r
)
770 (setq cl0
(current-column)))
774 (setq cr0
(current-column)))
775 (unless (and (= cl l
) (= cr r
))
779 (- l cl0
(if (and (= le pl
) (/= le lb
)) 1 0))
780 (if cua--virtual-edges-debug ?. ?\s
))
781 'face
(or (get-text-property (1- s
) 'face
) 'default
)))
788 (or bs
(/= cr0
(- cr tab-width
)))
789 (/= (mod cr tab-width
) 0))
795 (if cua--virtual-edges-debug ?
, ?\s
))
797 (if (cua--rectangle-right-side)
798 (put-text-property (1- (length ms
)) (length ms
) 'cursor
2 ms
)
799 (put-text-property 0 1 'cursor
2 ms
))
800 (setq bs
(concat bs ms
))
805 (- r cr0
(if (= le pr
) 1 0))
806 (if cua--virtual-edges-debug ?~ ?\s
))
808 (if (cua--rectangle-right-side)
809 (put-text-property (1- (length as
)) (length as
) 'cursor
2 as
)
810 (put-text-property 0 1 'cursor
2 as
))
812 (setq e
(1- e
))))))))
813 ;; Trim old leading overlays.
815 (setq overlay
(car old
))
816 (< (overlay-start overlay
) s
)
817 (/= (overlay-end overlay
) e
))
818 (delete-overlay overlay
)
819 (setq old
(cdr old
)))
820 ;; Reuse an overlay if possible, otherwise create one.
822 (setq overlay
(car old
))
823 (or (= (overlay-start overlay
) s
)
824 (= (overlay-end overlay
) e
)))
826 (move-overlay overlay s e
)
827 (setq old
(cdr old
)))
828 (setq overlay
(make-overlay s e
)))
829 (overlay-put overlay
'before-string bs
)
830 (overlay-put overlay
'after-string as
)
831 (overlay-put overlay
'face rface
)
832 (overlay-put overlay
'keymap cua--overlay-keymap
)
833 (overlay-put overlay
'window
(selected-window))
834 (setq new
(cons overlay new
))))))
835 ;; Trim old trailing overlays.
836 (mapc (function delete-overlay
) old
)
837 (setq cua--rectangle-overlays
(nreverse new
))))
839 (defun cua--indent-rectangle (&optional ch to-col clear
)
840 ;; Indent current rectangle.
841 (let ((col (cua--rectangle-insert-col))
842 (pad (cua--rectangle-virtual-edges))
844 (cua--rectangle-operation (if clear
'clear
'corners
) nil t pad nil
846 (move-to-column col pad
)
848 (< (current-column) col
))
849 (move-to-column col t
))
851 (to-col (indent-to to-col
))
853 (t (tab-to-tab-stop)))
854 (if (cua--rectangle-right-side t
)
855 (cua--rectangle-insert-col (current-column))
856 (setq indent
(- (current-column) l
))))
858 (when (and indent
(> indent
0))
859 (aset cua--rectangle
2 (+ l indent
))
860 (aset cua--rectangle
3 (+ r indent -
1)))))))
863 ;; rectangle functions / actions
866 (defvar cua--rectangle-initialized nil
)
868 (defun cua-set-rectangle-mark (&optional reopen
)
869 "Set mark and start in CUA rectangle mode.
870 With prefix argument, activate previous rectangle if possible."
872 (unless cua--rectangle-initialized
873 (cua--init-rectangles))
874 (when (not cua--rectangle
)
877 (eq (car cua--last-rectangle
) (current-buffer)))
878 (goto-char (car (cdr cua--last-rectangle
)))
879 (if (not mark-active
)
880 (push-mark nil nil t
)))
881 (cua--activate-rectangle)
882 (cua--rectangle-set-corners)
884 cua--explicit-region-start t
)
885 (if cua-enable-rectangle-auto-help
886 (cua-help-for-rectangle t
))))
888 (defun cua-clear-rectangle-mark ()
889 "Cancel current rectangle."
892 (setq mark-active nil
893 cua--explicit-region-start nil
)
894 (cua--deactivate-rectangle)))
896 (defun cua-toggle-rectangle-mark ()
899 (cua--deactivate-rectangle)
900 (unless cua--rectangle-initialized
901 (cua--init-rectangles))
902 (cua--activate-rectangle))
904 (if cua-enable-rectangle-auto-help
905 (cua-help-for-rectangle t
))
906 (if cua-enable-region-auto-help
907 (cua-help-for-region t
))))
909 (defun cua-restrict-regexp-rectangle (arg)
910 "Restrict rectangle to lines (not) matching REGEXP.
911 With prefix argument, the toggle restriction."
913 (let ((r (cua--rectangle-restriction)) regexp
)
914 (if (and r
(null (car (cdr r
))))
916 (cua--rectangle-restriction (car r
) nil
(not (car (cdr (cdr r
)))))
917 (cua--rectangle-restriction "" nil nil
))
918 (cua--rectangle-restriction
919 (read-from-minibuffer "Restrict rectangle (regexp): "
920 nil nil nil nil
) nil arg
))))
922 (defun cua-restrict-prefix-rectangle (arg)
923 "Restrict rectangle to lines (not) starting with CHAR.
924 With prefix argument, the toggle restriction."
926 (let ((r (cua--rectangle-restriction)) regexp
)
927 (if (and r
(car (cdr r
)))
929 (cua--rectangle-restriction (car r
) t
(not (car (cdr (cdr r
)))))
930 (cua--rectangle-restriction "" nil nil
))
931 (cua--rectangle-restriction
933 (read-char "Restrictive rectangle (char): ")) t arg
))))
935 (defun cua-move-rectangle-up ()
937 (cua--rectangle-move 'up
))
939 (defun cua-move-rectangle-down ()
941 (cua--rectangle-move 'down
))
943 (defun cua-move-rectangle-left ()
945 (cua--rectangle-move 'left
))
947 (defun cua-move-rectangle-right ()
949 (cua--rectangle-move 'right
))
951 (defun cua-copy-rectangle (arg)
953 (setq arg
(cua--prefix-arg arg
))
954 (cua--copy-rectangle-as-kill arg
)
955 (if cua-keep-region-after-copy
959 (defun cua-cut-rectangle (arg)
962 (cua-copy-rectangle arg
)
963 (setq arg
(cua--prefix-arg arg
))
964 (goto-char (min (mark) (point)))
965 (cua--copy-rectangle-as-kill arg
)
966 (cua--delete-rectangle))
969 (defun cua-delete-rectangle ()
971 (goto-char (min (point) (mark)))
972 (if cua-delete-copy-to-register-0
973 (set-register ?
0 (cua--extract-rectangle)))
974 (cua--delete-rectangle)
977 (defun cua-rotate-rectangle ()
979 (cua--rectangle-corner (if (= (cua--rectangle-left) (cua--rectangle-right)) 0 1))
980 (cua--rectangle-set-corners)
981 (if (cua--rectangle-virtual-edges)
982 (setq cua--buffer-and-point-before-command nil
)))
984 (defun cua-toggle-rectangle-virtual-edges ()
986 (cua--rectangle-virtual-edges t
(not (cua--rectangle-virtual-edges)))
987 (cua--rectangle-set-corners)
988 (setq cua--status-string
(and (cua--rectangle-virtual-edges) " [R]"))
991 (defun cua-do-rectangle-padding ()
994 (message "Cannot do padding in read-only buffer")
995 (cua--rectangle-operation nil nil t t t
)
996 (cua--rectangle-set-corners))
999 (defun cua-open-rectangle ()
1000 "Blank out CUA rectangle, shifting text right.
1001 The text previously in the region is not overwritten by the blanks,
1002 but instead winds up to the right of the rectangle."
1004 (cua--rectangle-operation 'corners nil t
1 nil
1006 (skip-chars-forward " \t")
1007 (let ((ws (- (current-column) l
))
1009 (skip-chars-backward " \t")
1010 (delete-region (point) p
)
1011 (indent-to (+ r ws
))))))
1013 (defun cua-close-rectangle (arg)
1014 "Delete all whitespace starting at left edge of CUA rectangle.
1015 On each line in the rectangle, all continuous whitespace starting
1016 at that column is deleted.
1017 With prefix arg, also delete whitespace to the left of that column."
1019 (cua--rectangle-operation 'clear nil t
1 nil
1022 (skip-syntax-backward " " (line-beginning-position))
1024 (skip-syntax-forward " " (line-end-position))
1025 (delete-region s
(point)))))
1027 (defun cua-blank-rectangle ()
1028 "Blank out CUA rectangle.
1029 The text previously in the rectangle is overwritten by the blanks."
1031 (cua--rectangle-operation 'keep nil nil
1 nil
1034 (skip-syntax-forward " " (line-end-position))
1036 (let ((column (current-column)))
1038 (skip-syntax-backward " " (line-beginning-position))
1039 (delete-region (point) e
)
1040 (indent-to column
)))))
1042 (defun cua-align-rectangle ()
1043 "Align rectangle lines to left column."
1046 (cua--rectangle-operation 'clear nil t t nil
1048 (let ((b (line-beginning-position)))
1049 (skip-syntax-backward "^ " b
)
1050 (skip-syntax-backward " " b
)
1052 (skip-syntax-forward " " (line-end-position))
1053 (delete-region s
(point))
1057 ;; (setq cua-save-point (point))
1060 (declare-function cua--cut-rectangle-to-global-mark
"cua-gmrk" (as-text))
1061 (declare-function cua--copy-rectangle-to-global-mark
"cua-gmrk" (as-text))
1063 (defun cua-copy-rectangle-as-text (&optional arg delete
)
1064 "Copy rectangle, but store as normal text."
1066 (if cua--global-mark-active
1068 (cua--cut-rectangle-to-global-mark t
)
1069 (cua--copy-rectangle-to-global-mark t
))
1070 (let* ((rect (cua--extract-rectangle))
1072 (function (lambda (row) (concat row
"\n")))
1074 (setq arg
(cua--prefix-arg arg
))
1076 (set-register cua--register text
)
1079 (cua--delete-rectangle))
1082 (defun cua-cut-rectangle-as-text (arg)
1083 "Kill rectangle, but store as normal text."
1085 (cua-copy-rectangle-as-text arg
(not buffer-read-only
)))
1087 (defun cua-string-rectangle (string)
1088 "Replace CUA rectangle contents with STRING on each line.
1089 The length of STRING need not be the same as the rectangle width."
1090 (interactive "sString rectangle: ")
1091 (cua--rectangle-operation 'keep nil t t nil
1094 (skip-chars-forward " \t")
1095 (let ((ws (- (current-column) l
)))
1096 (delete-region s
(point))
1098 (indent-to (+ (current-column) ws
))))
1099 (unless (cua--rectangle-restriction)
1101 (cua--rectangle-right (max l
(+ l
(length string
) -
1)))))))
1103 (defun cua-fill-char-rectangle (character)
1104 "Replace CUA rectangle contents with CHARACTER."
1105 (interactive "cFill rectangle with character: ")
1106 (cua--rectangle-operation 'clear nil t
1 nil
1109 (move-to-column l t
)
1110 (insert-char character
(- r l
)))))
1112 (defun cua-replace-in-rectangle (regexp newtext
)
1113 "Replace REGEXP with NEWTEXT in each line of CUA rectangle."
1114 (interactive "sReplace regexp: \nsNew text: ")
1115 (if buffer-read-only
1116 (message "Cannot replace in read-only buffer")
1117 (cua--rectangle-operation 'keep nil t
1 nil
1119 (if (re-search-forward regexp e t
)
1120 (replace-match newtext nil nil
))))))
1122 (defun cua-incr-rectangle (increment)
1123 "Increment each line of CUA rectangle by prefix amount."
1125 (cua--rectangle-operation 'keep nil t
1 nil
1128 ((re-search-forward "0x\\([0-9a-fA-F]+\\)" e t
)
1129 (let* ((txt (filter-buffer-substring (match-beginning 1) (match-end 1) nil t
))
1130 (n (string-to-number txt
16))
1131 (fmt (format "0x%%0%dx" (length txt
))))
1132 (replace-match (format fmt
(+ n increment
)))))
1133 ((re-search-forward "\\( *-?[0-9]+\\)" e t
)
1134 (let* ((txt (filter-buffer-substring (match-beginning 1) (match-end 1) nil t
))
1135 (prefix (if (= (aref txt
0) ?
0) "0" ""))
1136 (n (string-to-number txt
10))
1137 (fmt (format "%%%s%dd" prefix
(length txt
))))
1138 (replace-match (format fmt
(+ n increment
)))))
1141 (defvar cua--rectangle-seq-format
"%d"
1142 "Last format used by `cua-sequence-rectangle'.")
1144 (defun cua-sequence-rectangle (first incr format
)
1145 "Resequence each line of CUA rectangle starting from FIRST.
1146 The numbers are formatted according to the FORMAT string."
1148 (list (if current-prefix-arg
1149 (prefix-numeric-value current-prefix-arg
)
1151 (read-string "Start value: (0) " nil nil
"0")))
1153 (read-string "Increment: (1) " nil nil
"1"))
1154 (read-string (concat "Format: (" cua--rectangle-seq-format
") "))))
1155 (if (= (length format
) 0)
1156 (setq format cua--rectangle-seq-format
)
1157 (setq cua--rectangle-seq-format format
))
1158 (cua--rectangle-operation 'clear nil t
1 nil
1161 (insert (format format first
))
1162 (setq first
(+ first incr
)))))
1164 (defmacro cua--convert-rectangle-as
(command tabify
)
1165 `(cua--rectangle-operation 'clear nil nil nil
,tabify
1169 (defun cua-upcase-rectangle ()
1170 "Convert the rectangle to upper case."
1172 (cua--convert-rectangle-as upcase-region nil
))
1174 (defun cua-downcase-rectangle ()
1175 "Convert the rectangle to lower case."
1177 (cua--convert-rectangle-as downcase-region nil
))
1179 (defun cua-upcase-initials-rectangle ()
1180 "Convert the rectangle initials to upper case."
1182 (cua--convert-rectangle-as upcase-initials-region nil
))
1184 (defun cua-capitalize-rectangle ()
1185 "Convert the rectangle to proper case."
1187 (cua--convert-rectangle-as capitalize-region nil
))
1190 ;;; Replace/rearrange text in current rectangle
1192 (defun cua--rectangle-aux-replace (width adjust keep replace pad format-fct
&optional setup-fct
)
1193 ;; Process text inserted by calling SETUP-FCT or current rectangle if nil.
1194 ;; Then call FORMAT-FCT on text (if non-nil); takes two args: start and end.
1195 ;; Fill to WIDTH characters if > 0 or fill to current width if == 0.
1196 ;; Don't fill if WIDTH < 0.
1197 ;; Replace current rectangle by filled text if REPLACE is non-nil
1198 (let ((auxbuf (get-buffer-create "*CUA temp*"))
1199 (w (if (> width
1) width
1200 (- (cua--rectangle-right) (cua--rectangle-left) -
1)))
1201 (r (or setup-fct
(cua--extract-rectangle)))
1208 (cua--insert-rectangle r
))
1210 (let ((fill-column w
))
1211 (funcall format-fct
(point-min) (point-max))))
1213 (goto-char (point-min))
1215 (setq z
(cons (filter-buffer-substring (point) (line-end-position)) z
))
1217 (if (not cua--debug
)
1218 (kill-buffer auxbuf
))
1220 (setq z
(reverse z
))
1223 (cua--rectangle-operation nil nil t pad nil
1227 (skip-chars-forward " \t")
1228 (setq cc
(current-column))
1230 (print (list cc s e
) auxbuf
))
1231 (delete-region s
(point))
1234 (move-to-column l t
)
1236 (when (> (current-column) (+ l w
))
1238 (move-to-column (+ l w
) t
)
1239 (delete-region (point) y
)
1243 (print (list (current-column) cc
) auxbuf
))
1247 (message "Warning: Truncated %d row%s" tr
(if (> tr
1) "s" "")))
1249 (cua--rectangle-right (+ (cua--rectangle-left) w -
1)))
1251 (cua--rectangle-resized)))))
1253 (put 'cua--rectangle-aux-replace
'lisp-indent-function
4)
1255 (defun cua--left-fill-rectangle (start end
)
1257 (while (< (point) (point-max))
1258 (delete-horizontal-space nil
)
1260 (fill-region-as-paragraph (point-min) (point-max) 'left nil
)
1261 (untabify (point-min) (point-max)))
1263 (defun cua-text-fill-rectangle (width text
)
1264 "Replace rectagle with filled TEXT read from minibuffer.
1265 A numeric prefix argument is used a new width for the filled rectangle."
1267 (prefix-numeric-value current-prefix-arg
)
1268 (read-from-minibuffer "Enter text: "
1270 (cua--rectangle-aux-replace width t t t
1
1271 'cua--left-fill-rectangle
1272 '(lambda () (insert text
))))
1274 (defun cua-refill-rectangle (width)
1275 "Fill contents of current rectagle.
1276 A numeric prefix argument is used as new width for the filled rectangle."
1278 (cua--rectangle-aux-replace
1279 (if width
(prefix-numeric-value width
) 0)
1280 t t t
1 'cua--left-fill-rectangle
))
1282 (defun cua-shell-command-on-rectangle (replace command
)
1283 "Run shell command on rectangle like `shell-command-on-region'.
1284 With prefix arg, replace rectangle with output from command."
1287 (read-from-minibuffer "Shell command on rectangle: "
1289 'shell-command-history
)))
1290 (cua--rectangle-aux-replace -
1 t t replace
1
1292 (shell-command-on-region s e command
1293 replace replace nil
))))
1295 (defun cua-reverse-rectangle ()
1296 "Reverse the lines of the rectangle."
1298 (cua--rectangle-aux-replace 0 t t t t
'reverse-region
))
1300 (defun cua-scroll-rectangle-up ()
1301 "Remove the first line of the rectangle and scroll remaining lines up."
1303 (cua--rectangle-aux-replace 0 t t t t
1305 (if (= (forward-line 1) 0)
1306 (delete-region s
(point))))))
1308 (defun cua-scroll-rectangle-down ()
1309 "Insert a blank line at the first line of the rectangle.
1310 The remaining lines are scrolled down, losing the last line."
1312 (cua--rectangle-aux-replace 0 t t t t
1318 ;;; Insert/delete text to left or right of rectangle
1320 (defun cua-insert-char-rectangle (&optional ch
)
1322 (if buffer-read-only
1324 (cua--indent-rectangle (or ch
(aref (this-single-command-keys) 0)))
1328 (defun cua-indent-rectangle (column)
1329 "Indent rectangle to next tab stop.
1330 With prefix arg, indent to that column."
1333 (cua-insert-char-rectangle ?
\t)
1334 (cua--indent-rectangle nil
(prefix-numeric-value column
))))
1336 (defun cua-delete-char-rectangle ()
1337 "Delete char to left or right of rectangle."
1339 (let ((col (cua--rectangle-insert-col))
1340 (pad (cua--rectangle-virtual-edges))
1342 (cua--rectangle-operation 'corners nil t pad nil
1345 (if (cua--rectangle-right-side t
)
1350 (delete-backward-char 1)
1351 (if (cua--rectangle-right-side t
)
1352 (cua--rectangle-insert-col (current-column))
1353 (setq indent
(- l
(current-column))))))
1355 (when (and indent
(> indent
0))
1356 (aset cua--rectangle
2 (- l indent
))
1357 (aset cua--rectangle
3 (- r indent
1)))))))
1359 (defun cua-help-for-rectangle (&optional help
)
1361 (let ((M (cond ((eq cua--rectangle-modifier-key
'hyper
) " H-")
1362 ((eq cua--rectangle-modifier-key
'super
) " s-")
1363 ((eq cua--rectangle-modifier-key
'alt
) " A-")
1366 (concat (if help
"C-?:help" "")
1367 M
"p:pad" M
"o:open" M
"c:close" M
"b:blank"
1368 M
"s:string" M
"f:fill" M
"i:incr" M
"n:seq"))))
1371 ;;; CUA-like cut & paste for rectangles
1373 (defun cua--cancel-rectangle ()
1376 (cua--deactivate-rectangle))
1377 (setq cua--last-rectangle nil
))
1379 (defun cua--rectangle-post-command ()
1380 (if cua--restored-rectangle
1382 (setq cua--rectangle cua--restored-rectangle
1383 cua--restored-rectangle nil
1385 deactivate-mark nil
)
1386 (cua--rectangle-set-corners))
1387 (when (and cua--rectangle cua--buffer-and-point-before-command
1388 (equal (car cua--buffer-and-point-before-command
) (current-buffer))
1389 (not (= (cdr cua--buffer-and-point-before-command
) (point))))
1390 (if (cua--rectangle-right-side)
1391 (cua--rectangle-right (current-column))
1392 (cua--rectangle-left (current-column)))
1393 (if (>= (cua--rectangle-corner) 2)
1394 (cua--rectangle-bot t
)
1395 (cua--rectangle-top t
))))
1397 (if (and mark-active
1398 (not deactivate-mark
))
1399 (cua--highlight-rectangle)
1400 (cua--deactivate-rectangle))
1401 (when cua--rectangle-overlays
1402 ;; clean-up after revert-buffer
1403 (mapc (function delete-overlay
) cua--rectangle-overlays
)
1404 (setq cua--rectangle-overlays nil
)
1405 (setq deactivate-mark t
)))
1406 (when cua--rect-undo-set-point
1407 (goto-char cua--rect-undo-set-point
)
1408 (setq cua--rect-undo-set-point nil
)))
1412 (defun cua--rect-M/H-key
(key cmd
)
1413 (cua--M/H-key cua--rectangle-keymap key cmd
))
1415 (defun cua--init-rectangles ()
1416 (define-key cua--rectangle-keymap cua-rectangle-mark-key
'cua-clear-rectangle-mark
)
1417 (define-key cua--region-keymap cua-rectangle-mark-key
'cua-toggle-rectangle-mark
)
1418 (unless (eq cua--rectangle-modifier-key
'meta
)
1419 (cua--rect-M/H-key ?\s
'cua-clear-rectangle-mark
)
1420 (cua--M/H-key cua--region-keymap ?\s
'cua-toggle-rectangle-mark
))
1422 (define-key cua--rectangle-keymap
[remap copy-region-as-kill
] 'cua-copy-rectangle
)
1423 (define-key cua--rectangle-keymap
[remap kill-ring-save
] 'cua-copy-rectangle
)
1424 (define-key cua--rectangle-keymap
[remap kill-region
] 'cua-cut-rectangle
)
1425 (define-key cua--rectangle-keymap
[remap delete-char
] 'cua-delete-rectangle
)
1426 (define-key cua--rectangle-keymap
[remap set-mark-command
] 'cua-toggle-rectangle-mark
)
1428 (define-key cua--rectangle-keymap
[remap forward-char
] 'cua-resize-rectangle-right
)
1429 (define-key cua--rectangle-keymap
[remap backward-char
] 'cua-resize-rectangle-left
)
1430 (define-key cua--rectangle-keymap
[remap next-line
] 'cua-resize-rectangle-down
)
1431 (define-key cua--rectangle-keymap
[remap previous-line
] 'cua-resize-rectangle-up
)
1432 (define-key cua--rectangle-keymap
[remap end-of-line
] 'cua-resize-rectangle-eol
)
1433 (define-key cua--rectangle-keymap
[remap beginning-of-line
] 'cua-resize-rectangle-bol
)
1434 (define-key cua--rectangle-keymap
[remap end-of-buffer
] 'cua-resize-rectangle-bot
)
1435 (define-key cua--rectangle-keymap
[remap beginning-of-buffer
] 'cua-resize-rectangle-top
)
1436 (define-key cua--rectangle-keymap
[remap scroll-down
] 'cua-resize-rectangle-page-up
)
1437 (define-key cua--rectangle-keymap
[remap scroll-up
] 'cua-resize-rectangle-page-down
)
1439 (define-key cua--rectangle-keymap
[remap delete-backward-char
] 'cua-delete-char-rectangle
)
1440 (define-key cua--rectangle-keymap
[remap backward-delete-char
] 'cua-delete-char-rectangle
)
1441 (define-key cua--rectangle-keymap
[remap backward-delete-char-untabify
] 'cua-delete-char-rectangle
)
1442 (define-key cua--rectangle-keymap
[remap self-insert-command
] 'cua-insert-char-rectangle
)
1443 (define-key cua--rectangle-keymap
[remap self-insert-iso
] 'cua-insert-char-rectangle
)
1445 ;; Catch self-inserting characters which are "stolen" by other modes
1446 (define-key cua--rectangle-keymap
[t]
1447 '(menu-item "sic" cua-insert-char-rectangle :filter cua--self-insert-char-p))
1449 (define-key cua--rectangle-keymap "\r" 'cua-rotate-rectangle)
1450 (define-key cua--rectangle-keymap "\t" 'cua-indent-rectangle)
1452 (define-key cua--rectangle-keymap [(control ??)] 'cua-help-for-rectangle)
1454 (define-key cua--rectangle-keymap [mouse-1] 'cua-mouse-set-rectangle-mark)
1455 (define-key cua--rectangle-keymap [down-mouse-1] 'cua--mouse-ignore)
1456 (define-key cua--rectangle-keymap [drag-mouse-1] 'cua--mouse-ignore)
1457 (define-key cua--rectangle-keymap [mouse-3] 'cua-mouse-save-then-kill-rectangle)
1458 (define-key cua--rectangle-keymap [down-mouse-3] 'cua--mouse-ignore)
1459 (define-key cua--rectangle-keymap [drag-mouse-3] 'cua--mouse-ignore)
1461 (cua--rect-M/H-key 'up 'cua-move-rectangle-up)
1462 (cua--rect-M/H-key 'down 'cua-move-rectangle-down)
1463 (cua--rect-M/H-key 'left 'cua-move-rectangle-left)
1464 (cua--rect-M/H-key 'right 'cua-move-rectangle-right)
1466 (cua--rect-M/H-key '(control up) 'cua-scroll-rectangle-up)
1467 (cua--rect-M/H-key '(control down) 'cua-scroll-rectangle-down)
1469 (cua--rect-M/H-key ?a 'cua-align-rectangle)
1470 (cua--rect-M/H-key ?b 'cua-blank-rectangle)
1471 (cua--rect-M/H-key ?c 'cua-close-rectangle)
1472 (cua--rect-M/H-key ?f 'cua-fill-char-rectangle)
1473 (cua--rect-M/H-key ?i 'cua-incr-rectangle)
1474 (cua--rect-M/H-key ?k 'cua-cut-rectangle-as-text)
1475 (cua--rect-M/H-key ?l 'cua-downcase-rectangle)
1476 (cua--rect-M/H-key ?m 'cua-copy-rectangle-as-text)
1477 (cua--rect-M/H-key ?n 'cua-sequence-rectangle)
1478 (cua--rect-M/H-key ?o 'cua-open-rectangle)
1479 (cua--rect-M/H-key ?p 'cua-toggle-rectangle-virtual-edges)
1480 (cua--rect-M/H-key ?P 'cua-do-rectangle-padding)
1481 (cua--rect-M/H-key ?q 'cua-refill-rectangle)
1482 (cua--rect-M/H-key ?r 'cua-replace-in-rectangle)
1483 (cua--rect-M/H-key ?R 'cua-reverse-rectangle)
1484 (cua--rect-M/H-key ?s 'cua-string-rectangle)
1485 (cua--rect-M/H-key ?t 'cua-text-fill-rectangle)
1486 (cua--rect-M/H-key ?u 'cua-upcase-rectangle)
1487 (cua--rect-M/H-key ?| 'cua-shell-command-on-rectangle)
1488 (cua--rect-M/H-key ?' 'cua-restrict-prefix-rectangle)
1489 (cua--rect-M/H-key ?/ 'cua-restrict-regexp-rectangle)
1491 (setq cua--rectangle-initialized t))
1495 ;;; arch-tag: b730df53-17b9-4a89-bd63-4a71ec196731
1496 ;;; cua-rect.el ends here