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>.
47 ;; If non-nil, restrict current region to this rectangle.
48 ;; Value is a vector [top bot left right corner ins virt select].
49 ;; CORNER specifies currently active corner 0=t/l 1=t/r 2=b/l 3=b/r.
50 ;; INS specifies whether to insert on left(nil) or right(t) side.
51 ;; If VIRT is non-nil, virtual straight edges are enabled.
52 ;; If SELECT is a regexp, only lines starting with that regexp are affected.")
53 (defvar cua--rectangle nil
)
54 (make-variable-buffer-local 'cua--rectangle
)
56 ;; Most recent rectangle geometry. Note: car is buffer.
57 (defvar cua--last-rectangle nil
)
59 ;; Rectangle restored by undo.
60 (defvar cua--restored-rectangle nil
)
62 ;; Last rectangle copied/killed; nil if last kill was not a rectangle.
63 (defvar cua--last-killed-rectangle nil
)
65 ;; List of overlays used to display current rectangle.
66 (defvar cua--rectangle-overlays nil
)
67 (make-variable-buffer-local 'cua--rectangle-overlays
)
68 (put 'cua--rectangle-overlays
'permanent-local t
)
70 (defvar cua--overlay-keymap
71 (let ((map (make-sparse-keymap)))
72 (define-key map
"\r" 'cua-rotate-rectangle
)))
74 (defvar cua--virtual-edges-debug nil
)
76 ;; Undo rectangle commands.
78 (defvar cua--rect-undo-set-point nil
)
80 (defun cua--rectangle-undo-boundary ()
81 (when (listp buffer-undo-list
)
82 (let ((s (cua--rect-start-position))
83 (e (cua--rect-end-position)))
85 (push (list 'apply
0 s e
86 'cua--rect-undo-handler
87 (copy-sequence cua--rectangle
) t s e
)
90 (defun cua--rect-undo-handler (rect on s e
)
91 (if (setq on
(not on
))
92 (setq cua--rect-undo-set-point s
)
93 (setq cua--restored-rectangle
(copy-sequence rect
))
94 (setq cua--buffer-and-point-before-command nil
))
95 (push (list 'apply
0 s
(if on e s
)
96 'cua--rect-undo-handler rect on s e
)
99 ;;; Rectangle geometry
101 (defun cua--rectangle-top (&optional val
)
102 ;; Top of CUA rectangle (buffer position on first line).
104 (aref cua--rectangle
0)
105 (setq val
(line-beginning-position))
106 (if (<= val
(aref cua--rectangle
1))
107 (aset cua--rectangle
0 val
)
108 (aset cua--rectangle
1 val
)
109 (cua--rectangle-corner 2))))
111 (defun cua--rectangle-bot (&optional val
)
112 ;; Bot of CUA rectangle (buffer position on last line).
114 (aref cua--rectangle
1)
115 (setq val
(line-end-position))
116 (if (>= val
(aref cua--rectangle
0))
117 (aset cua--rectangle
1 val
)
118 (aset cua--rectangle
0 val
)
119 (cua--rectangle-corner 2))))
121 (defun cua--rectangle-left (&optional val
)
122 ;; Left column of CUA rectangle.
124 (if (<= val
(aref cua--rectangle
3))
125 (aset cua--rectangle
2 val
)
126 (aset cua--rectangle
3 val
)
127 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
128 (aref cua--rectangle
2)))
130 (defun cua--rectangle-right (&optional val
)
131 ;; Right column of CUA rectangle.
133 (if (>= val
(aref cua--rectangle
2))
134 (aset cua--rectangle
3 val
)
135 (aset cua--rectangle
2 val
)
136 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
137 (aref cua--rectangle
3)))
139 (defun cua--rectangle-corner (&optional advance
)
140 ;; Currently active corner of rectangle.
141 (let ((c (aref cua--rectangle
4)))
142 (if (not (integerp advance
))
144 (aset cua--rectangle
4
146 (- 3 c
) ; opposite corner
147 (mod (+ c
4 advance
) 4)))
148 (aset cua--rectangle
5 0))))
150 (defun cua--rectangle-right-side (&optional topbot
)
151 ;; t if point is on right side of rectangle.
152 (if (and topbot
(= (cua--rectangle-left) (cua--rectangle-right)))
153 (< (cua--rectangle-corner) 2)
154 (= (mod (cua--rectangle-corner) 2) 1)))
156 (defun cua--rectangle-column ()
157 (if (cua--rectangle-right-side)
158 (cua--rectangle-right)
159 (cua--rectangle-left)))
161 (defun cua--rectangle-insert-col (&optional col
)
162 ;; Currently active corner of rectangle.
164 (aset cua--rectangle
5 col
)
165 (if (cua--rectangle-right-side t
)
166 (if (= (aref cua--rectangle
5) 0)
167 (1+ (cua--rectangle-right))
168 (aref cua--rectangle
5))
169 (cua--rectangle-left))))
171 (defun cua--rectangle-virtual-edges (&optional set val
)
172 ;; Current setting of rectangle virtual-edges
174 (aset cua--rectangle
6 val
))
175 (and ;(not buffer-read-only)
176 (aref cua--rectangle
6)))
178 (defun cua--rectangle-restriction (&optional val bounded negated
)
179 ;; Current rectangle restriction
181 (aset cua--rectangle
7
184 (list val bounded negated
)))
185 (aref cua--rectangle
7)))
187 (defun cua--rectangle-assert ()
188 (message "%S (%d)" cua--rectangle
(point))
189 (if (< (cua--rectangle-right) (cua--rectangle-left))
190 (message "rectangle right < left"))
191 (if (< (cua--rectangle-bot) (cua--rectangle-top))
192 (message "rectangle bot < top")))
194 (defun cua--rectangle-get-corners ()
195 ;; Calculate the rectangular region represented by point and mark,
196 ;; putting start in the upper left corner and end in the
197 ;; bottom right corner.
198 (let ((top (point)) (bot (mark)) r l corner
)
201 (setq l
(current-column))
203 (setq r
(current-column))
205 (setq corner
(if (<= l r
) 0 1))
206 (setq top
(prog1 bot
(setq bot top
)))
207 (setq corner
(if (<= l r
) 2 3)))
211 (setq l
(prog1 r
(setq r l
)))
218 (vector top bot l r corner
0 cua-virtual-rectangle-edges nil
)))
220 (defun cua--rectangle-set-corners ()
221 ;; Set mark and point in opposite corners of current rectangle.
222 (let (pp pc mp mc
(c (cua--rectangle-corner)))
224 ((= c
0) ; top/left -> bot/right
225 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-left)
226 mp
(cua--rectangle-bot) mc
(cua--rectangle-right)))
227 ((= c
1) ; top/right -> bot/left
228 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-right)
229 mp
(cua--rectangle-bot) mc
(cua--rectangle-left)))
230 ((= c
2) ; bot/left -> top/right
231 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-left)
232 mp
(cua--rectangle-top) mc
(cua--rectangle-right)))
233 ((= c
3) ; bot/right -> top/left
234 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-right)
235 mp
(cua--rectangle-top) mc
(cua--rectangle-left))))
240 ;; Move cursor inside rectangle, except if char at rigth edge is a tab.
241 (if (and (if (cua--rectangle-right-side)
242 (and (= (move-to-column pc
) (- pc tab-width
))
244 (> (move-to-column pc
) pc
))
249 (defun cua--rect-start-position ()
250 ;; Return point of top left corner
252 (goto-char (cua--rectangle-top))
253 (and (> (move-to-column (cua--rectangle-left))
254 (cua--rectangle-left))
259 (defun cua--rect-end-position ()
260 ;; Return point of bottom right cornet
262 (goto-char (cua--rectangle-bot))
263 (and (= (move-to-column (cua--rectangle-right))
264 (- (cua--rectangle-right) tab-width
))
270 ;;; Rectangle resizing
272 (defun cua--forward-line (n)
273 ;; Move forward/backward one line. Returns t if movement.
275 (and (= (forward-line n
) 0)
276 ;; Deal with end of buffer
280 (defun cua--rectangle-resized ()
281 ;; Refresh state after resizing rectangle
282 (setq cua--buffer-and-point-before-command nil
)
283 (cua--rectangle-insert-col 0)
284 (cua--rectangle-set-corners)
287 (defun cua-resize-rectangle-right (n)
288 "Resize rectangle to the right."
290 (let ((resized (> n
0)))
294 ((cua--rectangle-right-side)
295 (cua--rectangle-right (1+ (cua--rectangle-right)))
296 (move-to-column (cua--rectangle-right)))
298 (cua--rectangle-left (1+ (cua--rectangle-left)))
299 (move-to-column (cua--rectangle-right)))))
301 (cua--rectangle-resized))))
303 (defun cua-resize-rectangle-left (n)
304 "Resize rectangle to the left."
309 (if (or (= (cua--rectangle-right) 0)
310 (and (not (cua--rectangle-right-side)) (= (cua--rectangle-left) 0)))
313 ((cua--rectangle-right-side)
314 (cua--rectangle-right (1- (cua--rectangle-right)))
315 (move-to-column (cua--rectangle-right)))
317 (cua--rectangle-left (1- (cua--rectangle-left)))
318 (move-to-column (cua--rectangle-right))))
321 (cua--rectangle-resized))))
323 (defun cua-resize-rectangle-down (n)
324 "Resize rectangle downwards."
330 ((>= (cua--rectangle-corner) 2)
331 (goto-char (cua--rectangle-bot))
332 (when (cua--forward-line 1)
333 (move-to-column (cua--rectangle-column))
334 (cua--rectangle-bot t
)
337 (goto-char (cua--rectangle-top))
338 (when (cua--forward-line 1)
339 (move-to-column (cua--rectangle-column))
340 (cua--rectangle-top t
)
343 (cua--rectangle-resized))))
345 (defun cua-resize-rectangle-up (n)
346 "Resize rectangle upwards."
352 ((>= (cua--rectangle-corner) 2)
353 (goto-char (cua--rectangle-bot))
354 (when (cua--forward-line -
1)
355 (move-to-column (cua--rectangle-column))
356 (cua--rectangle-bot t
)
359 (goto-char (cua--rectangle-top))
360 (when (cua--forward-line -
1)
361 (move-to-column (cua--rectangle-column))
362 (cua--rectangle-top t
)
365 (cua--rectangle-resized))))
367 (defun cua-resize-rectangle-eol ()
368 "Resize rectangle to end of line."
372 (if (> (current-column) (cua--rectangle-right))
373 (cua--rectangle-right (current-column)))
374 (if (not (cua--rectangle-right-side))
375 (cua--rectangle-corner 1))
376 (cua--rectangle-resized)))
378 (defun cua-resize-rectangle-bol ()
379 "Resize rectangle to beginning of line."
383 (cua--rectangle-left (current-column))
384 (if (cua--rectangle-right-side)
385 (cua--rectangle-corner -
1))
386 (cua--rectangle-resized)))
388 (defun cua-resize-rectangle-bot ()
389 "Resize rectangle to bottom of buffer."
391 (goto-char (point-max))
392 (move-to-column (cua--rectangle-column))
393 (cua--rectangle-bot t
)
394 (cua--rectangle-resized))
396 (defun cua-resize-rectangle-top ()
397 "Resize rectangle to top of buffer."
399 (goto-char (point-min))
400 (move-to-column (cua--rectangle-column))
401 (cua--rectangle-top t
)
402 (cua--rectangle-resized))
404 (defun cua-resize-rectangle-page-up ()
405 "Resize rectangle upwards by one scroll page."
408 (move-to-column (cua--rectangle-column))
409 (if (>= (cua--rectangle-corner) 2)
410 (cua--rectangle-bot t
)
411 (cua--rectangle-top t
))
412 (cua--rectangle-resized))
414 (defun cua-resize-rectangle-page-down ()
415 "Resize rectangle downwards by one scroll page."
418 (move-to-column (cua--rectangle-column))
419 (if (>= (cua--rectangle-corner) 2)
420 (cua--rectangle-bot t
)
421 (cua--rectangle-top t
))
422 (cua--rectangle-resized))
426 ;; This is pretty simplistic, but it does the job...
428 (defun cua-mouse-resize-rectangle (event)
429 "Set rectangle corner at mouse click position."
431 (mouse-set-point event
)
432 ;; FIX ME -- need to calculate virtual column.
433 (if (cua--rectangle-virtual-edges)
434 (move-to-column (car (posn-col-row (event-end event
))) t
))
435 (if (cua--rectangle-right-side)
436 (cua--rectangle-right (current-column))
437 (cua--rectangle-left (current-column)))
438 (if (>= (cua--rectangle-corner) 2)
439 (cua--rectangle-bot t
)
440 (cua--rectangle-top t
))
441 (cua--rectangle-resized))
443 (defvar cua--mouse-last-pos nil
)
445 (defun cua-mouse-set-rectangle-mark (event)
446 "Start rectangle at mouse click position."
449 (cua--deactivate-rectangle)
451 (setq cua--last-rectangle nil
)
452 (mouse-set-point event
)
453 ;; FIX ME -- need to calculate virtual column.
454 (cua-set-rectangle-mark)
455 (setq cua--buffer-and-point-before-command nil
)
456 (setq cua--mouse-last-pos nil
))
458 (defun cua-mouse-save-then-kill-rectangle (event arg
)
459 "Expand rectangle to mouse click position and copy rectangle.
460 If command is repeated at same position, delete the rectangle."
462 (if (and (eq this-command last-command
)
463 (eq (point) (car-safe cua--mouse-last-pos
))
464 (eq cua--last-killed-rectangle
(cdr-safe cua--mouse-last-pos
)))
466 (unless buffer-read-only
467 (cua--delete-rectangle))
469 (cua-mouse-resize-rectangle event
)
470 (let ((cua-keep-region-after-copy t
))
471 (cua-copy-rectangle arg
)
472 (setq cua--mouse-last-pos
(cons (point) cua--last-killed-rectangle
)))))
474 (defun cua--mouse-ignore (event)
476 (setq this-command last-command
))
478 (defun cua--rectangle-move (dir)
480 (top (cua--rectangle-top))
481 (bot (cua--rectangle-bot))
482 (l (cua--rectangle-left))
483 (r (cua--rectangle-right)))
487 (when (cua--forward-line -
1)
488 (cua--rectangle-top t
)
491 (cua--rectangle-bot t
)))
494 (when (cua--forward-line 1)
495 (cua--rectangle-bot t
)
497 (cua--forward-line 1)
498 (cua--rectangle-top t
)))
501 (cua--rectangle-left (1- l
))
502 (cua--rectangle-right (1- r
))))
504 (cua--rectangle-right (1+ r
))
505 (cua--rectangle-left (1+ l
)))
509 (setq cua--buffer-and-point-before-command nil
)
510 (cua--rectangle-set-corners)
511 (cua--keep-active))))
514 ;;; Operations on current rectangle
516 (defun cua--tabify-start (start end
)
517 ;; Return position where auto-tabify should start (or nil if not required).
521 (and (not buffer-read-only
)
522 cua-auto-tabify-rectangles
523 (if (or (not (integerp cua-auto-tabify-rectangles
))
524 (= (point-min) (point-max))
526 (goto-char (max (point-min)
527 (- start cua-auto-tabify-rectangles
)))
528 (search-forward "\t" (min (point-max)
529 (+ end cua-auto-tabify-rectangles
)) t
)))
532 (defun cua--rectangle-operation (keep-clear visible undo pad tabify
&optional fct post-fct
)
533 ;; Call FCT for each line of region with 4 parameters:
534 ;; Region start, end, left-col, right-col
535 ;; Point is at start when FCT is called
536 ;; Call fct with (s,e) = whole lines if VISIBLE non-nil.
537 ;; Only call fct for visible lines if VISIBLE==t.
538 ;; Set undo boundary if UNDO is non-nil.
539 ;; Rectangle is padded if PAD = t or numeric and (cua--rectangle-virtual-edges)
540 ;; Perform auto-tabify after operation if TABIFY is non-nil.
541 ;; Mark is kept if keep-clear is 'keep and cleared if keep-clear is 'clear.
542 (let* ((inhibit-field-text-motion t
)
543 (start (cua--rectangle-top))
544 (end (cua--rectangle-bot))
545 (l (cua--rectangle-left))
546 (r (1+ (cua--rectangle-right)))
548 (tabpad (and (integerp pad
) (= pad
2)))
549 (sel (cua--rectangle-restriction))
550 (tabify-start (and tabify
(cua--tabify-start start end
))))
552 (cua--rectangle-undo-boundary))
554 (setq pad
(cua--rectangle-virtual-edges)))
558 (when (> (cua--rectangle-corner) 1)
560 (and (bolp) (not (eolp)) (not (eobp))
561 (setq end
(1+ end
))))
563 (setq start
(max (window-start) start
))
564 (setq end
(min (window-end) end
)))
566 (setq end
(line-end-position))
567 (if (and visible
(bolp) (not (eobp)))
570 (setq start
(line-beginning-position))
571 (narrow-to-region start end
)
572 (goto-char (point-min))
573 (while (< (point) (point-max))
574 (move-to-column r pad
)
575 (and (not pad
) (not visible
) (> (current-column) r
)
577 (if (and tabpad
(not pad
) (looking-at "\t"))
579 (set-marker m
(point))
580 (move-to-column l pad
)
581 (if (and fct
(or visible
(and (>= (current-column) l
) (<= (current-column) r
))))
582 (let ((v t
) (p (point)))
585 (setq v
(looking-at (car sel
)))
586 (setq v
(re-search-forward (car sel
) m t
))
588 (if (car (cdr (cdr sel
)))
591 (funcall fct p m l r v
)
593 (funcall fct p m l r
)))))
597 (cua--rectangle-bot t
))
599 (funcall post-fct l r
))
601 (tabify tabify-start
(point)))))
603 ((eq keep-clear
'keep
)
605 ((eq keep-clear
'clear
)
607 ((eq keep-clear
'corners
)
608 (cua--rectangle-set-corners)
610 (setq cua--buffer-and-point-before-command nil
)))
612 (put 'cua--rectangle-operation
'lisp-indent-function
4)
614 (defun cua--delete-rectangle ()
616 (if (not (cua--rectangle-virtual-edges))
617 (cua--rectangle-operation nil nil t
2 t
619 (setq lines
(1+ lines
))
620 (if (and (> e s
) (<= e
(point-max)))
621 (delete-region s e
))))
622 (cua--rectangle-operation nil
1 t nil t
624 (setq lines
(1+ lines
))
625 (when (and (> e s
) (<= e
(point-max)))
626 (delete-region s e
)))))
629 (defun cua--extract-rectangle ()
631 (if (not (cua--rectangle-virtual-edges))
632 (cua--rectangle-operation nil nil nil nil nil
; do not tabify
634 (setq rect
(cons (filter-buffer-substring s e nil t
) rect
))))
635 (cua--rectangle-operation nil
1 nil nil nil
; do not tabify
637 (let ((copy t
) (bs 0) (as 0) row
)
638 (if (= s e
) (setq e
(1+ e
)))
641 (if (= (point) (line-end-position))
644 (skip-chars-forward "\s\t" e
)
645 (setq bs
(- (min r
(current-column)) l
)
648 (skip-chars-backward "\s\t" s
)
649 (setq as
(- r
(max (current-column) l
))
651 (setq row
(if (and copy
(> e s
))
652 (filter-buffer-substring s e nil t
)
655 (setq row
(concat (make-string bs ?\s
) row
)))
657 (setq row
(concat row
(make-string as ?\s
))))
658 (setq rect
(cons row rect
))))))
661 (defun cua--insert-rectangle (rect &optional below paste-column line-count
)
662 ;; Insert rectangle as insert-rectangle, but don't set mark and exit with
663 ;; point at either next to top right or below bottom left corner
664 ;; Notice: In overwrite mode, the rectangle is inserted as separate text lines.
666 (setq below
(and (bolp)
667 (or (eolp) (eobp) (= (1+ (point)) (point-max))))))
669 (setq paste-column
(current-column)))
672 (tabify-start (cua--tabify-start (point) (point)))
675 (while (or lines below
)
680 (or (bolp) (insert ?
\n))))
681 (unless overwrite-mode
682 (move-to-column paste-column t
))
685 (insert-for-yank (car lines
))
687 (setq last-column
(current-column)))
688 (setq lines
(cdr lines
))
689 (and first
(not below
)
692 (if (and line-count
(= (setq line-count
(1- line-count
)) 0))
694 (when (and line-count last-column
(not overwrite-mode
))
695 (while (> line-count
0)
697 (or (bolp) (insert ?
\n))
698 (move-to-column paste-column t
)
699 (insert-char ?\s
(- last-column paste-column -
1))
700 (setq line-count
(1- line-count
))))
701 (when (and tabify-start
702 (not overwrite-mode
))
703 (tabify tabify-start
(point)))
704 (and p
(not overwrite-mode
)
707 (defun cua--copy-rectangle-as-kill (&optional ring
)
709 (set-register cua--register
(cua--extract-rectangle))
710 (setq killed-rectangle
(cua--extract-rectangle))
711 (setq cua--last-killed-rectangle
(cons (and kill-ring
(car kill-ring
)) killed-rectangle
))
714 (function (lambda (row) (concat row
"\n")))
715 killed-rectangle
"")))))
717 (defun cua--activate-rectangle ()
718 ;; Turn on rectangular marking mode by disabling transient mark mode
719 ;; and manually handling highlighting from a post command hook.
720 ;; Be careful if we are already marking a rectangle.
722 (if (and cua--last-rectangle
723 (eq (car cua--last-rectangle
) (current-buffer))
724 (eq (car (cdr cua--last-rectangle
)) (point)))
725 (cdr (cdr cua--last-rectangle
))
726 (cua--rectangle-get-corners))
727 cua--status-string
(if (cua--rectangle-virtual-edges) " [R]" "")
728 cua--last-rectangle nil
))
730 ;; (defvar cua-save-point nil)
732 (defun cua--deactivate-rectangle ()
733 ;; This is used to clean up after `cua--activate-rectangle'.
734 (mapcar (function delete-overlay
) cua--rectangle-overlays
)
735 (setq cua--last-rectangle
(cons (current-buffer)
736 (cons (point) ;; cua-save-point
739 cua--rectangle-overlays nil
740 cua--status-string nil
741 cua--mouse-last-pos nil
))
743 (defun cua--highlight-rectangle ()
744 ;; This function is used to highlight the rectangular region.
745 ;; We do this by putting an overlay on each line within the rectangle.
746 ;; Each overlay extends across all the columns of the rectangle.
747 ;; We try to reuse overlays where possible because this is more efficient
748 ;; and results in less flicker.
749 ;; If cua--rectangle-virtual-edges is nil and the buffer contains tabs or short lines,
750 ;; the higlighted region may not be perfectly rectangular.
751 (let ((deactivate-mark deactivate-mark
)
752 (old cua--rectangle-overlays
)
754 (left (cua--rectangle-left))
755 (right (1+ (cua--rectangle-right))))
756 (when (/= left right
)
757 (sit-for 0) ; make window top/bottom reliable
758 (cua--rectangle-operation nil t nil nil nil
; do not tabify
760 (let ((rface (if v
'cua-rectangle
'cua-rectangle-noselect
))
762 (when (cua--rectangle-virtual-edges)
763 (let ((lb (line-beginning-position))
764 (le (line-end-position))
767 (setq cl
(move-to-column l
)
769 (setq cr
(move-to-column r
)
774 (setq cl0
(current-column)))
778 (setq cr0
(current-column)))
779 (unless (and (= cl l
) (= cr r
))
783 (- l cl0
(if (and (= le pl
) (/= le lb
)) 1 0))
784 (if cua--virtual-edges-debug ?. ?\s
))
785 'face
(or (get-text-property (1- s
) 'face
) 'default
)))
792 (or bs
(/= cr0
(- cr tab-width
)))
793 (/= (mod cr tab-width
) 0))
799 (if cua--virtual-edges-debug ?
, ?\s
))
801 (if (cua--rectangle-right-side)
802 (put-text-property (1- (length ms
)) (length ms
) 'cursor
2 ms
)
803 (put-text-property 0 1 'cursor
2 ms
))
804 (setq bs
(concat bs ms
))
809 (- r cr0
(if (= le pr
) 1 0))
810 (if cua--virtual-edges-debug ?~ ?\s
))
812 (if (cua--rectangle-right-side)
813 (put-text-property (1- (length as
)) (length as
) 'cursor
2 as
)
814 (put-text-property 0 1 'cursor
2 as
))
816 (setq e
(1- e
))))))))
817 ;; Trim old leading overlays.
819 (setq overlay
(car old
))
820 (< (overlay-start overlay
) s
)
821 (/= (overlay-end overlay
) e
))
822 (delete-overlay overlay
)
823 (setq old
(cdr old
)))
824 ;; Reuse an overlay if possible, otherwise create one.
826 (setq overlay
(car old
))
827 (or (= (overlay-start overlay
) s
)
828 (= (overlay-end overlay
) e
)))
830 (move-overlay overlay s e
)
831 (setq old
(cdr old
)))
832 (setq overlay
(make-overlay s e
)))
833 (overlay-put overlay
'before-string bs
)
834 (overlay-put overlay
'after-string as
)
835 (overlay-put overlay
'face rface
)
836 (overlay-put overlay
'keymap cua--overlay-keymap
)
837 (overlay-put overlay
'window
(selected-window))
838 (setq new
(cons overlay new
))))))
839 ;; Trim old trailing overlays.
840 (mapcar (function delete-overlay
) old
)
841 (setq cua--rectangle-overlays
(nreverse new
))))
843 (defun cua--indent-rectangle (&optional ch to-col clear
)
844 ;; Indent current rectangle.
845 (let ((col (cua--rectangle-insert-col))
846 (pad (cua--rectangle-virtual-edges))
848 (cua--rectangle-operation (if clear
'clear
'corners
) nil t pad nil
850 (move-to-column col pad
)
852 (< (current-column) col
))
853 (move-to-column col t
))
855 (to-col (indent-to to-col
))
857 (t (tab-to-tab-stop)))
858 (if (cua--rectangle-right-side t
)
859 (cua--rectangle-insert-col (current-column))
860 (setq indent
(- (current-column) l
))))
862 (when (and indent
(> indent
0))
863 (aset cua--rectangle
2 (+ l indent
))
864 (aset cua--rectangle
3 (+ r indent -
1)))))))
867 ;; rectangle functions / actions
870 (defvar cua--rectangle-initialized nil
)
872 (defun cua-set-rectangle-mark (&optional reopen
)
873 "Set mark and start in CUA rectangle mode.
874 With prefix argument, activate previous rectangle if possible."
876 (unless cua--rectangle-initialized
877 (cua--init-rectangles))
878 (when (not cua--rectangle
)
881 (eq (car cua--last-rectangle
) (current-buffer)))
882 (goto-char (car (cdr cua--last-rectangle
)))
883 (if (not mark-active
)
884 (push-mark nil nil t
)))
885 (cua--activate-rectangle)
886 (cua--rectangle-set-corners)
888 cua--explicit-region-start t
)
889 (if cua-enable-rectangle-auto-help
890 (cua-help-for-rectangle t
))))
892 (defun cua-clear-rectangle-mark ()
893 "Cancel current rectangle."
896 (setq mark-active nil
897 cua--explicit-region-start nil
)
898 (cua--deactivate-rectangle)))
900 (defun cua-toggle-rectangle-mark ()
903 (cua--deactivate-rectangle)
904 (unless cua--rectangle-initialized
905 (cua--init-rectangles))
906 (cua--activate-rectangle))
908 (if cua-enable-rectangle-auto-help
909 (cua-help-for-rectangle t
))
910 (if cua-enable-region-auto-help
911 (cua-help-for-region t
))))
913 (defun cua-restrict-regexp-rectangle (arg)
914 "Restrict rectangle to lines (not) matching REGEXP.
915 With prefix argument, the toggle restriction."
917 (let ((r (cua--rectangle-restriction)) regexp
)
918 (if (and r
(null (car (cdr r
))))
920 (cua--rectangle-restriction (car r
) nil
(not (car (cdr (cdr r
)))))
921 (cua--rectangle-restriction "" nil nil
))
922 (cua--rectangle-restriction
923 (read-from-minibuffer "Restrict rectangle (regexp): "
924 nil nil nil nil
) nil arg
))))
926 (defun cua-restrict-prefix-rectangle (arg)
927 "Restrict rectangle to lines (not) starting with CHAR.
928 With prefix argument, the toggle restriction."
930 (let ((r (cua--rectangle-restriction)) regexp
)
931 (if (and r
(car (cdr r
)))
933 (cua--rectangle-restriction (car r
) t
(not (car (cdr (cdr r
)))))
934 (cua--rectangle-restriction "" nil nil
))
935 (cua--rectangle-restriction
937 (read-char "Restrictive rectangle (char): ")) t arg
))))
939 (defun cua-move-rectangle-up ()
941 (cua--rectangle-move 'up
))
943 (defun cua-move-rectangle-down ()
945 (cua--rectangle-move 'down
))
947 (defun cua-move-rectangle-left ()
949 (cua--rectangle-move 'left
))
951 (defun cua-move-rectangle-right ()
953 (cua--rectangle-move 'right
))
955 (defun cua-copy-rectangle (arg)
957 (setq arg
(cua--prefix-arg arg
))
958 (cua--copy-rectangle-as-kill arg
)
959 (if cua-keep-region-after-copy
963 (defun cua-cut-rectangle (arg)
966 (cua-copy-rectangle arg
)
967 (setq arg
(cua--prefix-arg arg
))
968 (goto-char (min (mark) (point)))
969 (cua--copy-rectangle-as-kill arg
)
970 (cua--delete-rectangle))
973 (defun cua-delete-rectangle ()
975 (goto-char (min (point) (mark)))
976 (if cua-delete-copy-to-register-0
977 (set-register ?
0 (cua--extract-rectangle)))
978 (cua--delete-rectangle)
981 (defun cua-rotate-rectangle ()
983 (cua--rectangle-corner (if (= (cua--rectangle-left) (cua--rectangle-right)) 0 1))
984 (cua--rectangle-set-corners)
985 (if (cua--rectangle-virtual-edges)
986 (setq cua--buffer-and-point-before-command nil
)))
988 (defun cua-toggle-rectangle-virtual-edges ()
990 (cua--rectangle-virtual-edges t
(not (cua--rectangle-virtual-edges)))
991 (cua--rectangle-set-corners)
992 (setq cua--status-string
(and (cua--rectangle-virtual-edges) " [R]"))
995 (defun cua-do-rectangle-padding ()
998 (message "Cannot do padding in read-only buffer")
999 (cua--rectangle-operation nil nil t t t
)
1000 (cua--rectangle-set-corners))
1003 (defun cua-open-rectangle ()
1004 "Blank out CUA rectangle, shifting text right.
1005 The text previously in the region is not overwritten by the blanks,
1006 but instead winds up to the right of the rectangle."
1008 (cua--rectangle-operation 'corners nil t
1 nil
1010 (skip-chars-forward " \t")
1011 (let ((ws (- (current-column) l
))
1013 (skip-chars-backward " \t")
1014 (delete-region (point) p
)
1015 (indent-to (+ r ws
))))))
1017 (defun cua-close-rectangle (arg)
1018 "Delete all whitespace starting at left edge of CUA rectangle.
1019 On each line in the rectangle, all continuous whitespace starting
1020 at that column is deleted.
1021 With prefix arg, also delete whitespace to the left of that column."
1023 (cua--rectangle-operation 'clear nil t
1 nil
1026 (skip-syntax-backward " " (line-beginning-position))
1028 (skip-syntax-forward " " (line-end-position))
1029 (delete-region s
(point)))))
1031 (defun cua-blank-rectangle ()
1032 "Blank out CUA rectangle.
1033 The text previously in the rectangle is overwritten by the blanks."
1035 (cua--rectangle-operation 'keep nil nil
1 nil
1038 (skip-syntax-forward " " (line-end-position))
1040 (let ((column (current-column)))
1042 (skip-syntax-backward " " (line-beginning-position))
1043 (delete-region (point) e
)
1044 (indent-to column
)))))
1046 (defun cua-align-rectangle ()
1047 "Align rectangle lines to left column."
1050 (cua--rectangle-operation 'clear nil t t nil
1052 (let ((b (line-beginning-position)))
1053 (skip-syntax-backward "^ " b
)
1054 (skip-syntax-backward " " b
)
1056 (skip-syntax-forward " " (line-end-position))
1057 (delete-region s
(point))
1061 ;; (setq cua-save-point (point))
1064 (defun cua-copy-rectangle-as-text (&optional arg delete
)
1065 "Copy rectangle, but store as normal text."
1067 (if cua--global-mark-active
1069 (cua--cut-rectangle-to-global-mark t
)
1070 (cua--copy-rectangle-to-global-mark t
))
1071 (let* ((rect (cua--extract-rectangle))
1073 (function (lambda (row) (concat row
"\n")))
1075 (setq arg
(cua--prefix-arg arg
))
1077 (set-register cua--register text
)
1080 (cua--delete-rectangle))
1083 (defun cua-cut-rectangle-as-text (arg)
1084 "Kill rectangle, but store as normal text."
1086 (cua-copy-rectangle-as-text arg
(not buffer-read-only
)))
1088 (defun cua-string-rectangle (string)
1089 "Replace CUA rectangle contents with STRING on each line.
1090 The length of STRING need not be the same as the rectangle width."
1091 (interactive "sString rectangle: ")
1092 (cua--rectangle-operation 'keep nil t t nil
1095 (skip-chars-forward " \t")
1096 (let ((ws (- (current-column) l
)))
1097 (delete-region s
(point))
1099 (indent-to (+ (current-column) ws
))))
1100 (unless (cua--rectangle-restriction)
1102 (cua--rectangle-right (max l
(+ l
(length string
) -
1)))))))
1104 (defun cua-fill-char-rectangle (character)
1105 "Replace CUA rectangle contents with CHARACTER."
1106 (interactive "cFill rectangle with character: ")
1107 (cua--rectangle-operation 'clear nil t
1 nil
1110 (move-to-column l t
)
1111 (insert-char character
(- r l
)))))
1113 (defun cua-replace-in-rectangle (regexp newtext
)
1114 "Replace REGEXP with NEWTEXT in each line of CUA rectangle."
1115 (interactive "sReplace regexp: \nsNew text: ")
1116 (if buffer-read-only
1117 (message "Cannot replace in read-only buffer")
1118 (cua--rectangle-operation 'keep nil t
1 nil
1120 (if (re-search-forward regexp e t
)
1121 (replace-match newtext nil nil
))))))
1123 (defun cua-incr-rectangle (increment)
1124 "Increment each line of CUA rectangle by prefix amount."
1126 (cua--rectangle-operation 'keep nil t
1 nil
1129 ((re-search-forward "0x\\([0-9a-fA-F]+\\)" e t
)
1130 (let* ((txt (filter-buffer-substring (match-beginning 1) (match-end 1) nil t
))
1131 (n (string-to-number txt
16))
1132 (fmt (format "0x%%0%dx" (length txt
))))
1133 (replace-match (format fmt
(+ n increment
)))))
1134 ((re-search-forward "\\( *-?[0-9]+\\)" e t
)
1135 (let* ((txt (filter-buffer-substring (match-beginning 1) (match-end 1) nil t
))
1136 (prefix (if (= (aref txt
0) ?
0) "0" ""))
1137 (n (string-to-number txt
10))
1138 (fmt (format "%%%s%dd" prefix
(length txt
))))
1139 (replace-match (format fmt
(+ n increment
)))))
1142 (defvar cua--rectangle-seq-format
"%d"
1143 "Last format used by `cua-sequence-rectangle'.")
1145 (defun cua-sequence-rectangle (first incr format
)
1146 "Resequence each line of CUA rectangle starting from FIRST.
1147 The numbers are formatted according to the FORMAT string."
1149 (list (if current-prefix-arg
1150 (prefix-numeric-value current-prefix-arg
)
1152 (read-string "Start value: (0) " nil nil
"0")))
1154 (read-string "Increment: (1) " nil nil
"1"))
1155 (read-string (concat "Format: (" cua--rectangle-seq-format
") "))))
1156 (if (= (length format
) 0)
1157 (setq format cua--rectangle-seq-format
)
1158 (setq cua--rectangle-seq-format format
))
1159 (cua--rectangle-operation 'clear nil t
1 nil
1162 (insert (format format first
))
1163 (setq first
(+ first incr
)))))
1165 (defmacro cua--convert-rectangle-as
(command tabify
)
1166 `(cua--rectangle-operation 'clear nil nil nil
,tabify
1170 (defun cua-upcase-rectangle ()
1171 "Convert the rectangle to upper case."
1173 (cua--convert-rectangle-as upcase-region nil
))
1175 (defun cua-downcase-rectangle ()
1176 "Convert the rectangle to lower case."
1178 (cua--convert-rectangle-as downcase-region nil
))
1180 (defun cua-upcase-initials-rectangle ()
1181 "Convert the rectangle initials to upper case."
1183 (cua--convert-rectangle-as upcase-initials-region nil
))
1185 (defun cua-capitalize-rectangle ()
1186 "Convert the rectangle to proper case."
1188 (cua--convert-rectangle-as capitalize-region nil
))
1191 ;;; Replace/rearrange text in current rectangle
1193 (defun cua--rectangle-aux-replace (width adjust keep replace pad format-fct
&optional setup-fct
)
1194 ;; Process text inserted by calling SETUP-FCT or current rectangle if nil.
1195 ;; Then call FORMAT-FCT on text (if non-nil); takes two args: start and end.
1196 ;; Fill to WIDTH characters if > 0 or fill to current width if == 0.
1197 ;; Don't fill if WIDTH < 0.
1198 ;; Replace current rectangle by filled text if REPLACE is non-nil
1199 (let ((auxbuf (get-buffer-create "*CUA temp*"))
1200 (w (if (> width
1) width
1201 (- (cua--rectangle-right) (cua--rectangle-left) -
1)))
1202 (r (or setup-fct
(cua--extract-rectangle)))
1209 (cua--insert-rectangle r
))
1211 (let ((fill-column w
))
1212 (funcall format-fct
(point-min) (point-max))))
1214 (goto-char (point-min))
1216 (setq z
(cons (filter-buffer-substring (point) (line-end-position)) z
))
1218 (if (not cua--debug
)
1219 (kill-buffer auxbuf
))
1221 (setq z
(reverse z
))
1224 (cua--rectangle-operation nil nil t pad nil
1228 (skip-chars-forward " \t")
1229 (setq cc
(current-column))
1231 (print (list cc s e
) auxbuf
))
1232 (delete-region s
(point))
1235 (move-to-column l t
)
1237 (when (> (current-column) (+ l w
))
1239 (move-to-column (+ l w
) t
)
1240 (delete-region (point) y
)
1244 (print (list (current-column) cc
) auxbuf
))
1248 (message "Warning: Truncated %d row%s" tr
(if (> tr
1) "s" "")))
1250 (cua--rectangle-right (+ (cua--rectangle-left) w -
1)))
1252 (cua--rectangle-resized)))))
1254 (put 'cua--rectangle-aux-replace
'lisp-indent-function
4)
1256 (defun cua--left-fill-rectangle (start end
)
1258 (while (< (point) (point-max))
1259 (delete-horizontal-space nil
)
1261 (fill-region-as-paragraph (point-min) (point-max) 'left nil
)
1262 (untabify (point-min) (point-max)))
1264 (defun cua-text-fill-rectangle (width text
)
1265 "Replace rectagle with filled TEXT read from minibuffer.
1266 A numeric prefix argument is used a new width for the filled rectangle."
1268 (prefix-numeric-value current-prefix-arg
)
1269 (read-from-minibuffer "Enter text: "
1271 (cua--rectangle-aux-replace width t t t
1
1272 'cua--left-fill-rectangle
1273 '(lambda () (insert text
))))
1275 (defun cua-refill-rectangle (width)
1276 "Fill contents of current rectagle.
1277 A numeric prefix argument is used as new width for the filled rectangle."
1279 (cua--rectangle-aux-replace
1280 (if width
(prefix-numeric-value width
) 0)
1281 t t t
1 'cua--left-fill-rectangle
))
1283 (defun cua-shell-command-on-rectangle (replace command
)
1284 "Run shell command on rectangle like `shell-command-on-region'.
1285 With prefix arg, replace rectangle with output from command."
1288 (read-from-minibuffer "Shell command on rectangle: "
1290 'shell-command-history
)))
1291 (cua--rectangle-aux-replace -
1 t t replace
1
1293 (shell-command-on-region s e command
1294 replace replace nil
))))
1296 (defun cua-reverse-rectangle ()
1297 "Reverse the lines of the rectangle."
1299 (cua--rectangle-aux-replace 0 t t t t
'reverse-region
))
1301 (defun cua-scroll-rectangle-up ()
1302 "Remove the first line of the rectangle and scroll remaining lines up."
1304 (cua--rectangle-aux-replace 0 t t t t
1306 (if (= (forward-line 1) 0)
1307 (delete-region s
(point))))))
1309 (defun cua-scroll-rectangle-down ()
1310 "Insert a blank line at the first line of the rectangle.
1311 The remaining lines are scrolled down, losing the last line."
1313 (cua--rectangle-aux-replace 0 t t t t
1319 ;;; Insert/delete text to left or right of rectangle
1321 (defun cua-insert-char-rectangle (&optional ch
)
1323 (if buffer-read-only
1325 (cua--indent-rectangle (or ch
(aref (this-single-command-keys) 0)))
1329 (defun cua-indent-rectangle (column)
1330 "Indent rectangle to next tab stop.
1331 With prefix arg, indent to that column."
1334 (cua-insert-char-rectangle ?
\t)
1335 (cua--indent-rectangle nil
(prefix-numeric-value column
))))
1337 (defun cua-delete-char-rectangle ()
1338 "Delete char to left or right of rectangle."
1340 (let ((col (cua--rectangle-insert-col))
1341 (pad (cua--rectangle-virtual-edges))
1343 (cua--rectangle-operation 'corners nil t pad nil
1346 (if (cua--rectangle-right-side t
)
1351 (delete-backward-char 1)
1352 (if (cua--rectangle-right-side t
)
1353 (cua--rectangle-insert-col (current-column))
1354 (setq indent
(- l
(current-column))))))
1356 (when (and indent
(> indent
0))
1357 (aset cua--rectangle
2 (- l indent
))
1358 (aset cua--rectangle
3 (- r indent
1)))))))
1360 (defun cua-help-for-rectangle (&optional help
)
1362 (let ((M (cond ((eq cua--rectangle-modifier-key
'hyper
) " H-")
1363 ((eq cua--rectangle-modifier-key
'super
) " s-")
1364 ((eq cua--rectangle-modifier-key
'alt
) " A-")
1367 (concat (if help
"C-?:help" "")
1368 M
"p:pad" M
"o:open" M
"c:close" M
"b:blank"
1369 M
"s:string" M
"f:fill" M
"i:incr" M
"n:seq"))))
1372 ;;; CUA-like cut & paste for rectangles
1374 (defun cua--cancel-rectangle ()
1377 (cua--deactivate-rectangle))
1378 (setq cua--last-rectangle nil
))
1380 (defun cua--rectangle-post-command ()
1381 (if cua--restored-rectangle
1383 (setq cua--rectangle cua--restored-rectangle
1384 cua--restored-rectangle nil
1386 deactivate-mark nil
)
1387 (cua--rectangle-set-corners))
1388 (when (and cua--rectangle cua--buffer-and-point-before-command
1389 (equal (car cua--buffer-and-point-before-command
) (current-buffer))
1390 (not (= (cdr cua--buffer-and-point-before-command
) (point))))
1391 (if (cua--rectangle-right-side)
1392 (cua--rectangle-right (current-column))
1393 (cua--rectangle-left (current-column)))
1394 (if (>= (cua--rectangle-corner) 2)
1395 (cua--rectangle-bot t
)
1396 (cua--rectangle-top t
))))
1398 (if (and mark-active
1399 (not deactivate-mark
))
1400 (cua--highlight-rectangle)
1401 (cua--deactivate-rectangle))
1402 (when cua--rectangle-overlays
1403 ;; clean-up after revert-buffer
1404 (mapcar (function delete-overlay
) cua--rectangle-overlays
)
1405 (setq cua--rectangle-overlays nil
)
1406 (setq deactivate-mark t
)))
1407 (when cua--rect-undo-set-point
1408 (goto-char cua--rect-undo-set-point
)
1409 (setq cua--rect-undo-set-point nil
)))
1413 (defun cua--rect-M/H-key
(key cmd
)
1414 (cua--M/H-key cua--rectangle-keymap key cmd
))
1416 (defun cua--init-rectangles ()
1417 (define-key cua--rectangle-keymap cua-rectangle-mark-key
'cua-clear-rectangle-mark
)
1418 (define-key cua--region-keymap cua-rectangle-mark-key
'cua-toggle-rectangle-mark
)
1419 (unless (eq cua--rectangle-modifier-key
'meta
)
1420 (cua--rect-M/H-key ?\s
'cua-clear-rectangle-mark
)
1421 (cua--M/H-key cua--region-keymap ?\s
'cua-toggle-rectangle-mark
))
1423 (define-key cua--rectangle-keymap
[remap copy-region-as-kill
] 'cua-copy-rectangle
)
1424 (define-key cua--rectangle-keymap
[remap kill-ring-save
] 'cua-copy-rectangle
)
1425 (define-key cua--rectangle-keymap
[remap kill-region
] 'cua-cut-rectangle
)
1426 (define-key cua--rectangle-keymap
[remap delete-char
] 'cua-delete-rectangle
)
1427 (define-key cua--rectangle-keymap
[remap set-mark-command
] 'cua-toggle-rectangle-mark
)
1429 (define-key cua--rectangle-keymap
[remap forward-char
] 'cua-resize-rectangle-right
)
1430 (define-key cua--rectangle-keymap
[remap backward-char
] 'cua-resize-rectangle-left
)
1431 (define-key cua--rectangle-keymap
[remap next-line
] 'cua-resize-rectangle-down
)
1432 (define-key cua--rectangle-keymap
[remap previous-line
] 'cua-resize-rectangle-up
)
1433 (define-key cua--rectangle-keymap
[remap end-of-line
] 'cua-resize-rectangle-eol
)
1434 (define-key cua--rectangle-keymap
[remap beginning-of-line
] 'cua-resize-rectangle-bol
)
1435 (define-key cua--rectangle-keymap
[remap end-of-buffer
] 'cua-resize-rectangle-bot
)
1436 (define-key cua--rectangle-keymap
[remap beginning-of-buffer
] 'cua-resize-rectangle-top
)
1437 (define-key cua--rectangle-keymap
[remap scroll-down
] 'cua-resize-rectangle-page-up
)
1438 (define-key cua--rectangle-keymap
[remap scroll-up
] 'cua-resize-rectangle-page-down
)
1440 (define-key cua--rectangle-keymap
[remap delete-backward-char
] 'cua-delete-char-rectangle
)
1441 (define-key cua--rectangle-keymap
[remap backward-delete-char
] 'cua-delete-char-rectangle
)
1442 (define-key cua--rectangle-keymap
[remap backward-delete-char-untabify
] 'cua-delete-char-rectangle
)
1443 (define-key cua--rectangle-keymap
[remap self-insert-command
] 'cua-insert-char-rectangle
)
1444 (define-key cua--rectangle-keymap
[remap self-insert-iso
] 'cua-insert-char-rectangle
)
1446 ;; Catch self-inserting characters which are "stolen" by other modes
1447 (define-key cua--rectangle-keymap
[t]
1448 '(menu-item "sic" cua-insert-char-rectangle :filter cua--self-insert-char-p))
1450 (define-key cua--rectangle-keymap "\r" 'cua-rotate-rectangle)
1451 (define-key cua--rectangle-keymap "\t" 'cua-indent-rectangle)
1453 (define-key cua--rectangle-keymap [(control ??)] 'cua-help-for-rectangle)
1455 (define-key cua--rectangle-keymap [mouse-1] 'cua-mouse-set-rectangle-mark)
1456 (define-key cua--rectangle-keymap [down-mouse-1] 'cua--mouse-ignore)
1457 (define-key cua--rectangle-keymap [drag-mouse-1] 'cua--mouse-ignore)
1458 (define-key cua--rectangle-keymap [mouse-3] 'cua-mouse-save-then-kill-rectangle)
1459 (define-key cua--rectangle-keymap [down-mouse-3] 'cua--mouse-ignore)
1460 (define-key cua--rectangle-keymap [drag-mouse-3] 'cua--mouse-ignore)
1462 (cua--rect-M/H-key 'up 'cua-move-rectangle-up)
1463 (cua--rect-M/H-key 'down 'cua-move-rectangle-down)
1464 (cua--rect-M/H-key 'left 'cua-move-rectangle-left)
1465 (cua--rect-M/H-key 'right 'cua-move-rectangle-right)
1467 (cua--rect-M/H-key '(control up) 'cua-scroll-rectangle-up)
1468 (cua--rect-M/H-key '(control down) 'cua-scroll-rectangle-down)
1470 (cua--rect-M/H-key ?a 'cua-align-rectangle)
1471 (cua--rect-M/H-key ?b 'cua-blank-rectangle)
1472 (cua--rect-M/H-key ?c 'cua-close-rectangle)
1473 (cua--rect-M/H-key ?f 'cua-fill-char-rectangle)
1474 (cua--rect-M/H-key ?i 'cua-incr-rectangle)
1475 (cua--rect-M/H-key ?k 'cua-cut-rectangle-as-text)
1476 (cua--rect-M/H-key ?l 'cua-downcase-rectangle)
1477 (cua--rect-M/H-key ?m 'cua-copy-rectangle-as-text)
1478 (cua--rect-M/H-key ?n 'cua-sequence-rectangle)
1479 (cua--rect-M/H-key ?o 'cua-open-rectangle)
1480 (cua--rect-M/H-key ?p 'cua-toggle-rectangle-virtual-edges)
1481 (cua--rect-M/H-key ?P 'cua-do-rectangle-padding)
1482 (cua--rect-M/H-key ?q 'cua-refill-rectangle)
1483 (cua--rect-M/H-key ?r 'cua-replace-in-rectangle)
1484 (cua--rect-M/H-key ?R 'cua-reverse-rectangle)
1485 (cua--rect-M/H-key ?s 'cua-string-rectangle)
1486 (cua--rect-M/H-key ?t 'cua-text-fill-rectangle)
1487 (cua--rect-M/H-key ?u 'cua-upcase-rectangle)
1488 (cua--rect-M/H-key ?| 'cua-shell-command-on-rectangle)
1489 (cua--rect-M/H-key ?' 'cua-restrict-prefix-rectangle)
1490 (cua--rect-M/H-key ?/ 'cua-restrict-regexp-rectangle)
1492 (setq cua--rectangle-initialized t))
1494 ;;; arch-tag: b730df53-17b9-4a89-bd63-4a71ec196731
1495 ;;; cua-rect.el ends here