Mercurial > emacs
comparison lisp/emulation/cua-rect.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 0d8b17d428b5 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; cua-rect.el --- CUA unified rectangle support | 1 ;;; cua-rect.el --- CUA unified rectangle support |
2 | 2 |
3 ;; Copyright (C) 1997-2002 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: Kim F. Storm <storm@cua.dk> | 6 ;; Author: Kim F. Storm <storm@cua.dk> |
6 ;; Keywords: keyboard emulations convenience CUA | 7 ;; Keywords: keyboard emulations convenience CUA |
7 | 8 |
8 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 ;; GNU General Public License for more details. | 19 ;; GNU General Public License for more details. |
19 | 20 |
20 ;; You should have received a copy of the GNU General Public License | 21 ;; 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 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02110-1301, USA. |
24 | 25 |
25 ;;; Acknowledgements | 26 ;;; Acknowledgements |
26 | 27 |
27 ;; The rectangle handling and display code borrows from the standard | 28 ;; 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 ;; GNU emacs rect.el package and the rect-mark.el package by Rick |
42 ;;; Rectangle support | 43 ;;; Rectangle support |
43 | 44 |
44 (require 'rect) | 45 (require 'rect) |
45 | 46 |
46 ;; If non-nil, restrict current region to this rectangle. | 47 ;; If non-nil, restrict current region to this rectangle. |
47 ;; Value is a vector [top bot left right corner ins pad select]. | 48 ;; 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 ;; 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 ;; INS specifies whether to insert on left(nil) or right(t) side. |
50 ;; If PAD is non-nil, tabs are converted to spaces when necessary. | 51 ;; 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 ;; If SELECT is a regexp, only lines starting with that regexp are affected.") |
52 (defvar cua--rectangle nil) | 53 (defvar cua--rectangle nil) |
53 (make-variable-buffer-local 'cua--rectangle) | 54 (make-variable-buffer-local 'cua--rectangle) |
54 | 55 |
55 ;; Most recent rectangle geometry. Note: car is buffer. | 56 ;; Most recent rectangle geometry. Note: car is buffer. |
62 (defvar cua--last-killed-rectangle nil) | 63 (defvar cua--last-killed-rectangle nil) |
63 | 64 |
64 ;; List of overlays used to display current rectangle. | 65 ;; List of overlays used to display current rectangle. |
65 (defvar cua--rectangle-overlays nil) | 66 (defvar cua--rectangle-overlays nil) |
66 (make-variable-buffer-local 'cua--rectangle-overlays) | 67 (make-variable-buffer-local 'cua--rectangle-overlays) |
67 | 68 (put 'cua--rectangle-overlays 'permanent-local t) |
68 ;; Per-buffer CUA mode undo list. | 69 |
69 (defvar cua--undo-list nil) | 70 (defvar cua--overlay-keymap |
70 (make-variable-buffer-local 'cua--undo-list) | 71 (let ((map (make-sparse-keymap))) |
71 | 72 (define-key map "\r" 'cua-rotate-rectangle))) |
72 ;; Record undo boundary for rectangle undo. | 73 |
74 (defvar cua--virtual-edges-debug nil) | |
75 | |
76 ;; Undo rectangle commands. | |
77 | |
78 (defvar cua--rect-undo-set-point nil) | |
79 | |
73 (defun cua--rectangle-undo-boundary () | 80 (defun cua--rectangle-undo-boundary () |
74 (when (listp buffer-undo-list) | 81 (when (listp buffer-undo-list) |
75 (if (> (length cua--undo-list) cua-undo-max) | 82 (let ((s (cua--rect-start-position)) |
76 (setcdr (nthcdr (1- cua-undo-max) cua--undo-list) nil)) | 83 (e (cua--rect-end-position))) |
77 (undo-boundary) | 84 (undo-boundary) |
78 (setq cua--undo-list | 85 (push (list 'apply 0 s e |
79 (cons (cons (cdr buffer-undo-list) (copy-sequence cua--rectangle)) cua--undo-list)))) | 86 'cua--rect-undo-handler |
80 | 87 (copy-sequence cua--rectangle) t s e) |
81 (defun cua--rectangle-undo (&optional arg) | 88 buffer-undo-list)))) |
82 "Undo some previous changes. | 89 |
83 Knows about CUA rectangle highlighting in addition to standard undo." | 90 (defun cua--rect-undo-handler (rect on s e) |
84 (interactive "*P") | 91 (if (setq on (not on)) |
85 (if cua--rectangle | 92 (setq cua--rect-undo-set-point s) |
86 (cua--rectangle-undo-boundary)) | 93 (setq cua--restored-rectangle (copy-sequence rect)) |
87 (undo arg) | 94 (setq cua--buffer-and-point-before-command nil)) |
88 (let ((l cua--undo-list)) | 95 (push (list 'apply 0 s (if on e s) |
89 (while l | 96 'cua--rect-undo-handler rect on s e) |
90 (if (eq (car (car l)) pending-undo-list) | 97 buffer-undo-list)) |
91 (setq cua--restored-rectangle | |
92 (and (vectorp (cdr (car l))) (cdr (car l))) | |
93 l nil) | |
94 (setq l (cdr l))))) | |
95 (setq cua--buffer-and-point-before-command nil)) | |
96 | |
97 (defvar cua--tidy-undo-counter 0 | |
98 "Number of times `cua--tidy-undo-lists' have run successfully.") | |
99 | |
100 ;; Clean out danling entries from cua's undo list. | |
101 ;; Since this list contains pointers into the standard undo list, | |
102 ;; such references are only meningful as undo information if the | |
103 ;; corresponding entry is still on the standard undo list. | |
104 | |
105 (defun cua--tidy-undo-lists (&optional clean) | |
106 (let ((buffers (buffer-list)) (cnt cua--tidy-undo-counter)) | |
107 (while (and buffers (or clean (not (input-pending-p)))) | |
108 (with-current-buffer (car buffers) | |
109 (when (local-variable-p 'cua--undo-list) | |
110 (if (or clean (null cua--undo-list) (eq buffer-undo-list t)) | |
111 (progn | |
112 (kill-local-variable 'cua--undo-list) | |
113 (setq cua--tidy-undo-counter (1+ cua--tidy-undo-counter))) | |
114 (let* ((bul buffer-undo-list) | |
115 (cul (cons nil cua--undo-list)) | |
116 (cc (car (car (cdr cul))))) | |
117 (while (and bul cc) | |
118 (if (setq bul (memq cc bul)) | |
119 (setq cul (cdr cul) | |
120 cc (and (cdr cul) (car (car (cdr cul))))))) | |
121 (when cc | |
122 (if cua--debug | |
123 (setq cc (length (cdr cul)))) | |
124 (if (eq (cdr cul) cua--undo-list) | |
125 (setq cua--undo-list nil) | |
126 (setcdr cul nil)) | |
127 (setq cua--tidy-undo-counter (1+ cua--tidy-undo-counter)) | |
128 (if cua--debug | |
129 (message "Clean undo list in %s (%d)" | |
130 (buffer-name) cc))))))) | |
131 (setq buffers (cdr buffers))) | |
132 (/= cnt cua--tidy-undo-counter))) | |
133 | 98 |
134 ;;; Rectangle geometry | 99 ;;; Rectangle geometry |
135 | 100 |
136 (defun cua--rectangle-top (&optional val) | 101 (defun cua--rectangle-top (&optional val) |
137 ;; Top of CUA rectangle (buffer position on first line). | 102 ;; Top of CUA rectangle (buffer position on first line). |
201 (if (= (aref cua--rectangle 5) 0) | 166 (if (= (aref cua--rectangle 5) 0) |
202 (1+ (cua--rectangle-right)) | 167 (1+ (cua--rectangle-right)) |
203 (aref cua--rectangle 5)) | 168 (aref cua--rectangle 5)) |
204 (cua--rectangle-left)))) | 169 (cua--rectangle-left)))) |
205 | 170 |
206 (defun cua--rectangle-padding (&optional set val) | 171 (defun cua--rectangle-virtual-edges (&optional set val) |
207 ;; Current setting of rectangle padding | 172 ;; Current setting of rectangle virtual-edges |
208 (if set | 173 (if set |
209 (aset cua--rectangle 6 val)) | 174 (aset cua--rectangle 6 val)) |
210 (and (not buffer-read-only) | 175 (and ;(not buffer-read-only) |
211 (aref cua--rectangle 6))) | 176 (aref cua--rectangle 6))) |
212 | 177 |
213 (defun cua--rectangle-restriction (&optional val bounded negated) | 178 (defun cua--rectangle-restriction (&optional val bounded negated) |
214 ;; Current rectangle restriction | 179 ;; Current rectangle restriction |
215 (if val | 180 (if val |
224 (if (< (cua--rectangle-right) (cua--rectangle-left)) | 189 (if (< (cua--rectangle-right) (cua--rectangle-left)) |
225 (message "rectangle right < left")) | 190 (message "rectangle right < left")) |
226 (if (< (cua--rectangle-bot) (cua--rectangle-top)) | 191 (if (< (cua--rectangle-bot) (cua--rectangle-top)) |
227 (message "rectangle bot < top"))) | 192 (message "rectangle bot < top"))) |
228 | 193 |
229 (defun cua--rectangle-get-corners (&optional pad) | 194 (defun cua--rectangle-get-corners () |
230 ;; Calculate the rectangular region represented by point and mark, | 195 ;; Calculate the rectangular region represented by point and mark, |
231 ;; putting start in the upper left corner and end in the | 196 ;; putting start in the upper left corner and end in the |
232 ;; bottom right corner. | 197 ;; bottom right corner. |
233 (let ((top (point)) (bot (mark)) r l corner) | 198 (let ((top (point)) (bot (mark)) r l corner) |
234 (save-excursion | 199 (save-excursion |
243 (if (<= l r) | 208 (if (<= l r) |
244 (if (< l r) | 209 (if (< l r) |
245 (setq r (1- r))) | 210 (setq r (1- r))) |
246 (setq l (prog1 r (setq r l))) | 211 (setq l (prog1 r (setq r l))) |
247 (goto-char top) | 212 (goto-char top) |
248 (move-to-column l pad) | 213 (move-to-column l) |
249 (setq top (point)) | 214 (setq top (point)) |
250 (goto-char bot) | 215 (goto-char bot) |
251 (move-to-column r pad) | 216 (move-to-column r) |
252 (setq bot (point)))) | 217 (setq bot (point)))) |
253 (vector top bot l r corner 0 pad nil))) | 218 (vector top bot l r corner 0 cua-virtual-rectangle-edges nil))) |
254 | 219 |
255 (defun cua--rectangle-set-corners () | 220 (defun cua--rectangle-set-corners () |
256 ;; Set mark and point in opposite corners of current rectangle. | 221 ;; Set mark and point in opposite corners of current rectangle. |
257 (let (pp pc mp mc (c (cua--rectangle-corner))) | 222 (let (pp pc mp mc (c (cua--rectangle-corner))) |
258 (cond | 223 (cond |
267 mp (cua--rectangle-top) mc (cua--rectangle-right))) | 232 mp (cua--rectangle-top) mc (cua--rectangle-right))) |
268 ((= c 3) ; bot/right -> top/left | 233 ((= c 3) ; bot/right -> top/left |
269 (setq pp (cua--rectangle-bot) pc (cua--rectangle-right) | 234 (setq pp (cua--rectangle-bot) pc (cua--rectangle-right) |
270 mp (cua--rectangle-top) mc (cua--rectangle-left)))) | 235 mp (cua--rectangle-top) mc (cua--rectangle-left)))) |
271 (goto-char mp) | 236 (goto-char mp) |
272 (move-to-column mc (cua--rectangle-padding)) | 237 (move-to-column mc) |
273 (set-mark (point)) | 238 (set-mark (point)) |
274 (goto-char pp) | 239 (goto-char pp) |
275 (move-to-column pc (cua--rectangle-padding)))) | 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)) | |
243 (not (eolp))) | |
244 (> (move-to-column pc) pc)) | |
245 (not (bolp))) | |
246 (backward-char 1)) | |
247 )) | |
248 | |
249 (defun cua--rect-start-position () | |
250 ;; Return point of top left corner | |
251 (save-excursion | |
252 (goto-char (cua--rectangle-top)) | |
253 (and (> (move-to-column (cua--rectangle-left)) | |
254 (cua--rectangle-left)) | |
255 (not (bolp)) | |
256 (backward-char 1)) | |
257 (point))) | |
258 | |
259 (defun cua--rect-end-position () | |
260 ;; Return point of bottom right cornet | |
261 (save-excursion | |
262 (goto-char (cua--rectangle-bot)) | |
263 (and (= (move-to-column (cua--rectangle-right)) | |
264 (- (cua--rectangle-right) tab-width)) | |
265 (not (eolp)) | |
266 (not (bolp)) | |
267 (backward-char 1)) | |
268 (point))) | |
276 | 269 |
277 ;;; Rectangle resizing | 270 ;;; Rectangle resizing |
278 | 271 |
279 (defun cua--forward-line (n pad) | 272 (defun cua--forward-line (n) |
280 ;; Move forward/backward one line. Returns t if movement. | 273 ;; Move forward/backward one line. Returns t if movement. |
281 (if (or (not pad) (< n 0)) | 274 (let ((pt (point))) |
282 (= (forward-line n) 0) | 275 (and (= (forward-line n) 0) |
283 (next-line 1) | 276 ;; Deal with end of buffer |
284 t)) | 277 (or (not (eobp)) |
278 (goto-char pt))))) | |
285 | 279 |
286 (defun cua--rectangle-resized () | 280 (defun cua--rectangle-resized () |
287 ;; Refresh state after resizing rectangle | 281 ;; Refresh state after resizing rectangle |
288 (setq cua--buffer-and-point-before-command nil) | 282 (setq cua--buffer-and-point-before-command nil) |
289 (cua--pad-rectangle) | |
290 (cua--rectangle-insert-col 0) | 283 (cua--rectangle-insert-col 0) |
291 (cua--rectangle-set-corners) | 284 (cua--rectangle-set-corners) |
292 (cua--keep-active)) | 285 (cua--keep-active)) |
293 | 286 |
294 (defun cua-resize-rectangle-right (n) | 287 (defun cua-resize-rectangle-right (n) |
295 "Resize rectangle to the right." | 288 "Resize rectangle to the right." |
296 (interactive "p") | 289 (interactive "p") |
297 (let ((pad (cua--rectangle-padding)) (resized (> n 0))) | 290 (let ((resized (> n 0))) |
298 (while (> n 0) | 291 (while (> n 0) |
299 (setq n (1- n)) | 292 (setq n (1- n)) |
300 (cond | 293 (cond |
301 ((and (cua--rectangle-right-side) (or pad (eolp))) | 294 ((cua--rectangle-right-side) |
302 (cua--rectangle-right (1+ (cua--rectangle-right))) | 295 (cua--rectangle-right (1+ (cua--rectangle-right))) |
303 (move-to-column (cua--rectangle-right) pad)) | 296 (move-to-column (cua--rectangle-right))) |
304 ((cua--rectangle-right-side) | 297 (t |
305 (forward-char 1) | |
306 (cua--rectangle-right (current-column))) | |
307 ((or pad (eolp)) | |
308 (cua--rectangle-left (1+ (cua--rectangle-left))) | 298 (cua--rectangle-left (1+ (cua--rectangle-left))) |
309 (move-to-column (cua--rectangle-right) pad)) | 299 (move-to-column (cua--rectangle-right))))) |
310 (t | |
311 (forward-char 1) | |
312 (cua--rectangle-left (current-column))))) | |
313 (if resized | 300 (if resized |
314 (cua--rectangle-resized)))) | 301 (cua--rectangle-resized)))) |
315 | 302 |
316 (defun cua-resize-rectangle-left (n) | 303 (defun cua-resize-rectangle-left (n) |
317 "Resize rectangle to the left." | 304 "Resize rectangle to the left." |
318 (interactive "p") | 305 (interactive "p") |
319 (let ((pad (cua--rectangle-padding)) resized) | 306 (let (resized) |
320 (while (> n 0) | 307 (while (> n 0) |
321 (setq n (1- n)) | 308 (setq n (1- n)) |
322 (if (or (= (cua--rectangle-right) 0) | 309 (if (or (= (cua--rectangle-right) 0) |
323 (and (not (cua--rectangle-right-side)) (= (cua--rectangle-left) 0))) | 310 (and (not (cua--rectangle-right-side)) (= (cua--rectangle-left) 0))) |
324 (setq n 0) | 311 (setq n 0) |
325 (cond | 312 (cond |
326 ((and (cua--rectangle-right-side) (or pad (eolp) (bolp))) | 313 ((cua--rectangle-right-side) |
327 (cua--rectangle-right (1- (cua--rectangle-right))) | 314 (cua--rectangle-right (1- (cua--rectangle-right))) |
328 (move-to-column (cua--rectangle-right) pad)) | 315 (move-to-column (cua--rectangle-right))) |
329 ((cua--rectangle-right-side) | 316 (t |
330 (backward-char 1) | |
331 (cua--rectangle-right (current-column))) | |
332 ((or pad (eolp) (bolp)) | |
333 (cua--rectangle-left (1- (cua--rectangle-left))) | 317 (cua--rectangle-left (1- (cua--rectangle-left))) |
334 (move-to-column (cua--rectangle-right) pad)) | 318 (move-to-column (cua--rectangle-right)))) |
335 (t | |
336 (backward-char 1) | |
337 (cua--rectangle-left (current-column)))) | |
338 (setq resized t))) | 319 (setq resized t))) |
339 (if resized | 320 (if resized |
340 (cua--rectangle-resized)))) | 321 (cua--rectangle-resized)))) |
341 | 322 |
342 (defun cua-resize-rectangle-down (n) | 323 (defun cua-resize-rectangle-down (n) |
343 "Resize rectangle downwards." | 324 "Resize rectangle downwards." |
344 (interactive "p") | 325 (interactive "p") |
345 (let ((pad (cua--rectangle-padding)) resized) | 326 (let (resized) |
346 (while (> n 0) | 327 (while (> n 0) |
347 (setq n (1- n)) | 328 (setq n (1- n)) |
348 (cond | 329 (cond |
349 ((>= (cua--rectangle-corner) 2) | 330 ((>= (cua--rectangle-corner) 2) |
350 (goto-char (cua--rectangle-bot)) | 331 (goto-char (cua--rectangle-bot)) |
351 (when (cua--forward-line 1 pad) | 332 (when (cua--forward-line 1) |
352 (move-to-column (cua--rectangle-column) pad) | 333 (move-to-column (cua--rectangle-column)) |
353 (cua--rectangle-bot t) | 334 (cua--rectangle-bot t) |
354 (setq resized t))) | 335 (setq resized t))) |
355 (t | 336 (t |
356 (goto-char (cua--rectangle-top)) | 337 (goto-char (cua--rectangle-top)) |
357 (when (cua--forward-line 1 pad) | 338 (when (cua--forward-line 1) |
358 (move-to-column (cua--rectangle-column) pad) | 339 (move-to-column (cua--rectangle-column)) |
359 (cua--rectangle-top t) | 340 (cua--rectangle-top t) |
360 (setq resized t))))) | 341 (setq resized t))))) |
361 (if resized | 342 (if resized |
362 (cua--rectangle-resized)))) | 343 (cua--rectangle-resized)))) |
363 | 344 |
364 (defun cua-resize-rectangle-up (n) | 345 (defun cua-resize-rectangle-up (n) |
365 "Resize rectangle upwards." | 346 "Resize rectangle upwards." |
366 (interactive "p") | 347 (interactive "p") |
367 (let ((pad (cua--rectangle-padding)) resized) | 348 (let (resized) |
368 (while (> n 0) | 349 (while (> n 0) |
369 (setq n (1- n)) | 350 (setq n (1- n)) |
370 (cond | 351 (cond |
371 ((>= (cua--rectangle-corner) 2) | 352 ((>= (cua--rectangle-corner) 2) |
372 (goto-char (cua--rectangle-bot)) | 353 (goto-char (cua--rectangle-bot)) |
373 (when (cua--forward-line -1 pad) | 354 (when (cua--forward-line -1) |
374 (move-to-column (cua--rectangle-column) pad) | 355 (move-to-column (cua--rectangle-column)) |
375 (cua--rectangle-bot t) | 356 (cua--rectangle-bot t) |
376 (setq resized t))) | 357 (setq resized t))) |
377 (t | 358 (t |
378 (goto-char (cua--rectangle-top)) | 359 (goto-char (cua--rectangle-top)) |
379 (when (cua--forward-line -1 pad) | 360 (when (cua--forward-line -1) |
380 (move-to-column (cua--rectangle-column) pad) | 361 (move-to-column (cua--rectangle-column)) |
381 (cua--rectangle-top t) | 362 (cua--rectangle-top t) |
382 (setq resized t))))) | 363 (setq resized t))))) |
383 (if resized | 364 (if resized |
384 (cua--rectangle-resized)))) | 365 (cua--rectangle-resized)))) |
385 | 366 |
406 | 387 |
407 (defun cua-resize-rectangle-bot () | 388 (defun cua-resize-rectangle-bot () |
408 "Resize rectangle to bottom of buffer." | 389 "Resize rectangle to bottom of buffer." |
409 (interactive) | 390 (interactive) |
410 (goto-char (point-max)) | 391 (goto-char (point-max)) |
411 (move-to-column (cua--rectangle-column) (cua--rectangle-padding)) | 392 (move-to-column (cua--rectangle-column)) |
412 (cua--rectangle-bot t) | 393 (cua--rectangle-bot t) |
413 (cua--rectangle-resized)) | 394 (cua--rectangle-resized)) |
414 | 395 |
415 (defun cua-resize-rectangle-top () | 396 (defun cua-resize-rectangle-top () |
416 "Resize rectangle to top of buffer." | 397 "Resize rectangle to top of buffer." |
417 (interactive) | 398 (interactive) |
418 (goto-char (point-min)) | 399 (goto-char (point-min)) |
419 (move-to-column (cua--rectangle-column) (cua--rectangle-padding)) | 400 (move-to-column (cua--rectangle-column)) |
420 (cua--rectangle-top t) | 401 (cua--rectangle-top t) |
421 (cua--rectangle-resized)) | 402 (cua--rectangle-resized)) |
422 | 403 |
423 (defun cua-resize-rectangle-page-up () | 404 (defun cua-resize-rectangle-page-up () |
424 "Resize rectangle upwards by one scroll page." | 405 "Resize rectangle upwards by one scroll page." |
425 (interactive) | 406 (interactive) |
426 (let ((pad (cua--rectangle-padding))) | 407 (scroll-down) |
427 (scroll-down) | 408 (move-to-column (cua--rectangle-column)) |
428 (move-to-column (cua--rectangle-column) pad) | 409 (if (>= (cua--rectangle-corner) 2) |
429 (if (>= (cua--rectangle-corner) 2) | 410 (cua--rectangle-bot t) |
430 (cua--rectangle-bot t) | 411 (cua--rectangle-top t)) |
431 (cua--rectangle-top t)) | 412 (cua--rectangle-resized)) |
432 (cua--rectangle-resized))) | |
433 | 413 |
434 (defun cua-resize-rectangle-page-down () | 414 (defun cua-resize-rectangle-page-down () |
435 "Resize rectangle downwards by one scroll page." | 415 "Resize rectangle downwards by one scroll page." |
436 (interactive) | 416 (interactive) |
437 (let ((pad (cua--rectangle-padding))) | 417 (scroll-up) |
438 (scroll-up) | 418 (move-to-column (cua--rectangle-column)) |
439 (move-to-column (cua--rectangle-column) pad) | 419 (if (>= (cua--rectangle-corner) 2) |
440 (if (>= (cua--rectangle-corner) 2) | 420 (cua--rectangle-bot t) |
441 (cua--rectangle-bot t) | 421 (cua--rectangle-top t)) |
442 (cua--rectangle-top t)) | 422 (cua--rectangle-resized)) |
443 (cua--rectangle-resized))) | |
444 | 423 |
445 ;;; Mouse support | 424 ;;; Mouse support |
446 | 425 |
447 ;; This is pretty simplistic, but it does the job... | 426 ;; This is pretty simplistic, but it does the job... |
448 | 427 |
449 (defun cua-mouse-resize-rectangle (event) | 428 (defun cua-mouse-resize-rectangle (event) |
450 "Set rectangle corner at mouse click position." | 429 "Set rectangle corner at mouse click position." |
451 (interactive "e") | 430 (interactive "e") |
452 (mouse-set-point event) | 431 (mouse-set-point event) |
453 (if (cua--rectangle-padding) | 432 ;; FIX ME -- need to calculate virtual column. |
433 (if (cua--rectangle-virtual-edges) | |
454 (move-to-column (car (posn-col-row (event-end event))) t)) | 434 (move-to-column (car (posn-col-row (event-end event))) t)) |
455 (if (cua--rectangle-right-side) | 435 (if (cua--rectangle-right-side) |
456 (cua--rectangle-right (current-column)) | 436 (cua--rectangle-right (current-column)) |
457 (cua--rectangle-left (current-column))) | 437 (cua--rectangle-left (current-column))) |
458 (if (>= (cua--rectangle-corner) 2) | 438 (if (>= (cua--rectangle-corner) 2) |
468 (when cua--rectangle | 448 (when cua--rectangle |
469 (cua--deactivate-rectangle) | 449 (cua--deactivate-rectangle) |
470 (cua--deactivate t)) | 450 (cua--deactivate t)) |
471 (setq cua--last-rectangle nil) | 451 (setq cua--last-rectangle nil) |
472 (mouse-set-point event) | 452 (mouse-set-point event) |
453 ;; FIX ME -- need to calculate virtual column. | |
473 (cua-set-rectangle-mark) | 454 (cua-set-rectangle-mark) |
474 (setq cua--buffer-and-point-before-command nil) | 455 (setq cua--buffer-and-point-before-command nil) |
475 (setq cua--mouse-last-pos nil)) | 456 (setq cua--mouse-last-pos nil)) |
476 | 457 |
477 (defun cua-mouse-save-then-kill-rectangle (event arg) | 458 (defun cua-mouse-save-then-kill-rectangle (event arg) |
487 (cua--deactivate)) | 468 (cua--deactivate)) |
488 (cua-mouse-resize-rectangle event) | 469 (cua-mouse-resize-rectangle event) |
489 (let ((cua-keep-region-after-copy t)) | 470 (let ((cua-keep-region-after-copy t)) |
490 (cua-copy-rectangle arg) | 471 (cua-copy-rectangle arg) |
491 (setq cua--mouse-last-pos (cons (point) cua--last-killed-rectangle))))) | 472 (setq cua--mouse-last-pos (cons (point) cua--last-killed-rectangle))))) |
473 | |
492 (defun cua--mouse-ignore (event) | 474 (defun cua--mouse-ignore (event) |
493 (interactive "e") | 475 (interactive "e") |
494 (setq this-command last-command)) | 476 (setq this-command last-command)) |
495 | 477 |
496 (defun cua--rectangle-move (dir) | 478 (defun cua--rectangle-move (dir) |
497 (let ((pad (cua--rectangle-padding)) | 479 (let ((moved t) |
498 (moved t) | |
499 (top (cua--rectangle-top)) | 480 (top (cua--rectangle-top)) |
500 (bot (cua--rectangle-bot)) | 481 (bot (cua--rectangle-bot)) |
501 (l (cua--rectangle-left)) | 482 (l (cua--rectangle-left)) |
502 (r (cua--rectangle-right))) | 483 (r (cua--rectangle-right))) |
503 (cond | 484 (cond |
504 ((eq dir 'up) | 485 ((eq dir 'up) |
505 (goto-char top) | 486 (goto-char top) |
506 (when (cua--forward-line -1 pad) | 487 (when (cua--forward-line -1) |
507 (cua--rectangle-top t) | 488 (cua--rectangle-top t) |
508 (goto-char bot) | 489 (goto-char bot) |
509 (forward-line -1) | 490 (forward-line -1) |
510 (cua--rectangle-bot t))) | 491 (cua--rectangle-bot t))) |
511 ((eq dir 'down) | 492 ((eq dir 'down) |
512 (goto-char bot) | 493 (goto-char bot) |
513 (when (cua--forward-line 1 pad) | 494 (when (cua--forward-line 1) |
514 (cua--rectangle-bot t) | 495 (cua--rectangle-bot t) |
515 (goto-char top) | 496 (goto-char top) |
516 (cua--forward-line 1 pad) | 497 (cua--forward-line 1) |
517 (cua--rectangle-top t))) | 498 (cua--rectangle-top t))) |
518 ((eq dir 'left) | 499 ((eq dir 'left) |
519 (when (> l 0) | 500 (when (> l 0) |
520 (cua--rectangle-left (1- l)) | 501 (cua--rectangle-left (1- l)) |
521 (cua--rectangle-right (1- r)))) | 502 (cua--rectangle-right (1- r)))) |
524 (cua--rectangle-left (1+ l))) | 505 (cua--rectangle-left (1+ l))) |
525 (t | 506 (t |
526 (setq moved nil))) | 507 (setq moved nil))) |
527 (when moved | 508 (when moved |
528 (setq cua--buffer-and-point-before-command nil) | 509 (setq cua--buffer-and-point-before-command nil) |
529 (cua--pad-rectangle) | |
530 (cua--rectangle-set-corners) | 510 (cua--rectangle-set-corners) |
531 (cua--keep-active)))) | 511 (cua--keep-active)))) |
532 | 512 |
533 | 513 |
534 ;;; Operations on current rectangle | 514 ;;; Operations on current rectangle |
535 | 515 |
536 (defun cua--rectangle-operation (keep-clear visible undo pad &optional fct post-fct) | 516 (defun cua--tabify-start (start end) |
517 ;; Return position where auto-tabify should start (or nil if not required). | |
518 (save-excursion | |
519 (save-restriction | |
520 (widen) | |
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)) | |
525 (progn | |
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))) | |
530 start))))) | |
531 | |
532 (defun cua--rectangle-operation (keep-clear visible undo pad tabify &optional fct post-fct) | |
537 ;; Call FCT for each line of region with 4 parameters: | 533 ;; Call FCT for each line of region with 4 parameters: |
538 ;; Region start, end, left-col, right-col | 534 ;; Region start, end, left-col, right-col |
539 ;; Point is at start when FCT is called | 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. | |
540 ;; Set undo boundary if UNDO is non-nil. | 538 ;; Set undo boundary if UNDO is non-nil. |
541 ;; Rectangle is padded if PAD = t or numeric and (cua--rectangle-padding) | 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. | |
542 ;; Mark is kept if keep-clear is 'keep and cleared if keep-clear is 'clear. | 541 ;; Mark is kept if keep-clear is 'keep and cleared if keep-clear is 'clear. |
543 (let* ((start (cua--rectangle-top)) | 542 (let* ((inhibit-field-text-motion t) |
543 (start (cua--rectangle-top)) | |
544 (end (cua--rectangle-bot)) | 544 (end (cua--rectangle-bot)) |
545 (l (cua--rectangle-left)) | 545 (l (cua--rectangle-left)) |
546 (r (1+ (cua--rectangle-right))) | 546 (r (1+ (cua--rectangle-right))) |
547 (m (make-marker)) | 547 (m (make-marker)) |
548 (tabpad (and (integerp pad) (= pad 2))) | 548 (tabpad (and (integerp pad) (= pad 2))) |
549 (sel (cua--rectangle-restriction))) | 549 (sel (cua--rectangle-restriction)) |
550 (tabify-start (and tabify (cua--tabify-start start end)))) | |
550 (if undo | 551 (if undo |
551 (cua--rectangle-undo-boundary)) | 552 (cua--rectangle-undo-boundary)) |
552 (if (integerp pad) | 553 (if (integerp pad) |
553 (setq pad (cua--rectangle-padding))) | 554 (setq pad (cua--rectangle-virtual-edges))) |
554 (save-excursion | 555 (save-excursion |
555 (save-restriction | 556 (save-restriction |
556 (widen) | 557 (widen) |
557 (when (> (cua--rectangle-corner) 1) | 558 (when (> (cua--rectangle-corner) 1) |
558 (goto-char end) | 559 (goto-char end) |
559 (and (bolp) (not (eolp)) (not (eobp)) | 560 (and (bolp) (not (eolp)) (not (eobp)) |
560 (setq end (1+ end)))) | 561 (setq end (1+ end)))) |
561 (when visible | 562 (when (eq visible t) |
562 (setq start (max (window-start) start)) | 563 (setq start (max (window-start) start)) |
563 (setq end (min (window-end) end))) | 564 (setq end (min (window-end) end))) |
564 (goto-char end) | 565 (goto-char end) |
565 (setq end (line-end-position)) | 566 (setq end (line-end-position)) |
567 (if (and visible (bolp) (not (eobp))) | |
568 (setq end (1+ end))) | |
566 (goto-char start) | 569 (goto-char start) |
567 (setq start (line-beginning-position)) | 570 (setq start (line-beginning-position)) |
568 (narrow-to-region start end) | 571 (narrow-to-region start end) |
569 (goto-char (point-min)) | 572 (goto-char (point-min)) |
570 (while (< (point) (point-max)) | 573 (while (< (point) (point-max)) |
573 (backward-char 1)) | 576 (backward-char 1)) |
574 (if (and tabpad (not pad) (looking-at "\t")) | 577 (if (and tabpad (not pad) (looking-at "\t")) |
575 (forward-char 1)) | 578 (forward-char 1)) |
576 (set-marker m (point)) | 579 (set-marker m (point)) |
577 (move-to-column l pad) | 580 (move-to-column l pad) |
578 (if (and fct (>= (current-column) l) (<= (current-column) r)) | 581 (if (and fct (or visible (and (>= (current-column) l) (<= (current-column) r)))) |
579 (let ((v t) (p (point))) | 582 (let ((v t) (p (point))) |
580 (when sel | 583 (when sel |
581 (if (car (cdr sel)) | 584 (if (car (cdr sel)) |
582 (setq v (looking-at (car sel))) | 585 (setq v (looking-at (car sel))) |
583 (setq v (re-search-forward (car sel) m t)) | 586 (setq v (re-search-forward (car sel) m t)) |
584 (goto-char p)) | 587 (goto-char p)) |
585 (if (car (cdr (cdr sel))) | 588 (if (car (cdr (cdr sel))) |
586 (setq v (null v)))) | 589 (setq v (null v)))) |
587 (if visible | 590 (if visible |
588 (unless (eolp) | 591 (funcall fct p m l r v) |
589 (funcall fct p m l r v)) | |
590 (if v | 592 (if v |
591 (funcall fct p m l r))))) | 593 (funcall fct p m l r))))) |
592 (set-marker m nil) | 594 (set-marker m nil) |
593 (forward-line 1)) | 595 (forward-line 1)) |
594 (if (not visible) | 596 (if (not visible) |
595 (cua--rectangle-bot t)) | 597 (cua--rectangle-bot t)) |
596 (if post-fct | 598 (if post-fct |
597 (funcall post-fct l r)))) | 599 (funcall post-fct l r)) |
600 (when tabify-start | |
601 (tabify tabify-start (point))))) | |
598 (cond | 602 (cond |
599 ((eq keep-clear 'keep) | 603 ((eq keep-clear 'keep) |
600 (cua--keep-active)) | 604 (cua--keep-active)) |
601 ((eq keep-clear 'clear) | 605 ((eq keep-clear 'clear) |
602 (cua--deactivate)) | 606 (cua--deactivate)) |
605 (cua--keep-active))) | 609 (cua--keep-active))) |
606 (setq cua--buffer-and-point-before-command nil))) | 610 (setq cua--buffer-and-point-before-command nil))) |
607 | 611 |
608 (put 'cua--rectangle-operation 'lisp-indent-function 4) | 612 (put 'cua--rectangle-operation 'lisp-indent-function 4) |
609 | 613 |
610 (defun cua--pad-rectangle (&optional pad) | |
611 (if (or pad (cua--rectangle-padding)) | |
612 (cua--rectangle-operation nil nil t t))) | |
613 | |
614 (defun cua--delete-rectangle () | 614 (defun cua--delete-rectangle () |
615 (cua--rectangle-operation nil nil t 2 | 615 (let ((lines 0)) |
616 '(lambda (s e l r) | 616 (if (not (cua--rectangle-virtual-edges)) |
617 (if (and (> e s) (<= e (point-max))) | 617 (cua--rectangle-operation nil nil t 2 t |
618 (delete-region s e))))) | 618 '(lambda (s e l r v) |
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 | |
623 '(lambda (s e l r v) | |
624 (setq lines (1+ lines)) | |
625 (when (and (> e s) (<= e (point-max))) | |
626 (delete-region s e))))) | |
627 lines)) | |
619 | 628 |
620 (defun cua--extract-rectangle () | 629 (defun cua--extract-rectangle () |
621 (let (rect) | 630 (let (rect) |
622 (cua--rectangle-operation nil nil nil 1 | 631 (if (not (cua--rectangle-virtual-edges)) |
623 '(lambda (s e l r) | 632 (cua--rectangle-operation nil nil nil nil nil ; do not tabify |
624 (setq rect (cons (buffer-substring-no-properties s e) rect)))) | 633 '(lambda (s e l r) |
625 (nreverse rect))) | 634 (setq rect (cons (buffer-substring-no-properties s e) rect)))) |
626 | 635 (cua--rectangle-operation nil 1 nil nil nil ; do not tabify |
627 (defun cua--insert-rectangle (rect &optional below) | 636 '(lambda (s e l r v) |
637 (let ((copy t) (bs 0) (as 0) row) | |
638 (if (= s e) (setq e (1+ e))) | |
639 (goto-char s) | |
640 (move-to-column l) | |
641 (if (= (point) (line-end-position)) | |
642 (setq bs (- r l) | |
643 copy nil) | |
644 (skip-chars-forward "\s\t" e) | |
645 (setq bs (- (min r (current-column)) l) | |
646 s (point)) | |
647 (move-to-column r) | |
648 (skip-chars-backward "\s\t" s) | |
649 (setq as (- r (max (current-column) l)) | |
650 e (point))) | |
651 (setq row (if (and copy (> e s)) | |
652 (buffer-substring-no-properties s e) | |
653 "")) | |
654 (when (> bs 0) | |
655 (setq row (concat (make-string bs ?\s) row))) | |
656 (when (> as 0) | |
657 (setq row (concat row (make-string as ?\s)))) | |
658 (setq rect (cons row rect)))))) | |
659 (nreverse rect))) | |
660 | |
661 (defun cua--insert-rectangle (rect &optional below paste-column line-count) | |
628 ;; Insert rectangle as insert-rectangle, but don't set mark and exit with | 662 ;; Insert rectangle as insert-rectangle, but don't set mark and exit with |
629 ;; point at either next to top right or below bottom left corner | 663 ;; point at either next to top right or below bottom left corner |
630 ;; Notice: In overwrite mode, the rectangle is inserted as separate text lines. | 664 ;; Notice: In overwrite mode, the rectangle is inserted as separate text lines. |
631 (if (and below (eq below 'auto)) | 665 (if (eq below 'auto) |
632 (setq below (and (bolp) | 666 (setq below (and (bolp) |
633 (or (eolp) (eobp) (= (1+ (point)) (point-max)))))) | 667 (or (eolp) (eobp) (= (1+ (point)) (point-max)))))) |
668 (unless paste-column | |
669 (setq paste-column (current-column))) | |
634 (let ((lines rect) | 670 (let ((lines rect) |
635 (insertcolumn (current-column)) | |
636 (first t) | 671 (first t) |
672 (tabify-start (cua--tabify-start (point) (point))) | |
673 last-column | |
637 p) | 674 p) |
638 (while (or lines below) | 675 (while (or lines below) |
639 (or first | 676 (or first |
640 (if overwrite-mode | 677 (if overwrite-mode |
641 (insert ?\n) | 678 (insert ?\n) |
642 (forward-line 1) | 679 (forward-line 1) |
643 (or (bolp) (insert ?\n)) | 680 (or (bolp) (insert ?\n)))) |
644 (move-to-column insertcolumn t))) | 681 (unless overwrite-mode |
682 (move-to-column paste-column t)) | |
645 (if (not lines) | 683 (if (not lines) |
646 (setq below nil) | 684 (setq below nil) |
647 (insert-for-yank (car lines)) | 685 (insert-for-yank (car lines)) |
686 (unless last-column | |
687 (setq last-column (current-column))) | |
648 (setq lines (cdr lines)) | 688 (setq lines (cdr lines)) |
649 (and first (not below) | 689 (and first (not below) |
650 (setq p (point)))) | 690 (setq p (point)))) |
651 (setq first nil)) | 691 (setq first nil) |
692 (if (and line-count (= (setq line-count (1- line-count)) 0)) | |
693 (setq lines nil))) | |
694 (when (and line-count last-column (not overwrite-mode)) | |
695 (while (> line-count 0) | |
696 (forward-line 1) | |
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))) | |
652 (and p (not overwrite-mode) | 704 (and p (not overwrite-mode) |
653 (goto-char p)))) | 705 (goto-char p)))) |
654 | 706 |
655 (defun cua--copy-rectangle-as-kill (&optional ring) | 707 (defun cua--copy-rectangle-as-kill (&optional ring) |
656 (if cua--register | 708 (if cua--register |
660 (if ring | 712 (if ring |
661 (kill-new (mapconcat | 713 (kill-new (mapconcat |
662 (function (lambda (row) (concat row "\n"))) | 714 (function (lambda (row) (concat row "\n"))) |
663 killed-rectangle ""))))) | 715 killed-rectangle ""))))) |
664 | 716 |
665 (defun cua--activate-rectangle (&optional force) | 717 (defun cua--activate-rectangle () |
666 ;; Turn on rectangular marking mode by disabling transient mark mode | 718 ;; Turn on rectangular marking mode by disabling transient mark mode |
667 ;; and manually handling highlighting from a post command hook. | 719 ;; and manually handling highlighting from a post command hook. |
668 ;; Be careful if we are already marking a rectangle. | 720 ;; Be careful if we are already marking a rectangle. |
669 (setq cua--rectangle | 721 (setq cua--rectangle |
670 (if (and cua--last-rectangle | 722 (if (and cua--last-rectangle |
671 (eq (car cua--last-rectangle) (current-buffer)) | 723 (eq (car cua--last-rectangle) (current-buffer)) |
672 (eq (car (cdr cua--last-rectangle)) (point))) | 724 (eq (car (cdr cua--last-rectangle)) (point))) |
673 (cdr (cdr cua--last-rectangle)) | 725 (cdr (cdr cua--last-rectangle)) |
674 (cua--rectangle-get-corners | 726 (cua--rectangle-get-corners)) |
675 (and (not buffer-read-only) | 727 cua--status-string (if (cua--rectangle-virtual-edges) " [R]" "") |
676 (or cua-auto-expand-rectangles | |
677 force | |
678 (eq major-mode 'picture-mode))))) | |
679 cua--status-string (if (cua--rectangle-padding) " Pad" "") | |
680 cua--last-rectangle nil)) | 728 cua--last-rectangle nil)) |
681 | 729 |
682 ;; (defvar cua-save-point nil) | 730 ;; (defvar cua-save-point nil) |
683 | 731 |
684 (defun cua--deactivate-rectangle () | 732 (defun cua--deactivate-rectangle () |
696 ;; This function is used to highlight the rectangular region. | 744 ;; This function is used to highlight the rectangular region. |
697 ;; We do this by putting an overlay on each line within the rectangle. | 745 ;; We do this by putting an overlay on each line within the rectangle. |
698 ;; Each overlay extends across all the columns of the rectangle. | 746 ;; Each overlay extends across all the columns of the rectangle. |
699 ;; We try to reuse overlays where possible because this is more efficient | 747 ;; We try to reuse overlays where possible because this is more efficient |
700 ;; and results in less flicker. | 748 ;; and results in less flicker. |
701 ;; If cua--rectangle-padding is nil and the buffer contains tabs or short lines, | 749 ;; If cua--rectangle-virtual-edges is nil and the buffer contains tabs or short lines, |
702 ;; the higlighted region may not be perfectly rectangular. | 750 ;; the higlighted region may not be perfectly rectangular. |
703 (let ((deactivate-mark deactivate-mark) | 751 (let ((deactivate-mark deactivate-mark) |
704 (old cua--rectangle-overlays) | 752 (old cua--rectangle-overlays) |
705 (new nil) | 753 (new nil) |
706 (left (cua--rectangle-left)) | 754 (left (cua--rectangle-left)) |
707 (right (1+ (cua--rectangle-right)))) | 755 (right (1+ (cua--rectangle-right)))) |
708 (when (/= left right) | 756 (when (/= left right) |
709 (sit-for 0) ; make window top/bottom reliable | 757 (sit-for 0) ; make window top/bottom reliable |
710 (cua--rectangle-operation nil t nil nil | 758 (cua--rectangle-operation nil t nil nil nil ; do not tabify |
711 '(lambda (s e l r v) | 759 '(lambda (s e l r v) |
712 (let ((rface (if v 'cua-rectangle-face 'cua-rectangle-noselect-face)) | 760 (let ((rface (if v 'cua-rectangle 'cua-rectangle-noselect)) |
713 overlay) | 761 overlay bs ms as) |
714 ;; Trim old leading overlays. | 762 (when (cua--rectangle-virtual-edges) |
715 (if (= s e) (setq e (1+ e))) | 763 (let ((lb (line-beginning-position)) |
764 (le (line-end-position)) | |
765 cl cl0 pl cr cr0 pr) | |
766 (goto-char s) | |
767 (setq cl (move-to-column l) | |
768 pl (point)) | |
769 (setq cr (move-to-column r) | |
770 pr (point)) | |
771 (if (= lb pl) | |
772 (setq cl0 0) | |
773 (goto-char (1- pl)) | |
774 (setq cl0 (current-column))) | |
775 (if (= lb le) | |
776 (setq cr0 0) | |
777 (goto-char (1- pr)) | |
778 (setq cr0 (current-column))) | |
779 (unless (and (= cl l) (= cr r)) | |
780 (when (/= cl l) | |
781 (setq bs (propertize | |
782 (make-string | |
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))) | |
786 (if (/= pl le) | |
787 (setq s (1- s)))) | |
788 (cond | |
789 ((= cr r) | |
790 (if (and (/= pr le) | |
791 (/= cr0 (1- cr)) | |
792 (or bs (/= cr0 (- cr tab-width))) | |
793 (/= (mod cr tab-width) 0)) | |
794 (setq e (1- e)))) | |
795 ((= cr cl) | |
796 (setq ms (propertize | |
797 (make-string | |
798 (- r l) | |
799 (if cua--virtual-edges-debug ?, ?\s)) | |
800 'face rface)) | |
801 (if (cua--rectangle-right-side) | |
802 (put-text-property (1- (length ms)) (length ms) 'cursor t ms) | |
803 (put-text-property 0 1 'cursor t ms)) | |
804 (setq bs (concat bs ms)) | |
805 (setq rface nil)) | |
806 (t | |
807 (setq as (propertize | |
808 (make-string | |
809 (- r cr0 (if (= le pr) 1 0)) | |
810 (if cua--virtual-edges-debug ?~ ?\s)) | |
811 'face rface)) | |
812 (if (cua--rectangle-right-side) | |
813 (put-text-property (1- (length as)) (length as) 'cursor t as) | |
814 (put-text-property 0 1 'cursor t as)) | |
815 (if (/= pr le) | |
816 (setq e (1- e)))))))) | |
817 ;; Trim old leading overlays. | |
716 (while (and old | 818 (while (and old |
717 (setq overlay (car old)) | 819 (setq overlay (car old)) |
718 (< (overlay-start overlay) s) | 820 (< (overlay-start overlay) s) |
719 (/= (overlay-end overlay) e)) | 821 (/= (overlay-end overlay) e)) |
720 (delete-overlay overlay) | 822 (delete-overlay overlay) |
726 (= (overlay-end overlay) e))) | 828 (= (overlay-end overlay) e))) |
727 (progn | 829 (progn |
728 (move-overlay overlay s e) | 830 (move-overlay overlay s e) |
729 (setq old (cdr old))) | 831 (setq old (cdr old))) |
730 (setq overlay (make-overlay s e))) | 832 (setq overlay (make-overlay s e))) |
731 (overlay-put overlay 'face rface) | 833 (overlay-put overlay 'before-string bs) |
732 (setq new (cons overlay new)))))) | 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)))))) | |
733 ;; Trim old trailing overlays. | 839 ;; Trim old trailing overlays. |
734 (mapcar (function delete-overlay) old) | 840 (mapcar (function delete-overlay) old) |
735 (setq cua--rectangle-overlays (nreverse new)))) | 841 (setq cua--rectangle-overlays (nreverse new)))) |
736 | 842 |
737 (defun cua--indent-rectangle (&optional ch to-col clear) | 843 (defun cua--indent-rectangle (&optional ch to-col clear) |
738 ;; Indent current rectangle. | 844 ;; Indent current rectangle. |
739 (let ((col (cua--rectangle-insert-col)) | 845 (let ((col (cua--rectangle-insert-col)) |
740 (pad (cua--rectangle-padding)) | 846 (pad (cua--rectangle-virtual-edges)) |
741 indent) | 847 indent) |
742 (cua--rectangle-operation (if clear 'clear 'corners) nil t pad | 848 (cua--rectangle-operation (if clear 'clear 'corners) nil t pad nil |
743 '(lambda (s e l r) | 849 '(lambda (s e l r) |
744 (move-to-column col pad) | 850 (move-to-column col pad) |
745 (if (and (eolp) | 851 (if (and (eolp) |
746 (< (current-column) col)) | 852 (< (current-column) col)) |
747 (move-to-column col t)) | 853 (move-to-column col t)) |
873 (cua--deactivate)) | 979 (cua--deactivate)) |
874 | 980 |
875 (defun cua-rotate-rectangle () | 981 (defun cua-rotate-rectangle () |
876 (interactive) | 982 (interactive) |
877 (cua--rectangle-corner (if (= (cua--rectangle-left) (cua--rectangle-right)) 0 1)) | 983 (cua--rectangle-corner (if (= (cua--rectangle-left) (cua--rectangle-right)) 0 1)) |
878 (cua--rectangle-set-corners)) | 984 (cua--rectangle-set-corners) |
879 | 985 (if (cua--rectangle-virtual-edges) |
880 (defun cua-toggle-rectangle-padding () | 986 (setq cua--buffer-and-point-before-command nil))) |
987 | |
988 (defun cua-toggle-rectangle-virtual-edges () | |
989 (interactive) | |
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]")) | |
993 (cua--keep-active)) | |
994 | |
995 (defun cua-do-rectangle-padding () | |
881 (interactive) | 996 (interactive) |
882 (if buffer-read-only | 997 (if buffer-read-only |
883 (message "Cannot do padding in read-only buffer.") | 998 (message "Cannot do padding in read-only buffer") |
884 (cua--rectangle-padding t (not (cua--rectangle-padding))) | 999 (cua--rectangle-operation nil nil t t t) |
885 (cua--pad-rectangle) | |
886 (cua--rectangle-set-corners)) | |
887 (setq cua--status-string (and (cua--rectangle-padding) " Pad")) | |
888 (cua--keep-active)) | |
889 | |
890 (defun cua-do-rectangle-padding () | |
891 (interactive) | |
892 (if buffer-read-only | |
893 (message "Cannot do padding in read-only buffer.") | |
894 (cua--pad-rectangle t) | |
895 (cua--rectangle-set-corners)) | 1000 (cua--rectangle-set-corners)) |
896 (cua--keep-active)) | 1001 (cua--keep-active)) |
897 | 1002 |
898 (defun cua-open-rectangle () | 1003 (defun cua-open-rectangle () |
899 "Blank out CUA rectangle, shifting text right. | 1004 "Blank out CUA rectangle, shifting text right. |
900 The text previously in the region is not overwritten by the blanks, | 1005 The text previously in the region is not overwritten by the blanks, |
901 but instead winds up to the right of the rectangle." | 1006 but instead winds up to the right of the rectangle." |
902 (interactive) | 1007 (interactive) |
903 (cua--rectangle-operation 'corners nil t 1 | 1008 (cua--rectangle-operation 'corners nil t 1 nil |
904 '(lambda (s e l r) | 1009 '(lambda (s e l r) |
905 (skip-chars-forward " \t") | 1010 (skip-chars-forward " \t") |
906 (let ((ws (- (current-column) l)) | 1011 (let ((ws (- (current-column) l)) |
907 (p (point))) | 1012 (p (point))) |
908 (skip-chars-backward " \t") | 1013 (skip-chars-backward " \t") |
913 "Delete all whitespace starting at left edge of CUA rectangle. | 1018 "Delete all whitespace starting at left edge of CUA rectangle. |
914 On each line in the rectangle, all continuous whitespace starting | 1019 On each line in the rectangle, all continuous whitespace starting |
915 at that column is deleted. | 1020 at that column is deleted. |
916 With prefix arg, also delete whitespace to the left of that column." | 1021 With prefix arg, also delete whitespace to the left of that column." |
917 (interactive "P") | 1022 (interactive "P") |
918 (cua--rectangle-operation 'clear nil t 1 | 1023 (cua--rectangle-operation 'clear nil t 1 nil |
919 '(lambda (s e l r) | 1024 '(lambda (s e l r) |
920 (when arg | 1025 (when arg |
921 (skip-syntax-backward " " (line-beginning-position)) | 1026 (skip-syntax-backward " " (line-beginning-position)) |
922 (setq s (point))) | 1027 (setq s (point))) |
923 (skip-syntax-forward " " (line-end-position)) | 1028 (skip-syntax-forward " " (line-end-position)) |
925 | 1030 |
926 (defun cua-blank-rectangle () | 1031 (defun cua-blank-rectangle () |
927 "Blank out CUA rectangle. | 1032 "Blank out CUA rectangle. |
928 The text previously in the rectangle is overwritten by the blanks." | 1033 The text previously in the rectangle is overwritten by the blanks." |
929 (interactive) | 1034 (interactive) |
930 (cua--rectangle-operation 'keep nil nil 1 | 1035 (cua--rectangle-operation 'keep nil nil 1 nil |
931 '(lambda (s e l r) | 1036 '(lambda (s e l r) |
932 (goto-char e) | 1037 (goto-char e) |
933 (skip-syntax-forward " " (line-end-position)) | 1038 (skip-syntax-forward " " (line-end-position)) |
934 (setq e (point)) | 1039 (setq e (point)) |
935 (let ((column (current-column))) | 1040 (let ((column (current-column))) |
940 | 1045 |
941 (defun cua-align-rectangle () | 1046 (defun cua-align-rectangle () |
942 "Align rectangle lines to left column." | 1047 "Align rectangle lines to left column." |
943 (interactive) | 1048 (interactive) |
944 (let (x) | 1049 (let (x) |
945 (cua--rectangle-operation 'clear nil t t | 1050 (cua--rectangle-operation 'clear nil t t nil |
946 '(lambda (s e l r) | 1051 '(lambda (s e l r) |
947 (let ((b (line-beginning-position))) | 1052 (let ((b (line-beginning-position))) |
948 (skip-syntax-backward "^ " b) | 1053 (skip-syntax-backward "^ " b) |
949 (skip-syntax-backward " " b) | 1054 (skip-syntax-backward " " b) |
950 (setq s (point))) | 1055 (setq s (point))) |
982 | 1087 |
983 (defun cua-string-rectangle (string) | 1088 (defun cua-string-rectangle (string) |
984 "Replace CUA rectangle contents with STRING on each line. | 1089 "Replace CUA rectangle contents with STRING on each line. |
985 The length of STRING need not be the same as the rectangle width." | 1090 The length of STRING need not be the same as the rectangle width." |
986 (interactive "sString rectangle: ") | 1091 (interactive "sString rectangle: ") |
987 (cua--rectangle-operation 'keep nil t t | 1092 (cua--rectangle-operation 'keep nil t t nil |
988 '(lambda (s e l r) | 1093 '(lambda (s e l r) |
989 (delete-region s e) | 1094 (delete-region s e) |
990 (skip-chars-forward " \t") | 1095 (skip-chars-forward " \t") |
991 (let ((ws (- (current-column) l))) | 1096 (let ((ws (- (current-column) l))) |
992 (delete-region s (point)) | 1097 (delete-region s (point)) |
994 (indent-to (+ (current-column) ws)))) | 1099 (indent-to (+ (current-column) ws)))) |
995 (unless (cua--rectangle-restriction) | 1100 (unless (cua--rectangle-restriction) |
996 '(lambda (l r) | 1101 '(lambda (l r) |
997 (cua--rectangle-right (max l (+ l (length string) -1))))))) | 1102 (cua--rectangle-right (max l (+ l (length string) -1))))))) |
998 | 1103 |
999 (defun cua-fill-char-rectangle (ch) | 1104 (defun cua-fill-char-rectangle (character) |
1000 "Replace CUA rectangle contents with CHARACTER." | 1105 "Replace CUA rectangle contents with CHARACTER." |
1001 (interactive "cFill rectangle with character: ") | 1106 (interactive "cFill rectangle with character: ") |
1002 (cua--rectangle-operation 'clear nil t 1 | 1107 (cua--rectangle-operation 'clear nil t 1 nil |
1003 '(lambda (s e l r) | 1108 '(lambda (s e l r) |
1004 (delete-region s e) | 1109 (delete-region s e) |
1005 (move-to-column l t) | 1110 (move-to-column l t) |
1006 (insert-char ch (- r l))))) | 1111 (insert-char character (- r l))))) |
1007 | 1112 |
1008 (defun cua-replace-in-rectangle (regexp newtext) | 1113 (defun cua-replace-in-rectangle (regexp newtext) |
1009 "Replace REGEXP with NEWTEXT in each line of CUA rectangle." | 1114 "Replace REGEXP with NEWTEXT in each line of CUA rectangle." |
1010 (interactive "sReplace regexp: \nsNew text: ") | 1115 (interactive "sReplace regexp: \nsNew text: ") |
1011 (if buffer-read-only | 1116 (if buffer-read-only |
1012 (message "Cannot replace in read-only buffer") | 1117 (message "Cannot replace in read-only buffer") |
1013 (cua--rectangle-operation 'keep nil t 1 | 1118 (cua--rectangle-operation 'keep nil t 1 nil |
1014 '(lambda (s e l r) | 1119 '(lambda (s e l r) |
1015 (if (re-search-forward regexp e t) | 1120 (if (re-search-forward regexp e t) |
1016 (replace-match newtext nil nil)))))) | 1121 (replace-match newtext nil nil)))))) |
1017 | 1122 |
1018 (defun cua-incr-rectangle (increment) | 1123 (defun cua-incr-rectangle (increment) |
1019 "Increment each line of CUA rectangle by prefix amount." | 1124 "Increment each line of CUA rectangle by prefix amount." |
1020 (interactive "p") | 1125 (interactive "p") |
1021 (cua--rectangle-operation 'keep nil t 1 | 1126 (cua--rectangle-operation 'keep nil t 1 nil |
1022 '(lambda (s e l r) | 1127 '(lambda (s e l r) |
1023 (cond | 1128 (cond |
1024 ((re-search-forward "0x\\([0-9a-fA-F]+\\)" e t) | 1129 ((re-search-forward "0x\\([0-9a-fA-F]+\\)" e t) |
1025 (let* ((txt (buffer-substring-no-properties (match-beginning 1) (match-end 1))) | 1130 (let* ((txt (buffer-substring-no-properties (match-beginning 1) (match-end 1))) |
1026 (n (string-to-number txt 16)) | 1131 (n (string-to-number txt 16)) |
1033 (fmt (format "%%%s%dd" prefix (length txt)))) | 1138 (fmt (format "%%%s%dd" prefix (length txt)))) |
1034 (replace-match (format fmt (+ n increment))))) | 1139 (replace-match (format fmt (+ n increment))))) |
1035 (t nil))))) | 1140 (t nil))))) |
1036 | 1141 |
1037 (defvar cua--rectangle-seq-format "%d" | 1142 (defvar cua--rectangle-seq-format "%d" |
1038 "Last format used by cua-sequence-rectangle.") | 1143 "Last format used by `cua-sequence-rectangle'.") |
1039 | 1144 |
1040 (defun cua-sequence-rectangle (first incr fmt) | 1145 (defun cua-sequence-rectangle (first incr format) |
1041 "Resequence each line of CUA rectangle starting from FIRST. | 1146 "Resequence each line of CUA rectangle starting from FIRST. |
1042 The numbers are formatted according to the FORMAT string." | 1147 The numbers are formatted according to the FORMAT string." |
1043 (interactive | 1148 (interactive |
1044 (list (if current-prefix-arg | 1149 (list (if current-prefix-arg |
1045 (prefix-numeric-value current-prefix-arg) | 1150 (prefix-numeric-value current-prefix-arg) |
1046 (string-to-number | 1151 (string-to-number |
1047 (read-string "Start value: (0) " nil nil "0"))) | 1152 (read-string "Start value: (0) " nil nil "0"))) |
1048 (string-to-number | 1153 (string-to-number |
1049 (read-string "Increment: (1) " nil nil "1")) | 1154 (read-string "Increment: (1) " nil nil "1")) |
1050 (read-string (concat "Format: (" cua--rectangle-seq-format ") ")))) | 1155 (read-string (concat "Format: (" cua--rectangle-seq-format ") ")))) |
1051 (if (= (length fmt) 0) | 1156 (if (= (length format) 0) |
1052 (setq fmt cua--rectangle-seq-format) | 1157 (setq format cua--rectangle-seq-format) |
1053 (setq cua--rectangle-seq-format fmt)) | 1158 (setq cua--rectangle-seq-format format)) |
1054 (cua--rectangle-operation 'clear nil t 1 | 1159 (cua--rectangle-operation 'clear nil t 1 nil |
1055 '(lambda (s e l r) | 1160 '(lambda (s e l r) |
1056 (delete-region s e) | 1161 (delete-region s e) |
1057 (insert (format fmt first)) | 1162 (insert (format format first)) |
1058 (setq first (+ first incr))))) | 1163 (setq first (+ first incr))))) |
1164 | |
1165 (defmacro cua--convert-rectangle-as (command tabify) | |
1166 `(cua--rectangle-operation 'clear nil nil nil ,tabify | |
1167 '(lambda (s e l r) | |
1168 (,command s e)))) | |
1059 | 1169 |
1060 (defun cua-upcase-rectangle () | 1170 (defun cua-upcase-rectangle () |
1061 "Convert the rectangle to upper case." | 1171 "Convert the rectangle to upper case." |
1062 (interactive) | 1172 (interactive) |
1063 (cua--rectangle-operation 'clear nil nil nil | 1173 (cua--convert-rectangle-as upcase-region nil)) |
1064 '(lambda (s e l r) | |
1065 (upcase-region s e)))) | |
1066 | 1174 |
1067 (defun cua-downcase-rectangle () | 1175 (defun cua-downcase-rectangle () |
1068 "Convert the rectangle to lower case." | 1176 "Convert the rectangle to lower case." |
1069 (interactive) | 1177 (interactive) |
1070 (cua--rectangle-operation 'clear nil nil nil | 1178 (cua--convert-rectangle-as downcase-region nil)) |
1071 '(lambda (s e l r) | 1179 |
1072 (downcase-region s e)))) | 1180 (defun cua-upcase-initials-rectangle () |
1181 "Convert the rectangle initials to upper case." | |
1182 (interactive) | |
1183 (cua--convert-rectangle-as upcase-initials-region nil)) | |
1184 | |
1185 (defun cua-capitalize-rectangle () | |
1186 "Convert the rectangle to proper case." | |
1187 (interactive) | |
1188 (cua--convert-rectangle-as capitalize-region nil)) | |
1073 | 1189 |
1074 | 1190 |
1075 ;;; Replace/rearrange text in current rectangle | 1191 ;;; Replace/rearrange text in current rectangle |
1076 | 1192 |
1077 (defun cua--rectangle-aux-replace (width adjust keep replace pad format-fct &optional setup-fct) | 1193 (defun cua--rectangle-aux-replace (width adjust keep replace pad format-fct &optional setup-fct) |
1103 (kill-buffer auxbuf)) | 1219 (kill-buffer auxbuf)) |
1104 (when replace | 1220 (when replace |
1105 (setq z (reverse z)) | 1221 (setq z (reverse z)) |
1106 (if cua--debug | 1222 (if cua--debug |
1107 (print z auxbuf)) | 1223 (print z auxbuf)) |
1108 (cua--rectangle-operation nil nil t pad | 1224 (cua--rectangle-operation nil nil t pad nil |
1109 '(lambda (s e l r) | 1225 '(lambda (s e l r) |
1110 (let (cc) | 1226 (let (cc) |
1111 (goto-char e) | 1227 (goto-char e) |
1112 (skip-chars-forward " \t") | 1228 (skip-chars-forward " \t") |
1113 (setq cc (current-column)) | 1229 (setq cc (current-column)) |
1124 (delete-region (point) y) | 1240 (delete-region (point) y) |
1125 (setq tr (1+ tr))) | 1241 (setq tr (1+ tr))) |
1126 (setq z (cdr z))) | 1242 (setq z (cdr z))) |
1127 (if cua--debug | 1243 (if cua--debug |
1128 (print (list (current-column) cc) auxbuf)) | 1244 (print (list (current-column) cc) auxbuf)) |
1245 (just-one-space 0) | |
1129 (indent-to cc)))) | 1246 (indent-to cc)))) |
1130 (if (> tr 0) | 1247 (if (> tr 0) |
1131 (message "Warning: Truncated %d row%s" tr (if (> tr 1) "s" ""))) | 1248 (message "Warning: Truncated %d row%s" tr (if (> tr 1) "s" ""))) |
1132 (if adjust | 1249 (if adjust |
1133 (cua--rectangle-right (+ (cua--rectangle-left) w -1))) | 1250 (cua--rectangle-right (+ (cua--rectangle-left) w -1))) |
1219 | 1336 |
1220 (defun cua-delete-char-rectangle () | 1337 (defun cua-delete-char-rectangle () |
1221 "Delete char to left or right of rectangle." | 1338 "Delete char to left or right of rectangle." |
1222 (interactive) | 1339 (interactive) |
1223 (let ((col (cua--rectangle-insert-col)) | 1340 (let ((col (cua--rectangle-insert-col)) |
1224 (pad (cua--rectangle-padding)) | 1341 (pad (cua--rectangle-virtual-edges)) |
1225 indent) | 1342 indent) |
1226 (cua--rectangle-operation 'corners nil t pad | 1343 (cua--rectangle-operation 'corners nil t pad nil |
1227 '(lambda (s e l r) | 1344 '(lambda (s e l r) |
1228 (move-to-column | 1345 (move-to-column |
1229 (if (cua--rectangle-right-side t) | 1346 (if (cua--rectangle-right-side t) |
1230 (max (1+ r) col) l) | 1347 (max (1+ r) col) l) |
1231 pad) | 1348 pad) |
1240 (aset cua--rectangle 2 (- l indent)) | 1357 (aset cua--rectangle 2 (- l indent)) |
1241 (aset cua--rectangle 3 (- r indent 1))))))) | 1358 (aset cua--rectangle 3 (- r indent 1))))))) |
1242 | 1359 |
1243 (defun cua-help-for-rectangle (&optional help) | 1360 (defun cua-help-for-rectangle (&optional help) |
1244 (interactive) | 1361 (interactive) |
1245 (let ((M (if cua-use-hyper-key " H-" " M-"))) | 1362 (let ((M (cond ((eq cua--rectangle-modifier-key 'hyper) " H-") |
1363 ((eq cua--rectangle-modifier-key 'super) " s-") | |
1364 (t " M-")))) | |
1246 (message | 1365 (message |
1247 (concat (if help "C-?:help" "") | 1366 (concat (if help "C-?:help" "") |
1248 M "p:pad" M "o:open" M "c:close" M "b:blank" | 1367 M "p:pad" M "o:open" M "c:close" M "b:blank" |
1249 M "s:string" M "f:fill" M "i:incr" M "n:seq")))) | 1368 M "s:string" M "f:fill" M "i:incr" M "n:seq")))) |
1250 | 1369 |
1257 (cua--deactivate-rectangle)) | 1376 (cua--deactivate-rectangle)) |
1258 (setq cua--last-rectangle nil)) | 1377 (setq cua--last-rectangle nil)) |
1259 | 1378 |
1260 (defun cua--rectangle-post-command () | 1379 (defun cua--rectangle-post-command () |
1261 (if cua--restored-rectangle | 1380 (if cua--restored-rectangle |
1262 (setq cua--rectangle cua--restored-rectangle | 1381 (progn |
1263 cua--restored-rectangle nil | 1382 (setq cua--rectangle cua--restored-rectangle |
1264 mark-active t | 1383 cua--restored-rectangle nil |
1265 deactivate-mark nil) | 1384 mark-active t |
1385 deactivate-mark nil) | |
1386 (cua--rectangle-set-corners)) | |
1266 (when (and cua--rectangle cua--buffer-and-point-before-command | 1387 (when (and cua--rectangle cua--buffer-and-point-before-command |
1267 (equal (car cua--buffer-and-point-before-command) (current-buffer)) | 1388 (equal (car cua--buffer-and-point-before-command) (current-buffer)) |
1268 (not (= (cdr cua--buffer-and-point-before-command) (point)))) | 1389 (not (= (cdr cua--buffer-and-point-before-command) (point)))) |
1269 (if (cua--rectangle-right-side) | 1390 (if (cua--rectangle-right-side) |
1270 (cua--rectangle-right (current-column)) | 1391 (cua--rectangle-right (current-column)) |
1271 (cua--rectangle-left (current-column))) | 1392 (cua--rectangle-left (current-column))) |
1272 (if (>= (cua--rectangle-corner) 2) | 1393 (if (>= (cua--rectangle-corner) 2) |
1273 (cua--rectangle-bot t) | 1394 (cua--rectangle-bot t) |
1274 (cua--rectangle-top t)) | 1395 (cua--rectangle-top t)))) |
1275 (if (cua--rectangle-padding) | |
1276 (setq unread-command-events | |
1277 (cons (if cua-use-hyper-key ?\H-P ?\M-P) unread-command-events))))) | |
1278 (if cua--rectangle | 1396 (if cua--rectangle |
1279 (if (and mark-active | 1397 (if (and mark-active |
1280 (not deactivate-mark)) | 1398 (not deactivate-mark)) |
1281 (cua--highlight-rectangle) | 1399 (cua--highlight-rectangle) |
1282 (cua--deactivate-rectangle)))) | 1400 (cua--deactivate-rectangle)) |
1283 | 1401 (when cua--rectangle-overlays |
1402 ;; clean-up after revert-buffer | |
1403 (mapcar (function delete-overlay) cua--rectangle-overlays) | |
1404 (setq cua--rectangle-overlays nil) | |
1405 (setq deactivate-mark t))) | |
1406 (when cua--rect-undo-set-point | |
1407 (goto-char cua--rect-undo-set-point) | |
1408 (setq cua--rect-undo-set-point nil))) | |
1284 | 1409 |
1285 ;;; Initialization | 1410 ;;; Initialization |
1286 | 1411 |
1287 (defun cua--rect-M/H-key (key cmd) | 1412 (defun cua--rect-M/H-key (key cmd) |
1288 (cua--M/H-key cua--rectangle-keymap key cmd)) | 1413 (cua--M/H-key cua--rectangle-keymap key cmd)) |
1289 | 1414 |
1290 (defun cua--rectangle-on-off (on) | |
1291 (cancel-function-timers 'cua--tidy-undo-lists) | |
1292 (if on | |
1293 (run-with-idle-timer 10 t 'cua--tidy-undo-lists) | |
1294 (cua--tidy-undo-lists t))) | |
1295 | |
1296 (defun cua--init-rectangles () | 1415 (defun cua--init-rectangles () |
1297 (unless (face-background 'cua-rectangle-face) | 1416 (define-key cua--rectangle-keymap [(control return)] 'cua-clear-rectangle-mark) |
1298 (copy-face 'region 'cua-rectangle-face) | 1417 (define-key cua--region-keymap [(control return)] 'cua-toggle-rectangle-mark) |
1299 (set-face-background 'cua-rectangle-face "maroon") | 1418 (unless (eq cua--rectangle-modifier-key 'meta) |
1300 (set-face-foreground 'cua-rectangle-face "white")) | 1419 (cua--rect-M/H-key ?\s 'cua-clear-rectangle-mark) |
1301 | 1420 (cua--M/H-key cua--region-keymap ?\s 'cua-toggle-rectangle-mark)) |
1302 (unless (face-background 'cua-rectangle-noselect-face) | |
1303 (copy-face 'region 'cua-rectangle-noselect-face) | |
1304 (set-face-background 'cua-rectangle-noselect-face "dimgray") | |
1305 (set-face-foreground 'cua-rectangle-noselect-face "white")) | |
1306 | |
1307 (unless (eq cua-use-hyper-key 'only) | |
1308 (define-key cua--rectangle-keymap [(shift return)] 'cua-clear-rectangle-mark) | |
1309 (define-key cua--region-keymap [(shift return)] 'cua-toggle-rectangle-mark)) | |
1310 (when cua-use-hyper-key | |
1311 (cua--rect-M/H-key 'space 'cua-clear-rectangle-mark) | |
1312 (cua--M/H-key cua--region-keymap 'space 'cua-toggle-rectangle-mark)) | |
1313 | 1421 |
1314 (define-key cua--rectangle-keymap [remap copy-region-as-kill] 'cua-copy-rectangle) | 1422 (define-key cua--rectangle-keymap [remap copy-region-as-kill] 'cua-copy-rectangle) |
1315 (define-key cua--rectangle-keymap [remap kill-ring-save] 'cua-copy-rectangle) | 1423 (define-key cua--rectangle-keymap [remap kill-ring-save] 'cua-copy-rectangle) |
1316 (define-key cua--rectangle-keymap [remap kill-region] 'cua-cut-rectangle) | 1424 (define-key cua--rectangle-keymap [remap kill-region] 'cua-cut-rectangle) |
1317 (define-key cua--rectangle-keymap [remap delete-char] 'cua-delete-rectangle) | 1425 (define-key cua--rectangle-keymap [remap delete-char] 'cua-delete-rectangle) |
1366 (cua--rect-M/H-key ?k 'cua-cut-rectangle-as-text) | 1474 (cua--rect-M/H-key ?k 'cua-cut-rectangle-as-text) |
1367 (cua--rect-M/H-key ?l 'cua-downcase-rectangle) | 1475 (cua--rect-M/H-key ?l 'cua-downcase-rectangle) |
1368 (cua--rect-M/H-key ?m 'cua-copy-rectangle-as-text) | 1476 (cua--rect-M/H-key ?m 'cua-copy-rectangle-as-text) |
1369 (cua--rect-M/H-key ?n 'cua-sequence-rectangle) | 1477 (cua--rect-M/H-key ?n 'cua-sequence-rectangle) |
1370 (cua--rect-M/H-key ?o 'cua-open-rectangle) | 1478 (cua--rect-M/H-key ?o 'cua-open-rectangle) |
1371 (cua--rect-M/H-key ?p 'cua-toggle-rectangle-padding) | 1479 (cua--rect-M/H-key ?p 'cua-toggle-rectangle-virtual-edges) |
1372 (cua--rect-M/H-key ?P 'cua-do-rectangle-padding) | 1480 (cua--rect-M/H-key ?P 'cua-do-rectangle-padding) |
1373 (cua--rect-M/H-key ?q 'cua-refill-rectangle) | 1481 (cua--rect-M/H-key ?q 'cua-refill-rectangle) |
1374 (cua--rect-M/H-key ?r 'cua-replace-in-rectangle) | 1482 (cua--rect-M/H-key ?r 'cua-replace-in-rectangle) |
1375 (cua--rect-M/H-key ?R 'cua-reverse-rectangle) | 1483 (cua--rect-M/H-key ?R 'cua-reverse-rectangle) |
1376 (cua--rect-M/H-key ?s 'cua-string-rectangle) | 1484 (cua--rect-M/H-key ?s 'cua-string-rectangle) |
1380 (cua--rect-M/H-key ?' 'cua-restrict-prefix-rectangle) | 1488 (cua--rect-M/H-key ?' 'cua-restrict-prefix-rectangle) |
1381 (cua--rect-M/H-key ?/ 'cua-restrict-regexp-rectangle) | 1489 (cua--rect-M/H-key ?/ 'cua-restrict-regexp-rectangle) |
1382 | 1490 |
1383 (setq cua--rectangle-initialized t)) | 1491 (setq cua--rectangle-initialized t)) |
1384 | 1492 |
1493 ;;; arch-tag: b730df53-17b9-4a89-bd63-4a71ec196731 | |
1385 ;;; cua-rect.el ends here | 1494 ;;; cua-rect.el ends here |