1 ;;; cua-rect.el --- CUA unified rectangle support
3 ;; Copyright (C) 1997-2002, 2004, 2005 Free Software Foundation, Inc.
5 ;; Author: Kim F. Storm <storm@cua.dk>
6 ;; Keywords: keyboard emulations convenience CUA
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; The rectangle handling and display code borrows from the standard
28 ;; GNU emacs rect.el package and the rect-mark.el package by Rick
29 ;; Sladkey <jrs@world.std.com>.
46 ;; If non-nil, restrict current region to this rectangle.
47 ;; Value is a vector [top bot left right corner ins virt select].
48 ;; CORNER specifies currently active corner 0=t/l 1=t/r 2=b/l 3=b/r.
49 ;; INS specifies whether to insert on left(nil) or right(t) side.
50 ;; If VIRT is non-nil, virtual straight edges are enabled.
51 ;; If SELECT is a regexp, only lines starting with that regexp are affected.")
52 (defvar cua--rectangle nil
)
53 (make-variable-buffer-local 'cua--rectangle
)
55 ;; Most recent rectangle geometry. Note: car is buffer.
56 (defvar cua--last-rectangle nil
)
58 ;; Rectangle restored by undo.
59 (defvar cua--restored-rectangle nil
)
61 ;; Last rectangle copied/killed; nil if last kill was not a rectangle.
62 (defvar cua--last-killed-rectangle nil
)
64 ;; List of overlays used to display current rectangle.
65 (defvar cua--rectangle-overlays nil
)
66 (make-variable-buffer-local 'cua--rectangle-overlays
)
68 (defvar cua--overlay-keymap
69 (let ((map (make-sparse-keymap)))
70 (define-key map
"\r" 'cua-rotate-rectangle
)))
72 (defvar cua--virtual-edges-debug nil
)
74 ;; Undo rectangle commands.
76 (defvar cua--rect-undo-set-point nil
)
78 (defun cua--rectangle-undo-boundary ()
79 (when (listp buffer-undo-list
)
80 (let ((s (cua--rect-start-position))
81 (e (cua--rect-end-position)))
83 (push (list 'apply
0 s e
84 'cua--rect-undo-handler
85 (copy-sequence cua--rectangle
) t s e
)
88 (defun cua--rect-undo-handler (rect on s e
)
89 (if (setq on
(not on
))
90 (setq cua--rect-undo-set-point s
)
91 (setq cua--restored-rectangle
(copy-sequence rect
))
92 (setq cua--buffer-and-point-before-command nil
))
93 (push (list 'apply
0 s
(if on e s
)
94 'cua--rect-undo-handler rect on s e
)
97 ;;; Rectangle geometry
99 (defun cua--rectangle-top (&optional val
)
100 ;; Top of CUA rectangle (buffer position on first line).
102 (aref cua--rectangle
0)
103 (setq val
(line-beginning-position))
104 (if (<= val
(aref cua--rectangle
1))
105 (aset cua--rectangle
0 val
)
106 (aset cua--rectangle
1 val
)
107 (cua--rectangle-corner 2))))
109 (defun cua--rectangle-bot (&optional val
)
110 ;; Bot of CUA rectangle (buffer position on last line).
112 (aref cua--rectangle
1)
113 (setq val
(line-end-position))
114 (if (>= val
(aref cua--rectangle
0))
115 (aset cua--rectangle
1 val
)
116 (aset cua--rectangle
0 val
)
117 (cua--rectangle-corner 2))))
119 (defun cua--rectangle-left (&optional val
)
120 ;; Left column of CUA rectangle.
122 (if (<= val
(aref cua--rectangle
3))
123 (aset cua--rectangle
2 val
)
124 (aset cua--rectangle
3 val
)
125 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
126 (aref cua--rectangle
2)))
128 (defun cua--rectangle-right (&optional val
)
129 ;; Right column of CUA rectangle.
131 (if (>= val
(aref cua--rectangle
2))
132 (aset cua--rectangle
3 val
)
133 (aset cua--rectangle
2 val
)
134 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
135 (aref cua--rectangle
3)))
137 (defun cua--rectangle-corner (&optional advance
)
138 ;; Currently active corner of rectangle.
139 (let ((c (aref cua--rectangle
4)))
140 (if (not (integerp advance
))
142 (aset cua--rectangle
4
144 (- 3 c
) ; opposite corner
145 (mod (+ c
4 advance
) 4)))
146 (aset cua--rectangle
5 0))))
148 (defun cua--rectangle-right-side (&optional topbot
)
149 ;; t if point is on right side of rectangle.
150 (if (and topbot
(= (cua--rectangle-left) (cua--rectangle-right)))
151 (< (cua--rectangle-corner) 2)
152 (= (mod (cua--rectangle-corner) 2) 1)))
154 (defun cua--rectangle-column ()
155 (if (cua--rectangle-right-side)
156 (cua--rectangle-right)
157 (cua--rectangle-left)))
159 (defun cua--rectangle-insert-col (&optional col
)
160 ;; Currently active corner of rectangle.
162 (aset cua--rectangle
5 col
)
163 (if (cua--rectangle-right-side t
)
164 (if (= (aref cua--rectangle
5) 0)
165 (1+ (cua--rectangle-right))
166 (aref cua--rectangle
5))
167 (cua--rectangle-left))))
169 (defun cua--rectangle-virtual-edges (&optional set val
)
170 ;; Current setting of rectangle virtual-edges
172 (aset cua--rectangle
6 val
))
173 (and ;(not buffer-read-only)
174 (aref cua--rectangle
6)))
176 (defun cua--rectangle-restriction (&optional val bounded negated
)
177 ;; Current rectangle restriction
179 (aset cua--rectangle
7
182 (list val bounded negated
)))
183 (aref cua--rectangle
7)))
185 (defun cua--rectangle-assert ()
186 (message "%S (%d)" cua--rectangle
(point))
187 (if (< (cua--rectangle-right) (cua--rectangle-left))
188 (message "rectangle right < left"))
189 (if (< (cua--rectangle-bot) (cua--rectangle-top))
190 (message "rectangle bot < top")))
192 (defun cua--rectangle-get-corners ()
193 ;; Calculate the rectangular region represented by point and mark,
194 ;; putting start in the upper left corner and end in the
195 ;; bottom right corner.
196 (let ((top (point)) (bot (mark)) r l corner
)
199 (setq l
(current-column))
201 (setq r
(current-column))
203 (setq corner
(if (<= l r
) 0 1))
204 (setq top
(prog1 bot
(setq bot top
)))
205 (setq corner
(if (<= l r
) 2 3)))
209 (setq l
(prog1 r
(setq r l
)))
216 (vector top bot l r corner
0 cua-virtual-rectangle-edges nil
)))
218 (defun cua--rectangle-set-corners ()
219 ;; Set mark and point in opposite corners of current rectangle.
220 (let (pp pc mp mc
(c (cua--rectangle-corner)))
222 ((= c
0) ; top/left -> bot/right
223 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-left)
224 mp
(cua--rectangle-bot) mc
(cua--rectangle-right)))
225 ((= c
1) ; top/right -> bot/left
226 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-right)
227 mp
(cua--rectangle-bot) mc
(cua--rectangle-left)))
228 ((= c
2) ; bot/left -> top/right
229 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-left)
230 mp
(cua--rectangle-top) mc
(cua--rectangle-right)))
231 ((= c
3) ; bot/right -> top/left
232 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-right)
233 mp
(cua--rectangle-top) mc
(cua--rectangle-left))))
238 ;; Move cursor inside rectangle, except if char at rigth edge is a tab.
239 (if (and (if (cua--rectangle-right-side)
240 (and (= (move-to-column pc
) (- pc tab-width
))
242 (> (move-to-column pc
) pc
))
247 (defun cua--rect-start-position ()
248 ;; Return point of top left corner
250 (goto-char (cua--rectangle-top))
251 (and (> (move-to-column (cua--rectangle-left))
252 (cua--rectangle-left))
257 (defun cua--rect-end-position ()
258 ;; Return point of bottom right cornet
260 (goto-char (cua--rectangle-bot))
261 (and (= (move-to-column (cua--rectangle-right))
262 (- (cua--rectangle-right) tab-width
))
268 ;;; Rectangle resizing
270 (defun cua--forward-line (n)
271 ;; Move forward/backward one line. Returns t if movement.
273 (and (= (forward-line n
) 0)
274 ;; Deal with end of buffer
278 (defun cua--rectangle-resized ()
279 ;; Refresh state after resizing rectangle
280 (setq cua--buffer-and-point-before-command nil
)
281 (cua--rectangle-insert-col 0)
282 (cua--rectangle-set-corners)
285 (defun cua-resize-rectangle-right (n)
286 "Resize rectangle to the right."
288 (let ((resized (> n
0)))
292 ((cua--rectangle-right-side)
293 (cua--rectangle-right (1+ (cua--rectangle-right)))
294 (move-to-column (cua--rectangle-right)))
296 (cua--rectangle-left (1+ (cua--rectangle-left)))
297 (move-to-column (cua--rectangle-right)))))
299 (cua--rectangle-resized))))
301 (defun cua-resize-rectangle-left (n)
302 "Resize rectangle to the left."
307 (if (or (= (cua--rectangle-right) 0)
308 (and (not (cua--rectangle-right-side)) (= (cua--rectangle-left) 0)))
311 ((cua--rectangle-right-side)
312 (cua--rectangle-right (1- (cua--rectangle-right)))
313 (move-to-column (cua--rectangle-right)))
315 (cua--rectangle-left (1- (cua--rectangle-left)))
316 (move-to-column (cua--rectangle-right))))
319 (cua--rectangle-resized))))
321 (defun cua-resize-rectangle-down (n)
322 "Resize rectangle downwards."
328 ((>= (cua--rectangle-corner) 2)
329 (goto-char (cua--rectangle-bot))
330 (when (cua--forward-line 1)
331 (move-to-column (cua--rectangle-column))
332 (cua--rectangle-bot t
)
335 (goto-char (cua--rectangle-top))
336 (when (cua--forward-line 1)
337 (move-to-column (cua--rectangle-column))
338 (cua--rectangle-top t
)
341 (cua--rectangle-resized))))
343 (defun cua-resize-rectangle-up (n)
344 "Resize rectangle upwards."
350 ((>= (cua--rectangle-corner) 2)
351 (goto-char (cua--rectangle-bot))
352 (when (cua--forward-line -
1)
353 (move-to-column (cua--rectangle-column))
354 (cua--rectangle-bot t
)
357 (goto-char (cua--rectangle-top))
358 (when (cua--forward-line -
1)
359 (move-to-column (cua--rectangle-column))
360 (cua--rectangle-top t
)
363 (cua--rectangle-resized))))
365 (defun cua-resize-rectangle-eol ()
366 "Resize rectangle to end of line."
370 (if (> (current-column) (cua--rectangle-right))
371 (cua--rectangle-right (current-column)))
372 (if (not (cua--rectangle-right-side))
373 (cua--rectangle-corner 1))
374 (cua--rectangle-resized)))
376 (defun cua-resize-rectangle-bol ()
377 "Resize rectangle to beginning of line."
381 (cua--rectangle-left (current-column))
382 (if (cua--rectangle-right-side)
383 (cua--rectangle-corner -
1))
384 (cua--rectangle-resized)))
386 (defun cua-resize-rectangle-bot ()
387 "Resize rectangle to bottom of buffer."
389 (goto-char (point-max))
390 (move-to-column (cua--rectangle-column))
391 (cua--rectangle-bot t
)
392 (cua--rectangle-resized))
394 (defun cua-resize-rectangle-top ()
395 "Resize rectangle to top of buffer."
397 (goto-char (point-min))
398 (move-to-column (cua--rectangle-column))
399 (cua--rectangle-top t
)
400 (cua--rectangle-resized))
402 (defun cua-resize-rectangle-page-up ()
403 "Resize rectangle upwards by one scroll page."
406 (move-to-column (cua--rectangle-column))
407 (if (>= (cua--rectangle-corner) 2)
408 (cua--rectangle-bot t
)
409 (cua--rectangle-top t
))
410 (cua--rectangle-resized))
412 (defun cua-resize-rectangle-page-down ()
413 "Resize rectangle downwards by one scroll page."
416 (move-to-column (cua--rectangle-column))
417 (if (>= (cua--rectangle-corner) 2)
418 (cua--rectangle-bot t
)
419 (cua--rectangle-top t
))
420 (cua--rectangle-resized))
424 ;; This is pretty simplistic, but it does the job...
426 (defun cua-mouse-resize-rectangle (event)
427 "Set rectangle corner at mouse click position."
429 (mouse-set-point event
)
430 ;; FIX ME -- need to calculate virtual column.
431 (if (cua--rectangle-virtual-edges)
432 (move-to-column (car (posn-col-row (event-end event
))) t
))
433 (if (cua--rectangle-right-side)
434 (cua--rectangle-right (current-column))
435 (cua--rectangle-left (current-column)))
436 (if (>= (cua--rectangle-corner) 2)
437 (cua--rectangle-bot t
)
438 (cua--rectangle-top t
))
439 (cua--rectangle-resized))
441 (defvar cua--mouse-last-pos nil
)
443 (defun cua-mouse-set-rectangle-mark (event)
444 "Start rectangle at mouse click position."
447 (cua--deactivate-rectangle)
449 (setq cua--last-rectangle nil
)
450 (mouse-set-point event
)
451 ;; FIX ME -- need to calculate virtual column.
452 (cua-set-rectangle-mark)
453 (setq cua--buffer-and-point-before-command nil
)
454 (setq cua--mouse-last-pos nil
))
456 (defun cua-mouse-save-then-kill-rectangle (event arg
)
457 "Expand rectangle to mouse click position and copy rectangle.
458 If command is repeated at same position, delete the rectangle."
460 (if (and (eq this-command last-command
)
461 (eq (point) (car-safe cua--mouse-last-pos
))
462 (eq cua--last-killed-rectangle
(cdr-safe cua--mouse-last-pos
)))
464 (unless buffer-read-only
465 (cua--delete-rectangle))
467 (cua-mouse-resize-rectangle event
)
468 (let ((cua-keep-region-after-copy t
))
469 (cua-copy-rectangle arg
)
470 (setq cua--mouse-last-pos
(cons (point) cua--last-killed-rectangle
)))))
472 (defun cua--mouse-ignore (event)
474 (setq this-command last-command
))
476 (defun cua--rectangle-move (dir)
478 (top (cua--rectangle-top))
479 (bot (cua--rectangle-bot))
480 (l (cua--rectangle-left))
481 (r (cua--rectangle-right)))
485 (when (cua--forward-line -
1)
486 (cua--rectangle-top t
)
489 (cua--rectangle-bot t
)))
492 (when (cua--forward-line 1)
493 (cua--rectangle-bot t
)
495 (cua--forward-line 1)
496 (cua--rectangle-top t
)))
499 (cua--rectangle-left (1- l
))
500 (cua--rectangle-right (1- r
))))
502 (cua--rectangle-right (1+ r
))
503 (cua--rectangle-left (1+ l
)))
507 (setq cua--buffer-and-point-before-command nil
)
508 (cua--rectangle-set-corners)
509 (cua--keep-active))))
512 ;;; Operations on current rectangle
514 (defun cua--tabify-start (start end
)
515 ;; Return position where auto-tabify should start (or nil if not required).
519 (and (not buffer-read-only
)
520 cua-auto-tabify-rectangles
521 (if (or (not (integerp cua-auto-tabify-rectangles
))
522 (= (point-min) (point-max))
524 (goto-char (max (point-min)
525 (- start cua-auto-tabify-rectangles
)))
526 (search-forward "\t" (min (point-max)
527 (+ end cua-auto-tabify-rectangles
)) t
)))
530 (defun cua--rectangle-operation (keep-clear visible undo pad tabify
&optional fct post-fct
)
531 ;; Call FCT for each line of region with 4 parameters:
532 ;; Region start, end, left-col, right-col
533 ;; Point is at start when FCT is called
534 ;; Call fct with (s,e) = whole lines if VISIBLE non-nil.
535 ;; Only call fct for visible lines if VISIBLE==t.
536 ;; Set undo boundary if UNDO is non-nil.
537 ;; Rectangle is padded if PAD = t or numeric and (cua--rectangle-virtual-edges)
538 ;; Perform auto-tabify after operation if TABIFY is non-nil.
539 ;; Mark is kept if keep-clear is 'keep and cleared if keep-clear is 'clear.
540 (let* ((inhibit-field-text-motion t
)
541 (start (cua--rectangle-top))
542 (end (cua--rectangle-bot))
543 (l (cua--rectangle-left))
544 (r (1+ (cua--rectangle-right)))
546 (tabpad (and (integerp pad
) (= pad
2)))
547 (sel (cua--rectangle-restriction))
548 (tabify-start (and tabify
(cua--tabify-start start end
))))
550 (cua--rectangle-undo-boundary))
552 (setq pad
(cua--rectangle-virtual-edges)))
556 (when (> (cua--rectangle-corner) 1)
558 (and (bolp) (not (eolp)) (not (eobp))
559 (setq end
(1+ end
))))
561 (setq start
(max (window-start) start
))
562 (setq end
(min (window-end) end
)))
564 (setq end
(line-end-position))
565 (if (and visible
(bolp) (not (eobp)))
568 (setq start
(line-beginning-position))
569 (narrow-to-region start end
)
570 (goto-char (point-min))
571 (while (< (point) (point-max))
572 (move-to-column r pad
)
573 (and (not pad
) (not visible
) (> (current-column) r
)
575 (if (and tabpad
(not pad
) (looking-at "\t"))
577 (set-marker m
(point))
578 (move-to-column l pad
)
579 (if (and fct
(or visible
(and (>= (current-column) l
) (<= (current-column) r
))))
580 (let ((v t
) (p (point)))
583 (setq v
(looking-at (car sel
)))
584 (setq v
(re-search-forward (car sel
) m t
))
586 (if (car (cdr (cdr sel
)))
589 (funcall fct p m l r v
)
591 (funcall fct p m l r
)))))
595 (cua--rectangle-bot t
))
597 (funcall post-fct l r
))
599 (tabify tabify-start
(point)))))
601 ((eq keep-clear
'keep
)
603 ((eq keep-clear
'clear
)
605 ((eq keep-clear
'corners
)
606 (cua--rectangle-set-corners)
608 (setq cua--buffer-and-point-before-command nil
)))
610 (put 'cua--rectangle-operation
'lisp-indent-function
4)
612 (defun cua--delete-rectangle ()
614 (if (not (cua--rectangle-virtual-edges))
615 (cua--rectangle-operation nil nil t
2 t
617 (setq lines
(1+ lines
))
618 (if (and (> e s
) (<= e
(point-max)))
619 (delete-region s e
))))
620 (cua--rectangle-operation nil
1 t nil t
622 (setq lines
(1+ lines
))
623 (when (and (> e s
) (<= e
(point-max)))
624 (delete-region s e
)))))
627 (defun cua--extract-rectangle ()
629 (if (not (cua--rectangle-virtual-edges))
630 (cua--rectangle-operation nil nil nil nil nil
; do not tabify
632 (setq rect
(cons (buffer-substring-no-properties s e
) rect
))))
633 (cua--rectangle-operation nil
1 nil nil nil
; do not tabify
635 (let ((copy t
) (bs 0) (as 0) row
)
636 (if (= s e
) (setq e
(1+ e
)))
639 (if (= (point) (line-end-position))
642 (skip-chars-forward "\s\t" e
)
643 (setq bs
(- (min r
(current-column)) l
)
646 (skip-chars-backward "\s\t" s
)
647 (setq as
(- r
(max (current-column) l
))
649 (setq row
(if (and copy
(> e s
))
650 (buffer-substring-no-properties s e
)
653 (setq row
(concat (make-string bs ?\s
) row
)))
655 (setq row
(concat row
(make-string as ?\s
))))
656 (setq rect
(cons row rect
))))))
659 (defun cua--insert-rectangle (rect &optional below paste-column line-count
)
660 ;; Insert rectangle as insert-rectangle, but don't set mark and exit with
661 ;; point at either next to top right or below bottom left corner
662 ;; Notice: In overwrite mode, the rectangle is inserted as separate text lines.
664 (setq below
(and (bolp)
665 (or (eolp) (eobp) (= (1+ (point)) (point-max))))))
667 (setq paste-column
(current-column)))
670 (tabify-start (cua--tabify-start (point) (point)))
673 (while (or lines below
)
678 (or (bolp) (insert ?
\n))))
679 (unless overwrite-mode
680 (move-to-column paste-column t
))
683 (insert-for-yank (car lines
))
685 (setq last-column
(current-column)))
686 (setq lines
(cdr lines
))
687 (and first
(not below
)
690 (if (and line-count
(= (setq line-count
(1- line-count
)) 0))
692 (when (and line-count last-column
(not overwrite-mode
))
693 (while (> line-count
0)
695 (or (bolp) (insert ?
\n))
696 (move-to-column paste-column t
)
697 (insert-char ?\s
(- last-column paste-column -
1))
698 (setq line-count
(1- line-count
))))
699 (when (and tabify-start
700 (not overwrite-mode
))
701 (tabify tabify-start
(point)))
702 (and p
(not overwrite-mode
)
705 (defun cua--copy-rectangle-as-kill (&optional ring
)
707 (set-register cua--register
(cua--extract-rectangle))
708 (setq killed-rectangle
(cua--extract-rectangle))
709 (setq cua--last-killed-rectangle
(cons (and kill-ring
(car kill-ring
)) killed-rectangle
))
712 (function (lambda (row) (concat row
"\n")))
713 killed-rectangle
"")))))
715 (defun cua--activate-rectangle ()
716 ;; Turn on rectangular marking mode by disabling transient mark mode
717 ;; and manually handling highlighting from a post command hook.
718 ;; Be careful if we are already marking a rectangle.
720 (if (and cua--last-rectangle
721 (eq (car cua--last-rectangle
) (current-buffer))
722 (eq (car (cdr cua--last-rectangle
)) (point)))
723 (cdr (cdr cua--last-rectangle
))
724 (cua--rectangle-get-corners))
725 cua--status-string
(if (cua--rectangle-virtual-edges) " [R]" "")
726 cua--last-rectangle nil
))
728 ;; (defvar cua-save-point nil)
730 (defun cua--deactivate-rectangle ()
731 ;; This is used to clean up after `cua--activate-rectangle'.
732 (mapcar (function delete-overlay
) cua--rectangle-overlays
)
733 (setq cua--last-rectangle
(cons (current-buffer)
734 (cons (point) ;; cua-save-point
737 cua--rectangle-overlays nil
738 cua--status-string nil
739 cua--mouse-last-pos nil
))
741 (defun cua--highlight-rectangle ()
742 ;; This function is used to highlight the rectangular region.
743 ;; We do this by putting an overlay on each line within the rectangle.
744 ;; Each overlay extends across all the columns of the rectangle.
745 ;; We try to reuse overlays where possible because this is more efficient
746 ;; and results in less flicker.
747 ;; If cua--rectangle-virtual-edges is nil and the buffer contains tabs or short lines,
748 ;; the higlighted region may not be perfectly rectangular.
749 (let ((deactivate-mark deactivate-mark
)
750 (old cua--rectangle-overlays
)
752 (left (cua--rectangle-left))
753 (right (1+ (cua--rectangle-right))))
754 (when (/= left right
)
755 (sit-for 0) ; make window top/bottom reliable
756 (cua--rectangle-operation nil t nil nil nil
; do not tabify
758 (let ((rface (if v
'cua-rectangle-face
'cua-rectangle-noselect-face
))
760 (when (cua--rectangle-virtual-edges)
761 (let ((lb (line-beginning-position))
762 (le (line-end-position))
765 (setq cl
(move-to-column l
)
767 (setq cr
(move-to-column r
)
772 (setq cl0
(current-column)))
776 (setq cr0
(current-column)))
777 (unless (and (= cl l
) (= cr r
))
781 (- l cl0
(if (and (= le pl
) (/= le lb
)) 1 0))
782 (if cua--virtual-edges-debug ?. ?\s
))
790 (or bs
(/= cr0
(- cr tab-width
)))
791 (/= (mod cr tab-width
) 0))
797 (if cua--virtual-edges-debug ?
, ?\s
))
799 (if (cua--rectangle-right-side)
800 (put-text-property (1- (length ms
)) (length ms
) 'cursor t ms
)
801 (put-text-property 0 1 'cursor t ms
))
802 (setq bs
(concat bs ms
))
807 (- r cr0
(if (= le pr
) 1 0))
808 (if cua--virtual-edges-debug ?~ ?\s
))
810 (if (cua--rectangle-right-side)
811 (put-text-property (1- (length as
)) (length as
) 'cursor t as
)
812 (put-text-property 0 1 'cursor t as
))
814 (setq e
(1- e
))))))))
815 ;; Trim old leading overlays.
817 (setq overlay
(car old
))
818 (< (overlay-start overlay
) s
)
819 (/= (overlay-end overlay
) e
))
820 (delete-overlay overlay
)
821 (setq old
(cdr old
)))
822 ;; Reuse an overlay if possible, otherwise create one.
824 (setq overlay
(car old
))
825 (or (= (overlay-start overlay
) s
)
826 (= (overlay-end overlay
) e
)))
828 (move-overlay overlay s e
)
829 (setq old
(cdr old
)))
830 (setq overlay
(make-overlay s e
)))
831 (overlay-put overlay
'before-string bs
)
832 (overlay-put overlay
'after-string as
)
833 (overlay-put overlay
'face rface
)
834 (overlay-put overlay
'keymap cua--overlay-keymap
)
835 (setq new
(cons overlay new
))))))
836 ;; Trim old trailing overlays.
837 (mapcar (function delete-overlay
) old
)
838 (setq cua--rectangle-overlays
(nreverse new
))))
840 (defun cua--indent-rectangle (&optional ch to-col clear
)
841 ;; Indent current rectangle.
842 (let ((col (cua--rectangle-insert-col))
843 (pad (cua--rectangle-virtual-edges))
845 (cua--rectangle-operation (if clear
'clear
'corners
) nil t pad nil
847 (move-to-column col pad
)
849 (< (current-column) col
))
850 (move-to-column col t
))
852 (to-col (indent-to to-col
))
854 (t (tab-to-tab-stop)))
855 (if (cua--rectangle-right-side t
)
856 (cua--rectangle-insert-col (current-column))
857 (setq indent
(- (current-column) l
))))
859 (when (and indent
(> indent
0))
860 (aset cua--rectangle
2 (+ l indent
))
861 (aset cua--rectangle
3 (+ r indent -
1)))))))
864 ;; rectangle functions / actions
867 (defvar cua--rectangle-initialized nil
)
869 (defun cua-set-rectangle-mark (&optional reopen
)
870 "Set mark and start in CUA rectangle mode.
871 With prefix argument, activate previous rectangle if possible."
873 (unless cua--rectangle-initialized
874 (cua--init-rectangles))
875 (when (not cua--rectangle
)
878 (eq (car cua--last-rectangle
) (current-buffer)))
879 (goto-char (car (cdr cua--last-rectangle
)))
880 (if (not mark-active
)
881 (push-mark nil nil t
)))
882 (cua--activate-rectangle)
883 (cua--rectangle-set-corners)
885 cua--explicit-region-start t
)
886 (if cua-enable-rectangle-auto-help
887 (cua-help-for-rectangle t
))))
889 (defun cua-clear-rectangle-mark ()
890 "Cancel current rectangle."
893 (setq mark-active nil
894 cua--explicit-region-start nil
)
895 (cua--deactivate-rectangle)))
897 (defun cua-toggle-rectangle-mark ()
900 (cua--deactivate-rectangle)
901 (unless cua--rectangle-initialized
902 (cua--init-rectangles))
903 (cua--activate-rectangle))
905 (if cua-enable-rectangle-auto-help
906 (cua-help-for-rectangle t
))
907 (if cua-enable-region-auto-help
908 (cua-help-for-region t
))))
910 (defun cua-restrict-regexp-rectangle (arg)
911 "Restrict rectangle to lines (not) matching REGEXP.
912 With prefix argument, the toggle restriction."
914 (let ((r (cua--rectangle-restriction)) regexp
)
915 (if (and r
(null (car (cdr r
))))
917 (cua--rectangle-restriction (car r
) nil
(not (car (cdr (cdr r
)))))
918 (cua--rectangle-restriction "" nil nil
))
919 (cua--rectangle-restriction
920 (read-from-minibuffer "Restrict rectangle (regexp): "
921 nil nil nil nil
) nil arg
))))
923 (defun cua-restrict-prefix-rectangle (arg)
924 "Restrict rectangle to lines (not) starting with CHAR.
925 With prefix argument, the toggle restriction."
927 (let ((r (cua--rectangle-restriction)) regexp
)
928 (if (and r
(car (cdr r
)))
930 (cua--rectangle-restriction (car r
) t
(not (car (cdr (cdr r
)))))
931 (cua--rectangle-restriction "" nil nil
))
932 (cua--rectangle-restriction
934 (read-char "Restrictive rectangle (char): ")) t arg
))))
936 (defun cua-move-rectangle-up ()
938 (cua--rectangle-move 'up
))
940 (defun cua-move-rectangle-down ()
942 (cua--rectangle-move 'down
))
944 (defun cua-move-rectangle-left ()
946 (cua--rectangle-move 'left
))
948 (defun cua-move-rectangle-right ()
950 (cua--rectangle-move 'right
))
952 (defun cua-copy-rectangle (arg)
954 (setq arg
(cua--prefix-arg arg
))
955 (cua--copy-rectangle-as-kill arg
)
956 (if cua-keep-region-after-copy
960 (defun cua-cut-rectangle (arg)
963 (cua-copy-rectangle arg
)
964 (setq arg
(cua--prefix-arg arg
))
965 (goto-char (min (mark) (point)))
966 (cua--copy-rectangle-as-kill arg
)
967 (cua--delete-rectangle))
970 (defun cua-delete-rectangle ()
972 (goto-char (min (point) (mark)))
973 (if cua-delete-copy-to-register-0
974 (set-register ?
0 (cua--extract-rectangle)))
975 (cua--delete-rectangle)
978 (defun cua-rotate-rectangle ()
980 (cua--rectangle-corner (if (= (cua--rectangle-left) (cua--rectangle-right)) 0 1))
981 (cua--rectangle-set-corners)
982 (if (cua--rectangle-virtual-edges)
983 (setq cua--buffer-and-point-before-command nil
)))
985 (defun cua-toggle-rectangle-virtual-edges ()
987 (cua--rectangle-virtual-edges t
(not (cua--rectangle-virtual-edges)))
988 (cua--rectangle-set-corners)
989 (setq cua--status-string
(and (cua--rectangle-virtual-edges) " [R]"))
992 (defun cua-do-rectangle-padding ()
995 (message "Cannot do padding in read-only buffer.")
996 (cua--rectangle-operation nil nil t t t
)
997 (cua--rectangle-set-corners))
1000 (defun cua-open-rectangle ()
1001 "Blank out CUA rectangle, shifting text right.
1002 The text previously in the region is not overwritten by the blanks,
1003 but instead winds up to the right of the rectangle."
1005 (cua--rectangle-operation 'corners nil t
1 nil
1007 (skip-chars-forward " \t")
1008 (let ((ws (- (current-column) l
))
1010 (skip-chars-backward " \t")
1011 (delete-region (point) p
)
1012 (indent-to (+ r ws
))))))
1014 (defun cua-close-rectangle (arg)
1015 "Delete all whitespace starting at left edge of CUA rectangle.
1016 On each line in the rectangle, all continuous whitespace starting
1017 at that column is deleted.
1018 With prefix arg, also delete whitespace to the left of that column."
1020 (cua--rectangle-operation 'clear nil t
1 nil
1023 (skip-syntax-backward " " (line-beginning-position))
1025 (skip-syntax-forward " " (line-end-position))
1026 (delete-region s
(point)))))
1028 (defun cua-blank-rectangle ()
1029 "Blank out CUA rectangle.
1030 The text previously in the rectangle is overwritten by the blanks."
1032 (cua--rectangle-operation 'keep nil nil
1 nil
1035 (skip-syntax-forward " " (line-end-position))
1037 (let ((column (current-column)))
1039 (skip-syntax-backward " " (line-beginning-position))
1040 (delete-region (point) e
)
1041 (indent-to column
)))))
1043 (defun cua-align-rectangle ()
1044 "Align rectangle lines to left column."
1047 (cua--rectangle-operation 'clear nil t t nil
1049 (let ((b (line-beginning-position)))
1050 (skip-syntax-backward "^ " b
)
1051 (skip-syntax-backward " " b
)
1053 (skip-syntax-forward " " (line-end-position))
1054 (delete-region s
(point))
1058 ;; (setq cua-save-point (point))
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 (ch)
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 ch
(- 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 (buffer-substring-no-properties (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 (buffer-substring-no-properties (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 fmt
)
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 fmt
) 0)
1154 (setq fmt cua--rectangle-seq-format
)
1155 (setq cua--rectangle-seq-format fmt
))
1156 (cua--rectangle-operation 'clear nil t
1 nil
1159 (insert (format fmt 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)))
1206 (cua--insert-rectangle r
))
1208 (let ((fill-column w
))
1209 (funcall format-fct
(point-min) (point-max))))
1211 (goto-char (point-min))
1213 (setq z
(cons (buffer-substring (point) (line-end-position)) z
))
1215 (if (not cua--debug
)
1216 (kill-buffer auxbuf
))
1218 (setq z
(reverse z
))
1221 (cua--rectangle-operation nil nil t pad nil
1225 (skip-chars-forward " \t")
1226 (setq cc
(current-column))
1228 (print (list cc s e
) auxbuf
))
1229 (delete-region s
(point))
1232 (move-to-column l t
)
1234 (when (> (current-column) (+ l w
))
1236 (move-to-column (+ l w
) t
)
1237 (delete-region (point) y
)
1241 (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 (if cua-use-hyper-key
" H-" " M-")))
1360 (concat (if help
"C-?:help" "")
1361 M
"p:pad" M
"o:open" M
"c:close" M
"b:blank"
1362 M
"s:string" M
"f:fill" M
"i:incr" M
"n:seq"))))
1365 ;;; CUA-like cut & paste for rectangles
1367 (defun cua--cancel-rectangle ()
1370 (cua--deactivate-rectangle))
1371 (setq cua--last-rectangle nil
))
1373 (defun cua--rectangle-post-command ()
1374 (if cua--restored-rectangle
1376 (setq cua--rectangle cua--restored-rectangle
1377 cua--restored-rectangle nil
1379 deactivate-mark nil
)
1380 (cua--rectangle-set-corners))
1381 (when (and cua--rectangle cua--buffer-and-point-before-command
1382 (equal (car cua--buffer-and-point-before-command
) (current-buffer))
1383 (not (= (cdr cua--buffer-and-point-before-command
) (point))))
1384 (if (cua--rectangle-right-side)
1385 (cua--rectangle-right (current-column))
1386 (cua--rectangle-left (current-column)))
1387 (if (>= (cua--rectangle-corner) 2)
1388 (cua--rectangle-bot t
)
1389 (cua--rectangle-top t
))))
1391 (if (and mark-active
1392 (not deactivate-mark
))
1393 (cua--highlight-rectangle)
1394 (cua--deactivate-rectangle)))
1395 (when cua--rect-undo-set-point
1396 (goto-char cua--rect-undo-set-point
)
1397 (setq cua--rect-undo-set-point nil
)))
1401 (defun cua--rect-M/H-key
(key cmd
)
1402 (cua--M/H-key cua--rectangle-keymap key cmd
))
1404 (defun cua--init-rectangles ()
1405 (unless (face-background 'cua-rectangle-face
)
1406 (copy-face 'region
'cua-rectangle-face
)
1407 (set-face-background 'cua-rectangle-face
"maroon")
1408 (set-face-foreground 'cua-rectangle-face
"white"))
1410 (unless (face-background 'cua-rectangle-noselect-face
)
1411 (copy-face 'region
'cua-rectangle-noselect-face
)
1412 (set-face-background 'cua-rectangle-noselect-face
"dimgray")
1413 (set-face-foreground 'cua-rectangle-noselect-face
"white"))
1415 (unless (eq cua-use-hyper-key
'only
)
1416 (define-key cua--rectangle-keymap
[(shift return
)] 'cua-clear-rectangle-mark
)
1417 (define-key cua--region-keymap
[(shift return
)] 'cua-toggle-rectangle-mark
))
1418 (when cua-use-hyper-key
1419 (cua--rect-M/H-key
'space
'cua-clear-rectangle-mark
)
1420 (cua--M/H-key cua--region-keymap
'space
'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))
1493 ;;; arch-tag: b730df53-17b9-4a89-bd63-4a71ec196731
1494 ;;; cua-rect.el ends here