annotate lisp/vcursor.el @ 20319:81424cf4d446

(copy_keymap_1): Fix return type. (accessible_keymaps_char_table): Likewise. (where_is_internal_2): Likewise. (describe_vector_princ): Likewise. (Ftext_char_description): Fix type of `str'. (describe_vector): Likewise. Protoize parameter.
author Andreas Schwab <schwab@suse.de>
date Fri, 21 Nov 1997 15:18:28 +0000
parents e4a7b81d6c10
children 7813d4b7bea5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17450
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; vcursor.el --- manipulate an alternative ("virtual") cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
17902
e4a7b81d6c10 Fix copyright and permission notice.
Richard M. Stallman <rms@gnu.org>
parents: 17450
diff changeset
3 ;; Copyright (C) 1994, 1996 Free Software Foundation, Inc.
17450
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Peter Stephenson <pws@ifh.de>
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: virtual cursor, display, copying
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; Virtual cursor commands. I got this idea from the old BBC micro.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; You need Emacs 19 (I have not tried XEmacs) and a windowing
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; system: I have tried X Windows and Oemacs but any system which
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; supports multiple windows should have the ability to run vcursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; In fact, only overlays are required to work, though some of the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; key-bindings may need changing.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; This is much easier to use than the instructions are to read.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; I suggest you simply load it and play around with holding down Ctrl
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; and Shift and pressing up, down, left, right, tab, return, and see
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; what happens. (Find a scratch buffer before using C-S-tab: that
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; toggles copying.)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; Most of the functions described in this documentation are in
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; parentheses so that if you have the package loaded you can type C-h
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; f on top of them for help.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; Using the cursor keys with both control and shift held down moves
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; around a virtual cursor, which is initially at point. When active,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; it appears with an underline through it to distinguish it from the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; normal cursor. You can then use one of the other commands to copy
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; characters from the location of the virtual cursor to point. This
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; is very useful, for example, when copying some previous text while
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; making changes to it at the same time, since you never have to move
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; the "real" cursor away from where you are inserting.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; The remaining default key bindings are based around the PC-type
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; cluster found above the cursor keys on a lot of keyboards, the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; function keys which my limited knowledge of X terminals expects to
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; find at the top. Some functions are duplicated in more obvious
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; places for the X version.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; All the keybindings require you to hold down control and shift at
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; once. I assumed this combination wouldn't be heavily bound by most
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; people and that it would be easy to type with the left hand.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; Inevitably it will clash with some other packages, but I can't help
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; that: an intuitive binding is a prerequisite here. See below for
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; other alternatives (search for "Oemacs").
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; Holding down control and shift and pressing insert (vcursor-copy)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; copies one character from wherever the virtual cursor is to point;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; point and the virtual cursor advance in the separate and equal
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; station to which... (etc.). M-C-S-return (vcursor-copy-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; copies to the end of the line instead of just one character,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; C-S-delete or C-S-remove (vcursor-copy-word) copies a word.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; A more general way of copying is to use C-S-tab, which is a toggle.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; In the "on" state, moving the virtual cursor will copy the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; moved-over text to the normal cursor position (including when going
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; backwards, though each piece of text moved over is copied forwards:
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; compare the behaviour of C-S-up and C-S-left).
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; However, that's just a small part of the magic. If the virtual
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; cursor goes off the display, it will be redisplayed in some other
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; window. (See the function (vcursor-find-window) for details of how
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; this window is chosen.) This gives you fingertip control over two
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; windows at once.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; C-S-return (vcursor-disable) disables the virtual cursor, removing
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;; it so that it starts from point whenever you move it again --- note
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; that simply moving the cursor and virtual cursor on top of one
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; another does not have this effect.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;; If you gave C-S-return a positive prefix arg, it will also delete the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;; window (unless it's the current one). Whenever the virtual cursor
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; goes off-screen in its own window, point in that window is moved as
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;; well to restore it to view. (It's easier that way, that's why.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; However, point doesn't move unless the view in the window does, so
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; it's not tied to the virtual cursor location.)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;; You can also use C-S-return with a negative prefix argument which
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;; forces the vcursor to appear at point. This is particularly useful if
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; you actually want to edit in another window but would like to
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; remember the current cursor location for examining or copying from
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; that buffer. (I just hit C-S-right C-S-left, but I'm a hopeless
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; lowbrow.)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;; There is also C-S-f6 (vcursor-other-window) which behaves like
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;; C-x o on the virtual rather than the real cursor, except that it
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; will create another window if necessary.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;; The keys C-S-prior (vcursor-scroll-down) and C-S-next
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;; (vcursor-scroll-up) (i.e., PageUp and PageDown) will scroll the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; virtual cursor window, appropriately chosen. They will always
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;; create a new window or take over an old one if necessary.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; Likewise, M-C-S-left and M-C-S-right move you to the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;; beginning or end of a line, C-S-home and C-S-end the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; beginning or end of a buffer (these are also on M-C-S-up and
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 ;; M-C-S-down for those of us stuck with DEC keyboards).
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ;; C-S-f7 (vcursor-goto) will take you to the vcursor position
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; (swapping windows if it seems sensible) and (unless you give it a
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;; prefix argument) delete the virtual cursor, so this is useful for
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; you to take over editing at the virtual cursor position. It is not
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;; an error if the virtual cursor is not active; it simply leaves you
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 ;; at point, because that is where the virtual cursor would start
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;; from.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; In a similar vein, M-C-S-tab (hope your left hand's flexible;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;; C-S-select on DEC keyboards) (vcursor-swap-point) will take you to
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;; the virtual cursor position but simultaneously put the virtual
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; cursor at the old cursor position. It is also supposed to ensure
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; that both are visible.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; C-S-f8 (C-S-find on DEC keyboards) (vcursor-isearch-forward)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;; allows you to do an isearch in another window. It works a bit like
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;; vcursor-scroll-*; it moves into another window, calls isearch
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ;; there, and sets the virtual cursor position to the point found. In
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;; other words, it works just like isearch but with the virtual cursor
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;; instead of the real one (that's why it's called a "virtual
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; cursor"). While you are isearching, you are editing in the virtual
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;; cursor window, but when you have finished you return to where you
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;; started. Note that once you are in isearch all the keys are normal
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; --- use C-s, not C-S-f8, to search for the next occurrence.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;; If you set the variable vcursor-auto-disable, then any command
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 ;; which does not involve moving or copying from the virtual cursor
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ;; causes the virtual cursor to be disabled. If you don't intend to
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 ;; use this, you can comment out the `add-hook' line at the bottom of
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 ;; this file. (This feature partially emulates the way the "copy" key
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;; on the BBC micro worked; actually, the copy cursor was homed when
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 ;; you hit return. This was in keeping with the line-by-line way of
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;; entering BASIC, but is less appropriate here.)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; There is a way of moving the virtual cursor using ordinary
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 ;; commands: C-S-f9 (vcursor-execute-key) reads a key string,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ;; moves to the virtual cursor position, executes the command bound to
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 ;; the string, then returns to the original point. Thus C-S-f9 M-m
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 ;; moves the virtual cursor back to the first non-whitespace character
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 ;; on its line. As the command is called interactively all the usual
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ;; ways of passing information to the command called, such as by a
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;; prefix argument, are available. C-S-f10 (C-S-x)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ;; (vcursor-execute-command) behaves the same way but you enter the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 ;; name of the command. Of course, only some commands are useful
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; here, mainly simple movement commands. Killing at the virtual
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;; cursor position in this way works as well; you can even save
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;; another buffer with C-S-f9 C-x C-s. To do anything more
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;; complicated, you are better off using M-C-S-tab
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ;; (vcursor-swap-point), doing whatever it is, then calling M-C-S-tab
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; again.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;; If you want to add your own moving or copying functions you should
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;; be able to do this fairly easily with (vcursor-relative-move) and
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 ;; (vcursor-copy) together with (vcursor-get-char-count). If you want to
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 ;; do something in a different window, use (vcursor-window-funcall).
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; There is an alternative set of key bindings which will be used
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; automatically for a PC if Oemacs is detected. This set uses separate
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 ;; control, shift and meta keys with function keys 1 to 10. In
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 ;; particular, movement keys are concentrated on f5 to f8 with (in
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ;; increasing order of distance travelled) C-, M- and S- as prefixes.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 ;; See the actual bindings below (search for C-f1). This is because the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ;; C-S- prefix is represented by weird key sequences and the set is
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;; incomplete; if you don't mind that, some hints are given in comments
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 ;; below.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;; You can specify the usual or the Oemacs bindings by setting the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 ;; variable vcursor-key-bindings to `xterm' or `oemacs'. You can also set
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 ;; it to nil, in which case vcursor will not make any key bindings
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 ;; and you can define your own. The default is t, which makes vcursor
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 ;; guess (it will use xterm unless it thinks Oemacs is running). The
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 ;; oemacs set will work on an X terminal with function keys, but the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;; xterm set will not work under Oemacs.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;; Un-features:
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; - The vcursor will not move to point-max, since otherwise it would
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ;; disappear. However, no error is flagged as point-max is a valid
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ;; point in the buffer. Thus cursor right or down at the second
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 ;; last point in the file does not flag an error, which is inconsistent,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 ;; and if copying is on the last character (typically newline) will
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ;; be repeatedly copied. (I've tried making it flag an error
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 ;; instead and that's worse since often the vcursor is sent to
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 ;; point in some other window, which may be point-max.)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 ;; - The vcursor widens when over a tab character or right at the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 ;; end of the line. You're welcome to consider this a feature;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 ;; it's just a part of how overlays work.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 ;; - The vcursor obscures the real cursor. Creative use of overlays
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ;; could cure this.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ;; - The vcursor does not remember its own previous positions. If
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ;; you cycle it back into a window it was in before, it will be at
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 ;; point in that window. Often, that is where a previous recenter
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;; left point, not where the vcursor was before.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ;; (Note, however, that the vcursor does remember where it *is*,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; even if it's off-screen. This can also lead to surprises, but I
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; don't think it's a bug.)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 ;; - vcursor-window-funcall could perhaps be smarter about restoring
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 ;; the previous window state on failure.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 ;; - The logic in vcursor-find-window is rather complicated and
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 ;; therefore bug-prone, though in practice it seems to work OK.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 ;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;; Possible enhnacements:
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; It would be easy to implement vcursor-push (save vcursor position
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ;; as mark and deactivate) and vcursor-pop (deactivate vcursor and
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ;; move to last pushed position) functions.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;;; Code:
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (or (memq 'vcursor (face-list))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (progn
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (copy-face 'modeline 'vcursor)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (if (or (fboundp 'oemacs-version) (x-display-color-p))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (progn
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (set-face-foreground 'vcursor "blue")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (set-face-background 'vcursor "cyan")))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (set-face-underline-p 'vcursor t)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (defvar vcursor-auto-disable nil
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 "*If non-nil, disable the virtual cursor after use.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 Any non-vcursor command will force `vcursor-disable' to be called.")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (defvar vcursor-key-bindings t
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 "*How to bind keys when vcursor is loaded.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 If t (the default), guess; if xterm, use bindings suitable for an
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 X terminal; if oemacs, use bindings which work on a PC with Oemacs.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 If nil, don't define any key bindings.")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (defvar vcursor-overlay nil
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 "Overlay for the virtual cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 It is nil if that is not enabled.")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (defvar vcursor-window nil
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 "Last window to have displayed the virtual cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 See the function `vcursor-find-window' for how this is used.")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (defvar vcursor-last-command nil
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 "Non-nil if last command was a vcursor command.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 The commands `vcursor-copy', `vcursor-relative-move' and the ones for
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 scrolling set this. It is used by the `vcursor-auto-disable' code.")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 ;; could do some memq-ing with last-command instead, but this will
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;; automatically handle any new commands using the primitives.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (defvar vcursor-copy-flag nil
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 "*Non-nil means moving vcursor should copy characters moved over to point.")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (defvar vcursor-temp-goal-column nil
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 "Keeps track of temporary goal columns for the virtual cursor.")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (cond
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 ((not vcursor-key-bindings)) ;; don't set any key bindings
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ((or (eq vcursor-key-bindings 'oemacs)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (and (eq vcursor-key-bindings t) (fboundp 'oemacs-version)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (global-set-key [C-f1] 'vcursor-toggle-copy)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (global-set-key [C-f2] 'vcursor-copy)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (global-set-key [C-f3] 'vcursor-copy-word)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (global-set-key [C-f4] 'vcursor-copy-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (global-set-key [S-f1] 'vcursor-disable)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (global-set-key [S-f2] 'vcursor-other-window)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (global-set-key [S-f3] 'vcursor-goto)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (global-set-key [S-f4] 'vcursor-swap-point)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (global-set-key [C-f5] 'vcursor-backward-char)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (global-set-key [C-f6] 'vcursor-previous-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (global-set-key [C-f7] 'vcursor-next-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (global-set-key [C-f8] 'vcursor-forward-char)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (global-set-key [M-f5] 'vcursor-beginning-of-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (global-set-key [M-f6] 'vcursor-backward-word)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (global-set-key [M-f6] 'vcursor-forward-word)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (global-set-key [M-f8] 'vcursor-end-of-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (global-set-key [S-f5] 'vcursor-beginning-of-buffer)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (global-set-key [S-f6] 'vcursor-scroll-down)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (global-set-key [S-f7] 'vcursor-scroll-up)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (global-set-key [S-f8] 'vcursor-end-of-buffer)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (global-set-key [C-f9] 'vcursor-isearch-forward)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (global-set-key [S-f9] 'vcursor-execute-key)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (global-set-key [S-f10] 'vcursor-execute-command)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 ;;; Partial dictionary of Oemacs key sequences for you to roll your own,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 ;;; e.g C-S-up: (global-set-key "\M-[\C-f\M-\C-m" 'vcursor-previous-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 ;;; Sequence: Sends:
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 ;;; "\M-[\C-f\M-\C-m" C-S-up
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 ;;; "\M-[\C-f\M-\C-q" C-S-down
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 ;;; "\M-[\C-fs" C-S-left
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 ;;; "\M-[\C-ft" C-S-right
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 ;;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 ;;; "\M-[\C-fw" C-S-home
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ;;; "\M-[\C-b\C-o" S-tab
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 ;;; "\M-[\C-f\M-\C-r" C-S-insert
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 ;;; "\M-[\C-fu" C-S-end
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 ;;; "\M-[\C-f\M-\C-s" C-S-delete
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ;;; "\M-[\C-f\M-\C-d" C-S-prior
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 ;;; "\M-[\C-fv" C-S-next
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;;;
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ;;; "\M-[\C-f^" C-S-f1
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 ;;; "\M-[\C-f_" C-S-f2
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 ;;; "\M-[\C-f`" C-S-f3
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 ;;; "\M-[\C-fa" C-S-f4
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 ;;; "\M-[\C-fb" C-S-f5
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 ;;; "\M-[\C-fc" C-S-f6
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 ;;; "\M-[\C-fd" C-S-f7
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 ;;; "\M-[\C-fe" C-S-f8
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 ;;; "\M-[\C-ff" C-S-f9
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ;;; "\M-[\C-fg" C-S-f10
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (t
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (global-set-key [C-S-up] 'vcursor-previous-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (global-set-key [C-S-down] 'vcursor-next-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (global-set-key [C-S-left] 'vcursor-backward-char)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (global-set-key [C-S-right] 'vcursor-forward-char)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (global-set-key [C-S-return] 'vcursor-disable)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (global-set-key [C-S-insert] 'vcursor-copy)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (global-set-key [C-S-delete] 'vcursor-copy-word)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (global-set-key [C-S-remove] 'vcursor-copy-word)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (global-set-key [C-S-tab] 'vcursor-toggle-copy)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (global-set-key [C-S-home] 'vcursor-beginning-of-buffer)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (global-set-key [M-C-S-up] 'vcursor-beginning-of-buffer)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (global-set-key [C-S-end] 'vcursor-end-of-buffer)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (global-set-key [M-C-S-down] 'vcursor-end-of-buffer)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (global-set-key [C-S-prior] 'vcursor-scroll-down)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (global-set-key [C-S-next] 'vcursor-scroll-up)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (global-set-key [C-S-f6] 'vcursor-other-window)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (global-set-key [C-S-f7] 'vcursor-goto)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (global-set-key [C-S-select] 'vcursor-swap-point) ; DEC keyboards
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (global-set-key [M-C-S-tab] 'vcursor-swap-point)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (global-set-key [C-S-find] 'vcursor-isearch-forward) ; DEC keyboards
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (global-set-key [C-S-f8] 'vcursor-isearch-forward)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (global-set-key [M-C-S-left] 'vcursor-beginning-of-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (global-set-key [M-C-S-right] 'vcursor-end-of-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (global-set-key [M-C-S-prior] 'vcursor-backward-word)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (global-set-key [M-C-S-next] 'vcursor-forward-word)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (global-set-key [M-C-S-return] 'vcursor-copy-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (global-set-key [C-S-f9] 'vcursor-execute-key)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (global-set-key [C-S-f10] 'vcursor-execute-command)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 ))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (defun vcursor-locate ()
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 "Go to the starting point of the virtual cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 If that's disabled, don't go anywhere but don't complain."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 ;; This is where we go off-mass-shell. Assume there is a
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 ;; save-excursion to get us back to the pole, er, point.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (and (overlayp vcursor-overlay)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (overlay-buffer vcursor-overlay)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (set-buffer (overlay-buffer vcursor-overlay))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (goto-char (overlay-start vcursor-overlay)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (defun vcursor-find-window (&optional not-this new-win this-frame)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 "Return a suitable window for displaying the virtual cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 This is the first window in cyclic order where the vcursor is visible.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 With optional NOT-THIS non-nil never return the current window.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 With NEW-WIN non-nil, display the virtual cursor buffer in another
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 window if the virtual cursor is not currently visible \(note, however,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 that this function never changes window-point\).
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 With THIS-FRAME non-nil, don't search other frames for a new window
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 \(though if the vcursor is already off-frame then its current window is
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 always considered, and the value of `pop-up-frames' is always respected\).
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 Returns nil if the virtual cursor is not visible anywhere suitable.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 Set `vcursor-window' to the returned value as a side effect."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 ;; The order of priorities (respecting NOT-THIS) is (1)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 ;; vcursor-window if the virtual cursor is visible there (2) any
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 ;; window displaying the virtual cursor (3) vcursor-window provided
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 ;; it is still displaying the buffer containing the virtual cursor and
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 ;; is not selected (4) any unselected window displaying the vcursor
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 ;; buffer (5) with NEW-WIN, a window selected by display-buffer (so
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 ;; the variables pop-up-windows and pop-up-frames are significant)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 ;; (6) nil.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (let ((thiswin (selected-window)) winok winbuf)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (save-excursion
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (vcursor-locate)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (or (and (window-live-p vcursor-window)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (eq (current-buffer) (window-buffer vcursor-window))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (not (and not-this (eq thiswin vcursor-window))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (setq vcursor-window nil))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (or (and vcursor-window ; choice 1
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (pos-visible-in-window-p (point) vcursor-window))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (progn
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (walk-windows
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (function
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (lambda (win)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (and (not winok)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (eq (current-buffer) (window-buffer win))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (not (and not-this (eq thiswin win)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (cond
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 ((pos-visible-in-window-p (point) win) (setq winok win))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 ((eq thiswin win))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 ((not winbuf) (setq winbuf win))))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 nil (not this-frame))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (setq vcursor-window
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (cond
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (winok) ; choice 2
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 ((and vcursor-window ; choice 3
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (not (eq thiswin vcursor-window))) vcursor-window)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (winbuf) ; choice 4
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (new-win (display-buffer (current-buffer) t)) ; choice 5
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (t nil))))))) ; default (choice 6)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 vcursor-window
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (defun vcursor-toggle-copy (&optional arg nomsg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 "Toggle copying to point when the vcursor is moved.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 With a prefix ARG, turn on if non-negative, off if negative.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 Display a message unless optional NOMSG is non-nil."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (setq vcursor-copy-flag
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (cond ((not arg) (not vcursor-copy-flag))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 ((< (prefix-numeric-value arg) 0) nil)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (t))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 vcursor-last-command t)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (or nomsg (message "Copying from the vcursor is now %s."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (if vcursor-copy-flag "on" "off")))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (defun vcursor-move (pt)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 "Move the virtual cursor to the character to the right of PT.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 PT is an absolute location in the current buffer.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 If the new virtual cursor location would not be visible, display it in
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 another window."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 ;; this works even if we're on-mass-shell, but usually we won't be.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (if (eq pt (point-max)) (setq pt (1- pt)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (if (vcursor-check t)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (move-overlay vcursor-overlay pt (+ pt 1) (current-buffer))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (setq vcursor-overlay (make-overlay pt (+ pt 1)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (overlay-put vcursor-overlay 'face 'vcursor))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (vcursor-find-window nil t)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 ;; vcursor-window now contains the right buffer
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (or (pos-visible-in-window-p pt vcursor-window)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (set-window-point vcursor-window pt))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (defun vcursor-relative-move (fn &rest args)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 "Use FUNCTION with arbitrary ARG1 ... to move the virtual cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 This is called by most of the virtual-cursor motion commands."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (let (text opoint)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (save-excursion
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (vcursor-locate)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (setq opoint (point))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (apply fn args)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (and (eq opoint (point-max)) (eq opoint (point))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (signal 'end-of-buffer nil))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (vcursor-move (point))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (if vcursor-copy-flag (setq text (buffer-substring opoint (point)))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (if text (insert text)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (setq vcursor-last-command t)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (defun vcursor-goto (&optional arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 "Move the real cursor to the virtual cursor position.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 If the virtual cursor is (or was recently) visible in another window,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 switch to that first. Without a prefix ARG, disable the virtual
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 cursor as well."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (and (vcursor-find-window) (select-window vcursor-window))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (let ((buf (and vcursor-overlay (overlay-buffer vcursor-overlay))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 (and buf (not (eq (current-buffer) buf)) (switch-to-buffer buf)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (vcursor-locate)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (or arg (vcursor-disable))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (defun vcursor-swap-point ()
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 "Swap the location of point and that of the virtual cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 The virtual cursor window becomes the selected window and the old
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 window becomes the virtual cursor window. If the virtual cursor would
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 not be visible otherwise, display it in another window."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (interactive)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (let ((buf (current-buffer)) (here (point)) (win (selected-window)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (vcursor-goto) ; will disable the vcursor
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (save-excursion
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (set-buffer buf)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (setq vcursor-window win)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (vcursor-move here)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (defun vcursor-scroll-up (&optional n)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 "Scroll up the vcursor window ARG lines or near full screen if none.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 The vcursor will always appear in an unselected window."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (vcursor-window-funcall 'scroll-up n)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 (defun vcursor-scroll-down (&optional n)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 "Scroll down the vcursor window ARG lines or near-full screen if none.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 The vcursor will always appear in an unselected window."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (vcursor-window-funcall 'scroll-down n)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (defun vcursor-isearch-forward (&optional rep norecurs)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 "Perform forward incremental search in the virtual cursor window.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 The virtual cursor is moved to the resulting point; the ordinary
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 cursor stays where it was."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (vcursor-window-funcall 'isearch-forward rep norecurs)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (defun vcursor-window-funcall (func &rest args)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 "Call FUNC with ARGS ... in a virtual cursor window.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 A window other than the currently-selected one will always be used.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 The virtual cursor is moved to the value of point when the function
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 returns."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (vcursor-find-window t t)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (let ((sw (selected-window)) text)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 ;; We can't use save-window-excursion because that would restore
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 ;; the original display in the window we may want to alter.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (unwind-protect
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (let ((here (point)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (select-window vcursor-window)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (vcursor-locate)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (apply func args)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (if vcursor-copy-flag (setq text (buffer-substring here (point))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (vcursor-move (point)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (select-window sw))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (if text (insert text)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (setq vcursor-last-command t)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (defun vcursor-get-char-count (fn &rest args)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 "Apply FN to ARG1 ... and return the number of characters moved.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 Point is temporarily set to the virtual cursor position before FN is
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 called.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 This is called by most of the virtual-cursor copying commands to find
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 out how much to copy."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 (vcursor-check)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (save-excursion
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (set-buffer (overlay-buffer vcursor-overlay))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (let ((start (goto-char (overlay-start vcursor-overlay))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (- (progn (apply fn args) (point)) start)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 ;; Make sure the virtual cursor is active. Unless arg is non-nil,
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 ;; report an error if it is not.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (defun vcursor-check (&optional arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (cond
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 ((and (overlayp vcursor-overlay) (overlay-start vcursor-overlay))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 t)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (arg nil)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 (t (error "The virtual cursor is not active now.")))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (defun vcursor-disable (&optional arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 "Disable the virtual cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 Next time you use it, it will start from point.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 With a positive prefix ARG, the first window in cyclic order
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 displaying the virtual cursor (or which was recently displaying the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 virutal cursor) will be deleted unless it's the selected
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 window.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 With a negative prefix argument, enable the virtual cursor: make it
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 active at the same point as the real cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 Copying mode is always turned off: the next use of the vcursor will
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 not copy text until you turn it on again."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (if (overlayp vcursor-overlay)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 (progn
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 (delete-overlay vcursor-overlay)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (setq vcursor-overlay nil)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (cond
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 ((not (vcursor-find-window t)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 ((or (not arg) (< (prefix-numeric-value arg) 0)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 ((delete-window vcursor-window)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (and arg (< (prefix-numeric-value arg) 0)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (progn
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 (vcursor-move (point))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (setq vcursor-window (selected-window))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (setq vcursor-copy-flag nil)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 (defun vcursor-other-window (n &optional all-frames)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 "Activate the virtual cursor in another window.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 This is the next window cylically after one currently showing the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 virtual cursor, or else after the current selected window. If there
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 is no other window, the current window is split.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 Arguments N and optional ALL-FRAMES are the same as with other-window.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 ALL-FRAMES is also used to decide whether to split the window."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 (interactive "p")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (if (if (fboundp 'oemacs-version)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (one-window-p nil)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 (one-window-p nil all-frames))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (display-buffer (current-buffer) t))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 (save-excursion
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (save-window-excursion
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 ;; We don't use fancy vcursor-find-window trickery, since we're
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 ;; quite happy to have the vcursor cycle back into the current
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 ;; window.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 (let ((sw (selected-window))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 (win (vcursor-find-window nil nil (not all-frames))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 (if win (select-window win))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 ;; else start from here
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (other-window n all-frames)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 (vcursor-disable -1))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (defun vcursor-compare-windows (&optional arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 "Call `compare-windows' in the vcursor window.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 This has the effect of comparing the vcursor window with whichever
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 window `next-window' returns there, which may not be the selected one.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 A prefix argument, if any, is passed to `compare-windows'."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 (vcursor-window-funcall 'compare-windows arg))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 (defun vcursor-next-line (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 "Move the virtual cursor forward ARG lines."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 ;; This is next-line rewritten for the vcursor. Maybe it would
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 ;; be easier simply to rewrite line-move.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 (interactive "p")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 (let (temporary-goal-column opoint text)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 (save-excursion
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 (vcursor-locate)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 (setq temporary-goal-column
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (if (or (eq last-command 'vcursor-next-line)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 (eq last-command 'vcursor-previous-line))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (progn
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 (setq last-command 'next-line) ; trick line-move
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 vcursor-temp-goal-column)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 (if (and track-eol (eolp)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 (or (not (bolp)) (eq last-command 'end-of-line)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 9999
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 (current-column)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 opoint (point))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 (line-move arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (and (eq opoint (point-max)) (eq opoint (point))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 (signal 'end-of-buffer nil))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 (if vcursor-copy-flag (setq text (buffer-substring opoint (point))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 (vcursor-move (point))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (setq vcursor-temp-goal-column temporary-goal-column
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 vcursor-last-command t))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (if text (insert text)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 (defun vcursor-previous-line (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 "Move the virtual cursor back ARG lines."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 (interactive "p")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 (vcursor-next-line (- arg))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (defun vcursor-forward-char (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 "Move the virtual cursor forward ARG characters."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (interactive "p")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 (vcursor-relative-move 'forward-char arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 (defun vcursor-backward-char (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 "Move the virtual cursor backward ARG characters."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 (interactive "p")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 (vcursor-relative-move 'backward-char arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (defun vcursor-forward-word (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 "Move the virtual cursor forward ARG words."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 (interactive "p")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 (vcursor-relative-move 'forward-word arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 (defun vcursor-backward-word (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 "Move the virtual cursor backward ARG words."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (interactive "p")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (vcursor-relative-move 'backward-word arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 (defun vcursor-beginning-of-line (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 "Move the virtual cursor to beginning of its current line.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 ARG is as for `beginning-of-line'."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (vcursor-relative-move 'beginning-of-line
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 (if arg (prefix-numeric-value arg)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 (defun vcursor-end-of-line (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 "Move the virtual cursor to end of its current line.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 ARG is as for `end-of-line'."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 (vcursor-relative-move 'end-of-line
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 (if arg (prefix-numeric-value arg)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (defun vcursor-beginning-of-buffer (&optional arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 "Move the virtual cursor to the beginning of its buffer.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 ARG is as for beginning-of-buffer."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 (vcursor-relative-move
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 (lambda (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 (goto-char (if arg (/ (* arg (- (point-max) (point-min))) 10)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 (point-min))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 (if arg (prefix-numeric-value arg)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 (defun vcursor-end-of-buffer (&optional arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 "Move the virtual cursor to the end of its buffer.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 ARG is as for end-of-buffer.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 Actually, the vcursor is moved to the second from last character or it
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 would be invisible."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 (vcursor-relative-move
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 (lambda (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 (goto-char (if arg (- (point-max)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 (/ (* arg (- (point-max) (point-min))) 10))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 (point-max))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 (if arg (prefix-numeric-value arg)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 (defun vcursor-execute-command (cmd)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 "Execute COMMAND for the virtual cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 COMMAND is called interactively. Not all commands (in fact, only a
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 small subset) are useful."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 (interactive "CCommand: ")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 (let (text opoint)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (save-excursion
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 (vcursor-locate)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (setq opoint (point))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 (call-interactively cmd)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 (if vcursor-copy-flag (setq text (buffer-substring opoint (point))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 (vcursor-move (point)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 (if text (insert text)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 (setq vcursor-last-command t)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770 (defun vcursor-execute-key (keys)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 "Execute the command bound to KEYS for the virtual cursor.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 The command found is called interactively, so prefix argument etc.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 are usable."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 (interactive "kKey sequence: ")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 (let ((cmd (key-binding keys)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 (if cmd (vcursor-execute-command (key-binding keys))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 (defun vcursor-copy (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 "Copy ARG characters from the virtual cursor position to point."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (interactive "p")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 (vcursor-check)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 (insert
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (save-excursion
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 (set-buffer (overlay-buffer vcursor-overlay))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 (let* ((ostart (overlay-start vcursor-overlay))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 (end (+ ostart arg)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 (prog1
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 (buffer-substring ostart end)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 (vcursor-move end)))))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 (setq vcursor-last-command t)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 (defun vcursor-copy-word (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 "Copy ARG words from the virtual cursor position to point."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 (interactive "p")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 (vcursor-copy (vcursor-get-char-count 'forward-word arg))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 (defun vcursor-copy-line (arg)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 "Copy up to ARGth line after virtual cursor position.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 With no argument, copy to the end of the current line.
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 Behaviour with regard to newlines is similar (but not identical) to
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 `kill-line'; the main difference is that whitespace at the end of the
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 line is treated like ordinary characters."
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 (interactive "P")
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 (let* ((num (prefix-numeric-value arg))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 (count (vcursor-get-char-count 'end-of-line num)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 (vcursor-copy (if (or (= count 0) arg) (1+ count) count)))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 (defun vcursor-post-command ()
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 (and vcursor-auto-disable (not vcursor-last-command)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 vcursor-overlay (vcursor-disable))
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 (setq vcursor-last-command nil)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 )
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 (add-hook 'post-command-hook 'vcursor-post-command)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 (provide 'vcursor)
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824
bbf1df3de440 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 ;; vcursor.el ends here