Mercurial > emacs
annotate lisp/vcursor.el @ 21070:f88e08d192a8
(isearch-*-char): Do nothing special if quoted with \.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 05 Mar 1998 02:28:44 +0000 |
parents | 7813d4b7bea5 |
children | ac1673121774 |
rev | line source |
---|---|
17450 | 1 ;;; vcursor.el --- manipulate an alternative ("virtual") cursor. |
2 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
3 ;; Copyright (C) 1994, 1996, 1998 Free Software Foundation, Inc. |
17450 | 4 |
5 ;; Author: Peter Stephenson <pws@ifh.de> | |
6 ;; Keywords: virtual cursor, display, copying | |
7 | |
17902
e4a7b81d6c10
Fix copyright and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
17450
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
e4a7b81d6c10
Fix copyright and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
17450
diff
changeset
|
9 |
e4a7b81d6c10
Fix copyright and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
17450
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
17450 | 11 ;; it under the terms of the GNU General Public License as published by |
17902
e4a7b81d6c10
Fix copyright and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
17450
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
e4a7b81d6c10
Fix copyright and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
17450
diff
changeset
|
13 ;; any later version. |
17450 | 14 |
17902
e4a7b81d6c10
Fix copyright and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
17450
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
17450 | 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
27 ;; Latest changes (1.6) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
28 ;; ==================== |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
29 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
30 ;; - works on dumb terminals with Emacs 19.29 and later |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
31 ;; - new keymap vcursor-map for binding to a prefix key |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
32 ;; - vcursor-compare-windows substantially improved |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
33 ;; - vcursor-execute-{key,command} much better about using the |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
34 ;; right keymaps and arranging for the correct windows to be used |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
35 ;; - vcursor-window-funcall can call functions interactively |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
36 ;; - vcursor-interpret-input for special effects |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
37 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
38 ;; Introduction |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
39 ;; ============ |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
40 ;; |
17450 | 41 ;; Virtual cursor commands. I got this idea from the old BBC micro. |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
42 ;; You need Emacs 19 or 20 and a window system for the best effects. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
43 ;; For character terminals, at least Emacs 19.29 is required |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
44 ;; (special behaviour for the overlay property |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
45 ;; "before-string" must be implemented). Search for "dumb terminals" |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
46 ;; for more information. |
17450 | 47 ;; |
48 ;; This is much easier to use than the instructions are to read. | |
49 ;; I suggest you simply load it and play around with holding down Ctrl | |
50 ;; and Shift and pressing up, down, left, right, tab, return, and see | |
51 ;; what happens. (Find a scratch buffer before using C-S-tab: that | |
52 ;; toggles copying.) | |
53 ;; | |
54 ;; Most of the functions described in this documentation are in | |
55 ;; parentheses so that if you have the package loaded you can type C-h | |
56 ;; f on top of them for help. | |
57 ;; | |
58 ;; Using the cursor keys with both control and shift held down moves | |
59 ;; around a virtual cursor, which is initially at point. When active, | |
60 ;; it appears with an underline through it to distinguish it from the | |
61 ;; normal cursor. You can then use one of the other commands to copy | |
62 ;; characters from the location of the virtual cursor to point. This | |
63 ;; is very useful, for example, when copying some previous text while | |
64 ;; making changes to it at the same time, since you never have to move | |
65 ;; the "real" cursor away from where you are inserting. | |
66 ;; | |
67 ;; The remaining default key bindings are based around the PC-type | |
68 ;; cluster found above the cursor keys on a lot of keyboards, the | |
69 ;; function keys which my limited knowledge of X terminals expects to | |
70 ;; find at the top. Some functions are duplicated in more obvious | |
71 ;; places for the X version. | |
72 ;; | |
73 ;; All the keybindings require you to hold down control and shift at | |
74 ;; once. I assumed this combination wouldn't be heavily bound by most | |
75 ;; people and that it would be easy to type with the left hand. | |
76 ;; Inevitably it will clash with some other packages, but I can't help | |
77 ;; that: an intuitive binding is a prerequisite here. See below for | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
78 ;; other alternatives (search for "Oemacs"). There is also a keymap |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
79 ;; which you can bind to a prefix key, which may give some more |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
80 ;; intuitive alternatives in some cases, see `The vcursor keymap' below. |
17450 | 81 ;; |
82 ;; Holding down control and shift and pressing insert (vcursor-copy) | |
83 ;; copies one character from wherever the virtual cursor is to point; | |
84 ;; point and the virtual cursor advance in the separate and equal | |
85 ;; station to which... (etc.). M-C-S-return (vcursor-copy-line) | |
86 ;; copies to the end of the line instead of just one character, | |
87 ;; C-S-delete or C-S-remove (vcursor-copy-word) copies a word. | |
88 ;; | |
89 ;; A more general way of copying is to use C-S-tab, which is a toggle. | |
90 ;; In the "on" state, moving the virtual cursor will copy the | |
91 ;; moved-over text to the normal cursor position (including when going | |
92 ;; backwards, though each piece of text moved over is copied forwards: | |
93 ;; compare the behaviour of C-S-up and C-S-left). | |
94 ;; | |
95 ;; However, that's just a small part of the magic. If the virtual | |
96 ;; cursor goes off the display, it will be redisplayed in some other | |
97 ;; window. (See the function (vcursor-find-window) for details of how | |
98 ;; this window is chosen.) This gives you fingertip control over two | |
99 ;; windows at once. | |
100 ;; | |
101 ;; C-S-return (vcursor-disable) disables the virtual cursor, removing | |
102 ;; it so that it starts from point whenever you move it again --- note | |
103 ;; that simply moving the cursor and virtual cursor on top of one | |
104 ;; another does not have this effect. | |
105 ;; | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
106 ;; If you give C-S-return a positive prefix arg, it will also delete the |
17450 | 107 ;; window (unless it's the current one). Whenever the virtual cursor |
108 ;; goes off-screen in its own window, point in that window is moved as | |
109 ;; well to restore it to view. (It's easier that way, that's why. | |
110 ;; However, point doesn't move unless the view in the window does, so | |
111 ;; it's not tied to the virtual cursor location.) | |
112 ;; | |
113 ;; You can also use C-S-return with a negative prefix argument which | |
114 ;; forces the vcursor to appear at point. This is particularly useful if | |
115 ;; you actually want to edit in another window but would like to | |
116 ;; remember the current cursor location for examining or copying from | |
117 ;; that buffer. (I just hit C-S-right C-S-left, but I'm a hopeless | |
118 ;; lowbrow.) | |
119 ;; | |
120 ;; There is also C-S-f6 (vcursor-other-window) which behaves like | |
121 ;; C-x o on the virtual rather than the real cursor, except that it | |
122 ;; will create another window if necessary. | |
123 ;; | |
124 ;; The keys C-S-prior (vcursor-scroll-down) and C-S-next | |
125 ;; (vcursor-scroll-up) (i.e., PageUp and PageDown) will scroll the | |
126 ;; virtual cursor window, appropriately chosen. They will always | |
127 ;; create a new window or take over an old one if necessary. | |
128 ;; Likewise, M-C-S-left and M-C-S-right move you to the | |
129 ;; beginning or end of a line, C-S-home and C-S-end the | |
130 ;; beginning or end of a buffer (these are also on M-C-S-up and | |
131 ;; M-C-S-down for those of us stuck with DEC keyboards). | |
132 ;; | |
133 ;; C-S-f7 (vcursor-goto) will take you to the vcursor position | |
134 ;; (swapping windows if it seems sensible) and (unless you give it a | |
135 ;; prefix argument) delete the virtual cursor, so this is useful for | |
136 ;; you to take over editing at the virtual cursor position. It is not | |
137 ;; an error if the virtual cursor is not active; it simply leaves you | |
138 ;; at point, because that is where the virtual cursor would start | |
139 ;; from. | |
140 ;; | |
141 ;; In a similar vein, M-C-S-tab (hope your left hand's flexible; | |
142 ;; C-S-select on DEC keyboards) (vcursor-swap-point) will take you to | |
143 ;; the virtual cursor position but simultaneously put the virtual | |
144 ;; cursor at the old cursor position. It is also supposed to ensure | |
145 ;; that both are visible. | |
146 ;; | |
147 ;; C-S-f8 (C-S-find on DEC keyboards) (vcursor-isearch-forward) | |
148 ;; allows you to do an isearch in another window. It works a bit like | |
149 ;; vcursor-scroll-*; it moves into another window, calls isearch | |
150 ;; there, and sets the virtual cursor position to the point found. In | |
151 ;; other words, it works just like isearch but with the virtual cursor | |
152 ;; instead of the real one (that's why it's called a "virtual | |
153 ;; cursor"). While you are isearching, you are editing in the virtual | |
154 ;; cursor window, but when you have finished you return to where you | |
155 ;; started. Note that once you are in isearch all the keys are normal | |
156 ;; --- use C-s, not C-S-f8, to search for the next occurrence. | |
157 ;; | |
158 ;; If you set the variable vcursor-auto-disable, then any command | |
159 ;; which does not involve moving or copying from the virtual cursor | |
160 ;; causes the virtual cursor to be disabled. If you don't intend to | |
161 ;; use this, you can comment out the `add-hook' line at the bottom of | |
162 ;; this file. (This feature partially emulates the way the "copy" key | |
163 ;; on the BBC micro worked; actually, the copy cursor was homed when | |
164 ;; you hit return. This was in keeping with the line-by-line way of | |
165 ;; entering BASIC, but is less appropriate here.) | |
166 ;; | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
167 ;; vcursor-compare-windows is now a reliable adaption of |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
168 ;; compare-windows, which compares between point in the current buffer |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
169 ;; and the vcursor location in the other one. It is an error if |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
170 ;; vcursor is not set, however it will be brought up in another window |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
171 ;; if it is not currently visible. The prefix argument acts just like |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
172 ;; compare-windows, ignoring whitespace if set. (In versions before |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
173 ;; 1.6, this simply called compare-windows, which was much less likely |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
174 ;; to pick the two windows you wanted.) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
175 ;; |
17450 | 176 ;; There is a way of moving the virtual cursor using ordinary |
177 ;; commands: C-S-f9 (vcursor-execute-key) reads a key string, | |
178 ;; moves to the virtual cursor position, executes the command bound to | |
179 ;; the string, then returns to the original point. Thus C-S-f9 M-m | |
180 ;; moves the virtual cursor back to the first non-whitespace character | |
181 ;; on its line. As the command is called interactively all the usual | |
182 ;; ways of passing information to the command called, such as by a | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
183 ;; prefix argument, are available. This has many uses not necessarily |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
184 ;; related to moving the vcursor itself; it can do essentially |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
185 ;; everything that the \C-x 4 series of commands can do and a lot |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
186 ;; more. Note, however, that a new window is not used if the vcursor |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
187 ;; is visible in the current one: this can lead to some strange effects, |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
188 ;; but it is preferable to making a new window every time the vcursor |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
189 ;; is moved in this may. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
190 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
191 ;; C-S-f10 (C-S-x) (vcursor-execute-command) behaves the same way but |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
192 ;; you enter the name of the command. To do anything really |
17450 | 193 ;; complicated, you are better off using M-C-S-tab |
194 ;; (vcursor-swap-point), doing whatever it is, then calling M-C-S-tab | |
195 ;; again. | |
196 ;; | |
197 ;; If you want to add your own moving or copying functions you should | |
198 ;; be able to do this fairly easily with (vcursor-relative-move) and | |
199 ;; (vcursor-copy) together with (vcursor-get-char-count). If you want to | |
200 ;; do something in a different window, use (vcursor-window-funcall). | |
201 ;; | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
202 ;; Key bindings |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
203 ;; ============ |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
204 ;; |
17450 | 205 ;; There is an alternative set of key bindings which will be used |
206 ;; automatically for a PC if Oemacs is detected. This set uses separate | |
207 ;; control, shift and meta keys with function keys 1 to 10. In | |
208 ;; particular, movement keys are concentrated on f5 to f8 with (in | |
209 ;; increasing order of distance travelled) C-, M- and S- as prefixes. | |
210 ;; See the actual bindings below (search for C-f1). This is because the | |
211 ;; C-S- prefix is represented by weird key sequences and the set is | |
212 ;; incomplete; if you don't mind that, some hints are given in comments | |
213 ;; below. | |
214 ;; | |
215 ;; You can specify the usual or the Oemacs bindings by setting the | |
216 ;; variable vcursor-key-bindings to `xterm' or `oemacs'. You can also set | |
217 ;; it to nil, in which case vcursor will not make any key bindings | |
218 ;; and you can define your own. The default is t, which makes vcursor | |
219 ;; guess (it will use xterm unless it thinks Oemacs is running). The | |
220 ;; oemacs set will work on an X terminal with function keys, but the | |
221 ;; xterm set will not work under Oemacs. | |
222 ;; | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
223 ;; Usage on dumb terminals |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
224 ;; ======================= |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
225 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
226 ;; If Emacs has set the variable window-system to nil, vcursor will |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
227 ;; assume that overlays cannot be displayed in a different face, |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
228 ;; and will instead use an string (the variable vcursor-string, by |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
229 ;; default "**>") to show its position. This was first implemented |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
230 ;; in Emacs 19.29. Unlike the old-fashioned overlay arrow (as used |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
231 ;; by debuggers), this appears between existing text, which can |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
232 ;; make it hard to read if you're not used to it. (This seemed the |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
233 ;; better option here.) This means moving the vcursor up and down is |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
234 ;; a very efficient way of locating it! |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
235 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
236 ;; Everything else should function as expected, but there is no way to |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
237 ;; get an easy key binding for the vcursor keys on a generic terminal. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
238 ;; Consequently a special keymap is defined for you to use traditional |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
239 ;; methods: the keymap, however, is available on any terminal type. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
240 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
241 ;; The vcursor keymap |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
242 ;; ================== |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
243 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
244 ;; In addition to any other bindings, vcursor-map contains key definitions |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
245 ;; for handling the vcursor. You should assign this to a prefix key |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
246 ;; in the usual way, e.g. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
247 ;; (global-set-key [f14] vcursor-map) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
248 ;; and also as usual \C-h in this map will list the key definitions, which |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
249 ;; are designed to be easy to remember. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
250 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
251 ;; A special feature is provided by (vcursor-toggle-vcursor-map), bound |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
252 ;; to t in that keymap. With this in effect, the main keymap |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
253 ;; is overridden by the vcursor map, so keys like \C-p and so on |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
254 ;; move the vcursor instead. Remember how to turn it off (type t), |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
255 ;; or you are in serious trouble! Note that the cursor keys are not |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
256 ;; bound by default in this keymap and will continue to move the |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
257 ;; ordinary cursor. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
258 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
259 ;; Interpreted input |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
260 ;; ================= |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
261 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
262 ;; Just occasionally, you may want to pretend the strings copied from |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
263 ;; the vcursor position are to be interpreted as if you had typed them |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
264 ;; from the keyboard. Normally, they will just insert themselves anyway, |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
265 ;; but in some modes (Info and calc for example) typing ordinary characters |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
266 ;; does something else. To get this effect, set |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
267 ;; vcursor-interpret-input to t. This is normally not a good idea as |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
268 ;; interpreting input is very much slower than copying text. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
269 ;; |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
270 ;; Un-features |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
271 ;; =========== |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
272 ;; |
17450 | 273 ;; - The vcursor will not move to point-max, since otherwise it would |
274 ;; disappear. However, no error is flagged as point-max is a valid | |
275 ;; point in the buffer. Thus cursor right or down at the second | |
276 ;; last point in the file does not flag an error, which is inconsistent, | |
277 ;; and if copying is on the last character (typically newline) will | |
278 ;; be repeatedly copied. (I've tried making it flag an error | |
279 ;; instead and that's worse since often the vcursor is sent to | |
280 ;; point in some other window, which may be point-max.) | |
281 ;; - The vcursor widens when over a tab character or right at the | |
282 ;; end of the line. You're welcome to consider this a feature; | |
283 ;; it's just a part of how overlays work. | |
284 ;; - The vcursor obscures the real cursor. Creative use of overlays | |
285 ;; could cure this. | |
286 ;; - The vcursor does not remember its own previous positions. If | |
287 ;; you cycle it back into a window it was in before, it will be at | |
288 ;; point in that window. Often, that is where a previous recenter | |
289 ;; left point, not where the vcursor was before. | |
290 ;; (Note, however, that the vcursor does remember where it *is*, | |
291 ;; even if it's off-screen. This can also lead to surprises, but I | |
292 ;; don't think it's a bug.) | |
293 ;; - vcursor-window-funcall could perhaps be smarter about restoring | |
294 ;; the previous window state on failure. | |
295 ;; - The logic in vcursor-find-window is rather complicated and | |
296 ;; therefore bug-prone, though in practice it seems to work OK. | |
297 ;; | |
298 ;; Possible enhnacements: | |
299 ;; It would be easy to implement vcursor-push (save vcursor position | |
300 ;; as mark and deactivate) and vcursor-pop (deactivate vcursor and | |
301 ;; move to last pushed position) functions. | |
302 | |
303 ;;; Code: | |
304 | |
305 (or (memq 'vcursor (face-list)) | |
306 (progn | |
307 (copy-face 'modeline 'vcursor) | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
308 (if (or (fboundp 'oemacs-version) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
309 (and (eq window-system 'x) (x-display-color-p))) |
17450 | 310 (progn |
311 (set-face-foreground 'vcursor "blue") | |
312 (set-face-background 'vcursor "cyan"))) | |
313 (set-face-underline-p 'vcursor t))) | |
314 | |
315 (defvar vcursor-auto-disable nil | |
316 "*If non-nil, disable the virtual cursor after use. | |
317 Any non-vcursor command will force `vcursor-disable' to be called.") | |
318 | |
319 (defvar vcursor-key-bindings t | |
320 "*How to bind keys when vcursor is loaded. | |
321 If t (the default), guess; if xterm, use bindings suitable for an | |
322 X terminal; if oemacs, use bindings which work on a PC with Oemacs. | |
323 If nil, don't define any key bindings.") | |
324 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
325 (defvar vcursor-interpret-input nil |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
326 "*If non-nil, input from the vcursor is treated as interactive input. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
327 This will cause text insertion to be much slower. Note that no special |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
328 interpretation of strings is done: \"\C-x\" is a string of four |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
329 characters. The default is simply to copy strings.") |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
330 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
331 (defvar vcursor-string "**>" |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
332 "String used to show the vcursor position on dumb terminals.") |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
333 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
334 (defvar vcursor-overlay nil |
17450 | 335 "Overlay for the virtual cursor. |
336 It is nil if that is not enabled.") | |
337 | |
338 (defvar vcursor-window nil | |
339 "Last window to have displayed the virtual cursor. | |
340 See the function `vcursor-find-window' for how this is used.") | |
341 | |
342 (defvar vcursor-last-command nil | |
343 "Non-nil if last command was a vcursor command. | |
344 The commands `vcursor-copy', `vcursor-relative-move' and the ones for | |
345 scrolling set this. It is used by the `vcursor-auto-disable' code.") | |
346 ;; could do some memq-ing with last-command instead, but this will | |
347 ;; automatically handle any new commands using the primitives. | |
348 | |
349 (defvar vcursor-copy-flag nil | |
350 "*Non-nil means moving vcursor should copy characters moved over to point.") | |
351 | |
352 (defvar vcursor-temp-goal-column nil | |
353 "Keeps track of temporary goal columns for the virtual cursor.") | |
354 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
355 (defvar vcursor-use-vcursor-map nil |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
356 "Non-nil if the vcursor map is mapped directly onto the main keymap. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
357 See vcursor-toggle-vcursor-map.") |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
358 (make-variable-buffer-local 'vcursor-use-vcursor-map) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
359 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
360 (defvar vcursor-map nil "Keymap for vcursor command.") |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
361 (define-prefix-command 'vcursor-map) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
362 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
363 (define-key vcursor-map "t" 'vcursor-toggle-vcursor-map) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
364 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
365 (define-key vcursor-map "\C-p" 'vcursor-previous-line) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
366 (define-key vcursor-map "\C-n" 'vcursor-next-line) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
367 (define-key vcursor-map "\C-b" 'vcursor-backward-char) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
368 (define-key vcursor-map "\C-f" 'vcursor-forward-char) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
369 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
370 (define-key vcursor-map "\r" 'vcursor-disable) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
371 (define-key vcursor-map " " 'vcursor-copy) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
372 (define-key vcursor-map "\C-y" 'vcursor-copy-word) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
373 (define-key vcursor-map "\C-i" 'vcursor-toggle-copy) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
374 (define-key vcursor-map "<" 'vcursor-beginning-of-buffer) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
375 (define-key vcursor-map ">" 'vcursor-end-of-buffer) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
376 (define-key vcursor-map "\M-v" 'vcursor-scroll-down) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
377 (define-key vcursor-map "\C-v" 'vcursor-scroll-up) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
378 (define-key vcursor-map "o" 'vcursor-other-window) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
379 (define-key vcursor-map "g" 'vcursor-goto) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
380 (define-key vcursor-map "x" 'vcursor-swap-point) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
381 (define-key vcursor-map "\C-s" 'vcursor-isearch-forward) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
382 (define-key vcursor-map "\C-r" 'vcursor-isearch-backward) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
383 (define-key vcursor-map "\C-a" 'vcursor-beginning-of-line) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
384 (define-key vcursor-map "\C-e" 'vcursor-end-of-line) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
385 (define-key vcursor-map "\M-w" 'vcursor-forward-word) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
386 (define-key vcursor-map "\M-b" 'vcursor-backward-word) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
387 (define-key vcursor-map "\M-l" 'vcursor-copy-line) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
388 (define-key vcursor-map "c" 'vcursor-compare-windows) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
389 (define-key vcursor-map "k" 'vcursor-execute-key) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
390 (define-key vcursor-map "\M-x" 'vcursor-execute-command) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
391 |
17450 | 392 (cond |
393 ((not vcursor-key-bindings)) ;; don't set any key bindings | |
394 ((or (eq vcursor-key-bindings 'oemacs) | |
395 (and (eq vcursor-key-bindings t) (fboundp 'oemacs-version))) | |
396 (global-set-key [C-f1] 'vcursor-toggle-copy) | |
397 (global-set-key [C-f2] 'vcursor-copy) | |
398 (global-set-key [C-f3] 'vcursor-copy-word) | |
399 (global-set-key [C-f4] 'vcursor-copy-line) | |
400 | |
401 (global-set-key [S-f1] 'vcursor-disable) | |
402 (global-set-key [S-f2] 'vcursor-other-window) | |
403 (global-set-key [S-f3] 'vcursor-goto) | |
404 (global-set-key [S-f4] 'vcursor-swap-point) | |
405 | |
406 (global-set-key [C-f5] 'vcursor-backward-char) | |
407 (global-set-key [C-f6] 'vcursor-previous-line) | |
408 (global-set-key [C-f7] 'vcursor-next-line) | |
409 (global-set-key [C-f8] 'vcursor-forward-char) | |
410 | |
411 (global-set-key [M-f5] 'vcursor-beginning-of-line) | |
412 (global-set-key [M-f6] 'vcursor-backward-word) | |
413 (global-set-key [M-f6] 'vcursor-forward-word) | |
414 (global-set-key [M-f8] 'vcursor-end-of-line) | |
415 | |
416 (global-set-key [S-f5] 'vcursor-beginning-of-buffer) | |
417 (global-set-key [S-f6] 'vcursor-scroll-down) | |
418 (global-set-key [S-f7] 'vcursor-scroll-up) | |
419 (global-set-key [S-f8] 'vcursor-end-of-buffer) | |
420 | |
421 (global-set-key [C-f9] 'vcursor-isearch-forward) | |
422 | |
423 (global-set-key [S-f9] 'vcursor-execute-key) | |
424 (global-set-key [S-f10] 'vcursor-execute-command) | |
425 | |
426 ;;; Partial dictionary of Oemacs key sequences for you to roll your own, | |
427 ;;; e.g C-S-up: (global-set-key "\M-[\C-f\M-\C-m" 'vcursor-previous-line) | |
428 ;;; Sequence: Sends: | |
429 ;;; "\M-[\C-f\M-\C-m" C-S-up | |
430 ;;; "\M-[\C-f\M-\C-q" C-S-down | |
431 ;;; "\M-[\C-fs" C-S-left | |
432 ;;; "\M-[\C-ft" C-S-right | |
433 ;;; | |
434 ;;; "\M-[\C-fw" C-S-home | |
435 ;;; "\M-[\C-b\C-o" S-tab | |
436 ;;; "\M-[\C-f\M-\C-r" C-S-insert | |
437 ;;; "\M-[\C-fu" C-S-end | |
438 ;;; "\M-[\C-f\M-\C-s" C-S-delete | |
439 ;;; "\M-[\C-f\M-\C-d" C-S-prior | |
440 ;;; "\M-[\C-fv" C-S-next | |
441 ;;; | |
442 ;;; "\M-[\C-f^" C-S-f1 | |
443 ;;; "\M-[\C-f_" C-S-f2 | |
444 ;;; "\M-[\C-f`" C-S-f3 | |
445 ;;; "\M-[\C-fa" C-S-f4 | |
446 ;;; "\M-[\C-fb" C-S-f5 | |
447 ;;; "\M-[\C-fc" C-S-f6 | |
448 ;;; "\M-[\C-fd" C-S-f7 | |
449 ;;; "\M-[\C-fe" C-S-f8 | |
450 ;;; "\M-[\C-ff" C-S-f9 | |
451 ;;; "\M-[\C-fg" C-S-f10 | |
452 ) | |
453 (t | |
454 (global-set-key [C-S-up] 'vcursor-previous-line) | |
455 (global-set-key [C-S-down] 'vcursor-next-line) | |
456 (global-set-key [C-S-left] 'vcursor-backward-char) | |
457 (global-set-key [C-S-right] 'vcursor-forward-char) | |
458 | |
459 (global-set-key [C-S-return] 'vcursor-disable) | |
460 (global-set-key [C-S-insert] 'vcursor-copy) | |
461 (global-set-key [C-S-delete] 'vcursor-copy-word) | |
462 (global-set-key [C-S-remove] 'vcursor-copy-word) | |
463 (global-set-key [C-S-tab] 'vcursor-toggle-copy) | |
464 (global-set-key [C-S-home] 'vcursor-beginning-of-buffer) | |
465 (global-set-key [M-C-S-up] 'vcursor-beginning-of-buffer) | |
466 (global-set-key [C-S-end] 'vcursor-end-of-buffer) | |
467 (global-set-key [M-C-S-down] 'vcursor-end-of-buffer) | |
468 (global-set-key [C-S-prior] 'vcursor-scroll-down) | |
469 (global-set-key [C-S-next] 'vcursor-scroll-up) | |
470 | |
471 (global-set-key [C-S-f6] 'vcursor-other-window) | |
472 (global-set-key [C-S-f7] 'vcursor-goto) | |
473 | |
474 (global-set-key [C-S-select] 'vcursor-swap-point) ; DEC keyboards | |
475 (global-set-key [M-C-S-tab] 'vcursor-swap-point) | |
476 | |
477 (global-set-key [C-S-find] 'vcursor-isearch-forward) ; DEC keyboards | |
478 (global-set-key [C-S-f8] 'vcursor-isearch-forward) | |
479 | |
480 (global-set-key [M-C-S-left] 'vcursor-beginning-of-line) | |
481 (global-set-key [M-C-S-right] 'vcursor-end-of-line) | |
482 | |
483 (global-set-key [M-C-S-prior] 'vcursor-backward-word) | |
484 (global-set-key [M-C-S-next] 'vcursor-forward-word) | |
485 | |
486 (global-set-key [M-C-S-return] 'vcursor-copy-line) | |
487 | |
488 (global-set-key [C-S-f9] 'vcursor-execute-key) | |
489 (global-set-key [C-S-f10] 'vcursor-execute-command) | |
490 )) | |
491 | |
492 (defun vcursor-locate () | |
493 "Go to the starting point of the virtual cursor. | |
494 If that's disabled, don't go anywhere but don't complain." | |
495 ;; This is where we go off-mass-shell. Assume there is a | |
496 ;; save-excursion to get us back to the pole, er, point. | |
497 | |
498 (and (overlayp vcursor-overlay) | |
499 (overlay-buffer vcursor-overlay) | |
500 (set-buffer (overlay-buffer vcursor-overlay)) | |
501 (goto-char (overlay-start vcursor-overlay))) | |
502 ) | |
503 | |
504 (defun vcursor-find-window (&optional not-this new-win this-frame) | |
505 "Return a suitable window for displaying the virtual cursor. | |
506 This is the first window in cyclic order where the vcursor is visible. | |
507 | |
508 With optional NOT-THIS non-nil never return the current window. | |
509 | |
510 With NEW-WIN non-nil, display the virtual cursor buffer in another | |
511 window if the virtual cursor is not currently visible \(note, however, | |
512 that this function never changes window-point\). | |
513 | |
514 With THIS-FRAME non-nil, don't search other frames for a new window | |
515 \(though if the vcursor is already off-frame then its current window is | |
516 always considered, and the value of `pop-up-frames' is always respected\). | |
517 | |
518 Returns nil if the virtual cursor is not visible anywhere suitable. | |
519 Set `vcursor-window' to the returned value as a side effect." | |
520 | |
521 ;; The order of priorities (respecting NOT-THIS) is (1) | |
522 ;; vcursor-window if the virtual cursor is visible there (2) any | |
523 ;; window displaying the virtual cursor (3) vcursor-window provided | |
524 ;; it is still displaying the buffer containing the virtual cursor and | |
525 ;; is not selected (4) any unselected window displaying the vcursor | |
526 ;; buffer (5) with NEW-WIN, a window selected by display-buffer (so | |
527 ;; the variables pop-up-windows and pop-up-frames are significant) | |
528 ;; (6) nil. | |
529 | |
530 (let ((thiswin (selected-window)) winok winbuf) | |
531 (save-excursion | |
532 (vcursor-locate) | |
533 (or (and (window-live-p vcursor-window) | |
534 (eq (current-buffer) (window-buffer vcursor-window)) | |
535 (not (and not-this (eq thiswin vcursor-window)))) | |
536 (setq vcursor-window nil)) | |
537 (or (and vcursor-window ; choice 1 | |
538 (pos-visible-in-window-p (point) vcursor-window)) | |
539 (progn | |
540 (walk-windows | |
541 (function | |
542 (lambda (win) | |
543 (and (not winok) | |
544 (eq (current-buffer) (window-buffer win)) | |
545 (not (and not-this (eq thiswin win))) | |
546 (cond | |
547 ((pos-visible-in-window-p (point) win) (setq winok win)) | |
548 ((eq thiswin win)) | |
549 ((not winbuf) (setq winbuf win)))))) | |
550 nil (not this-frame)) | |
551 (setq vcursor-window | |
552 (cond | |
553 (winok) ; choice 2 | |
554 ((and vcursor-window ; choice 3 | |
555 (not (eq thiswin vcursor-window))) vcursor-window) | |
556 (winbuf) ; choice 4 | |
557 (new-win (display-buffer (current-buffer) t)) ; choice 5 | |
558 (t nil))))))) ; default (choice 6) | |
559 vcursor-window | |
560 ) | |
561 | |
562 (defun vcursor-toggle-copy (&optional arg nomsg) | |
563 "Toggle copying to point when the vcursor is moved. | |
564 With a prefix ARG, turn on if non-negative, off if negative. | |
565 Display a message unless optional NOMSG is non-nil." | |
566 (interactive "P") | |
567 (setq vcursor-copy-flag | |
568 (cond ((not arg) (not vcursor-copy-flag)) | |
569 ((< (prefix-numeric-value arg) 0) nil) | |
570 (t)) | |
571 vcursor-last-command t) | |
572 (or nomsg (message "Copying from the vcursor is now %s." | |
573 (if vcursor-copy-flag "on" "off"))) | |
574 ) | |
575 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
576 (defun vcursor-move (pt &optional leave-b leave-w) |
17450 | 577 "Move the virtual cursor to the character to the right of PT. |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
578 PT is an absolute location in the current buffer. With optional |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
579 LEAVE-B, PT is in the same buffer the vcursor is currently in. |
17450 | 580 |
581 If the new virtual cursor location would not be visible, display it in | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
582 another window. With LEAVE-W, use the current `vcursor-window'." |
17450 | 583 ;; this works even if we're on-mass-shell, but usually we won't be. |
584 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
585 (save-excursion |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
586 (and leave-b (vcursor-check t) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
587 (set-buffer (overlay-buffer vcursor-overlay))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
588 (if (eq pt (point-max)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
589 (setq pt (1- pt))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
590 (if (vcursor-check t) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
591 (move-overlay vcursor-overlay pt (+ pt 1) (current-buffer)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
592 (setq vcursor-overlay (make-overlay pt (+ pt 1))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
593 (or window-system |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
594 (overlay-put vcursor-overlay 'before-string vcursor-string)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
595 (overlay-put vcursor-overlay 'face 'vcursor)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
596 (or leave-w (vcursor-find-window nil t)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
597 ;; vcursor-window now contains the right buffer |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
598 (or (pos-visible-in-window-p pt vcursor-window) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
599 (set-window-point vcursor-window pt))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
600 ) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
601 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
602 (defun vcursor-insert (text) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
603 "Insert TEXT, respecting `vcursor-interpret-input'." |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
604 (if vcursor-interpret-input |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
605 (setq unread-command-events |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
606 (append (listify-key-sequence text) unread-command-events)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
607 (insert text)) |
17450 | 608 ) |
609 | |
610 (defun vcursor-relative-move (fn &rest args) | |
611 "Use FUNCTION with arbitrary ARG1 ... to move the virtual cursor. | |
612 | |
613 This is called by most of the virtual-cursor motion commands." | |
614 (let (text opoint) | |
615 (save-excursion | |
616 (vcursor-locate) | |
617 (setq opoint (point)) | |
618 (apply fn args) | |
619 (and (eq opoint (point-max)) (eq opoint (point)) | |
620 (signal 'end-of-buffer nil)) | |
621 (vcursor-move (point)) | |
622 (if vcursor-copy-flag (setq text (buffer-substring opoint (point))))) | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
623 (if text (vcursor-insert text))) |
17450 | 624 (setq vcursor-last-command t) |
625 ) | |
626 | |
627 (defun vcursor-goto (&optional arg) | |
628 "Move the real cursor to the virtual cursor position. | |
629 If the virtual cursor is (or was recently) visible in another window, | |
630 switch to that first. Without a prefix ARG, disable the virtual | |
631 cursor as well." | |
632 | |
633 (interactive "P") | |
634 (and (vcursor-find-window) (select-window vcursor-window)) | |
635 (let ((buf (and vcursor-overlay (overlay-buffer vcursor-overlay)))) | |
636 (and buf (not (eq (current-buffer) buf)) (switch-to-buffer buf))) | |
637 (vcursor-locate) | |
638 (or arg (vcursor-disable)) | |
639 ) | |
640 | |
641 (defun vcursor-swap-point () | |
642 "Swap the location of point and that of the virtual cursor. | |
643 | |
644 The virtual cursor window becomes the selected window and the old | |
645 window becomes the virtual cursor window. If the virtual cursor would | |
646 not be visible otherwise, display it in another window." | |
647 | |
648 (interactive) | |
649 (let ((buf (current-buffer)) (here (point)) (win (selected-window))) | |
650 (vcursor-goto) ; will disable the vcursor | |
651 (save-excursion | |
652 (set-buffer buf) | |
653 (setq vcursor-window win) | |
654 (vcursor-move here))) | |
655 ) | |
656 | |
657 (defun vcursor-scroll-up (&optional n) | |
658 "Scroll up the vcursor window ARG lines or near full screen if none. | |
659 The vcursor will always appear in an unselected window." | |
660 | |
661 (interactive "P") | |
662 (vcursor-window-funcall 'scroll-up n) | |
663 ) | |
664 | |
665 (defun vcursor-scroll-down (&optional n) | |
666 "Scroll down the vcursor window ARG lines or near-full screen if none. | |
667 The vcursor will always appear in an unselected window." | |
668 | |
669 (interactive "P") | |
670 (vcursor-window-funcall 'scroll-down n) | |
671 ) | |
672 | |
673 (defun vcursor-isearch-forward (&optional rep norecurs) | |
674 "Perform forward incremental search in the virtual cursor window. | |
675 The virtual cursor is moved to the resulting point; the ordinary | |
676 cursor stays where it was." | |
677 | |
678 (interactive "P") | |
679 (vcursor-window-funcall 'isearch-forward rep norecurs) | |
680 ) | |
681 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
682 (defun vcursor-isearch-backward (&optional rep norecurs) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
683 "Perform backward incremental search in the virtual cursor window. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
684 The virtual cursor is moved to the resulting point; the ordinary |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
685 cursor stays where it was." |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
686 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
687 (interactive "P") |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
688 (vcursor-window-funcall 'isearch-backward rep norecurs) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
689 ) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
690 |
17450 | 691 (defun vcursor-window-funcall (func &rest args) |
692 "Call FUNC with ARGS ... in a virtual cursor window. | |
693 A window other than the currently-selected one will always be used. | |
694 The virtual cursor is moved to the value of point when the function | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
695 returns. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
696 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
697 If FUNC is a list, call the car of the list interactively, ignoring |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
698 ARGS. In this case, a new window will not be created if the vcursor |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
699 is visible in the current one." |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
700 ;; that's to avoid messing up compatibility with old versions |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
701 ;; by introducing a new argument, which would have to come before ARGS. |
17450 | 702 |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
703 (vcursor-find-window (not (and (listp func) (vcursor-check t))) t) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
704 (save-excursion |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
705 (let ((sw (selected-window)) text) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
706 ;; We can't use save-window-excursion because that would restore |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
707 ;; the original display in the window we may want to alter. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
708 (unwind-protect |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
709 (let ((here (point))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
710 (select-window vcursor-window) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
711 (vcursor-locate) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
712 (if (listp func) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
713 (call-interactively (car func)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
714 (apply func args)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
715 (setq vcursor-window (selected-window)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
716 (and vcursor-copy-flag |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
717 (eq (current-buffer) (overlay-buffer vcursor-overlay)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
718 (setq text (buffer-substring here (point)))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
719 ;; vcursor-window and the current buffer are definitely |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
720 ;; right, so make sure vcursor-move doesn't pick others. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
721 (vcursor-move (point) nil t)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
722 (select-window sw)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
723 (if text (vcursor-insert text)))) |
17450 | 724 (setq vcursor-last-command t) |
725 ) | |
726 | |
727 (defun vcursor-get-char-count (fn &rest args) | |
728 "Apply FN to ARG1 ... and return the number of characters moved. | |
729 Point is temporarily set to the virtual cursor position before FN is | |
730 called. | |
731 | |
732 This is called by most of the virtual-cursor copying commands to find | |
733 out how much to copy." | |
734 | |
735 (vcursor-check) | |
736 (save-excursion | |
737 (set-buffer (overlay-buffer vcursor-overlay)) | |
738 (let ((start (goto-char (overlay-start vcursor-overlay)))) | |
739 (- (progn (apply fn args) (point)) start))) | |
740 ) | |
741 | |
742 ;; Make sure the virtual cursor is active. Unless arg is non-nil, | |
743 ;; report an error if it is not. | |
744 (defun vcursor-check (&optional arg) | |
745 (cond | |
746 ((and (overlayp vcursor-overlay) (overlay-start vcursor-overlay)) | |
747 t) | |
748 (arg nil) | |
749 (t (error "The virtual cursor is not active now."))) | |
750 ) | |
751 | |
752 (defun vcursor-disable (&optional arg) | |
753 "Disable the virtual cursor. | |
754 Next time you use it, it will start from point. | |
755 | |
756 With a positive prefix ARG, the first window in cyclic order | |
757 displaying the virtual cursor (or which was recently displaying the | |
758 virutal cursor) will be deleted unless it's the selected | |
759 window. | |
760 | |
761 With a negative prefix argument, enable the virtual cursor: make it | |
762 active at the same point as the real cursor. | |
763 | |
764 Copying mode is always turned off: the next use of the vcursor will | |
765 not copy text until you turn it on again." | |
766 | |
767 (interactive "P") | |
768 (if (overlayp vcursor-overlay) | |
769 (progn | |
770 (delete-overlay vcursor-overlay) | |
771 (setq vcursor-overlay nil))) | |
772 (cond | |
773 ((not (vcursor-find-window t))) | |
774 ((or (not arg) (< (prefix-numeric-value arg) 0))) | |
775 ((delete-window vcursor-window))) | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
776 (cond |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
777 ((and arg (< (prefix-numeric-value arg) 0)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
778 (vcursor-move (point)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
779 (setq vcursor-window (selected-window))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
780 (vcursor-use-vcursor-map (vcursor-toggle-vcursor-map 0))) |
17450 | 781 (setq vcursor-copy-flag nil) |
782 ) | |
783 | |
784 (defun vcursor-other-window (n &optional all-frames) | |
785 "Activate the virtual cursor in another window. | |
786 This is the next window cylically after one currently showing the | |
787 virtual cursor, or else after the current selected window. If there | |
788 is no other window, the current window is split. | |
789 | |
790 Arguments N and optional ALL-FRAMES are the same as with other-window. | |
791 ALL-FRAMES is also used to decide whether to split the window." | |
792 | |
793 (interactive "p") | |
794 (if (if (fboundp 'oemacs-version) | |
795 (one-window-p nil) | |
796 (one-window-p nil all-frames)) | |
797 (display-buffer (current-buffer) t)) | |
798 (save-excursion | |
799 (save-window-excursion | |
800 ;; We don't use fancy vcursor-find-window trickery, since we're | |
801 ;; quite happy to have the vcursor cycle back into the current | |
802 ;; window. | |
803 (let ((sw (selected-window)) | |
804 (win (vcursor-find-window nil nil (not all-frames)))) | |
805 (if win (select-window win)) | |
806 ;; else start from here | |
807 (other-window n all-frames) | |
808 (vcursor-disable -1)))) | |
809 ) | |
810 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
811 ;; vcursor-compare-windows is copied from compare-w.el with only |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
812 ;; minor modifications; these are too bound up with the function |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
813 ;; to make it really useful to call compare-windows itself. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
814 (defun vcursor-compare-windows (&optional ignore-whitespace) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
815 "Compare text in current window with text in window with vcursor. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
816 Compares the text starting at point in the current window and at the |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
817 vcursor position in the other window, moving over text in each one as |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
818 far as they match. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
819 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
820 A prefix argument, if any, means ignore changes in whitespace. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
821 The variable `compare-windows-whitespace' controls how whitespace is skipped. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
822 If `compare-ignore-case' is non-nil, changes in case are also ignored." |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
823 (interactive "P") |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
824 ;; (vcursor-window-funcall 'compare-windows arg) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
825 (require 'compare-w) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
826 (let* (p1 p2 maxp1 maxp2 b1 b2 w2 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
827 success size |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
828 (opoint1 (point)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
829 opoint2 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
830 (skip-whitespace (if ignore-whitespace |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
831 compare-windows-whitespace))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
832 (setq p1 (point) b1 (current-buffer)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
833 (setq w2 (vcursor-find-window t t)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
834 (if (or (eq w2 (selected-window)) (not w2)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
835 (error "No other window with vcursor")) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
836 (save-excursion |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
837 (vcursor-locate) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
838 (setq p2 (point) b2 (current-buffer))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
839 (setq opoint2 p2) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
840 (setq maxp1 (point-max)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
841 (save-excursion |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
842 (set-buffer b2) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
843 (setq maxp2 (point-max))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
844 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
845 (setq success t) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
846 (while success |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
847 (setq success nil) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
848 ;; if interrupted, show how far we've gotten |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
849 (goto-char p1) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
850 (vcursor-move p2 t) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
851 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
852 ;; If both buffers have whitespace next to point, |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
853 ;; optionally skip over it. |
17450 | 854 |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
855 (and skip-whitespace |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
856 (save-excursion |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
857 (let (p1a p2a w1 w2 result1 result2) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
858 (setq result1 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
859 (if (stringp skip-whitespace) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
860 (compare-windows-skip-whitespace opoint1) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
861 (funcall skip-whitespace opoint1))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
862 (setq p1a (point)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
863 (set-buffer b2) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
864 (goto-char p2) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
865 (setq result2 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
866 (if (stringp skip-whitespace) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
867 (compare-windows-skip-whitespace opoint2) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
868 (funcall skip-whitespace opoint2))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
869 (setq p2a (point)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
870 (if (or (stringp skip-whitespace) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
871 (and result1 result2 (eq result1 result2))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
872 (setq p1 p1a |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
873 p2 p2a))))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
874 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
875 ;; Try advancing comparing 1000 chars at a time. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
876 ;; When that fails, go 500 chars at a time, and so on. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
877 (let ((size 1000) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
878 success-1 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
879 (case-fold-search compare-ignore-case)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
880 (while (> size 0) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
881 (setq success-1 t) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
882 ;; Try comparing SIZE chars at a time, repeatedly, till that fails. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
883 (while success-1 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
884 (setq size (min size (- maxp1 p1) (- maxp2 p2))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
885 (setq success-1 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
886 (and (> size 0) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
887 (= 0 (compare-buffer-substrings b2 p2 (+ size p2) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
888 b1 p1 (+ size p1))))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
889 (if success-1 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
890 (setq p1 (+ p1 size) p2 (+ p2 size) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
891 success t))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
892 ;; If SIZE chars don't match, try fewer. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
893 (setq size (/ size 2))))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
894 |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
895 (goto-char p1) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
896 (vcursor-move p2 t) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
897 (if (= (point) opoint1) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
898 (ding))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
899 ) |
17450 | 900 |
901 (defun vcursor-next-line (arg) | |
902 "Move the virtual cursor forward ARG lines." | |
903 ;; This is next-line rewritten for the vcursor. Maybe it would | |
904 ;; be easier simply to rewrite line-move. | |
905 (interactive "p") | |
906 (let (temporary-goal-column opoint text) | |
907 (save-excursion | |
908 (vcursor-locate) | |
909 (setq temporary-goal-column | |
910 (if (or (eq last-command 'vcursor-next-line) | |
911 (eq last-command 'vcursor-previous-line)) | |
912 (progn | |
913 (setq last-command 'next-line) ; trick line-move | |
914 vcursor-temp-goal-column) | |
915 (if (and track-eol (eolp) | |
916 (or (not (bolp)) (eq last-command 'end-of-line))) | |
917 9999 | |
918 (current-column))) | |
919 opoint (point)) | |
920 (line-move arg) | |
921 (and (eq opoint (point-max)) (eq opoint (point)) | |
922 (signal 'end-of-buffer nil)) | |
923 (if vcursor-copy-flag (setq text (buffer-substring opoint (point)))) | |
924 (vcursor-move (point)) | |
925 (setq vcursor-temp-goal-column temporary-goal-column | |
926 vcursor-last-command t)) | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
927 (if text (vcursor-insert text))) |
17450 | 928 ) |
929 | |
930 (defun vcursor-previous-line (arg) | |
931 "Move the virtual cursor back ARG lines." | |
932 (interactive "p") | |
933 (vcursor-next-line (- arg)) | |
934 ) | |
935 | |
936 (defun vcursor-forward-char (arg) | |
937 "Move the virtual cursor forward ARG characters." | |
938 (interactive "p") | |
939 (vcursor-relative-move 'forward-char arg) | |
940 ) | |
941 | |
942 (defun vcursor-backward-char (arg) | |
943 "Move the virtual cursor backward ARG characters." | |
944 (interactive "p") | |
945 (vcursor-relative-move 'backward-char arg) | |
946 ) | |
947 | |
948 (defun vcursor-forward-word (arg) | |
949 "Move the virtual cursor forward ARG words." | |
950 (interactive "p") | |
951 (vcursor-relative-move 'forward-word arg) | |
952 ) | |
953 | |
954 (defun vcursor-backward-word (arg) | |
955 "Move the virtual cursor backward ARG words." | |
956 (interactive "p") | |
957 (vcursor-relative-move 'backward-word arg) | |
958 ) | |
959 | |
960 (defun vcursor-beginning-of-line (arg) | |
961 "Move the virtual cursor to beginning of its current line. | |
962 ARG is as for `beginning-of-line'." | |
963 (interactive "P") | |
964 (vcursor-relative-move 'beginning-of-line | |
965 (if arg (prefix-numeric-value arg))) | |
966 ) | |
967 | |
968 (defun vcursor-end-of-line (arg) | |
969 "Move the virtual cursor to end of its current line. | |
970 ARG is as for `end-of-line'." | |
971 (interactive "P") | |
972 (vcursor-relative-move 'end-of-line | |
973 (if arg (prefix-numeric-value arg))) | |
974 ) | |
975 | |
976 (defun vcursor-beginning-of-buffer (&optional arg) | |
977 "Move the virtual cursor to the beginning of its buffer. | |
978 ARG is as for beginning-of-buffer." | |
979 (interactive "P") | |
980 (vcursor-relative-move | |
981 (lambda (arg) | |
982 (goto-char (if arg (/ (* arg (- (point-max) (point-min))) 10) | |
983 (point-min)))) | |
984 (if arg (prefix-numeric-value arg))) | |
985 ) | |
986 | |
987 (defun vcursor-end-of-buffer (&optional arg) | |
988 "Move the virtual cursor to the end of its buffer. | |
989 ARG is as for end-of-buffer. | |
990 | |
991 Actually, the vcursor is moved to the second from last character or it | |
992 would be invisible." | |
993 (interactive "P") | |
994 (vcursor-relative-move | |
995 (lambda (arg) | |
996 (goto-char (if arg (- (point-max) | |
997 (/ (* arg (- (point-max) (point-min))) 10)) | |
998 (point-max)))) | |
999 (if arg (prefix-numeric-value arg))) | |
1000 ) | |
1001 | |
1002 (defun vcursor-execute-command (cmd) | |
1003 "Execute COMMAND for the virtual cursor. | |
1004 COMMAND is called interactively. Not all commands (in fact, only a | |
1005 small subset) are useful." | |
1006 (interactive "CCommand: ") | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1007 (vcursor-window-funcall (list cmd)) |
17450 | 1008 ) |
1009 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1010 (defun vcursor-execute-key () |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1011 "Read a key sequence and execute the bound command for the virtual cursor. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1012 The key sequence is read at the vcursor location. The command found |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1013 is called interactively, so prefix argument etc. are usable." |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1014 (interactive) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1015 (let (cmd) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1016 (save-excursion |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1017 ;; We'd like to avoid the display changing when we locate |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1018 ;; to the vcursor position and read a key sequence. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1019 (vcursor-find-window (not (vcursor-check t)) t) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1020 (save-window-excursion |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1021 (select-window vcursor-window) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1022 (vcursor-locate) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1023 (setq cmd (key-binding (read-key-sequence "Key sequence: "))))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1024 (vcursor-window-funcall (list cmd))) |
17450 | 1025 ) |
1026 | |
1027 (defun vcursor-copy (arg) | |
1028 "Copy ARG characters from the virtual cursor position to point." | |
1029 (interactive "p") | |
1030 (vcursor-check) | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1031 (vcursor-insert |
17450 | 1032 (save-excursion |
1033 (set-buffer (overlay-buffer vcursor-overlay)) | |
1034 (let* ((ostart (overlay-start vcursor-overlay)) | |
1035 (end (+ ostart arg))) | |
1036 (prog1 | |
1037 (buffer-substring ostart end) | |
1038 (vcursor-move end))))) | |
1039 (setq vcursor-last-command t) | |
1040 ) | |
1041 | |
1042 (defun vcursor-copy-word (arg) | |
1043 "Copy ARG words from the virtual cursor position to point." | |
1044 (interactive "p") | |
1045 (vcursor-copy (vcursor-get-char-count 'forward-word arg)) | |
1046 ) | |
1047 | |
1048 (defun vcursor-copy-line (arg) | |
1049 "Copy up to ARGth line after virtual cursor position. | |
1050 With no argument, copy to the end of the current line. | |
1051 | |
1052 Behaviour with regard to newlines is similar (but not identical) to | |
1053 `kill-line'; the main difference is that whitespace at the end of the | |
1054 line is treated like ordinary characters." | |
1055 | |
1056 (interactive "P") | |
1057 (let* ((num (prefix-numeric-value arg)) | |
1058 (count (vcursor-get-char-count 'end-of-line num))) | |
1059 (vcursor-copy (if (or (= count 0) arg) (1+ count) count))) | |
1060 ) | |
1061 | |
21061
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1062 (defun vcursor-toggle-vcursor-map (&optional force noredisp) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1063 "Toggle the state of the vcursor key map. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1064 When on, the keys defined in it are mapped directly on top of the main |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1065 keymap, allowing you to move the vcursor with ordinary motion keys. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1066 An indication \"!VC\" appears in the mode list. The effect is |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1067 local to the current buffer. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1068 With prefix FORCE, turn on, or off if it is 0. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1069 With NOREDISP, don't force redisplay. |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1070 Disabling the vcursor automatically turns this off." |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1071 (interactive "P") |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1072 (let ((new (cond ((not force) (not vcursor-use-vcursor-map)) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1073 ((eq force 0) nil) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1074 (t)))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1075 (or (eq new vcursor-use-vcursor-map) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1076 (progn |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1077 (setq vcursor-use-vcursor-map new) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1078 (or (assq 'vcursor-use-vcursor-map minor-mode-map-alist) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1079 (setq minor-mode-map-alist |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1080 (cons (cons 'vcursor-use-vcursor-map vcursor-map) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1081 minor-mode-map-alist))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1082 (or (assq 'vcursor-use-vcursor-map minor-mode-alist) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1083 (setq minor-mode-alist |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1084 (cons (list 'vcursor-use-vcursor-map " !VC") |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1085 minor-mode-alist))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1086 (or noredisp (redraw-display))))) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1087 ) |
7813d4b7bea5
Some support for character terminals provided.
Richard M. Stallman <rms@gnu.org>
parents:
17902
diff
changeset
|
1088 |
17450 | 1089 (defun vcursor-post-command () |
1090 (and vcursor-auto-disable (not vcursor-last-command) | |
1091 vcursor-overlay (vcursor-disable)) | |
1092 (setq vcursor-last-command nil) | |
1093 ) | |
1094 | |
1095 (add-hook 'post-command-hook 'vcursor-post-command) | |
1096 | |
1097 (provide 'vcursor) | |
1098 | |
1099 ;; vcursor.el ends here |