1 ;;; cua-rect.el --- CUA unified rectangle support
3 ;; Copyright (C) 1997-2018 Free Software Foundation, Inc.
5 ;; Author: Kim F. Storm <storm@cua.dk>
6 ;; Keywords: keyboard emulations convenience CUA
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
26 ;; The rectangle handling and display code borrows from the standard
27 ;; GNU emacs rect.el package and the rect-mark.el package by Rick
28 ;; Sladkey <jrs@world.std.com>.
40 ;; If non-nil, restrict current region to this rectangle.
41 ;; Value is a vector [top bot left right corner ins virt select].
42 ;; CORNER specifies currently active corner 0=t/l 1=t/r 2=b/l 3=b/r.
43 ;; INS specifies whether to insert on left(nil) or right(t) side.
44 ;; If VIRT is non-nil, virtual straight edges are enabled.
45 ;; If SELECT is a regexp, only lines starting with that regexp are affected.")
46 (defvar cua--rectangle nil
)
47 (make-variable-buffer-local 'cua--rectangle
)
49 ;; Most recent rectangle geometry. Note: car is buffer.
50 (defvar cua--last-rectangle nil
)
52 ;; Rectangle restored by undo.
53 (defvar cua--restored-rectangle nil
)
55 ;; Last rectangle copied/killed; nil if last kill was not a rectangle.
56 (defvar cua--last-killed-rectangle nil
)
58 ;; List of overlays used to display current rectangle.
59 (defvar cua--rectangle-overlays nil
)
60 (make-variable-buffer-local 'cua--rectangle-overlays
)
61 (put 'cua--rectangle-overlays
'permanent-local t
)
63 (defvar cua--overlay-keymap
64 (let ((map (make-sparse-keymap)))
65 (define-key map
"\r" 'cua-rotate-rectangle
)))
67 (defvar cua--virtual-edges-debug nil
)
69 ;; Undo rectangle commands.
71 (defvar cua--rect-undo-set-point nil
)
73 (defun cua--rectangle-undo-boundary ()
74 (when (listp buffer-undo-list
)
75 (let ((s (cua--rect-start-position))
76 (e (cua--rect-end-position)))
78 (push (list 'apply
0 s e
79 'cua--rect-undo-handler
80 (copy-sequence cua--rectangle
) t s e
)
83 (defun cua--rect-undo-handler (rect on s e
)
84 (if (setq on
(not on
))
85 (setq cua--rect-undo-set-point s
)
86 (setq cua--restored-rectangle
(copy-sequence rect
))
87 (setq cua--buffer-and-point-before-command nil
))
88 (push (list 'apply
0 s
(if on e s
)
89 'cua--rect-undo-handler rect on s e
)
93 (define-minor-mode cua-rectangle-mark-mode
94 "Toggle the region as rectangular.
95 Activates the region if needed. Only lasts until the region is deactivated."
96 :keymap cua--rectangle-keymap
98 (cua-rectangle-mark-mode
99 (add-hook 'deactivate-mark-hook
100 (lambda () (cua-rectangle-mark-mode -
1)))
101 (add-hook 'post-command-hook
#'cua--rectangle-post-command nil t
)
102 (cua-set-rectangle-mark))
104 (cua--deactivate-rectangle)
105 (remove-hook 'post-command-hook
#'cua--rectangle-post-command t
))))
107 ;;; Rectangle geometry
109 (defun cua--rectangle-top (&optional val
)
110 ;; Top of CUA rectangle (buffer position on first line).
112 (aref cua--rectangle
0)
113 (setq val
(line-beginning-position))
114 (if (<= val
(aref cua--rectangle
1))
115 (aset cua--rectangle
0 val
)
116 (aset cua--rectangle
1 val
)
117 (cua--rectangle-corner 2))))
119 (defun cua--rectangle-bot (&optional val
)
120 ;; Bot of CUA rectangle (buffer position on last line).
122 (aref cua--rectangle
1)
123 (setq val
(line-end-position))
124 (if (>= val
(aref cua--rectangle
0))
125 (aset cua--rectangle
1 val
)
126 (aset cua--rectangle
0 val
)
127 (cua--rectangle-corner 2))))
129 (defun cua--rectangle-left (&optional val
)
130 ;; Left column of CUA rectangle.
132 (if (<= val
(aref cua--rectangle
3))
133 (aset cua--rectangle
2 val
)
134 (aset cua--rectangle
3 val
)
135 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
136 (aref cua--rectangle
2)))
138 (defun cua--rectangle-right (&optional val
)
139 ;; Right column of CUA rectangle.
141 (if (>= val
(aref cua--rectangle
2))
142 (aset cua--rectangle
3 val
)
143 (aset cua--rectangle
2 val
)
144 (cua--rectangle-corner (if (cua--rectangle-right-side) -
1 1)))
145 (aref cua--rectangle
3)))
147 (defun cua--rectangle-corner (&optional advance
)
148 ;; Currently active corner of rectangle.
149 (let ((c (aref cua--rectangle
4)))
150 (if (not (integerp advance
))
152 (aset cua--rectangle
4
154 (- 3 c
) ; opposite corner
155 (mod (+ c
4 advance
) 4)))
156 (aset cua--rectangle
5 0))))
158 (defun cua--rectangle-right-side (&optional topbot
)
159 ;; t if point is on right side of rectangle.
160 (if (and topbot
(= (cua--rectangle-left) (cua--rectangle-right)))
161 (< (cua--rectangle-corner) 2)
162 (= (mod (cua--rectangle-corner) 2) 1)))
164 (defun cua--rectangle-column ()
165 (if (cua--rectangle-right-side)
166 (cua--rectangle-right)
167 (cua--rectangle-left)))
169 (defun cua--rectangle-insert-col (&optional col
)
170 ;; Currently active corner of rectangle.
172 (aset cua--rectangle
5 col
)
173 (if (cua--rectangle-right-side t
)
174 (if (= (aref cua--rectangle
5) 0)
175 (1+ (cua--rectangle-right))
176 (aref cua--rectangle
5))
177 (cua--rectangle-left))))
179 (defun cua--rectangle-virtual-edges (&optional set val
)
180 ;; Current setting of rectangle virtual-edges
182 (aset cua--rectangle
6 val
))
183 (and ;(not buffer-read-only)
184 (aref cua--rectangle
6)))
186 (defun cua--rectangle-restriction (&optional val bounded negated
)
187 ;; Current rectangle restriction
189 (aset cua--rectangle
7
192 (list val bounded negated
)))
193 (aref cua--rectangle
7)))
195 (defun cua--rectangle-assert ()
196 (message "%S (%d)" cua--rectangle
(point))
197 (if (< (cua--rectangle-right) (cua--rectangle-left))
198 (message "rectangle right < left"))
199 (if (< (cua--rectangle-bot) (cua--rectangle-top))
200 (message "rectangle bot < top")))
202 (defun cua--rectangle-get-corners ()
203 ;; Calculate the rectangular region represented by point and mark,
204 ;; putting start in the upper left corner and end in the
205 ;; bottom right corner.
206 (let ((top (point)) (bot (mark)) r l corner
)
209 (setq l
(current-column))
211 (setq r
(current-column))
213 (setq corner
(if (<= l r
) 0 1))
214 (setq top
(prog1 bot
(setq bot top
)))
215 (setq corner
(if (<= l r
) 2 3)))
219 (setq l
(prog1 r
(setq r l
)))
226 (vector top bot l r corner
0 cua-virtual-rectangle-edges nil
)))
228 (defun cua--rectangle-set-corners ()
229 ;; Set mark and point in opposite corners of current rectangle.
230 (let (pp pc mp mc
(c (cua--rectangle-corner)))
232 ((= c
0) ; top/left -> bot/right
233 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-left)
234 mp
(cua--rectangle-bot) mc
(cua--rectangle-right)))
235 ((= c
1) ; top/right -> bot/left
236 (setq pp
(cua--rectangle-top) pc
(cua--rectangle-right)
237 mp
(cua--rectangle-bot) mc
(cua--rectangle-left)))
238 ((= c
2) ; bot/left -> top/right
239 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-left)
240 mp
(cua--rectangle-top) mc
(cua--rectangle-right)))
241 ((= c
3) ; bot/right -> top/left
242 (setq pp
(cua--rectangle-bot) pc
(cua--rectangle-right)
243 mp
(cua--rectangle-top) mc
(cua--rectangle-left))))
248 ;; Move cursor inside rectangle, except if char at right edge is a tab.
249 (if (and (if (cua--rectangle-right-side)
250 (and (= (move-to-column pc
) (- pc tab-width
))
252 (> (move-to-column pc
) pc
))
257 (defun cua--rect-start-position ()
258 ;; Return point of top left corner
260 (goto-char (cua--rectangle-top))
261 (and (> (move-to-column (cua--rectangle-left))
262 (cua--rectangle-left))
267 (defun cua--rect-end-position ()
268 ;; Return point of bottom right cornet
270 (goto-char (cua--rectangle-bot))
271 (and (= (move-to-column (cua--rectangle-right))
272 (- (cua--rectangle-right) tab-width
))
278 ;;; Rectangle resizing
280 (defun cua--forward-line (n)
281 ;; Move forward/backward one line. Returns t if movement.
283 (and (= (forward-line n
) 0)
284 ;; Deal with end of buffer
288 (defun cua--rectangle-resized ()
289 ;; Refresh state after resizing rectangle
290 (setq cua--buffer-and-point-before-command nil
)
291 (cua--rectangle-insert-col 0)
292 (cua--rectangle-set-corners)
295 (defun cua-resize-rectangle-right (n)
296 "Resize rectangle to the right."
298 (let ((resized (> n
0)))
302 ((cua--rectangle-right-side)
303 (cua--rectangle-right (1+ (cua--rectangle-right)))
304 (move-to-column (cua--rectangle-right)))
306 (cua--rectangle-left (1+ (cua--rectangle-left)))
307 (move-to-column (cua--rectangle-right)))))
309 (cua--rectangle-resized))))
311 (defun cua-resize-rectangle-left (n)
312 "Resize rectangle to the left."
317 (if (or (= (cua--rectangle-right) 0)
318 (and (not (cua--rectangle-right-side)) (= (cua--rectangle-left) 0)))
321 ((cua--rectangle-right-side)
322 (cua--rectangle-right (1- (cua--rectangle-right)))
323 (move-to-column (cua--rectangle-right)))
325 (cua--rectangle-left (1- (cua--rectangle-left)))
326 (move-to-column (cua--rectangle-right))))
329 (cua--rectangle-resized))))
331 (defun cua-resize-rectangle-down (n)
332 "Resize rectangle downwards."
338 ((>= (cua--rectangle-corner) 2)
339 (goto-char (cua--rectangle-bot))
340 (when (cua--forward-line 1)
341 (move-to-column (cua--rectangle-column))
342 (cua--rectangle-bot t
)
345 (goto-char (cua--rectangle-top))
346 (when (cua--forward-line 1)
347 (move-to-column (cua--rectangle-column))
348 (cua--rectangle-top t
)
351 (cua--rectangle-resized))))
353 (defun cua-resize-rectangle-up (n)
354 "Resize rectangle upwards."
360 ((>= (cua--rectangle-corner) 2)
361 (goto-char (cua--rectangle-bot))
362 (when (cua--forward-line -
1)
363 (move-to-column (cua--rectangle-column))
364 (cua--rectangle-bot t
)
367 (goto-char (cua--rectangle-top))
368 (when (cua--forward-line -
1)
369 (move-to-column (cua--rectangle-column))
370 (cua--rectangle-top t
)
373 (cua--rectangle-resized))))
375 (defun cua-resize-rectangle-eol ()
376 "Resize rectangle to end of line."
380 (if (> (current-column) (cua--rectangle-right))
381 (cua--rectangle-right (current-column)))
382 (if (not (cua--rectangle-right-side))
383 (cua--rectangle-corner 1))
384 (cua--rectangle-resized)))
386 (defun cua-resize-rectangle-bol ()
387 "Resize rectangle to beginning of line."
391 (cua--rectangle-left (current-column))
392 (if (cua--rectangle-right-side)
393 (cua--rectangle-corner -
1))
394 (cua--rectangle-resized)))
396 (defun cua-resize-rectangle-bot ()
397 "Resize rectangle to bottom of buffer."
399 (goto-char (point-max))
400 (move-to-column (cua--rectangle-column))
401 (cua--rectangle-bot t
)
402 (cua--rectangle-resized))
404 (defun cua-resize-rectangle-top ()
405 "Resize rectangle to top of buffer."
407 (goto-char (point-min))
408 (move-to-column (cua--rectangle-column))
409 (cua--rectangle-top t
)
410 (cua--rectangle-resized))
412 (defun cua-resize-rectangle-page-up ()
413 "Resize rectangle upwards 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))
422 (defun cua-resize-rectangle-page-down ()
423 "Resize rectangle downwards by one scroll page."
426 (move-to-column (cua--rectangle-column))
427 (if (>= (cua--rectangle-corner) 2)
428 (cua--rectangle-bot t
)
429 (cua--rectangle-top t
))
430 (cua--rectangle-resized))
434 ;; This is pretty simplistic, but it does the job...
436 (defun cua-mouse-resize-rectangle (event)
437 "Set rectangle corner at mouse click position."
439 (mouse-set-point event
)
440 ;; FIX ME -- need to calculate virtual column.
441 (if (cua--rectangle-virtual-edges)
442 (move-to-column (car (posn-col-row (event-end event
))) t
))
443 (if (cua--rectangle-right-side)
444 (cua--rectangle-right (current-column))
445 (cua--rectangle-left (current-column)))
446 (if (>= (cua--rectangle-corner) 2)
447 (cua--rectangle-bot t
)
448 (cua--rectangle-top t
))
449 (cua--rectangle-resized))
451 (defvar cua--mouse-last-pos nil
)
453 (defun cua-mouse-set-rectangle-mark (event)
454 "Start rectangle at mouse click position."
457 (cua--deactivate-rectangle)
459 (setq cua--last-rectangle nil
)
460 (mouse-set-point event
)
461 ;; FIX ME -- need to calculate virtual column.
462 (cua-set-rectangle-mark)
463 (setq cua--buffer-and-point-before-command nil
)
464 (setq cua--mouse-last-pos nil
))
466 (defun cua-mouse-save-then-kill-rectangle (event arg
)
467 "Expand rectangle to mouse click position and copy rectangle.
468 If command is repeated at same position, delete the rectangle."
470 (if (and (eq this-command last-command
)
471 (eq (point) (car-safe cua--mouse-last-pos
))
472 (eq cua--last-killed-rectangle
(cdr-safe cua--mouse-last-pos
)))
474 (unless buffer-read-only
475 (cua--delete-rectangle))
477 (cua-mouse-resize-rectangle event
)
478 (let ((cua-keep-region-after-copy t
))
479 (cua-copy-region arg
)
480 (setq cua--mouse-last-pos
(cons (point) cua--last-killed-rectangle
)))))
482 (defun cua--mouse-ignore (_event)
484 (setq this-command last-command
))
486 (defun cua--rectangle-move (dir)
488 (top (cua--rectangle-top))
489 (bot (cua--rectangle-bot))
490 (l (cua--rectangle-left))
491 (r (cua--rectangle-right)))
495 (when (cua--forward-line -
1)
496 (cua--rectangle-top t
)
499 (cua--rectangle-bot t
)))
502 (when (cua--forward-line 1)
503 (cua--rectangle-bot t
)
505 (cua--forward-line 1)
506 (cua--rectangle-top t
)))
509 (cua--rectangle-left (1- l
))
510 (cua--rectangle-right (1- r
))))
512 (cua--rectangle-right (1+ r
))
513 (cua--rectangle-left (1+ l
)))
517 (setq cua--buffer-and-point-before-command nil
)
518 (cua--rectangle-set-corners)
519 (cua--keep-active))))
522 ;;; Operations on current rectangle
524 (defun cua--tabify-start (start end
)
525 ;; Return position where auto-tabify should start (or nil if not required).
529 (and (not buffer-read-only
)
530 cua-auto-tabify-rectangles
531 (if (or (not (integerp cua-auto-tabify-rectangles
))
532 (= (point-min) (point-max))
534 (goto-char (max (point-min)
535 (- start cua-auto-tabify-rectangles
)))
536 (search-forward "\t" (min (point-max)
537 (+ end cua-auto-tabify-rectangles
)) t
)))
540 (defun cua--rectangle-operation (keep-clear visible undo pad tabify
&optional fct post-fct
)
541 ;; Call FCT for each line of region with 4 parameters:
542 ;; Region start, end, left-col, right-col
543 ;; Point is at start when FCT is called
544 ;; Call fct with (s,e) = whole lines if VISIBLE non-nil.
545 ;; Only call fct for visible lines if VISIBLE==t.
546 ;; Set undo boundary if UNDO is non-nil.
547 ;; Rectangle is padded if PAD = t or numeric and (cua--rectangle-virtual-edges)
548 ;; Perform auto-tabify after operation if TABIFY is non-nil.
549 ;; Mark is kept if keep-clear is 'keep and cleared if keep-clear is 'clear.
550 (let* ((inhibit-field-text-motion t
)
551 (start (cua--rectangle-top))
552 (end (cua--rectangle-bot))
553 (l (cua--rectangle-left))
554 (r (1+ (cua--rectangle-right)))
556 (tabpad (and (integerp pad
) (= pad
2)))
557 (sel (cua--rectangle-restriction))
558 (tabify-start (and tabify
(cua--tabify-start start end
))))
560 (cua--rectangle-undo-boundary))
562 (setq pad
(cua--rectangle-virtual-edges)))
566 (when (> (cua--rectangle-corner) 1)
568 (and (bolp) (not (eolp)) (not (eobp))
569 (setq end
(1+ end
))))
571 (setq start
(max (window-start) start
))
572 (setq end
(min (window-end) end
)))
574 (setq end
(line-end-position))
575 (if (and visible
(bolp) (not (eobp)))
578 (setq start
(line-beginning-position))
579 (narrow-to-region start end
)
580 (goto-char (point-min))
581 (while (< (point) (point-max))
582 (move-to-column r pad
)
583 (and (not pad
) (not visible
) (> (current-column) r
)
585 (if (and tabpad
(not pad
) (looking-at "\t"))
587 (set-marker m
(point))
588 (move-to-column l pad
)
589 (if (and fct
(or visible
(and (>= (current-column) l
) (<= (current-column) r
))))
590 (let ((v t
) (p (point)))
593 (setq v
(looking-at (car sel
)))
594 (setq v
(re-search-forward (car sel
) m t
))
596 (if (car (cdr (cdr sel
)))
599 (funcall fct p m l r v
)
601 (funcall fct p m l r
)))))
605 (cua--rectangle-bot t
))
607 (funcall post-fct l r
))
609 (tabify tabify-start
(point)))))
611 ((eq keep-clear
'keep
)
613 ((eq keep-clear
'clear
)
615 ((eq keep-clear
'corners
)
616 (cua--rectangle-set-corners)
618 (setq cua--buffer-and-point-before-command nil
)))
620 (put 'cua--rectangle-operation
'lisp-indent-function
4)
622 (defun cua--delete-rectangle ()
624 (if (not (cua--rectangle-virtual-edges))
625 (cua--rectangle-operation nil nil t
2 t
626 (lambda (s e _l _r _v
)
627 (setq lines
(1+ lines
))
628 (if (and (> e s
) (<= e
(point-max)))
629 (delete-region s e
))))
630 (cua--rectangle-operation nil
1 t nil t
631 (lambda (s e _l _r _v
)
632 (setq lines
(1+ lines
))
633 (when (and (> e s
) (<= e
(point-max)))
634 (delete-region s e
)))))
637 (defun cua--extract-rectangle ()
639 (if (not (cua--rectangle-virtual-edges))
640 (cua--rectangle-operation nil nil nil nil nil
; do not tabify
642 (setq rect
(cons (cua--filter-buffer-noprops s e
) rect
))))
643 (cua--rectangle-operation nil
1 nil nil nil
; do not tabify
645 (let ((copy t
) (bs 0) (as 0) row
)
646 (if (= s e
) (setq e
(1+ e
)))
649 (if (= (point) (line-end-position))
652 (skip-chars-forward "\s\t" e
)
653 (setq bs
(- (min r
(current-column)) l
)
656 (skip-chars-backward "\s\t" s
)
657 (setq as
(- r
(max (current-column) l
))
659 (setq row
(if (and copy
(> e s
))
660 (cua--filter-buffer-noprops s e
)
663 (setq row
(concat (make-string bs ?\s
) row
)))
665 (setq row
(concat row
(make-string as ?\s
))))
666 (setq rect
(cons row rect
))))))
669 (defun cua--extract-rectangle-bounds ()
671 (if (not (cua--rectangle-virtual-edges))
672 (cua--rectangle-operation nil nil nil nil nil
; do not tabify
674 (setq rect
(cons (cons s e
) rect
))))
675 (cua--rectangle-operation nil
1 nil nil nil
; do not tabify
682 (setq rect
(cons (cons s e
) rect
)))))
685 (defun cua--insert-rectangle (rect &optional below paste-column line-count
)
686 ;; Insert rectangle as insert-rectangle, but don't set mark and exit with
687 ;; point at either next to top right or below bottom left corner
688 ;; Notice: In overwrite mode, the rectangle is inserted as separate text lines.
690 (setq below
(and (bolp)
691 (or (eolp) (eobp) (= (1+ (point)) (point-max))))))
693 (setq paste-column
(current-column)))
696 (tabify-start (cua--tabify-start (point) (point)))
699 (while (or lines below
)
704 (or (bolp) (insert ?
\n))))
705 (unless overwrite-mode
706 (move-to-column paste-column t
))
709 (insert-for-yank (car lines
))
711 (setq last-column
(current-column)))
712 (setq lines
(cdr lines
))
713 (and first
(not below
)
716 (if (and line-count
(= (setq line-count
(1- line-count
)) 0))
718 (when (and line-count last-column
(not overwrite-mode
))
719 (while (> line-count
0)
721 (or (bolp) (insert ?
\n))
722 (move-to-column paste-column t
)
723 (insert-char ?\s
(- last-column paste-column -
1))
724 (setq line-count
(1- line-count
))))
725 (when (and tabify-start
726 (not overwrite-mode
))
727 (tabify tabify-start
(point)))
728 (and p
(not overwrite-mode
)
731 (defun cua--copy-rectangle-as-kill (&optional ring
)
733 (set-register cua--register
(cua--extract-rectangle))
734 (setq killed-rectangle
(cua--extract-rectangle))
735 (setq cua--last-killed-rectangle
(cons (and kill-ring
(car kill-ring
)) killed-rectangle
))
738 (function (lambda (row) (concat row
"\n")))
739 killed-rectangle
"")))))
741 (defun cua--activate-rectangle ()
742 ;; Set cua--rectangle to indicate we're marking a rectangle.
743 ;; Be careful if we are already marking a rectangle.
745 (or (and cua--last-rectangle
746 (eq (car cua--last-rectangle
) (current-buffer))
747 (eq (car (cdr cua--last-rectangle
)) (point))
748 (cdr (cdr cua--last-rectangle
)))
749 (cua--rectangle-get-corners))
750 cua--status-string
(if (cua--rectangle-virtual-edges) " [R]" "")
751 cua--last-rectangle nil
)
754 ;; (defvar cua-save-point nil)
756 (defun cua--deactivate-rectangle ()
757 ;; This is used to clean up after `cua--activate-rectangle'.
758 (mapc #'delete-overlay cua--rectangle-overlays
)
759 (setq cua--last-rectangle
(cons (current-buffer)
760 (cons (point) ;; cua-save-point
763 cua--rectangle-overlays nil
764 cua--status-string nil
765 cua--mouse-last-pos nil
)
766 ;; FIXME: This call to cua-rectangle-mark-mode is a workaround.
767 ;; Deactivation can happen in various different ways, and we
768 ;; currently don't handle them all in a coherent way.
769 (if cua-rectangle-mark-mode
(cua-rectangle-mark-mode -
1)))
771 (defun cua--highlight-rectangle ()
772 ;; This function is used to highlight the rectangular region.
773 ;; We do this by putting an overlay on each line within the rectangle.
774 ;; Each overlay extends across all the columns of the rectangle.
775 ;; We try to reuse overlays where possible because this is more efficient
776 ;; and results in less flicker.
777 ;; If cua--rectangle-virtual-edges is nil and the buffer contains tabs or short lines,
778 ;; the highlighted region may not be perfectly rectangular.
779 (let ((deactivate-mark deactivate-mark
)
780 (old cua--rectangle-overlays
)
782 (left (cua--rectangle-left))
783 (right (1+ (cua--rectangle-right))))
784 (when (/= left right
)
785 (sit-for 0) ; make window top/bottom reliable
786 (cua--rectangle-operation nil t nil nil nil
; do not tabify
788 (let ((rface (if v
'cua-rectangle
'cua-rectangle-noselect
))
790 (when (cua--rectangle-virtual-edges)
791 (let ((lb (line-beginning-position))
792 (le (line-end-position))
795 (setq cl
(move-to-column l
)
797 (setq cr
(move-to-column r
)
802 (setq cl0
(current-column)))
806 (setq cr0
(current-column)))
807 (unless (and (= cl l
) (= cr r
))
811 (- l cl0
(if (and (= le pl
) (/= le lb
)) 1 0))
812 (if cua--virtual-edges-debug ?. ?\s
))
813 'face
(or (get-text-property (max (1- s
) (point-min)) 'face
) 'default
)))
820 (or bs
(/= cr0
(- cr tab-width
)))
821 (/= (mod cr tab-width
) 0))
827 (if cua--virtual-edges-debug ?
, ?\s
))
829 (if (cua--rectangle-right-side)
830 (put-text-property (1- (length ms
)) (length ms
) 'cursor
2 ms
)
831 (put-text-property 0 1 'cursor
2 ms
))
832 (setq bs
(concat bs ms
))
837 (- r cr0
(if (= le pr
) 1 0))
838 (if cua--virtual-edges-debug ?~ ?\s
))
840 (if (cua--rectangle-right-side)
841 (put-text-property (1- (length as
)) (length as
) 'cursor
2 as
)
842 (put-text-property 0 1 'cursor
2 as
))
844 (setq e
(1- e
))))))))
845 ;; Trim old leading overlays.
847 (setq overlay
(car old
))
848 (< (overlay-start overlay
) s
)
849 (/= (overlay-end overlay
) e
))
850 (delete-overlay overlay
)
851 (setq old
(cdr old
)))
852 ;; Reuse an overlay if possible, otherwise create one.
854 (setq overlay
(car old
))
855 (or (= (overlay-start overlay
) s
)
856 (= (overlay-end overlay
) e
)))
858 (move-overlay overlay s e
)
859 (setq old
(cdr old
)))
860 (setq overlay
(make-overlay s e
)))
861 (overlay-put overlay
'before-string bs
)
862 (overlay-put overlay
'after-string as
)
863 (overlay-put overlay
'face rface
)
864 (overlay-put overlay
'keymap cua--overlay-keymap
)
865 (overlay-put overlay
'window
(selected-window))
866 (setq new
(cons overlay new
))))))
867 ;; Trim old trailing overlays.
868 (mapc (function delete-overlay
) old
)
869 (setq cua--rectangle-overlays
(nreverse new
))))
871 (defun cua--indent-rectangle (&optional ch to-col clear
)
872 ;; Indent current rectangle.
873 (let ((col (cua--rectangle-insert-col))
874 (pad (cua--rectangle-virtual-edges))
876 (cua--rectangle-operation (if clear
'clear
'corners
) nil t pad nil
878 (move-to-column col pad
)
880 (< (current-column) col
))
881 (move-to-column col t
))
883 (to-col (indent-to to-col
))
884 ((and ch
(not (eq ch ?
\t))) (insert ch
))
885 (t (tab-to-tab-stop)))
886 (if (cua--rectangle-right-side t
)
887 (cua--rectangle-insert-col (current-column))
888 (setq indent
(- (current-column) l
))))
890 (when (and indent
(> indent
0))
891 (aset cua--rectangle
2 (+ l indent
))
892 (aset cua--rectangle
3 (+ r indent -
1)))))))
895 ;; rectangle functions / actions
898 (defvar cua--rectangle-initialized nil
)
900 (defun cua-set-rectangle-mark (&optional reopen
)
901 "Set mark and start in CUA rectangle mode.
902 With prefix argument, activate previous rectangle if possible."
904 (unless cua--rectangle-initialized
905 (cua--init-rectangles))
906 (when (not cua--rectangle
)
909 (eq (car cua--last-rectangle
) (current-buffer)))
910 (goto-char (car (cdr cua--last-rectangle
)))
911 (if (not mark-active
)
912 (push-mark nil nil t
)))
913 (cua--activate-rectangle)
914 (cua--rectangle-set-corners)
915 (if cua-enable-rectangle-auto-help
916 (cua-help-for-rectangle t
))))
918 (defun cua-clear-rectangle-mark ()
919 "Cancel current rectangle."
922 (setq mark-active nil
)
923 (cua--deactivate-rectangle)))
925 (defun cua-toggle-rectangle-mark ()
928 (cua--deactivate-rectangle)
929 (unless cua--rectangle-initialized
930 (cua--init-rectangles))
931 (cua--activate-rectangle))
933 (if cua-enable-rectangle-auto-help
934 (cua-help-for-rectangle t
))
935 (if cua-enable-region-auto-help
936 (cua-help-for-region t
))))
938 (defun cua-restrict-regexp-rectangle (arg)
939 "Restrict rectangle to lines (not) matching regexp.
940 With prefix argument, toggle restriction."
942 (let ((r (cua--rectangle-restriction)))
943 (if (and r
(null (car (cdr r
))))
945 (cua--rectangle-restriction (car r
) nil
(not (car (cdr (cdr r
)))))
946 (cua--rectangle-restriction "" nil nil
))
947 (cua--rectangle-restriction
948 (read-from-minibuffer "Restrict rectangle (regexp): "
949 nil nil nil nil
) nil arg
))))
951 (defun cua-restrict-prefix-rectangle (arg)
952 "Restrict rectangle to lines (not) starting with CHAR.
953 With prefix argument, toggle restriction."
955 (let ((r (cua--rectangle-restriction)))
956 (if (and r
(car (cdr r
)))
958 (cua--rectangle-restriction (car r
) t
(not (car (cdr (cdr r
)))))
959 (cua--rectangle-restriction "" nil nil
))
960 (cua--rectangle-restriction
962 (read-char "Restrictive rectangle (char): ")) t arg
))))
964 (defun cua-move-rectangle-up ()
966 (cua--rectangle-move 'up
))
968 (defun cua-move-rectangle-down ()
970 (cua--rectangle-move 'down
))
972 (defun cua-move-rectangle-left ()
974 (cua--rectangle-move 'left
))
976 (defun cua-move-rectangle-right ()
978 (cua--rectangle-move 'right
))
980 (defun cua-rotate-rectangle ()
982 (cua--rectangle-corner (if (= (cua--rectangle-left) (cua--rectangle-right)) 0 1))
983 (cua--rectangle-set-corners)
984 (if (cua--rectangle-virtual-edges)
985 (setq cua--buffer-and-point-before-command nil
)))
987 (defun cua-toggle-rectangle-virtual-edges ()
989 (cua--rectangle-virtual-edges t
(not (cua--rectangle-virtual-edges)))
990 (cua--rectangle-set-corners)
991 (setq cua--status-string
(and (cua--rectangle-virtual-edges) " [R]"))
994 (defun cua-do-rectangle-padding ()
997 (message "Cannot do padding in read-only buffer")
998 (cua--rectangle-operation nil nil t t t
)
999 (cua--rectangle-set-corners))
1002 (defun cua-open-rectangle ()
1003 "Blank out CUA rectangle, shifting text right.
1004 The text previously in the region is not overwritten by the blanks,
1005 but instead winds up to the right of the rectangle."
1007 (cua--rectangle-operation 'corners nil t
1 nil
1009 (skip-chars-forward " \t")
1010 (let ((ws (- (current-column) l
))
1012 (skip-chars-backward " \t")
1013 (delete-region (point) p
)
1014 (indent-to (+ r ws
))))))
1016 (defun cua-close-rectangle (arg)
1017 "Delete all whitespace starting at left edge of CUA rectangle.
1018 On each line in the rectangle, all continuous whitespace starting
1019 at that column is deleted.
1020 With prefix arg, also delete whitespace to the left of that column."
1022 (cua--rectangle-operation 'clear nil t
1 nil
1023 (lambda (s _e _l _r
)
1025 (skip-syntax-backward " " (line-beginning-position))
1027 (skip-syntax-forward " " (line-end-position))
1028 (delete-region s
(point)))))
1030 (defun cua-blank-rectangle ()
1031 "Blank out CUA rectangle.
1032 The text previously in the rectangle is overwritten by the blanks."
1034 (cua--rectangle-operation 'keep nil nil
1 nil
1037 (skip-syntax-forward " " (line-end-position))
1039 (let ((column (current-column)))
1041 (skip-syntax-backward " " (line-beginning-position))
1042 (delete-region (point) e
)
1043 (indent-to column
)))))
1045 (defun cua-align-rectangle ()
1046 "Align rectangle lines to left column."
1048 (cua--rectangle-operation 'clear nil t t nil
1050 (let ((b (line-beginning-position)))
1051 (skip-syntax-backward "^ " b
)
1052 (skip-syntax-backward " " b
)
1054 (skip-syntax-forward " " (line-end-position))
1055 (delete-region s
(point))
1059 ;; (setq cua-save-point (point))
1062 (declare-function cua--cut-rectangle-to-global-mark
"cua-gmrk" (as-text))
1063 (declare-function cua--copy-rectangle-to-global-mark
"cua-gmrk" (as-text))
1065 (defun cua-copy-rectangle-as-text (&optional arg delete
)
1066 "Copy rectangle, but store as normal text."
1068 (if cua--global-mark-active
1070 (cua--cut-rectangle-to-global-mark t
)
1071 (cua--copy-rectangle-to-global-mark t
))
1072 (let* ((rect (cua--extract-rectangle))
1074 (function (lambda (row) (concat row
"\n")))
1076 (setq arg
(cua--prefix-arg arg
))
1078 (set-register cua--register text
)
1081 (cua--delete-rectangle))
1084 (defun cua-cut-rectangle-as-text (arg)
1085 "Kill rectangle, but store as normal text."
1087 (cua-copy-rectangle-as-text arg
(not buffer-read-only
)))
1089 (defun cua-string-rectangle (string)
1090 "Replace CUA rectangle contents with STRING on each line.
1091 The length of STRING need not be the same as the rectangle width."
1092 (interactive "sString rectangle: ")
1093 (cua--rectangle-operation 'keep nil t t nil
1096 (skip-chars-forward " \t")
1097 (let ((ws (- (current-column) l
)))
1098 (delete-region s
(point))
1100 (indent-to (+ (current-column) ws
))))
1101 (unless (cua--rectangle-restriction)
1103 (cua--rectangle-right (max l
(+ l
(length string
) -
1)))))))
1105 (defun cua-fill-char-rectangle (character)
1106 "Replace CUA rectangle contents with CHARACTER."
1107 (interactive "cFill rectangle with character: ")
1108 (cua--rectangle-operation 'clear nil t
1 nil
1111 (move-to-column l t
)
1112 (insert-char character
(- r l
)))))
1114 (defun cua-replace-in-rectangle (regexp newtext
)
1115 "Replace REGEXP with NEWTEXT in each line of CUA rectangle."
1116 (interactive "sReplace regexp: \nsNew text: ")
1117 (if buffer-read-only
1118 (message "Cannot replace in read-only buffer")
1119 (cua--rectangle-operation 'keep nil t
1 nil
1120 (lambda (_s e _l _r
)
1121 (if (re-search-forward regexp e t
)
1122 (replace-match newtext nil nil
))))))
1124 (defun cua-incr-rectangle (increment)
1125 "Increment each line of CUA rectangle by prefix amount."
1127 (cua--rectangle-operation 'keep nil t
1 nil
1128 (lambda (_s e _l _r
)
1130 ((re-search-forward "0x\\([0-9a-fA-F]+\\)" e t
)
1131 (let* ((txt (cua--filter-buffer-noprops (match-beginning 1) (match-end 1)))
1132 (n (string-to-number txt
16))
1133 (fmt (format "0x%%0%dx" (length txt
))))
1134 (replace-match (format fmt
(+ n increment
)))))
1135 ((re-search-forward "\\( *-?[0-9]+\\)" e t
)
1136 (let* ((txt (cua--filter-buffer-noprops (match-beginning 1) (match-end 1)))
1137 (prefix (if (= (aref txt
0) ?
0) "0" ""))
1138 (n (string-to-number txt
10))
1139 (fmt (format "%%%s%dd" prefix
(length txt
))))
1140 (replace-match (format fmt
(+ n increment
)))))
1143 (defvar cua--rectangle-seq-format
"%d"
1144 "Last format used by `cua-sequence-rectangle'.")
1146 (defun cua-sequence-rectangle (first incr format
)
1147 "Resequence each line of CUA rectangle starting from FIRST.
1148 The numbers are formatted according to the FORMAT string."
1150 (list (if current-prefix-arg
1151 (prefix-numeric-value current-prefix-arg
)
1153 (read-string "Start value: (0) " nil nil
"0")))
1155 (read-string "Increment: (1) " nil nil
"1"))
1156 (read-string (concat "Format: (" cua--rectangle-seq-format
") "))))
1157 (if (= (length format
) 0)
1158 (setq format cua--rectangle-seq-format
)
1159 (setq cua--rectangle-seq-format format
))
1160 (cua--rectangle-operation 'clear nil t
1 nil
1163 (insert (format format first
))
1164 (setq first
(+ first incr
)))))
1166 (defmacro cua--convert-rectangle-as
(command tabify
)
1167 `(cua--rectangle-operation 'clear nil nil nil
,tabify
1171 (defun cua-upcase-rectangle ()
1172 "Convert the rectangle to upper case."
1174 (cua--convert-rectangle-as upcase-region nil
))
1176 (defun cua-downcase-rectangle ()
1177 "Convert the rectangle to lower case."
1179 (cua--convert-rectangle-as downcase-region nil
))
1181 (defun cua-upcase-initials-rectangle ()
1182 "Convert the rectangle initials to upper case."
1184 (cua--convert-rectangle-as upcase-initials-region nil
))
1186 (defun cua-capitalize-rectangle ()
1187 "Convert the rectangle to proper case."
1189 (cua--convert-rectangle-as capitalize-region nil
))
1192 ;;; Replace/rearrange text in current rectangle
1194 (defun cua--rectangle-aux-replace (width adjust keep replace pad format-fct
&optional setup-fct
)
1195 ;; Process text inserted by calling SETUP-FCT or current rectangle if nil.
1196 ;; Then call FORMAT-FCT on text (if non-nil); takes two args: start and end.
1197 ;; Fill to WIDTH characters if > 0 or fill to current width if == 0.
1198 ;; Don't fill if WIDTH < 0.
1199 ;; Replace current rectangle by filled text if REPLACE is non-nil
1200 (let ((auxbuf (get-buffer-create "*CUA temp*"))
1201 (w (if (> width
1) width
1202 (- (cua--rectangle-right) (cua--rectangle-left) -
1)))
1203 (r (or setup-fct
(cua--extract-rectangle)))
1205 (with-current-buffer auxbuf
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 rectangle 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 rectangle.
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
)
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 (mapc (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
)))
1411 (add-function :around region-extract-function
1412 #'cua--rectangle-region-extract
)
1413 (add-function :around region-insert-function
1414 #'cua--insert-rectangle
)
1415 (add-function :around redisplay-highlight-region-function
1416 #'cua--rectangle-highlight-for-redisplay
)
1418 (defun cua--rectangle-highlight-for-redisplay (orig &rest args
)
1419 (if (not cua--rectangle
) (apply orig args
)
1420 ;; When cua--rectangle is active, just don't highlight at all, since we
1421 ;; already do it elsewhere.
1422 (funcall redisplay-unhighlight-region-function
(nth 3 args
))))
1424 (defun cua--rectangle-region-extract (orig &optional delete
)
1426 ((not cua--rectangle
)
1427 (funcall orig delete
))
1428 ((eq delete
'bounds
)
1429 (cua--extract-rectangle-bounds))
1430 ((eq delete
'delete-only
)
1431 (cua--delete-rectangle))
1433 (let* ((strs (cua--extract-rectangle))
1434 (str (mapconcat #'identity strs
"\n")))
1435 (if delete
(cua--delete-rectangle))
1436 (setq killed-rectangle strs
)
1437 (setq cua--last-killed-rectangle
1438 (cons (and kill-ring
(car kill-ring
)) killed-rectangle
))
1439 (when (eq last-command
'kill-region
)
1440 ;; Try to prevent kill-region from appending this to some
1442 (setq last-command
'kill-region-dont-append
))
1444 (put-text-property 0 (length str
) 'yank-handler
1445 `(rectangle--insert-for-yank ,strs t
)
1451 (defun cua--rect-M/H-key
(key cmd
)
1452 (cua--M/H-key cua--rectangle-keymap key cmd
))
1454 (defun cua--init-rectangles ()
1455 (define-key cua--rectangle-keymap cua-rectangle-mark-key
'cua-clear-rectangle-mark
)
1456 (define-key cua--region-keymap cua-rectangle-mark-key
'cua-toggle-rectangle-mark
)
1457 (unless (eq cua--rectangle-modifier-key
'meta
)
1458 (cua--rect-M/H-key ?\s
'cua-clear-rectangle-mark
)
1459 (cua--M/H-key cua--region-keymap ?\s
'cua-toggle-rectangle-mark
))
1461 (define-key cua--rectangle-keymap
[remap set-mark-command
] 'cua-toggle-rectangle-mark
)
1463 (define-key cua--rectangle-keymap
[remap forward-char
] 'cua-resize-rectangle-right
)
1464 (define-key cua--rectangle-keymap
[remap right-char
] 'cua-resize-rectangle-right
)
1465 (define-key cua--rectangle-keymap
[remap backward-char
] 'cua-resize-rectangle-left
)
1466 (define-key cua--rectangle-keymap
[remap left-char
] 'cua-resize-rectangle-left
)
1467 (define-key cua--rectangle-keymap
[remap next-line
] 'cua-resize-rectangle-down
)
1468 (define-key cua--rectangle-keymap
[remap previous-line
] 'cua-resize-rectangle-up
)
1469 (define-key cua--rectangle-keymap
[remap end-of-line
] 'cua-resize-rectangle-eol
)
1470 (define-key cua--rectangle-keymap
[remap beginning-of-line
] 'cua-resize-rectangle-bol
)
1471 (define-key cua--rectangle-keymap
[remap end-of-buffer
] 'cua-resize-rectangle-bot
)
1472 (define-key cua--rectangle-keymap
[remap beginning-of-buffer
] 'cua-resize-rectangle-top
)
1473 (define-key cua--rectangle-keymap
[remap scroll-down
] 'cua-resize-rectangle-page-up
)
1474 (define-key cua--rectangle-keymap
[remap scroll-up
] 'cua-resize-rectangle-page-down
)
1475 (define-key cua--rectangle-keymap
[remap scroll-down-command
] 'cua-resize-rectangle-page-up
)
1476 (define-key cua--rectangle-keymap
[remap scroll-up-command
] 'cua-resize-rectangle-page-down
)
1478 (define-key cua--rectangle-keymap
[remap delete-backward-char
] 'cua-delete-char-rectangle
)
1479 (define-key cua--rectangle-keymap
[remap backward-delete-char
] 'cua-delete-char-rectangle
)
1480 (define-key cua--rectangle-keymap
[remap backward-delete-char-untabify
] 'cua-delete-char-rectangle
)
1481 (define-key cua--rectangle-keymap
[remap self-insert-command
] 'cua-insert-char-rectangle
)
1483 ;; Catch self-inserting characters which are "stolen" by other modes
1484 (define-key cua--rectangle-keymap
[t]
1485 '(menu-item "sic" cua-insert-char-rectangle :filter cua--self-insert-char-p))
1487 (define-key cua--rectangle-keymap "\r" 'cua-rotate-rectangle)
1488 (define-key cua--rectangle-keymap "\t" 'cua-indent-rectangle)
1490 (define-key cua--rectangle-keymap [(control ??)] 'cua-help-for-rectangle)
1492 (define-key cua--rectangle-keymap [mouse-1] 'cua-mouse-set-rectangle-mark)
1493 (define-key cua--rectangle-keymap [down-mouse-1] 'cua--mouse-ignore)
1494 (define-key cua--rectangle-keymap [drag-mouse-1] 'cua--mouse-ignore)
1495 (define-key cua--rectangle-keymap [mouse-3] 'cua-mouse-save-then-kill-rectangle)
1496 (define-key cua--rectangle-keymap [down-mouse-3] 'cua--mouse-ignore)
1497 (define-key cua--rectangle-keymap [drag-mouse-3] 'cua--mouse-ignore)
1499 (cua--rect-M/H-key 'up 'cua-move-rectangle-up)
1500 (cua--rect-M/H-key 'down 'cua-move-rectangle-down)
1501 (cua--rect-M/H-key 'left 'cua-move-rectangle-left)
1502 (cua--rect-M/H-key 'right 'cua-move-rectangle-right)
1504 (cua--rect-M/H-key '(control up) 'cua-scroll-rectangle-up)
1505 (cua--rect-M/H-key '(control down) 'cua-scroll-rectangle-down)
1507 (cua--rect-M/H-key ?a 'cua-align-rectangle)
1508 (cua--rect-M/H-key ?b 'cua-blank-rectangle)
1509 (cua--rect-M/H-key ?c 'cua-close-rectangle)
1510 (cua--rect-M/H-key ?f 'cua-fill-char-rectangle)
1511 (cua--rect-M/H-key ?i 'cua-incr-rectangle)
1512 (cua--rect-M/H-key ?k 'cua-cut-rectangle-as-text)
1513 (cua--rect-M/H-key ?l 'cua-downcase-rectangle)
1514 (cua--rect-M/H-key ?m 'cua-copy-rectangle-as-text)
1515 (cua--rect-M/H-key ?n 'cua-sequence-rectangle)
1516 (cua--rect-M/H-key ?o 'cua-open-rectangle)
1517 (cua--rect-M/H-key ?p 'cua-toggle-rectangle-virtual-edges)
1518 (cua--rect-M/H-key ?P 'cua-do-rectangle-padding)
1519 (cua--rect-M/H-key ?q 'cua-refill-rectangle)
1520 (cua--rect-M/H-key ?r 'cua-replace-in-rectangle)
1521 (cua--rect-M/H-key ?R 'cua-reverse-rectangle)
1522 (cua--rect-M/H-key ?s 'cua-string-rectangle)
1523 (cua--rect-M/H-key ?t 'cua-text-fill-rectangle)
1524 (cua--rect-M/H-key ?u 'cua-upcase-rectangle)
1525 (cua--rect-M/H-key ?| 'cua-shell-command-on-rectangle)
1526 (cua--rect-M/H-key ?' 'cua-restrict-prefix-rectangle)
1527 (cua--rect-M/H-key ?/ 'cua-restrict-regexp-rectangle)
1529 (setq cua--rectangle-initialized t))
1533 ;;; cua-rect.el ends here