Mercurial > emacs
comparison lisp/emulation/cua-base.el @ 89969:3219f94257bc
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-34
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-514
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-522
Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sat, 04 Sep 2004 09:14:28 +0000 |
parents | 97905c4f1a42 8425c441196c |
children | e24e2e78deda |
comparison
equal
deleted
inserted
replaced
89968:1e9fa4848335 | 89969:3219f94257bc |
---|---|
139 ;; Emacs' normal rectangle support is based on interpreting the region | 139 ;; Emacs' normal rectangle support is based on interpreting the region |
140 ;; between the mark and point as a "virtual rectangle", and using a | 140 ;; between the mark and point as a "virtual rectangle", and using a |
141 ;; completely separate set of "rectangle commands" [C-x r ...] on the | 141 ;; completely separate set of "rectangle commands" [C-x r ...] on the |
142 ;; region to copy, kill, fill a.s.o. the virtual rectangle. | 142 ;; region to copy, kill, fill a.s.o. the virtual rectangle. |
143 ;; | 143 ;; |
144 ;; cua-mode's superior rectangle support is based on using a true visual | 144 ;; cua-mode's superior rectangle support uses a true visual |
145 ;; representation of the selected rectangle. To start a rectangle, use | 145 ;; representation of the selected rectangle, i.e. it highlights the |
146 ;; [S-return] and extend it using the normal movement keys (up, down, | 146 ;; actual part of the buffer that is currently selected as part of the |
147 ;; left, right, home, end, C-home, C-end). Once the rectangle has the | 147 ;; rectangle. Unlike emacs' traditional rectangle commands, the |
148 ;; desired size, you can cut or copy it using C-x and C-c (or C-w and M-w), | 148 ;; selected rectangle always as straight left and right edges, even |
149 ;; and you can subsequently insert it - as a rectangle - using C-v (or | 149 ;; when those are in the middle of a TAB character or beyond the end |
150 ;; C-y). So the only new command you need to know to work with | 150 ;; of the current line. And it does this without actually modifying |
151 ;; cua-mode rectangles is S-return! | 151 ;; the buffer contents (it uses display overlays to visualize the |
152 ;; virtual dimensions of the rectangle). | |
153 ;; | |
154 ;; This means that cua-mode's rectangles are not limited to the actual | |
155 ;; contents of the buffer, so if the cursor is currently at the end of a | |
156 ;; short line, you can still extend the rectangle to include more columns | |
157 ;; of longer lines in the same rectangle. And you can also have the | |
158 ;; left edge of a rectangle start in the middle of a TAB character. | |
159 ;; Sounds strange? Try it! | |
160 ;; | |
161 ;; To start a rectangle, use [S-return] and extend it using the normal | |
162 ;; movement keys (up, down, left, right, home, end, C-home, | |
163 ;; C-end). Once the rectangle has the desired size, you can cut or | |
164 ;; copy it using C-x and C-c (or C-w and M-w), and you can | |
165 ;; subsequently insert it - as a rectangle - using C-v (or C-y). So | |
166 ;; the only new command you need to know to work with cua-mode | |
167 ;; rectangles is S-return! | |
152 ;; | 168 ;; |
153 ;; Normally, when you paste a rectangle using C-v (C-y), each line of | 169 ;; Normally, when you paste a rectangle using C-v (C-y), each line of |
154 ;; the rectangle is inserted into the existing lines in the buffer. | 170 ;; the rectangle is inserted into the existing lines in the buffer. |
155 ;; If overwrite-mode is active when you paste a rectangle, it is | 171 ;; If overwrite-mode is active when you paste a rectangle, it is |
156 ;; inserted as normal (multi-line) text. | 172 ;; inserted as normal (multi-line) text. |
157 ;; | 173 ;; |
158 ;; Furthermore, cua-mode's rectangles are not limited to the actual | 174 ;; If you prefer the traditional rectangle marking (i.e. don't want |
159 ;; contents of the buffer, so if the cursor is currently at the end of a | 175 ;; straight edges), [M-p] toggles this for the current rectangle, |
160 ;; short line, you can still extend the rectangle to include more columns | 176 ;; or you can customize cua-virtual-rectangle-edges. |
161 ;; of longer lines in the same rectangle. Sounds strange? Try it! | |
162 ;; | |
163 ;; You can enable padding for just this rectangle by pressing [M-p]; | |
164 ;; this works like entering `picture-mode' where the tabs and spaces | |
165 ;; are automatically converted/inserted to make the rectangle truly | |
166 ;; rectangular. Or you can do it for all rectangles by setting the | |
167 ;; `cua-auto-expand-rectangles' variable. | |
168 | 177 |
169 ;; And there's more: If you want to extend or reduce the size of the | 178 ;; And there's more: If you want to extend or reduce the size of the |
170 ;; rectangle in one of the other corners of the rectangle, just use | 179 ;; rectangle in one of the other corners of the rectangle, just use |
171 ;; [return] to move the cursor to the "next" corner. Or you can use | 180 ;; [return] to move the cursor to the "next" corner. Or you can use |
172 ;; the [M-up], [M-down], [M-left], and [M-right] keys to move the | 181 ;; the [M-up], [M-down], [M-left], and [M-right] keys to move the |
202 ;; [M-m] copies the rectangle as normal multi-line text (for paste) | 211 ;; [M-m] copies the rectangle as normal multi-line text (for paste) |
203 ;; [M-n] fills each line of the rectangle with increasing numbers using | 212 ;; [M-n] fills each line of the rectangle with increasing numbers using |
204 ;; a supplied format string (prompt) | 213 ;; a supplied format string (prompt) |
205 ;; [M-o] opens the rectangle by moving the highlighted text to the | 214 ;; [M-o] opens the rectangle by moving the highlighted text to the |
206 ;; right of the rectangle and filling the rectangle with blanks. | 215 ;; right of the rectangle and filling the rectangle with blanks. |
207 ;; [M-p] toggles rectangle padding, i.e. insert tabs and spaces to | 216 ;; [M-p] toggles virtual straight rectangle edges |
208 ;; make rectangles truly rectangular | 217 ;; [M-P] inserts tabs and spaces (padding) to make real straight edges |
209 ;; [M-q] performs text filling on the rectangle | 218 ;; [M-q] performs text filling on the rectangle |
210 ;; [M-r] replaces REGEXP (prompt) by STRING (prompt) in rectangle | 219 ;; [M-r] replaces REGEXP (prompt) by STRING (prompt) in rectangle |
211 ;; [M-R] reverse the lines in the rectangle | 220 ;; [M-R] reverse the lines in the rectangle |
212 ;; [M-s] fills each line of the rectangle with the same STRING (prompt) | 221 ;; [M-s] fills each line of the rectangle with the same STRING (prompt) |
213 ;; [M-t] performs text fill of the rectangle with TEXT (prompt) | 222 ;; [M-t] performs text fill of the rectangle with TEXT (prompt) |
345 :group 'cua) | 354 :group 'cua) |
346 | 355 |
347 | 356 |
348 ;;; Rectangle Customization | 357 ;;; Rectangle Customization |
349 | 358 |
350 (defcustom cua-auto-expand-rectangles nil | 359 (defcustom cua-virtual-rectangle-edges t |
351 "*If non-nil, rectangles are padded with spaces to make straight edges. | 360 "*If non-nil, rectangles have virtual straight edges. |
352 This implies modifying buffer contents by expanding tabs and inserting spaces. | 361 Note that although rectangles are always DISPLAYED with straight edges, the |
353 Consequently, this is inhibited in read-only buffers. | 362 buffer is NOT modified, until you execute a command that actually modifies it. |
354 Can be toggled by [M-p] while the rectangle is active," | 363 \[M-p] toggles this feature when a rectangle is active." |
355 :type 'boolean | 364 :type 'boolean |
365 :group 'cua) | |
366 | |
367 (defcustom cua-auto-tabify-rectangles 1000 | |
368 "*If non-nil, automatically tabify after rectangle commands. | |
369 This basically means that `tabify' is applied to all lines that | |
370 are modified by inserting or deleting a rectangle. If value is | |
371 an integer, cua will look for existing tabs in a region around | |
372 the rectangle, and only do the conversion if any tabs are already | |
373 present. The number specifies then number of characters before | |
374 and after the region marked by the rectangle to search." | |
375 :type '(choice (number :tag "Auto detect (limit)") | |
376 (const :tag "Disabled" nil) | |
377 (other :tag "Enabled" t)) | |
356 :group 'cua) | 378 :group 'cua) |
357 | 379 |
358 (defcustom cua-enable-rectangle-auto-help t | 380 (defcustom cua-enable-rectangle-auto-help t |
359 "*If non-nil, automatically show help for region, rectangle and global mark." | 381 "*If non-nil, automatically show help for region, rectangle and global mark." |
360 :type 'boolean | 382 :type 'boolean |
410 (assoc 'cursor-color default-frame-alist) | 432 (assoc 'cursor-color default-frame-alist) |
411 (cdr (assoc 'cursor-color default-frame-alist))) | 433 (cdr (assoc 'cursor-color default-frame-alist))) |
412 (frame-parameter nil 'cursor-color) | 434 (frame-parameter nil 'cursor-color) |
413 "red") | 435 "red") |
414 "Normal (non-overwrite) cursor color. | 436 "Normal (non-overwrite) cursor color. |
415 Also used to indicate that rectangle padding is not in effect. | |
416 Default is to load cursor color from initial or default frame parameters. | 437 Default is to load cursor color from initial or default frame parameters. |
417 | 438 |
418 If the value is a COLOR name, then only the `cursor-color' attribute will be | 439 If the value is a COLOR name, then only the `cursor-color' attribute will be |
419 affected. If the value is a cursor TYPE (one of: box, hollow, bar, or hbar), | 440 affected. If the value is a cursor TYPE (one of: box, hollow, bar, or hbar), |
420 then only the `cursor-type' property will be affected. If the value is | 441 then only the `cursor-type' property will be affected. If the value is |
460 (color :tag "Color"))) | 481 (color :tag "Color"))) |
461 :group 'cua) | 482 :group 'cua) |
462 | 483 |
463 (defcustom cua-overwrite-cursor-color "yellow" | 484 (defcustom cua-overwrite-cursor-color "yellow" |
464 "*Cursor color used when overwrite mode is set, if non-nil. | 485 "*Cursor color used when overwrite mode is set, if non-nil. |
465 Also used to indicate that rectangle padding is in effect. | |
466 Only used when `cua-enable-cursor-indications' is non-nil. | 486 Only used when `cua-enable-cursor-indications' is non-nil. |
467 | 487 |
468 If the value is a COLOR name, then only the `cursor-color' attribute will be | 488 If the value is a COLOR name, then only the `cursor-color' attribute will be |
469 affected. If the value is a cursor TYPE (one of: box, hollow, bar, or hbar), | 489 affected. If the value is a cursor TYPE (one of: box, hollow, bar, or hbar), |
470 then only the `cursor-type' property will be affected. If the value is | 490 then only the `cursor-type' property will be affected. If the value is |
804 With numeric prefix arg, paste from register 0-9 instead. | 824 With numeric prefix arg, paste from register 0-9 instead. |
805 If global mark is active, copy from register or one character." | 825 If global mark is active, copy from register or one character." |
806 (interactive "P") | 826 (interactive "P") |
807 (setq arg (cua--prefix-arg arg)) | 827 (setq arg (cua--prefix-arg arg)) |
808 (let ((regtxt (and cua--register (get-register cua--register))) | 828 (let ((regtxt (and cua--register (get-register cua--register))) |
809 (count (prefix-numeric-value arg))) | 829 (count (prefix-numeric-value arg)) |
830 paste-column paste-lines) | |
810 (cond | 831 (cond |
811 ((and cua--register (not regtxt)) | 832 ((and cua--register (not regtxt)) |
812 (message "Nothing in register %c" cua--register)) | 833 (message "Nothing in register %c" cua--register)) |
813 (cua--global-mark-active | 834 (cua--global-mark-active |
814 (if regtxt | 835 (if regtxt |
823 (if mark-active | 844 (if mark-active |
824 ;; Before a yank command, make sure we don't yank | 845 ;; Before a yank command, make sure we don't yank |
825 ;; the same region that we are going to delete. | 846 ;; the same region that we are going to delete. |
826 ;; That would make yank a no-op. | 847 ;; That would make yank a no-op. |
827 (if cua--rectangle | 848 (if cua--rectangle |
828 (cua--delete-rectangle) | 849 (progn |
850 (goto-char (min (mark) (point))) | |
851 (setq paste-column (cua--rectangle-left)) | |
852 (setq paste-lines (cua--delete-rectangle)) | |
853 (if (= paste-lines 1) | |
854 (setq paste-lines nil))) ;; paste all | |
829 (if (string= (buffer-substring (point) (mark)) | 855 (if (string= (buffer-substring (point) (mark)) |
830 (car kill-ring)) | 856 (car kill-ring)) |
831 (current-kill 1)) | 857 (current-kill 1)) |
832 (cua-delete-region))) | 858 (cua-delete-region))) |
833 (cond | 859 (cond |
841 (let ((pt (point))) | 867 (let ((pt (point))) |
842 (when (not (eq buffer-undo-list t)) | 868 (when (not (eq buffer-undo-list t)) |
843 (setq this-command 'cua--paste-rectangle) | 869 (setq this-command 'cua--paste-rectangle) |
844 (undo-boundary) | 870 (undo-boundary) |
845 (setq buffer-undo-list (cons pt buffer-undo-list))) | 871 (setq buffer-undo-list (cons pt buffer-undo-list))) |
846 (cua--insert-rectangle (cdr cua--last-killed-rectangle)) | 872 (cua--insert-rectangle (cdr cua--last-killed-rectangle) |
873 nil paste-column paste-lines) | |
847 (if arg (goto-char pt)))) | 874 (if arg (goto-char pt)))) |
848 (t (yank arg))))))) | 875 (t (yank arg))))))) |
849 | 876 |
850 (defun cua-paste-pop (arg) | 877 (defun cua-paste-pop (arg) |
851 "Replace a just-pasted text or rectangle with a different text. | 878 "Replace a just-pasted text or rectangle with a different text. |
1031 cua-global-mark-cursor-color) | 1058 cua-global-mark-cursor-color) |
1032 cua-global-mark-cursor-color) | 1059 cua-global-mark-cursor-color) |
1033 ((and buffer-read-only | 1060 ((and buffer-read-only |
1034 cua-read-only-cursor-color) | 1061 cua-read-only-cursor-color) |
1035 cua-read-only-cursor-color) | 1062 cua-read-only-cursor-color) |
1036 ((and cua-overwrite-cursor-color | 1063 ((and cua-overwrite-cursor-color overwrite-mode) |
1037 (or overwrite-mode | |
1038 (and cua--rectangle (cua--rectangle-padding)))) | |
1039 cua-overwrite-cursor-color) | 1064 cua-overwrite-cursor-color) |
1040 (t cua-normal-cursor-color))) | 1065 (t cua-normal-cursor-color))) |
1041 (color (if (consp cursor) (cdr cursor) cursor)) | 1066 (color (if (consp cursor) (cdr cursor) cursor)) |
1042 (type (if (consp cursor) (car cursor) cursor))) | 1067 (type (if (consp cursor) (car cursor) cursor))) |
1043 (if (and color | 1068 (if (and color |