annotate lisp/emulation/cua-rect.el @ 44938:358d42530d42

Added cua-mode based files [split from original cua.el]: cua-base.el, cua-rect.el, cua-gmrk.el, and keypad.el
author Kim F. Storm <storm@cua.dk>
date Sun, 28 Apr 2002 21:48:39 +0000
parents
children 829beb9a6a4b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44938
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1 ;;; cua-rect.el --- CUA unified rectangle support
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
2
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
3 ;; Copyright (C) 1997-2002 Free Software Foundation, Inc.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
4
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
5 ;; Author: Kim F. Storm <storm@cua.dk>
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
6 ;; Keywords: keyboard emulations convenience CUA
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
7
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
9
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
13 ;; any later version.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
14
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
18 ;; GNU General Public License for more details.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
19
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
24
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
25 ;;; Acknowledgements
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
26
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
27 ;; The rectangle handling and display code borrows from the standard
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
28 ;; GNU emacs rect.el package and the the rect-mark.el package by Rick
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
29 ;; Sladkey <jrs@world.std.com>.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
30
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
31 (provide 'cua-rect)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
32
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
33 (eval-when-compile
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
34 (require 'cua-base)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
35 (require 'cua-gmrk)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
36 )
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
37
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
38 ;;; Rectangle support
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
39
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
40 (require 'rect)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
41
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
42 ;; If non-nil, restrict current region to this rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
43 ;; Value is a vector [top bot left right corner ins pad select].
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
44 ;; CORNER specifies currently active corner 0=t/l 1=t/r 2=b/l 3=b/r.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
45 ;; INS specifies whether to insert on left(nil) or right(t) side.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
46 ;; If PAD is non-nil, tabs are converted to spaces when necessary.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
47 ;; If SELECT is a regexp, only lines starting with that regexp are affected.")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
48 (defvar cua--rectangle nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
49 (make-variable-buffer-local 'cua--rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
50
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
51 ;; Most recent rectangle geometry. Note: car is buffer.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
52 (defvar cua--last-rectangle nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
53
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
54 ;; Rectangle restored by undo.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
55 (defvar cua--restored-rectangle nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
56
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
57 ;; Last rectangle copied/killed; nil if last kill was not a rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
58 (defvar cua--last-killed-rectangle nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
59
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
60 ;; List of overlays used to display current rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
61 (defvar cua--rectangle-overlays nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
62 (make-variable-buffer-local 'cua--rectangle-overlays)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
63
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
64 ;; Per-buffer CUA mode undo list.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
65 (defvar cua--undo-list nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
66 (make-variable-buffer-local 'cua--undo-list)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
67
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
68 ;; Record undo boundary for rectangle undo.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
69 (defun cua--rectangle-undo-boundary ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
70 (when (listp buffer-undo-list)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
71 (if (> (length cua--undo-list) cua-undo-max)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
72 (setcdr (nthcdr (1- cua-undo-max) cua--undo-list) nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
73 (undo-boundary)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
74 (setq cua--undo-list
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
75 (cons (cons (cdr buffer-undo-list) (copy-sequence cua--rectangle)) cua--undo-list))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
76
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
77 (defun cua--rectangle-undo (&optional arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
78 "Undo some previous changes.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
79 Knows about CUA rectangle highlighting in addition to standard undo."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
80 (interactive "*P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
81 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
82 (cua--rectangle-undo-boundary))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
83 (undo arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
84 (let ((l cua--undo-list))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
85 (while l
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
86 (if (eq (car (car l)) pending-undo-list)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
87 (setq cua--restored-rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
88 (and (vectorp (cdr (car l))) (cdr (car l)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
89 l nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
90 (setq l (cdr l)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
91 (setq cua--buffer-and-point-before-command nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
92
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
93 (defvar cua--tidy-undo-counter 0
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
94 "Number of times `cua--tidy-undo-lists' have run successfully.")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
95
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
96 ;; Clean out danling entries from cua's undo list.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
97 ;; Since this list contains pointers into the standard undo list,
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
98 ;; such references are only meningful as undo information if the
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
99 ;; corresponding entry is still on the standard undo list.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
100
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
101 (defun cua--tidy-undo-lists (&optional clean)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
102 (let ((buffers (buffer-list)) (cnt cua--tidy-undo-counter))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
103 (while (and buffers (or clean (not (input-pending-p))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
104 (with-current-buffer (car buffers)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
105 (when (local-variable-p 'cua--undo-list)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
106 (if (or clean (null cua--undo-list) (eq buffer-undo-list t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
107 (progn
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
108 (kill-local-variable 'cua--undo-list)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
109 (setq cua--tidy-undo-counter (1+ cua--tidy-undo-counter)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
110 (let* ((bul buffer-undo-list)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
111 (cul (cons nil cua--undo-list))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
112 (cc (car (car (cdr cul)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
113 (while (and bul cc)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
114 (if (setq bul (memq cc bul))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
115 (setq cul (cdr cul)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
116 cc (and (cdr cul) (car (car (cdr cul)))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
117 (when cc
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
118 (if cua--debug
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
119 (setq cc (length (cdr cul))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
120 (if (eq (cdr cul) cua--undo-list)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
121 (setq cua--undo-list nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
122 (setcdr cul nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
123 (setq cua--tidy-undo-counter (1+ cua--tidy-undo-counter))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
124 (if cua--debug
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
125 (message "Clean undo list in %s (%d)"
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
126 (buffer-name) cc)))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
127 (setq buffers (cdr buffers)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
128 (/= cnt cua--tidy-undo-counter)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
129
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
130 ;;; Rectangle geometry
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
131
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
132 (defun cua--rectangle-top (&optional val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
133 ;; Top of CUA rectangle (buffer position on first line).
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
134 (if (not val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
135 (aref cua--rectangle 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
136 (setq val (line-beginning-position))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
137 (if (<= val (aref cua--rectangle 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
138 (aset cua--rectangle 0 val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
139 (aset cua--rectangle 1 val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
140 (cua--rectangle-corner 2))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
141
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
142 (defun cua--rectangle-bot (&optional val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
143 ;; Bot of CUA rectangle (buffer position on last line).
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
144 (if (not val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
145 (aref cua--rectangle 1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
146 (setq val (line-end-position))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
147 (if (>= val (aref cua--rectangle 0))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
148 (aset cua--rectangle 1 val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
149 (aset cua--rectangle 0 val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
150 (cua--rectangle-corner 2))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
151
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
152 (defun cua--rectangle-left (&optional val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
153 ;; Left column of CUA rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
154 (if (integerp val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
155 (if (<= val (aref cua--rectangle 3))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
156 (aset cua--rectangle 2 val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
157 (aset cua--rectangle 3 val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
158 (cua--rectangle-corner (if (cua--rectangle-right-side) -1 1)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
159 (aref cua--rectangle 2)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
160
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
161 (defun cua--rectangle-right (&optional val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
162 ;; Right column of CUA rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
163 (if (integerp val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
164 (if (>= val (aref cua--rectangle 2))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
165 (aset cua--rectangle 3 val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
166 (aset cua--rectangle 2 val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
167 (cua--rectangle-corner (if (cua--rectangle-right-side) -1 1)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
168 (aref cua--rectangle 3)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
169
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
170 (defun cua--rectangle-corner (&optional advance)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
171 ;; Currently active corner of rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
172 (let ((c (aref cua--rectangle 4)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
173 (if (not (integerp advance))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
174 c
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
175 (aset cua--rectangle 4
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
176 (if (= advance 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
177 (- 3 c) ; opposite corner
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
178 (mod (+ c 4 advance) 4)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
179 (aset cua--rectangle 5 0))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
180
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
181 (defun cua--rectangle-right-side (&optional topbot)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
182 ;; t if point is on right side of rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
183 (if (and topbot (= (cua--rectangle-left) (cua--rectangle-right)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
184 (< (cua--rectangle-corner) 2)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
185 (= (mod (cua--rectangle-corner) 2) 1)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
186
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
187 (defun cua--rectangle-column ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
188 (if (cua--rectangle-right-side)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
189 (cua--rectangle-right)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
190 (cua--rectangle-left)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
191
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
192 (defun cua--rectangle-insert-col (&optional col)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
193 ;; Currently active corner of rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
194 (if (integerp col)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
195 (aset cua--rectangle 5 col)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
196 (if (cua--rectangle-right-side t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
197 (if (= (aref cua--rectangle 5) 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
198 (1+ (cua--rectangle-right))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
199 (aref cua--rectangle 5))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
200 (cua--rectangle-left))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
201
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
202 (defun cua--rectangle-padding (&optional set val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
203 ;; Current setting of rectangle padding
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
204 (if set
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
205 (aset cua--rectangle 6 val))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
206 (and (not buffer-read-only)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
207 (aref cua--rectangle 6)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
208
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
209 (defun cua--rectangle-restriction (&optional val bounded negated)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
210 ;; Current rectangle restriction
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
211 (if val
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
212 (aset cua--rectangle 7
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
213 (and (stringp val)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
214 (> (length val) 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
215 (list val bounded negated)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
216 (aref cua--rectangle 7)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
217
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
218 (defun cua--rectangle-assert ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
219 (message "%S (%d)" cua--rectangle (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
220 (if (< (cua--rectangle-right) (cua--rectangle-left))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
221 (message "rectangle right < left"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
222 (if (< (cua--rectangle-bot) (cua--rectangle-top))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
223 (message "rectangle bot < top")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
224
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
225 (defun cua--rectangle-get-corners (&optional pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
226 ;; Calculate the rectangular region represented by point and mark,
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
227 ;; putting start in the upper left corner and end in the
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
228 ;; bottom right corner.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
229 (let ((top (point)) (bot (mark)) r l corner)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
230 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
231 (goto-char top)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
232 (setq l (current-column))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
233 (goto-char bot)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
234 (setq r (current-column))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
235 (if (<= top bot)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
236 (setq corner (if (<= l r) 0 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
237 (setq top (prog1 bot (setq bot top)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
238 (setq corner (if (<= l r) 2 3)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
239 (if (<= l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
240 (if (< l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
241 (setq r (1- r)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
242 (setq l (prog1 r (setq r l)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
243 (goto-char top)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
244 (move-to-column l pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
245 (setq top (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
246 (goto-char bot)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
247 (move-to-column r pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
248 (setq bot (point))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
249 (vector top bot l r corner 0 pad nil)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
250
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
251 (defun cua--rectangle-set-corners ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
252 ;; Set mark and point in opposite corners of current rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
253 (let (pp pc mp mc (c (cua--rectangle-corner)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
254 (cond
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
255 ((= c 0) ; top/left -> bot/right
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
256 (setq pp (cua--rectangle-top) pc (cua--rectangle-left)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
257 mp (cua--rectangle-bot) mc (cua--rectangle-right)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
258 ((= c 1) ; top/right -> bot/left
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
259 (setq pp (cua--rectangle-top) pc (cua--rectangle-right)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
260 mp (cua--rectangle-bot) mc (cua--rectangle-left)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
261 ((= c 2) ; bot/left -> top/right
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
262 (setq pp (cua--rectangle-bot) pc (cua--rectangle-left)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
263 mp (cua--rectangle-top) mc (cua--rectangle-right)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
264 ((= c 3) ; bot/right -> top/left
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
265 (setq pp (cua--rectangle-bot) pc (cua--rectangle-right)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
266 mp (cua--rectangle-top) mc (cua--rectangle-left))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
267 (goto-char mp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
268 (move-to-column mc (cua--rectangle-padding))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
269 (set-mark (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
270 (goto-char pp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
271 (move-to-column pc (cua--rectangle-padding))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
272
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
273 ;;; Rectangle resizing
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
274
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
275 (defun cua--forward-line (n pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
276 ;; Move forward/backward one line. Returns t if movement.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
277 (if (or (not pad) (< n 0))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
278 (= (forward-line n) 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
279 (next-line 1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
280 t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
281
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
282 (defun cua--rectangle-resized ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
283 ;; Refresh state after resizing rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
284 (setq cua--buffer-and-point-before-command nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
285 (cua--pad-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
286 (cua--rectangle-insert-col 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
287 (cua--rectangle-set-corners)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
288 (cua--keep-active))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
289
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
290 (defun cua-resize-rectangle-right (n)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
291 "Resize rectangle to the right."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
292 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
293 (let ((pad (cua--rectangle-padding)) (resized (> n 0)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
294 (while (> n 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
295 (setq n (1- n))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
296 (cond
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
297 ((and (cua--rectangle-right-side) (or pad (eolp)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
298 (cua--rectangle-right (1+ (cua--rectangle-right)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
299 (move-to-column (cua--rectangle-right) pad))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
300 ((cua--rectangle-right-side)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
301 (forward-char 1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
302 (cua--rectangle-right (current-column)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
303 ((or pad (eolp))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
304 (cua--rectangle-left (1+ (cua--rectangle-left)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
305 (move-to-column (cua--rectangle-right) pad))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
306 (t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
307 (forward-char 1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
308 (cua--rectangle-left (current-column)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
309 (if resized
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
310 (cua--rectangle-resized))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
311
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
312 (defun cua-resize-rectangle-left (n)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
313 "Resize rectangle to the left."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
314 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
315 (let ((pad (cua--rectangle-padding)) resized)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
316 (while (> n 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
317 (setq n (1- n))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
318 (if (or (= (cua--rectangle-right) 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
319 (and (not (cua--rectangle-right-side)) (= (cua--rectangle-left) 0)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
320 (setq n 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
321 (cond
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
322 ((and (cua--rectangle-right-side) (or pad (eolp) (bolp)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
323 (cua--rectangle-right (1- (cua--rectangle-right)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
324 (move-to-column (cua--rectangle-right) pad))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
325 ((cua--rectangle-right-side)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
326 (backward-char 1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
327 (cua--rectangle-right (current-column)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
328 ((or pad (eolp) (bolp))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
329 (cua--rectangle-left (1- (cua--rectangle-left)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
330 (move-to-column (cua--rectangle-right) pad))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
331 (t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
332 (backward-char 1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
333 (cua--rectangle-left (current-column))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
334 (setq resized t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
335 (if resized
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
336 (cua--rectangle-resized))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
337
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
338 (defun cua-resize-rectangle-down (n)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
339 "Resize rectangle downwards."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
340 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
341 (let ((pad (cua--rectangle-padding)) resized)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
342 (while (> n 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
343 (setq n (1- n))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
344 (cond
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
345 ((>= (cua--rectangle-corner) 2)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
346 (goto-char (cua--rectangle-bot))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
347 (when (cua--forward-line 1 pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
348 (move-to-column (cua--rectangle-column) pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
349 (cua--rectangle-bot t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
350 (setq resized t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
351 (t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
352 (goto-char (cua--rectangle-top))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
353 (when (cua--forward-line 1 pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
354 (move-to-column (cua--rectangle-column) pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
355 (cua--rectangle-top t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
356 (setq resized t)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
357 (if resized
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
358 (cua--rectangle-resized))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
359
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
360 (defun cua-resize-rectangle-up (n)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
361 "Resize rectangle upwards."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
362 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
363 (let ((pad (cua--rectangle-padding)) resized)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
364 (while (> n 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
365 (setq n (1- n))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
366 (cond
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
367 ((>= (cua--rectangle-corner) 2)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
368 (goto-char (cua--rectangle-bot))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
369 (when (cua--forward-line -1 pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
370 (move-to-column (cua--rectangle-column) pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
371 (cua--rectangle-bot t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
372 (setq resized t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
373 (t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
374 (goto-char (cua--rectangle-top))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
375 (when (cua--forward-line -1 pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
376 (move-to-column (cua--rectangle-column) pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
377 (cua--rectangle-top t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
378 (setq resized t)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
379 (if resized
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
380 (cua--rectangle-resized))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
381
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
382 (defun cua-resize-rectangle-eol ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
383 "Resize rectangle to end of line."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
384 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
385 (unless (eolp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
386 (end-of-line)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
387 (if (> (current-column) (cua--rectangle-right))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
388 (cua--rectangle-right (current-column)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
389 (if (not (cua--rectangle-right-side))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
390 (cua--rectangle-corner 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
391 (cua--rectangle-resized)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
392
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
393 (defun cua-resize-rectangle-bol ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
394 "Resize rectangle to beginning of line."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
395 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
396 (unless (bolp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
397 (beginning-of-line)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
398 (cua--rectangle-left (current-column))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
399 (if (cua--rectangle-right-side)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
400 (cua--rectangle-corner -1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
401 (cua--rectangle-resized)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
402
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
403 (defun cua-resize-rectangle-bot ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
404 "Resize rectangle to bottom of buffer."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
405 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
406 (goto-char (point-max))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
407 (move-to-column (cua--rectangle-column) (cua--rectangle-padding))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
408 (cua--rectangle-bot t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
409 (cua--rectangle-resized))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
410
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
411 (defun cua-resize-rectangle-top ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
412 "Resize rectangle to top of buffer."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
413 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
414 (goto-char (point-min))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
415 (move-to-column (cua--rectangle-column) (cua--rectangle-padding))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
416 (cua--rectangle-top t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
417 (cua--rectangle-resized))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
418
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
419 (defun cua-resize-rectangle-page-up ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
420 "Resize rectangle upwards by one scroll page."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
421 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
422 (let ((pad (cua--rectangle-padding)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
423 (scroll-down)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
424 (move-to-column (cua--rectangle-column) pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
425 (if (>= (cua--rectangle-corner) 2)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
426 (cua--rectangle-bot t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
427 (cua--rectangle-top t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
428 (cua--rectangle-resized)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
429
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
430 (defun cua-resize-rectangle-page-down ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
431 "Resize rectangle downwards by one scroll page."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
432 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
433 (let ((pad (cua--rectangle-padding)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
434 (scroll-up)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
435 (move-to-column (cua--rectangle-column) pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
436 (if (>= (cua--rectangle-corner) 2)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
437 (cua--rectangle-bot t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
438 (cua--rectangle-top t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
439 (cua--rectangle-resized)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
440
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
441 ;;; Mouse support
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
442
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
443 ;; This is pretty simplistic, but it does the job...
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
444
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
445 (defun cua-mouse-resize-rectangle (event)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
446 "Set rectangle corner at mouse click position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
447 (interactive "e")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
448 (mouse-set-point event)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
449 (if (cua--rectangle-padding)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
450 (move-to-column (car (posn-col-row (event-end event))) t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
451 (if (cua--rectangle-right-side)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
452 (cua--rectangle-right (current-column))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
453 (cua--rectangle-left (current-column)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
454 (if (>= (cua--rectangle-corner) 2)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
455 (cua--rectangle-bot t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
456 (cua--rectangle-top t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
457 (cua--rectangle-resized))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
458
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
459 (defvar cua--mouse-last-pos nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
460
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
461 (defun cua-mouse-set-rectangle-mark (event)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
462 "Start rectangle at mouse click position."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
463 (interactive "e")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
464 (when cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
465 (cua--deactivate-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
466 (cua--deactivate t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
467 (setq cua--last-rectangle nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
468 (mouse-set-point event)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
469 (cua-set-rectangle-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
470 (setq cua--buffer-and-point-before-command nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
471 (setq cua--mouse-last-pos nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
472
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
473 (defun cua-mouse-save-then-kill-rectangle (event arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
474 "Expand rectangle to mouse click position and copy rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
475 If command is repeated at same position, delete the rectangle."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
476 (interactive "e\nP")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
477 (if (and (eq this-command last-command)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
478 (eq (point) (car-safe cua--mouse-last-pos))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
479 (eq cua--last-killed-rectangle (cdr-safe cua--mouse-last-pos)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
480 (progn
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
481 (unless buffer-read-only
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
482 (cua--delete-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
483 (cua--deactivate))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
484 (cua-mouse-resize-rectangle event)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
485 (let ((cua-keep-region-after-copy t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
486 (cua-copy-rectangle arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
487 (setq cua--mouse-last-pos (cons (point) cua--last-killed-rectangle)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
488 (defun cua--mouse-ignore (event)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
489 (interactive "e")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
490 (setq this-command last-command))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
491
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
492 (defun cua--rectangle-move (dir)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
493 (let ((pad (cua--rectangle-padding))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
494 (moved t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
495 (top (cua--rectangle-top))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
496 (bot (cua--rectangle-bot))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
497 (l (cua--rectangle-left))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
498 (r (cua--rectangle-right)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
499 (cond
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
500 ((eq dir 'up)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
501 (goto-char top)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
502 (when (cua--forward-line -1 pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
503 (cua--rectangle-top t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
504 (goto-char bot)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
505 (forward-line -1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
506 (cua--rectangle-bot t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
507 ((eq dir 'down)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
508 (goto-char bot)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
509 (when (cua--forward-line 1 pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
510 (cua--rectangle-bot t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
511 (goto-char top)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
512 (cua--forward-line 1 pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
513 (cua--rectangle-top t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
514 ((eq dir 'left)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
515 (when (> l 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
516 (cua--rectangle-left (1- l))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
517 (cua--rectangle-right (1- r))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
518 ((eq dir 'right)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
519 (cua--rectangle-right (1+ r))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
520 (cua--rectangle-left (1+ l)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
521 (t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
522 (setq moved nil)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
523 (when moved
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
524 (setq cua--buffer-and-point-before-command nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
525 (cua--pad-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
526 (cua--rectangle-set-corners)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
527 (cua--keep-active))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
528
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
529
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
530 ;;; Operations on current rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
531
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
532 (defun cua--rectangle-operation (keep-clear visible undo pad &optional fct post-fct)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
533 ;; Call FCT for each line of region with 4 parameters:
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
534 ;; Region start, end, left-col, right-col
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
535 ;; Point is at start when FCT is called
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
536 ;; Set undo boundary if UNDO is non-nil.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
537 ;; Rectangle is padded if PAD = t or numeric and (cua--rectangle-padding)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
538 ;; Mark is kept if keep-clear is 'keep and cleared if keep-clear is 'clear.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
539 (let* ((start (cua--rectangle-top))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
540 (end (cua--rectangle-bot))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
541 (l (cua--rectangle-left))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
542 (r (1+ (cua--rectangle-right)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
543 (m (make-marker))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
544 (tabpad (and (integerp pad) (= pad 2)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
545 (sel (cua--rectangle-restriction)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
546 (if undo
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
547 (cua--rectangle-undo-boundary))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
548 (if (integerp pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
549 (setq pad (cua--rectangle-padding)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
550 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
551 (save-restriction
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
552 (widen)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
553 (when (> (cua--rectangle-corner) 1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
554 (goto-char end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
555 (and (bolp) (not (eolp)) (not (eobp))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
556 (setq end (1+ end))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
557 (when visible
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
558 (setq start (max (window-start) start))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
559 (setq end (min (window-end) end)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
560 (goto-char end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
561 (setq end (line-end-position))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
562 (goto-char start)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
563 (setq start (line-beginning-position))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
564 (narrow-to-region start end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
565 (goto-char (point-min))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
566 (while (< (point) (point-max))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
567 (move-to-column r pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
568 (and (not pad) (not visible) (> (current-column) r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
569 (backward-char 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
570 (if (and tabpad (not pad) (looking-at "\t"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
571 (forward-char 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
572 (set-marker m (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
573 (move-to-column l pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
574 (if fct
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
575 (let ((v t) (p (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
576 (when sel
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
577 (if (car (cdr sel))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
578 (setq v (looking-at (car sel)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
579 (setq v (re-search-forward (car sel) m t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
580 (goto-char p))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
581 (if (car (cdr (cdr sel)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
582 (setq v (null v))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
583 (if visible
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
584 (funcall fct p m l r v)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
585 (if v
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
586 (funcall fct p m l r)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
587 (set-marker m nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
588 (forward-line 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
589 (if (not visible)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
590 (cua--rectangle-bot t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
591 (if post-fct
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
592 (funcall post-fct l r))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
593 (cond
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
594 ((eq keep-clear 'keep)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
595 (cua--keep-active))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
596 ((eq keep-clear 'clear)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
597 (cua--deactivate))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
598 ((eq keep-clear 'corners)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
599 (cua--rectangle-set-corners)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
600 (cua--keep-active)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
601 (setq cua--buffer-and-point-before-command nil)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
602
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
603 (put 'cua--rectangle-operation 'lisp-indent-function 4)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
604
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
605 (defun cua--pad-rectangle (&optional pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
606 (if (or pad (cua--rectangle-padding))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
607 (cua--rectangle-operation nil nil t t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
608
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
609 (defun cua--delete-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
610 (cua--rectangle-operation nil nil t 2
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
611 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
612 (delete-region s (if (> e s) e (1+ e))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
613
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
614 (defun cua--extract-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
615 (let (rect)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
616 (cua--rectangle-operation nil nil nil 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
617 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
618 (setq rect (cons (buffer-substring-no-properties s e) rect))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
619 (nreverse rect)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
620
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
621 (defun cua--insert-rectangle (rect &optional below)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
622 ;; Insert rectangle as insert-rectangle, but don't set mark and exit with
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
623 ;; point at either next to top right or below bottom left corner
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
624 ;; Notice: In overwrite mode, the rectangle is inserted as separate text lines.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
625 (if (and below (eq below 'auto))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
626 (setq below (and (bolp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
627 (or (eolp) (eobp) (= (1+ (point)) (point-max))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
628 (let ((lines rect)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
629 (insertcolumn (current-column))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
630 (first t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
631 p)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
632 (while (or lines below)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
633 (or first
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
634 (if overwrite-mode
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
635 (insert ?\n)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
636 (forward-line 1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
637 (or (bolp) (insert ?\n))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
638 (move-to-column insertcolumn t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
639 (if (not lines)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
640 (setq below nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
641 (insert-for-yank (car lines))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
642 (setq lines (cdr lines))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
643 (and first (not below)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
644 (setq p (point))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
645 (setq first nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
646 (and p (not overwrite-mode)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
647 (goto-char p))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
648
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
649 (defun cua--copy-rectangle-as-kill (&optional ring)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
650 (if cua--register
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
651 (set-register cua--register (cua--extract-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
652 (setq killed-rectangle (cua--extract-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
653 (setq cua--last-killed-rectangle (cons (and kill-ring (car kill-ring)) killed-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
654 (if ring
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
655 (kill-new (mapconcat
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
656 (function (lambda (row) (concat row "\n")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
657 killed-rectangle "")))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
658
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
659 (defun cua--activate-rectangle (&optional force)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
660 ;; Turn on rectangular marking mode by disabling transient mark mode
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
661 ;; and manually handling highlighting from a post command hook.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
662 ;; Be careful if we are already marking a rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
663 (setq cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
664 (if (and cua--last-rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
665 (eq (car cua--last-rectangle) (current-buffer))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
666 (eq (car (cdr cua--last-rectangle)) (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
667 (cdr (cdr cua--last-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
668 (cua--rectangle-get-corners
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
669 (and (not buffer-read-only)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
670 (or cua-auto-expand-rectangles
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
671 force
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
672 (eq major-mode 'picture-mode)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
673 cua--status-string (if (cua--rectangle-padding) " Pad" "")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
674 cua--last-rectangle nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
675
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
676 ;; (defvar cua-save-point nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
677
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
678 (defun cua--deactivate-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
679 ;; This is used to clean up after `cua--activate-rectangle'.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
680 (mapcar (function delete-overlay) cua--rectangle-overlays)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
681 (setq cua--last-rectangle (cons (current-buffer)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
682 (cons (point) ;; cua-save-point
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
683 cua--rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
684 cua--rectangle nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
685 cua--rectangle-overlays nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
686 cua--status-string nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
687 cua--mouse-last-pos nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
688
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
689 (defun cua--highlight-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
690 ;; This function is used to highlight the rectangular region.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
691 ;; We do this by putting an overlay on each line within the rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
692 ;; Each overlay extends across all the columns of the rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
693 ;; We try to reuse overlays where possible because this is more efficient
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
694 ;; and results in less flicker.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
695 ;; If cua--rectangle-padding is nil and the buffer contains tabs or short lines,
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
696 ;; the higlighted region may not be perfectly rectangular.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
697 (let ((deactivate-mark deactivate-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
698 (old cua--rectangle-overlays)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
699 (new nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
700 (left (cua--rectangle-left))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
701 (right (1+ (cua--rectangle-right))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
702 (when (/= left right)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
703 (sit-for 0) ; make window top/bottom reliable
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
704 (cua--rectangle-operation nil t nil nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
705 '(lambda (s e l r v)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
706 (let ((rface (if v 'cua-rectangle-face 'cua-rectangle-noselect-face))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
707 overlay)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
708 ;; Trim old leading overlays.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
709 (if (= s e) (setq e (1+ e)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
710 (while (and old
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
711 (setq overlay (car old))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
712 (< (overlay-start overlay) s)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
713 (/= (overlay-end overlay) e))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
714 (delete-overlay overlay)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
715 (setq old (cdr old)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
716 ;; Reuse an overlay if possible, otherwise create one.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
717 (if (and old
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
718 (setq overlay (car old))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
719 (or (= (overlay-start overlay) s)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
720 (= (overlay-end overlay) e)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
721 (progn
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
722 (move-overlay overlay s e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
723 (setq old (cdr old)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
724 (setq overlay (make-overlay s e)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
725 (overlay-put overlay 'face rface)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
726 (setq new (cons overlay new))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
727 ;; Trim old trailing overlays.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
728 (mapcar (function delete-overlay) old)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
729 (setq cua--rectangle-overlays (nreverse new))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
730
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
731 (defun cua--indent-rectangle (&optional ch to-col clear)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
732 ;; Indent current rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
733 (let ((col (cua--rectangle-insert-col))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
734 (pad (cua--rectangle-padding))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
735 indent)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
736 (cua--rectangle-operation (if clear 'clear 'corners) nil t pad
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
737 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
738 (move-to-column col pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
739 (if (and (eolp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
740 (< (current-column) col))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
741 (move-to-column col t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
742 (cond
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
743 (to-col (indent-to to-col))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
744 (ch (insert ch))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
745 (t (tab-to-tab-stop)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
746 (if (cua--rectangle-right-side t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
747 (cua--rectangle-insert-col (current-column))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
748 (setq indent (- (current-column) l))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
749 '(lambda (l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
750 (when (and indent (> indent 0))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
751 (aset cua--rectangle 2 (+ l indent))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
752 (aset cua--rectangle 3 (+ r indent -1)))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
753
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
754 ;;
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
755 ;; rectangle functions / actions
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
756 ;;
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
757
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
758 (defvar cua--rectangle-initialized nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
759
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
760 (defun cua-set-rectangle-mark (&optional reopen)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
761 "Set mark and start in CUA rectangle mode.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
762 With prefix argument, activate previous rectangle if possible."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
763 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
764 (unless cua--rectangle-initialized
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
765 (cua--init-rectangles))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
766 (when (not cua--rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
767 (if (and reopen
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
768 cua--last-rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
769 (eq (car cua--last-rectangle) (current-buffer)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
770 (goto-char (car (cdr cua--last-rectangle)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
771 (if (not mark-active)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
772 (push-mark nil nil t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
773 (cua--activate-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
774 (cua--rectangle-set-corners)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
775 (setq mark-active t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
776 cua--explicit-region-start t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
777 (if cua-enable-rectangle-auto-help
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
778 (cua-help-for-rectangle t))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
779
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
780 (defun cua-clear-rectangle-mark ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
781 "Cancel current rectangle."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
782 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
783 (when cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
784 (setq mark-active nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
785 cua--explicit-region-start nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
786 (cua--deactivate-rectangle)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
787
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
788 (defun cua-toggle-rectangle-mark ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
789 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
790 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
791 (cua--deactivate-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
792 (unless cua--rectangle-initialized
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
793 (cua--init-rectangles))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
794 (cua--activate-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
795 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
796 (if cua-enable-rectangle-auto-help
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
797 (cua-help-for-rectangle t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
798 (if cua-enable-region-auto-help
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
799 (cua-help-for-region t))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
800
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
801 (defun cua-restrict-regexp-rectangle (arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
802 "Restrict rectangle to lines (not) matching REGEXP.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
803 With prefix argument, the toggle restriction."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
804 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
805 (let ((r (cua--rectangle-restriction)) regexp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
806 (if (and r (null (car (cdr r))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
807 (if arg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
808 (cua--rectangle-restriction (car r) nil (not (car (cdr (cdr r)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
809 (cua--rectangle-restriction "" nil nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
810 (cua--rectangle-restriction
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
811 (read-from-minibuffer "Restrict rectangle (regexp): "
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
812 nil nil nil nil) nil arg))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
813
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
814 (defun cua-restrict-prefix-rectangle (arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
815 "Restrict rectangle to lines (not) starting with CHAR.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
816 With prefix argument, the toggle restriction."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
817 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
818 (let ((r (cua--rectangle-restriction)) regexp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
819 (if (and r (car (cdr r)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
820 (if arg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
821 (cua--rectangle-restriction (car r) t (not (car (cdr (cdr r)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
822 (cua--rectangle-restriction "" nil nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
823 (cua--rectangle-restriction
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
824 (format "[%c]"
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
825 (read-char "Restrictive rectangle (char): ")) t arg))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
826
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
827 (defun cua-move-rectangle-up ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
828 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
829 (cua--rectangle-move 'up))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
830
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
831 (defun cua-move-rectangle-down ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
832 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
833 (cua--rectangle-move 'down))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
834
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
835 (defun cua-move-rectangle-left ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
836 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
837 (cua--rectangle-move 'left))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
838
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
839 (defun cua-move-rectangle-right ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
840 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
841 (cua--rectangle-move 'right))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
842
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
843 (defun cua-copy-rectangle (arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
844 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
845 (setq arg (cua--prefix-arg arg))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
846 (cua--copy-rectangle-as-kill arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
847 (if cua-keep-region-after-copy
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
848 (cua--keep-active)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
849 (cua--deactivate)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
850
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
851 (defun cua-cut-rectangle (arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
852 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
853 (if buffer-read-only
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
854 (cua-copy-rectangle arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
855 (setq arg (cua--prefix-arg arg))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
856 (goto-char (min (mark) (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
857 (cua--copy-rectangle-as-kill arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
858 (cua--delete-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
859 (cua--deactivate))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
860
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
861 (defun cua-delete-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
862 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
863 (goto-char (min (point) (mark)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
864 (if cua-delete-copy-to-register-0
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
865 (set-register ?0 (cua--extract-rectangle)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
866 (cua--delete-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
867 (cua--deactivate))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
868
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
869 (defun cua-rotate-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
870 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
871 (cua--rectangle-corner (if (= (cua--rectangle-left) (cua--rectangle-right)) 0 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
872 (cua--rectangle-set-corners))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
873
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
874 (defun cua-toggle-rectangle-padding ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
875 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
876 (if buffer-read-only
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
877 (message "Cannot do padding in read-only buffer.")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
878 (cua--rectangle-padding t (not (cua--rectangle-padding)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
879 (cua--pad-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
880 (cua--rectangle-set-corners))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
881 (setq cua--status-string (and (cua--rectangle-padding) " Pad"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
882 (cua--keep-active))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
883
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
884 (defun cua-do-rectangle-padding ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
885 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
886 (if buffer-read-only
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
887 (message "Cannot do padding in read-only buffer.")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
888 (cua--pad-rectangle t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
889 (cua--rectangle-set-corners))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
890 (cua--keep-active))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
891
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
892 (defun cua-open-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
893 "Blank out CUA rectangle, shifting text right.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
894 The text previously in the region is not overwritten by the blanks,
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
895 but instead winds up to the right of the rectangle."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
896 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
897 (cua--rectangle-operation 'corners nil t 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
898 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
899 (skip-chars-forward " \t")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
900 (let ((ws (- (current-column) l))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
901 (p (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
902 (skip-chars-backward " \t")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
903 (delete-region (point) p)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
904 (indent-to (+ r ws))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
905
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
906 (defun cua-close-rectangle (arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
907 "Delete all whitespace starting at left edge of CUA rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
908 On each line in the rectangle, all continuous whitespace starting
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
909 at that column is deleted.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
910 With prefix arg, also delete whitespace to the left of that column."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
911 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
912 (cua--rectangle-operation 'clear nil t 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
913 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
914 (when arg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
915 (skip-syntax-backward " " (line-beginning-position))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
916 (setq s (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
917 (skip-syntax-forward " " (line-end-position))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
918 (delete-region s (point)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
919
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
920 (defun cua-blank-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
921 "Blank out CUA rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
922 The text previously in the rectangle is overwritten by the blanks."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
923 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
924 (cua--rectangle-operation 'keep nil nil 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
925 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
926 (goto-char e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
927 (skip-syntax-forward " " (line-end-position))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
928 (setq e (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
929 (let ((column (current-column)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
930 (goto-char s)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
931 (skip-syntax-backward " " (line-beginning-position))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
932 (delete-region (point) e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
933 (indent-to column)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
934
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
935 (defun cua-align-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
936 "Align rectangle lines to left column."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
937 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
938 (let (x)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
939 (cua--rectangle-operation 'clear nil t t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
940 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
941 (let ((b (line-beginning-position)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
942 (skip-syntax-backward "^ " b)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
943 (skip-syntax-backward " " b)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
944 (setq s (point)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
945 (skip-syntax-forward " " (line-end-position))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
946 (delete-region s (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
947 (indent-to l))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
948 '(lambda (l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
949 (move-to-column l)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
950 ;; (setq cua-save-point (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
951 ))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
952
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
953 (defun cua-copy-rectangle-as-text (&optional arg delete)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
954 "Copy rectangle, but store as normal text."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
955 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
956 (if cua--global-mark-active
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
957 (if delete
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
958 (cua--cut-rectangle-to-global-mark t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
959 (cua--copy-rectangle-to-global-mark t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
960 (let* ((rect (cua--extract-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
961 (text (mapconcat
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
962 (function (lambda (row) (concat row "\n")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
963 rect "")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
964 (setq arg (cua--prefix-arg arg))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
965 (if cua--register
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
966 (set-register cua--register text)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
967 (kill-new text)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
968 (if delete
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
969 (cua--delete-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
970 (cua--deactivate)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
971
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
972 (defun cua-cut-rectangle-as-text (arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
973 "Kill rectangle, but store as normal text."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
974 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
975 (cua-copy-rectangle-as-text arg (not buffer-read-only)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
976
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
977 (defun cua-string-rectangle (string)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
978 "Replace CUA rectangle contents with STRING on each line.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
979 The length of STRING need not be the same as the rectangle width."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
980 (interactive "sString rectangle: ")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
981 (cua--rectangle-operation 'keep nil t t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
982 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
983 (delete-region s e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
984 (skip-chars-forward " \t")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
985 (let ((ws (- (current-column) l)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
986 (delete-region s (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
987 (insert string)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
988 (indent-to (+ (current-column) ws))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
989 (unless (cua--rectangle-restriction)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
990 '(lambda (l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
991 (cua--rectangle-right (max l (+ l (length string) -1)))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
992
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
993 (defun cua-fill-char-rectangle (ch)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
994 "Replace CUA rectangle contents with CHARACTER."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
995 (interactive "cFill rectangle with character: ")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
996 (cua--rectangle-operation 'clear nil t 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
997 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
998 (delete-region s e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
999 (move-to-column l t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1000 (insert-char ch (- r l)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1001
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1002 (defun cua-replace-in-rectangle (regexp newtext)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1003 "Replace REGEXP with NEWTEXT in each line of CUA rectangle."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1004 (interactive "sReplace regexp: \nsNew text: ")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1005 (if buffer-read-only
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1006 (message "Cannot replace in read-only buffer")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1007 (cua--rectangle-operation 'keep nil t 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1008 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1009 (if (re-search-forward regexp e t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1010 (replace-match newtext nil nil))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1011
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1012 (defun cua-incr-rectangle (increment)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1013 "Increment each line of CUA rectangle by prefix amount."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1014 (interactive "p")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1015 (cua--rectangle-operation 'keep nil t 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1016 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1017 (cond
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1018 ((re-search-forward "0x\\([0-9a-fA-F]+\\)" e t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1019 (let* ((txt (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1020 (n (string-to-number txt 16))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1021 (fmt (format "0x%%0%dx" (length txt))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1022 (replace-match (format fmt (+ n increment)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1023 ((re-search-forward "\\( *-?[0-9]+\\)" e t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1024 (let* ((txt (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1025 (prefix (if (= (aref txt 0) ?0) "0" ""))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1026 (n (string-to-number txt 10))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1027 (fmt (format "%%%s%dd" prefix (length txt))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1028 (replace-match (format fmt (+ n increment)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1029 (t nil)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1030
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1031 (defvar cua--rectangle-seq-format "%d"
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1032 "Last format used by cua-sequence-rectangle.")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1033
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1034 (defun cua-sequence-rectangle (first incr fmt)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1035 "Resequence each line of CUA rectangle starting from FIRST.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1036 The numbers are formatted according to the FORMAT string."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1037 (interactive
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1038 (list (if current-prefix-arg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1039 (prefix-numeric-value current-prefix-arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1040 (string-to-number
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1041 (read-string "Start value: (0) " nil nil "0")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1042 (string-to-number
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1043 (read-string "Increment: (1) " nil nil "1"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1044 (read-string (concat "Format: (" cua--rectangle-seq-format ") "))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1045 (if (= (length fmt) 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1046 (setq fmt cua--rectangle-seq-format)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1047 (setq cua--rectangle-seq-format fmt))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1048 (cua--rectangle-operation 'clear nil t 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1049 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1050 (delete-region s e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1051 (insert (format fmt first))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1052 (setq first (+ first incr)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1053
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1054 (defun cua-upcase-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1055 "Convert the rectangle to upper case."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1056 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1057 (cua--rectangle-operation 'clear nil nil nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1058 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1059 (upcase-region s e))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1060
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1061 (defun cua-downcase-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1062 "Convert the rectangle to lower case."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1063 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1064 (cua--rectangle-operation 'clear nil nil nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1065 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1066 (downcase-region s e))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1067
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1068
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1069 ;;; Replace/rearrange text in current rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1070
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1071 (defun cua--rectangle-aux-replace (width adjust keep replace pad format-fct &optional setup-fct)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1072 ;; Process text inserted by calling SETUP-FCT or current rectangle if nil.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1073 ;; Then call FORMAT-FCT on text (if non-nil); takes two args: start and end.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1074 ;; Fill to WIDTH characters if > 0 or fill to current width if == 0.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1075 ;; Don't fill if WIDTH < 0.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1076 ;; Replace current rectangle by filled text if REPLACE is non-nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1077 (let ((auxbuf (get-buffer-create "*CUA temp*"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1078 (w (if (> width 1) width
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1079 (- (cua--rectangle-right) (cua--rectangle-left) -1)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1080 (r (or setup-fct (cua--extract-rectangle)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1081 y z (tr 0))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1082 (save-excursion
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1083 (set-buffer auxbuf)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1084 (erase-buffer)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1085 (if setup-fct
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1086 (funcall setup-fct)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1087 (cua--insert-rectangle r))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1088 (if format-fct
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1089 (let ((fill-column w))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1090 (funcall format-fct (point-min) (point-max))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1091 (when replace
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1092 (goto-char (point-min))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1093 (while (not (eobp))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1094 (setq z (cons (buffer-substring (point) (line-end-position)) z))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1095 (forward-line 1))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1096 (if (not cua--debug)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1097 (kill-buffer auxbuf))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1098 (when replace
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1099 (setq z (reverse z))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1100 (if cua--debug
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1101 (print z auxbuf))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1102 (cua--rectangle-operation nil nil t pad
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1103 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1104 (let (cc)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1105 (goto-char e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1106 (skip-chars-forward " \t")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1107 (setq cc (current-column))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1108 (if cua--debug
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1109 (print (list cc s e) auxbuf))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1110 (delete-region s (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1111 (if (not z)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1112 (setq y 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1113 (move-to-column l t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1114 (insert (car z))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1115 (when (> (current-column) (+ l w))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1116 (setq y (point))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1117 (move-to-column (+ l w) t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1118 (delete-region (point) y)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1119 (setq tr (1+ tr)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1120 (setq z (cdr z)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1121 (if cua--debug
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1122 (print (list (current-column) cc) auxbuf))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1123 (indent-to cc))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1124 (if (> tr 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1125 (message "Warning: Truncated %d row%s" tr (if (> tr 1) "s" "")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1126 (if adjust
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1127 (cua--rectangle-right (+ (cua--rectangle-left) w -1)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1128 (if keep
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1129 (cua--rectangle-resized)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1130
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1131 (put 'cua--rectangle-aux-replace 'lisp-indent-function 4)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1132
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1133 (defun cua--left-fill-rectangle (start end)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1134 (beginning-of-line)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1135 (while (< (point) (point-max))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1136 (delete-horizontal-space nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1137 (forward-line 1))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1138 (fill-region-as-paragraph (point-min) (point-max) 'left nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1139 (untabify (point-min) (point-max)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1140
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1141 (defun cua-text-fill-rectangle (width text)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1142 "Replace rectagle with filled TEXT read from minibuffer.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1143 A numeric prefix argument is used a new width for the filled rectangle."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1144 (interactive (list
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1145 (prefix-numeric-value current-prefix-arg)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1146 (read-from-minibuffer "Enter text: "
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1147 nil nil nil nil)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1148 (cua--rectangle-aux-replace width t t t 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1149 'cua--left-fill-rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1150 '(lambda () (insert text))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1151
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1152 (defun cua-refill-rectangle (width)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1153 "Fill contents of current rectagle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1154 A numeric prefix argument is used as new width for the filled rectangle."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1155 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1156 (cua--rectangle-aux-replace
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1157 (if width (prefix-numeric-value width) 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1158 t t t 1 'cua--left-fill-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1159
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1160 (defun cua-shell-command-on-rectangle (replace command)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1161 "Run shell command on rectangle like `shell-command-on-region'.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1162 With prefix arg, replace rectangle with output from command."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1163 (interactive (list
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1164 current-prefix-arg
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1165 (read-from-minibuffer "Shell command on rectangle: "
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1166 nil nil nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1167 'shell-command-history)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1168 (cua--rectangle-aux-replace -1 t t replace 1
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1169 '(lambda (s e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1170 (shell-command-on-region s e command
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1171 replace replace nil))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1172
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1173 (defun cua-reverse-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1174 "Reverse the lines of the rectangle."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1175 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1176 (cua--rectangle-aux-replace 0 t t t t 'reverse-region))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1177
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1178 (defun cua-scroll-rectangle-up ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1179 "Remove the first line of the rectangle and scroll remaining lines up."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1180 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1181 (cua--rectangle-aux-replace 0 t t t t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1182 '(lambda (s e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1183 (if (= (forward-line 1) 0)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1184 (delete-region s (point))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1185
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1186 (defun cua-scroll-rectangle-down ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1187 "Insert a blank line at the first line of the rectangle.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1188 The remaining lines are scrolled down, losing the last line."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1189 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1190 (cua--rectangle-aux-replace 0 t t t t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1191 '(lambda (s e)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1192 (goto-char s)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1193 (insert "\n"))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1194
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1195
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1196 ;;; Insert/delete text to left or right of rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1197
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1198 (defun cua-insert-char-rectangle (&optional ch)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1199 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1200 (if buffer-read-only
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1201 (ding)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1202 (cua--indent-rectangle (or ch (aref (this-single-command-keys) 0)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1203 (cua--keep-active))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1204 t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1205
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1206 (defun cua-indent-rectangle (column)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1207 "Indent rectangle to next tab stop.
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1208 With prefix arg, indent to that column."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1209 (interactive "P")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1210 (if (null column)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1211 (cua-insert-char-rectangle ?\t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1212 (cua--indent-rectangle nil (prefix-numeric-value column))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1213
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1214 (defun cua-delete-char-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1215 "Delete char to left or right of rectangle."
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1216 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1217 (let ((col (cua--rectangle-insert-col))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1218 (pad (cua--rectangle-padding))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1219 indent)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1220 (cua--rectangle-operation 'corners nil t pad
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1221 '(lambda (s e l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1222 (move-to-column
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1223 (if (cua--rectangle-right-side t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1224 (max (1+ r) col) l)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1225 pad)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1226 (if (bolp)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1227 nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1228 (delete-backward-char 1)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1229 (if (cua--rectangle-right-side t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1230 (cua--rectangle-insert-col (current-column))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1231 (setq indent (- l (current-column))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1232 '(lambda (l r)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1233 (when (and indent (> indent 0))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1234 (aset cua--rectangle 2 (- l indent))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1235 (aset cua--rectangle 3 (- r indent 1)))))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1236
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1237 (defun cua-help-for-rectangle (&optional help)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1238 (interactive)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1239 (let ((M (if cua-use-hyper-key " H-" " M-")))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1240 (message
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1241 (concat (if help "C-?:help" "")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1242 M "p:pad" M "o:open" M "c:close" M "b:blank"
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1243 M "s:string" M "f:fill" M "i:incr" M "n:seq"))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1244
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1245
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1246 ;;; CUA-like cut & paste for rectangles
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1247
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1248 (defun cua--cancel-rectangle ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1249 ;; Cancel rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1250 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1251 (cua--deactivate-rectangle))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1252 (setq cua--last-rectangle nil))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1253
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1254 (defun cua--rectangle-post-command ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1255 (if cua--restored-rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1256 (setq cua--rectangle cua--restored-rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1257 cua--restored-rectangle nil
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1258 mark-active t
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1259 deactivate-mark nil)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1260 (when (and cua--rectangle cua--buffer-and-point-before-command
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1261 (equal (car cua--buffer-and-point-before-command) (current-buffer))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1262 (not (= (cdr cua--buffer-and-point-before-command) (point))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1263 (if (cua--rectangle-right-side)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1264 (cua--rectangle-right (current-column))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1265 (cua--rectangle-left (current-column)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1266 (if (>= (cua--rectangle-corner) 2)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1267 (cua--rectangle-bot t)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1268 (cua--rectangle-top t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1269 (if (cua--rectangle-padding)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1270 (setq unread-command-events
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1271 (cons (if cua-use-hyper-key ?\H-P ?\M-P) unread-command-events)))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1272 (if cua--rectangle
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1273 (if (and mark-active
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1274 (not deactivate-mark))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1275 (cua--highlight-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1276 (cua--deactivate-rectangle))))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1277
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1278
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1279 ;;; Initialization
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1280
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1281 (defun cua--rect-M/H-key (key cmd)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1282 (cua--M/H-key cua--rectangle-keymap key cmd))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1283
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1284 (defun cua--rectangle-on-off (on)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1285 (cancel-function-timers 'cua--tidy-undo-lists)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1286 (if on
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1287 (run-with-idle-timer 10 t 'cua--tidy-undo-lists)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1288 (cua--tidy-undo-lists t)))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1289
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1290 (defun cua--init-rectangles ()
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1291 (unless (face-background 'cua-rectangle-face)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1292 (copy-face 'region 'cua-rectangle-face)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1293 (set-face-background 'cua-rectangle-face "maroon")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1294 (set-face-foreground 'cua-rectangle-face "white"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1295
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1296 (unless (face-background 'cua-rectangle-noselect-face)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1297 (copy-face 'region 'cua-rectangle-noselect-face)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1298 (set-face-background 'cua-rectangle-noselect-face "dimgray")
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1299 (set-face-foreground 'cua-rectangle-noselect-face "white"))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1300
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1301 (unless (eq cua-use-hyper-key 'only)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1302 (define-key cua--rectangle-keymap [(shift return)] 'cua-clear-rectangle-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1303 (define-key cua--region-keymap [(shift return)] 'cua-toggle-rectangle-mark))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1304 (when cua-use-hyper-key
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1305 (cua--rect-M/H-key 'space 'cua-clear-rectangle-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1306 (cua--M/H-key cua--region-keymap 'space 'cua-toggle-rectangle-mark))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1307
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1308 (define-key cua--rectangle-keymap [remap copy-region-as-kill] 'cua-copy-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1309 (define-key cua--rectangle-keymap [remap kill-ring-save] 'cua-copy-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1310 (define-key cua--rectangle-keymap [remap kill-region] 'cua-cut-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1311 (define-key cua--rectangle-keymap [remap delete-char] 'cua-delete-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1312 (define-key cua--rectangle-keymap [remap set-mark-command] 'cua-toggle-rectangle-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1313
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1314 (define-key cua--rectangle-keymap [remap forward-char] 'cua-resize-rectangle-right)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1315 (define-key cua--rectangle-keymap [remap backward-char] 'cua-resize-rectangle-left)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1316 (define-key cua--rectangle-keymap [remap next-line] 'cua-resize-rectangle-down)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1317 (define-key cua--rectangle-keymap [remap previous-line] 'cua-resize-rectangle-up)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1318 (define-key cua--rectangle-keymap [remap end-of-line] 'cua-resize-rectangle-eol)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1319 (define-key cua--rectangle-keymap [remap beginning-of-line] 'cua-resize-rectangle-bol)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1320 (define-key cua--rectangle-keymap [remap end-of-buffer] 'cua-resize-rectangle-bot)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1321 (define-key cua--rectangle-keymap [remap beginning-of-buffer] 'cua-resize-rectangle-top)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1322 (define-key cua--rectangle-keymap [remap scroll-down] 'cua-resize-rectangle-page-up)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1323 (define-key cua--rectangle-keymap [remap scroll-up] 'cua-resize-rectangle-page-down)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1324
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1325 (define-key cua--rectangle-keymap [remap delete-backward-char] 'cua-delete-char-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1326 (define-key cua--rectangle-keymap [remap backward-delete-char] 'cua-delete-char-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1327 (define-key cua--rectangle-keymap [remap backward-delete-char-untabify] 'cua-delete-char-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1328 (define-key cua--rectangle-keymap [remap self-insert-command] 'cua-insert-char-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1329 (define-key cua--rectangle-keymap [remap self-insert-iso] 'cua-insert-char-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1330
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1331 (define-key cua--rectangle-keymap "\r" 'cua-rotate-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1332 (define-key cua--rectangle-keymap "\t" 'cua-indent-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1333
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1334 (define-key cua--rectangle-keymap [(control ??)] 'cua-help-for-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1335
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1336 (define-key cua--rectangle-keymap [mouse-1] 'cua-mouse-set-rectangle-mark)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1337 (define-key cua--rectangle-keymap [down-mouse-1] 'cua--mouse-ignore)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1338 (define-key cua--rectangle-keymap [drag-mouse-1] 'cua--mouse-ignore)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1339 (define-key cua--rectangle-keymap [mouse-3] 'cua-mouse-save-then-kill-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1340 (define-key cua--rectangle-keymap [down-mouse-3] 'cua--mouse-ignore)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1341 (define-key cua--rectangle-keymap [drag-mouse-3] 'cua--mouse-ignore)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1342
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1343 (cua--rect-M/H-key 'up 'cua-move-rectangle-up)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1344 (cua--rect-M/H-key 'down 'cua-move-rectangle-down)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1345 (cua--rect-M/H-key 'left 'cua-move-rectangle-left)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1346 (cua--rect-M/H-key 'right 'cua-move-rectangle-right)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1347
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1348 (cua--rect-M/H-key '(control up) 'cua-scroll-rectangle-up)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1349 (cua--rect-M/H-key '(control down) 'cua-scroll-rectangle-down)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1350
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1351 (cua--rect-M/H-key ?a 'cua-align-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1352 (cua--rect-M/H-key ?b 'cua-blank-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1353 (cua--rect-M/H-key ?c 'cua-close-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1354 (cua--rect-M/H-key ?f 'cua-fill-char-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1355 (cua--rect-M/H-key ?i 'cua-incr-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1356 (cua--rect-M/H-key ?k 'cua-cut-rectangle-as-text)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1357 (cua--rect-M/H-key ?l 'cua-downcase-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1358 (cua--rect-M/H-key ?m 'cua-copy-rectangle-as-text)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1359 (cua--rect-M/H-key ?n 'cua-sequence-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1360 (cua--rect-M/H-key ?o 'cua-open-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1361 (cua--rect-M/H-key ?p 'cua-toggle-rectangle-padding)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1362 (cua--rect-M/H-key ?P 'cua-do-rectangle-padding)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1363 (cua--rect-M/H-key ?q 'cua-refill-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1364 (cua--rect-M/H-key ?r 'cua-replace-in-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1365 (cua--rect-M/H-key ?R 'cua-reverse-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1366 (cua--rect-M/H-key ?s 'cua-string-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1367 (cua--rect-M/H-key ?t 'cua-text-fill-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1368 (cua--rect-M/H-key ?u 'cua-upcase-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1369 (cua--rect-M/H-key ?| 'cua-shell-command-on-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1370 (cua--rect-M/H-key ?' 'cua-restrict-prefix-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1371 (cua--rect-M/H-key ?/ 'cua-restrict-regexp-rectangle)
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1372
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1373 (setq cua--rectangle-initialized t))
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1374
358d42530d42 Added cua-mode based files [split from original cua.el]:
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1375 ;;; cua-rect.el ends here