annotate lisp/viper/viper.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children bcdc7deadc19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; viper.el --- A full-featured Vi emulator for GNU Emacs 19 and XEmacs 19,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; a VI Plan for Emacs Rescue,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; and a venomous VI PERil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Viper Is also a Package for Emacs Rebels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: emulations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 (defconst viper-version "2.90 of June 19, 1996"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 "The current version of Viper")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; Viper is a full-featured Vi emulator for Emacs 19. It emulates and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; improves upon the standard features of Vi and, at the same time, allows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; full access to all Emacs facilities. Viper supports multiple undo,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; file name completion, command, file, and search history and it extends
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; Vi in many other ways. Viper is highly customizable through the various
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; hooks, user variables, and keymaps. It is implemented as a collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; of minor modes and it is designed to provide full access to all Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; major and minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; History
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; Viper is a new name for a package formerly known as VIP-19,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; which was a successor of VIP version 3.5 by Masahiko Sato
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; <ms@sail.stanford.edu> and VIP version 4.2 by Aamod Sane
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; <sane@cs.uiuc.edu>. Some ideas from vip 4.4.2 by Aamod Sane
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; were also shamelessly plagiarized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; Viper maintains some degree of compatibility with these older
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; packages. See the documentation for customization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; The main difference between Viper and these older packages are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; 1. Viper emulates Vi at several levels, from almost complete conformity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; to a rather loose Vi-compliance.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; 2. Viper provides full access to all major and minor modes of Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; without the need to type extra keys.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; The older versions of VIP (and other Vi emulators) do not work with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; some major and minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; 3. Viper supports vi-style undo.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; 4. Viper fully emulates (and improves upon) vi's replacement mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; 5. Viper has a better interface to ex, including command, variable, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; file name completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; 6. Viper uses native Emacs history and completion features; it doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; rely on other packages (such as gmhist.el and completer.el) to provide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; these features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; 7. Viper supports Vi-style editing in the minibuffer, by allowing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; user to switch from Insert state to Vi state to Replace state, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; 8. Viper keeps history of recently inserted pieces of text and recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; executed Vi-style destructive commands, such as `i', `d', etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; These pieces of text can be inserted in later insertion commands;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; the previous destructive commands can be re-executed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; 9. Viper has Vi-style keyboard macros, which enhances the similar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; facility in the original Vi.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; First, one can execute any Emacs command while defining a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; macro, not just the Vi commands. Second, macros are defined in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; WYSYWYG mode, using an interface to Emacs' WYSIWYG style of defining
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; macros. Third, in Viper, one can define macros that are specific to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; a given buffer, a given major mode, or macros defined for all buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; The same macro name can have several different definitions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; one global, several definitions for various major modes, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; definitions for specific buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; Bffer-specific definitions override mode-specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; definitions, which, in turn, override global definitions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;; Installation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; -------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; (require 'viper)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;; Acknowledgements:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; -----------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; Bug reports and ideas contributed by the following users
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; have helped improve Viper and the various versions of VIP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;; See the on-line manual for a complete list of contributors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;; Notes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; 1. Major modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; In most cases, Viper handles major modes correctly, i.e., they come up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; in the right state (either vi-state or emacs-state). For instance, text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; files come up in vi-state, while, say, Dired appears in emacs-state by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; However, some modes do not appear in the right mode in the beginning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; usually because they neglect to follow Emacs conventions (e.g., they don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; use kill-all-local-variables when they start). Some major modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; may fail to come up in emacs-state if they call hooks, such as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; text-hook, for no good reason.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; As an immediate solution, you can hit C-z to bring about the right mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; An interim solution is to add an appropriate hook to the mode like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; (add-hook 'your-favorite-mode 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; (add-hook 'your-favorite-mode 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; whichever applies. The right thing to do, however, is to complain to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; author of the respective package. (Sometimes they also neglect to equip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; their modes with hooks, which is one more reason for complaining.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;; 2. Keymap handling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; Because Emacs 19 has an elegant mechanism for turning minor mode keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; on and off, implementation of Viper has been greatly simplified. Viper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; has several minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; Viper's Vi state consists of seven minor modes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; vip-vi-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; vip-vi-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; vip-vi-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; vip-vi-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; vip-vi-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; vip-vi-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; vip-vi-basic-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; Bindings done to the keymap of the first mode overshadow those done to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; the second, which, in turn, overshadows those done to the third, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; The last vip-vi-basic-minor-mode contains most of the usual Vi bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; in its edit mode. This mode provides access to all Emacs facilities.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; Novice users, however, may want to set their vip-expert-level to 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; in their .vip file. This will enable vip-vi-diehard-minor-mode. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; minor mode's bindings make Viper simulate the usual Vi very closely.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; For instance, C-c will not have its standard Emacs binding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; and so many of the goodies of Emacs are not available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; An skilled user, should set vip-expert-level to at least 3. This will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; enable ;; C-c and many Emacs facilities will become available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; In this case, vip-vi-diehard-minor-mode is inactive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;; Viper gurus should have at least
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; (setq vip-expert-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; in their ~/.vip files. This will unsuppress all Emacs keys that are not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; essential for VI-style editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;; Pick-and-choose users may want to put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;; (setq vip-expert-level 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;; in ~/.vip. Viper will then leave it up to the user to set the variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; vip-want-* See vip-set-expert-level for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; The very first minor mode, vip-vi-intercept-minor-mode, is of no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; concern for the user. It is needed to bind Viper's vital keys, such as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; ESC and C-z.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;; The second mode, vip-vi-local-user-minor-mode, usually has an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; empty keymap. However, the user can set bindings in this keymap, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; will overshadow the corresponding bindings in the other two minor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; modes. This is useful, for example, for setting up ZZ in gnus,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; rmail, mh-e, etc., to send message instead of saving it in a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; Likewise, in Dired mode, you may want to bind ZN and ZP to commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;; that would visit the next or the previous file in the Dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;; Setting local keys is tricky, so don't do it directly. Instead, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;; vip-add-local-keys function (see its doc).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; The third minor mode, vip-vi-global-user-minor-mode, is also intended
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; for the users but, unlike vip-vi-local-user-minor-mode, its key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; bindings are seen in all Viper buffers. This mode keys can be done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;; with define-key command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; The fourth minor mode, vip-vi-kbd-minor-mode, is used by keyboard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; macros. Users are NOT supposed to modify this keymap directly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; The fifth mode, vip-vi-state-modifier-minor-mode, can be used to set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; key bindings that are visible in some major modes but not in others.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; Users are allowed to modify keymaps that belong to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; vip-vi-local-user-minor-mode, vip-vi-global-user-minor-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; and vip-vi-state-modifier-minor-mode only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; Viper's Insert state also has seven minor modes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; vip-insert-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; vip-insert-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; vip-insert-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; vip-insert-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; vip-insert-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; vip-insert-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; vip-insert-basic-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;; As with VI's editing modes, the first mode, vip-insert-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; is used to bind vital keys that are not to be changed by the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; The next mode, vip-insert-local-user-minor-mode, is used to customize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;; bindings in the insert state of Viper. The third mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;; vip-insert-global-user-minor-mode is like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; vip-insert-local-user-minor-mode, except that its bindings are seen in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;; all Viper buffers. As with vip-vi-local-user-minor-mode, its bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; should be done via the function vip-add-local-keys. Bindings for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; vip-insert-global-user-minor-mode can be set with the define-key command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;; The next minor mode, vip-insert-kbd-minor-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; is used for keyboard VI-style macros defined with :map!.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;; The fifth minor mode, vip-insert-state-modifier-minor-mode, is like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;; vip-vi-state-modifier-minor-mode, except that it is used in the Insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; state; it can be used to modify keys in a mode-specific fashion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; The minor mode vip-insert-diehard-minor-mode is in effect when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;; the user wants a high degree of Vi compatibility (a bad idea, really!).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; The last minor mode, vip-insert-basic-minor-mode, is always in effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;; when Viper is in insert state. It binds a small number of keys needed for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;; Viper's operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; Finally, Viper provides minor modes for overriding bindings set by Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; modes when Viper is in Emacs state:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;; vip-emacs-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; vip-emacs-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;; vip-emacs-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; vip-emacs-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;; These minor modes are in effect when Viper is in Emacs state. The keymap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; associated with vip-emacs-global-user-minor-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; vip-emacs-global-user-map, overrides the global and local keymaps as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; well as the minor mode keymaps set by other modes. The keymap of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; vip-emacs-local-user-minor-mode, vip-emacs-local-user-map, overrides
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;; everything, but it is used on a per buffer basis.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;; The keymap associated with vip-emacs-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ;; overrides keys on a per-major-mode basis. The mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; vip-emacs-kbd-minor-mode is used to define Vi-style macros in Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;; state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;; 3. There is also one minor mode that is used when Viper is in its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;; replace-state (used for commands like cw, C, etc.). This mode is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ;; called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; vip-replace-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;; and its keymap is vip-replace-map. Replace minor mode is always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; used in conjunction with the minor modes for insert-state, and its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;; keymap overshadows the keymaps for insert minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; 4. Defining buffer-local bindings in Vi and Insert modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; As mentioned before, sometimes, it is convenient to have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; buffer-specific of mode-specific key bindings in Vi and insert modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; Viper provides a special function, vip-add-local-keys, to do precisely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; this. For instance, is you need to add couple of mode-specific bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;; to Insert mode, you can put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; (vip-add-local-keys 'insert-state '((key1 . func1) (key2 .func2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;; somewhere in a hook of this major mode. If you put something like this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; in your own elisp function, this will define bindings specific to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;; buffer that was current at the time of the call to vip-add-local-keys.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;; The only thing to make sure here is that the major mode of this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ;; is written according to Emacs conventions, which includes a call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;; (kill-all-local-variables). See vip-add-local-keys for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;; TO DO (volunteers?):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;; 1. Some of the code that is inherited from VIP-3.5 is rather
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; convoluted. Instead of vip-command-argument, keymaps should bind the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; actual commands. E.g., "dw" should be bound to a generic command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; vip-delete that will delete things based on the value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; last-command-char. This would greatly simplify the logic and the code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ;; 2. Somebody should venture to write a customization package a la
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ;; options.el that would allow the user to change values of variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ;; that meet certain specs (e.g., match a regexp) and whose doc string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;; starts with a '*'. Then, the user should be offered to save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;; variables that were changed. This will make user's customization job
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ;; much easier.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;; Code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (require 'advice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (require 'cl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (require 'ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (require 'viper-util)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;; Compiler pacifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (defvar vip-minibuffer-current-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (defvar vip-minibuffer-insert-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (defvar vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (defvar vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (defvar iso-accents-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (defvar zmacs-region-stays)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; end pacifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;;; Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;; Is t until viper-mode executes for the very first time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ;; Prevents recursive descend into startup messages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (defvar vip-first-time t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (defvar vip-expert-level 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 "User's expert level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 The minor mode vip-vi-diehard-minor-mode is in effect when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 vip-expert-level is 1 or 2 or when vip-want-emacs-keys-in-vi is t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 The minor mode vip-insert-diehard-minor-mode is in effect when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 vip-expert-level is 1 or 2 or if vip-want-emacs-keys-in-insert is t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 Use `M-x vip-set-expert-level' to change this.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;; Max expert level supported by Viper. This is NOT a user option.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;; It is here to make it hard for the user from resetting it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (defconst vip-max-expert-level 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ;; Contains user settings for vars affected by vip-set-expert-level function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;; Not a user option.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (defvar vip-saved-user-settings nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 ;;; Viper minor modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 ;; This is not local in Emacs, so we make it local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (make-variable-buffer-local 'minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; Mode for vital things like \e, C-z.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (vip-deflocalvar vip-vi-intercept-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (vip-deflocalvar vip-vi-basic-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 "Viper's minor mode for Vi bindings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (vip-deflocalvar vip-vi-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 "Auxiliary minor mode for user-defined local bindings in Vi state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (vip-deflocalvar vip-vi-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 "Auxiliary minor mode for user-defined global bindings in Vi state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (vip-deflocalvar vip-vi-state-modifier-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 "Minor mode used to make major-mode-specific modification to Vi state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (vip-deflocalvar vip-vi-diehard-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 "This minor mode is in effect when the user wants Viper to be Vi.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (vip-deflocalvar vip-vi-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 "Minor mode for Ex command macros in Vi state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 The corresponding keymap stores key bindings of Vi macros defined with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 the Ex command :map.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;; Mode for vital things like \e, C-z.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (vip-deflocalvar vip-insert-intercept-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (vip-deflocalvar vip-insert-basic-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 "Viper's minor mode for bindings in Insert mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (vip-deflocalvar vip-insert-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 "Auxiliary minor mode for buffer-local user-defined bindings in Insert state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 This is a way to overshadow normal Insert mode bindings locally to certain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 designated buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (vip-deflocalvar vip-insert-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 "Auxiliary minor mode for global user-defined bindings in Insert state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 "Minor mode used to make major-mode-specific modification to Insert state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (vip-deflocalvar vip-insert-diehard-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 "Minor mode that simulates Vi very closely.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 Not recommened, except for the novice user.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (vip-deflocalvar vip-insert-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 "Minor mode for Ex command macros Insert state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 The corresponding keymap stores key bindings of Vi macros defined with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 the Ex command :map!.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (vip-deflocalvar vip-replace-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 "Minor mode in effect in replace state (cw, C, and the like commands).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 ;; Mode for vital things like \C-z and \C-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;; This is t, by default. So, any new buffer will have C-z defined as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;; switch to Vi, unless we switched states in this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (vip-deflocalvar vip-emacs-intercept-minor-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (vip-deflocalvar vip-emacs-local-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 "Minor mode for local user bindings effective in Emacs state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 Users can use it to override Emacs bindings when Viper is in its Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (vip-deflocalvar vip-emacs-global-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 "Minor mode for global user bindings in effect in Emacs state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 Users can use it to override Emacs bindings when Viper is in its Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (vip-deflocalvar vip-emacs-kbd-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 "Minor mode for Vi style macros in Emacs state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 The corresponding keymap stores key bindings of Vi macros defined with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 `vip-record-kbd-macro' command. There is no Ex-level command to do this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 interactively.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (vip-deflocalvar vip-emacs-state-modifier-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 "Minor mode used to make major-mode-specific modification to Emacs state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 For instance, a Vi purist may want to bind `dd' in Dired mode to a function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 that deletes a file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;;; ISO characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (vip-deflocalvar vip-automatic-iso-accents nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 "*If non-nil, ISO accents will be turned on in insert/replace emacs states and turned off in vi-state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 For some users, this behavior may be too primitive. In this case, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 insert/emacs/vi state hooks.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ;;; Emacs keys in other states.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (defvar vip-want-emacs-keys-in-insert t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 "*Set to nil if you want complete Vi compatibility in insert mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 Complete compatibility with Vi is not recommended for power use of Viper.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (defvar vip-want-emacs-keys-in-vi t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 "*Set to nil if you want complete Vi compatibility in Vi mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 Full Vi compatibility is not recommended for power use of Viper.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ;; VI-style Undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ;; Used to 'undo' complex commands, such as replace and insert commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (vip-deflocalvar vip-undo-needs-adjustment nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (put 'vip-undo-needs-adjustment 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;; A mark that Viper puts on buffer-undo-list. Marks the beginning of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ;; complex command that must be undone atomically. If inserted, it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ;; erased by vip-change-state-to-vi and vip-repeat.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (defconst vip-buffer-undo-list-mark 'viper)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (defvar vip-keep-point-on-undo nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 "*Non-nil means not to move point while undoing commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 This style is different from Emacs and Vi. Try it to see if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 it better fits your working style.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;; Replace mode and changing text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 ;; Viper's own after/before change functions, which get vip-add-hook'ed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ;; Emacs's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (vip-deflocalvar vip-after-change-functions nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (vip-deflocalvar vip-before-change-functions nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (vip-deflocalvar vip-post-command-hooks nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (vip-deflocalvar vip-pre-command-hooks nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; Can be used to pass global states around for short period of time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (vip-deflocalvar vip-intermediate-command nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; Indicates that the current destructive command has started in replace mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (vip-deflocalvar vip-began-as-replace nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (defvar vip-replace-overlay-cursor-color "Red"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 "*Cursor color to use in Replace state")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (vip-deflocalvar vip-replace-overlay nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (put 'vip-replace-overlay 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (make-face 'vip-replace-overlay-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (vip-hide-face 'vip-replace-overlay-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (or (face-differs-from-default-p 'vip-replace-overlay-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (if (vip-can-use-colors "darkseagreen2" "Black")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (set-face-background
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 'vip-replace-overlay-face "darkseagreen2")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (set-face-foreground 'vip-replace-overlay-face "Black")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (set-face-underline-p 'vip-replace-overlay-face t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (defvar vip-replace-overlay-face 'vip-replace-overlay-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 "*Face for highlighting replace regions on a window display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (defvar vip-replace-region-end-delimiter "$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 "A string marking the end of replacement regions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 It is used only with TTYs or if `vip-use-replace-region-delimiters'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 is non-nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (defvar vip-replace-region-start-delimiter ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 "A string marking the beginning of replacement regions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 It is used only with TTYs or if `vip-use-replace-region-delimiters'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 is non-nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (defvar vip-use-replace-region-delimiters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (or (not (vip-has-face-support-p)) (not (vip-color-display-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 "*If non-nil, Viper will always use `vip-replace-region-end-delimiter' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 `vip-replace-region-start-delimiter' to delimit replacement regions, even on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 color displays. By default, the delimiters are used only on TTYs or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 monochrome displays.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;; XEmacs requires glyphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (if vip-xemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (or (glyphp vip-replace-region-end-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (setq vip-replace-region-end-delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (make-glyph vip-replace-region-end-delimiter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (or (glyphp vip-replace-region-start-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (setq vip-replace-region-start-delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (make-glyph vip-replace-region-start-delimiter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ;; These are local marker that must be initialized to nil and moved with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ;; `vip-move-marker-locally'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; Remember the last position inside the replace region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (vip-deflocalvar vip-last-posn-in-replace-region nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ;; Remember the last position while inserting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (vip-deflocalvar vip-last-posn-while-in-insert-state nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (put 'vip-last-posn-in-replace-region 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (put 'vip-last-posn-while-in-insert-state 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (vip-deflocalvar vip-sitting-in-replace nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (put 'vip-sitting-in-replace 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ;; Remember the number of characters that have to be deleted in replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;; mode to compensate for the inserted characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (vip-deflocalvar vip-replace-chars-to-delete 0 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (vip-deflocalvar vip-replace-chars-deleted 0 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ;; Insertion ring and command ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (defvar vip-insertion-ring-size 14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 "The size of the insertion ring.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 ;; The insertion ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (defvar vip-insertion-ring nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ;; This is temp insertion ring. Used to do rotation for display purposes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ;; When rotation just started, it is initialized to vip-insertion-ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (defvar vip-temp-insertion-ring nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (defvar vip-last-inserted-string-from-insertion-ring "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (defvar vip-command-ring-size 14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 "The size of the command ring.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ;; The command ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (defvar vip-command-ring nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ;; This is temp command ring. Used to do rotation for display purposes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;; When rotation just started, it is initialized to vip-command-ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (defvar vip-temp-command-ring nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ;; Modes and related variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ;; Current mode. One of: `emacs-state', `vi-state', `insert-state'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (vip-deflocalvar vip-current-state 'emacs-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (defvar vip-toggle-key "\C-z"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 "The key used to change states from emacs to Vi and back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 In insert mode, this key also functions as Meta.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 Must be set in .vip file or prior to loading Viper.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 This setting cannot be changed interactively.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (defvar vip-ESC-key "\e"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 "Key used to ESC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 Must be set in .vip file or prior to loading Viper.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 This setting cannot be changed interactively.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (defvar vip-no-multiple-ESC t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 "*If true, multiple ESC in Vi mode will cause bell to ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 \_ is then mapped to Meta.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 This is set to t on a windowing terminal and to 'twice on a dumb
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 enables cursor keys and is generally more convenient, as terminals usually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 don't have a convenient Meta key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 Setting vip-no-multiple-ESC to nil will allow as many multiple ESC,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 as is allowed by the major mode in effect.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (defvar vip-want-ctl-h-help nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 "*If t then C-h is bound to help-command in insert mode, if nil then it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 bound to delete-backward-char.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ;; Autoindent in insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 ;; Variable that keeps track of whether C-t has been pressed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (vip-deflocalvar vip-cted nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 ;; Preserve the indent value, used by C-d in insert mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (vip-deflocalvar vip-current-indent 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 ;; Whether to preserve the indent, used by C-d in insert mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (vip-deflocalvar vip-preserve-indent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (vip-deflocalvar vip-auto-indent nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 "*Autoindent if t.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (vip-deflocalvar vip-electric-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 "*If t, enable electric behavior.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 Currently only enables auto-indentation `according to mode'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (defconst vip-shift-width 8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 "*The shiftwidth variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 ;; Variables for repeating destructive commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (defconst vip-keep-point-on-repeat t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 "*If t, don't move point when repeating previous command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 This is useful for doing repeated changes with the '.' key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 The user can change this to nil, if she likes when the cursor moves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 to a new place after repeating previous Vi command.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 ;; Remember insert point as a marker. This is a local marker that must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;; initialized to nil and moved with `vip-move-marker-locally'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (vip-deflocalvar vip-insert-point nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (put 'vip-insert-point 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 ;; This remembers the point before dabbrev-expand was called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 ;; If vip-insert-point turns out to be bigger than that, it is reset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 ;; back to vip-pre-command-point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 ;; The reason this is needed is because dabbrev-expand (and possibly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ;; others) may jump to before the insertion point, delete something and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 ;; then reinsert a bigger piece. For instance: bla^blo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ;; If dabbrev-expand is called after `blo' and ^ undicates vip-insert-point,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 ;; will insert the expansion, and we get: blablo^
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ;; Whatever we insert next goes before the ^, i.e., before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;; vip-insert-point marker. So, Viper will think that nothing was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;; inserted. Remembering the orig position of the marker circumvents the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 ;; problem.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 ;; We don't know of any command, except dabbrev-expand, that has the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 ;; problem. However, the same trick can be used if such a command is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;; discovered later.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (vip-deflocalvar vip-pre-command-point nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (put 'vip-pre-command-point 'permanent-local t) ; this is probably an overkill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 ;; This is used for saving inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (defvar vip-last-insertion nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 ;; Remembers the last replaced region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (defvar vip-last-replace-region "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ;; Remember com point as a marker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 ;; This is a local marker. Should be moved with `vip-move-marker-locally'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (vip-deflocalvar vip-com-point nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; If non-nil, the value is a list (M-COM VAL COM REG inserted-text cmd-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 ;; It is used to re-execute last destructive command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 ;; M-COM is a Lisp symbol representing the function to be executed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;; VAL is the prefix argument that was used with that command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;; COM is an internal descriptor, such as ?r, ?c, ?C, which contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 ;; additional information on how the function in M-COM is to be handled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 ;; REG is the register used by command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 ;; INSERTED-TEXT is text inserted by that command (in case of o, c, C, i, r
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ;; commands).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 ;; COMMAND-KEYS are the keys that were typed to invoke the command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (defvar vip-d-com nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 ;; The character remembered by the Vi `r' command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (defvar vip-d-char nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 ;; Name of register to store deleted or yanked strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (defvar vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 ;; Variables for Moves and Searches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 ;; For use by `;' command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (defvar vip-f-char nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 ;; For use by `.' command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (defvar vip-F-char nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 ;; For use by `;' command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (defvar vip-f-forward nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ;; For use by `;' command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (defvar vip-f-offset nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 ;; Last search string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (defvar vip-s-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (defvar vip-quote-string "> "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 "String inserted at the beginning of quoted region.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 ;; If t, search is forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (defvar vip-s-forward nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (defconst vip-case-fold-search nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 "*If t, search ignores cases.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (defconst vip-re-search t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 "*If t, search is reg-exp search, otherwise vanilla search.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (defconst vip-re-query-replace t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 "*If t then do regexp replace, if nil then do string replace.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (defconst vip-re-replace t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 "*If t, do regexp replace. nil means do string replace.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (vip-deflocalvar vip-ex-style-motion t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 "*Ex-style: the commands l,h do not cross lines, etc.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (vip-deflocalvar vip-ex-style-editing-in-insert t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 "*The keys ^H, ^? don't jump lines in insert, ESC moves cursor back, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 Note: this doesn't preclude ^H and ^? from deleting characters by moving
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 past the insertion point. This is a feature, not a bug. ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (vip-deflocalvar vip-delete-backwards-in-replace nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 "*If t, DEL key will delete characters while moving the cursor backwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 If nil, the cursor will move backwards without deleting anything.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (defconst vip-buffer-search-char nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 "*Key bound for buffer-searching.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (defconst vip-search-wrap-around-t t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 "*If t, search wraps around.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (vip-deflocalvar vip-related-files-and-buffers-ring nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 "*Ring of file and buffer names that are considered to be related to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 These buffers can be cycled through via :R and :P commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (put 'vip-related-files-and-buffers-ring 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;; Used to find out if we are done with searching the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (vip-deflocalvar vip-local-search-start-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;; As above, but global
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (defvar vip-search-start-marker (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 ;; the search overlay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (vip-deflocalvar vip-search-overlay nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (defvar vip-heading-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (concat "^\\s-*(\\s-*defun\\s-\\|" ; lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 "^{\\s-*$\\|^[_a-zA-Z][^()]*[()].*{\\s-*$\\|" ; C/C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 "^\\s-*class.*{\\|^\\s-*struct.*{\\|^\\s-*enum.*{\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 "^\\\\[sb][a-z]*{.*}\\s-*$\\|" ; latex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 "^@node\\|@table\\|^@m?enu\\|^@itemize\\|^@if\\|" ; texinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 "^.+:-") ; prolog
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 "*Regexps for Headings. Used by \[\[ and \]\].")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (defvar vip-heading-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (concat "^}\\|" ; C/C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 "^\\\\end{\\|" ; latex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 "^@end \\|" ; texinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 ")\n\n[ \t\n]*\\|" ; lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 "\\.\\s-*$") ; prolog
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 "*Regexps to end Headings/Sections. Used by \[\].")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 ;; These two vars control the interaction of jumps performed by ' and `.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 ;; In this new version, '' doesn't erase the marks set by ``, so one can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 ;; use both kinds of jumps interchangeably and without loosing positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 ;; inside the lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 ;; Remembers position of the last jump done using ``'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (vip-deflocalvar vip-last-jump nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;; Remembers position of the last jump done using `''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (vip-deflocalvar vip-last-jump-ignore 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 ;; Some common error messages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (defconst vip-SpuriousText "Spurious text after command" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (defconst vip-BadExCommand "Not an editor command" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (defconst vip-InvalidCommandArgument "Invalid command argument" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (defconst vip-NoPrevSearch "No previous search string" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (defconst vip-EmptyRegister "`%c': Nothing in this register" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (defconst vip-InvalidRegister "`%c': Invalid register" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (defconst vip-EmptyTextmarker "`%c': Text marker doesn't point anywhere" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (defconst vip-InvalidTextmarker "`%c': Invalid text marker" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (defconst vip-InvalidViCommand "Invalid command" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (defconst vip-BadAddress "Ill-formed address" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (defconst vip-FirstAddrExceedsSecond "First address exceeds second" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (defconst vip-NoFileSpecified "No file specified" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ;; History variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 ;; History of search strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (defvar vip-search-history (list ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 ;; History of query-replace strings used as a source.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (defvar vip-replace1-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;; History of query-replace strings used as replacement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (defvar vip-replace2-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ;; History of region quoting strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (defvar vip-quote-region-history (list vip-quote-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ;; History of Ex-style commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (defvar vip-ex-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ;; History of shell commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (defvar vip-shell-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 ;; Last shell command. There are two of these, one for Ex (in viper-ex)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 ;; and one for Vi.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 ;; Last shell command executed with ! command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (defvar vip-last-shell-com nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;;; Miscellaneous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 ;; don't bark when mark is inactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (setq mark-even-if-inactive t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (defvar vip-inhibit-startup-message nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 "Whether Viper startup message should be inhibited.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (defvar vip-always t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 "t means, arrange that vi-state will be a default.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (defvar vip-ms-style-os-p (memq system-type '(ms-dos windows-nt windows-95))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 "Tells is Emacs is running under an MS-style OS: ms-dos, window-nt, W95.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (defvar vip-vms-os-p (memq system-type '(vax-vms axp-vms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 "Tells if Emacs is running under VMS.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (defvar vip-custom-file-name (cond (vip-vms-os-p "sys$login:.vip")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 ((memq system-type '(emx ms-dos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 "/_vip")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 ((memq system-type '(windows-nt windows-95))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 "~/_vip")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (t ; Unix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 "~/.vip"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 "Viper customisation file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 This variable must be set _before_ loading Viper.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (defvar vip-spell-function 'ispell-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 "Spell function used by #s<move> command to spell.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (defvar vip-tags-file-name "TAGS"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 "The tags file used by Viper.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 ;; Minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (defvar vip-vi-style-in-minibuffer t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 "If t, use vi-style editing in minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 Should be set in `~/.vip' file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 ;; overlay used in the minibuffer to indicate which state it is in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (vip-deflocalvar vip-minibuffer-overlay nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 ;; Beginning with Emacs 19.26, the standard `minibuffer-exit-hook' is run
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ;; *after* exiting the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (defvar vip-minibuffer-exit-hook nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (vip-deflocalvar vip-vi-minibuffer-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 "Minor mode that forces Vi-style when the Minibuffer is in Vi state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (vip-deflocalvar vip-insert-minibuffer-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 "Minor mode that forces Vi-style when the Minibuffer is in Insert state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 ;; setup emacs-supported vi-style feel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (setq next-line-add-newlines nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 require-final-newline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (make-variable-buffer-local 'require-final-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 ;; Mode line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (defconst vip-vi-state-id "<V> "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 "Mode line tag identifying the Vi mode of Viper.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (defconst vip-emacs-state-id "<E> "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 "Mode line tag identifying the Emacs mode of Viper.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (defconst vip-insert-state-id "<I> "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 "Mode line tag identifying the Insert mode of Viper.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (defconst vip-replace-state-id "<R> "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 "Mode line tag identifying the Replace mode of Viper.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 ;; Viper changes the default mode-line-buffer-identification
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (setq-default mode-line-buffer-identification '(" %b"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 ;; Variable displaying the current Viper state in the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (vip-deflocalvar vip-mode-string vip-emacs-state-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (or (memq 'vip-mode-string global-mode-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (setq global-mode-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (append '("" vip-mode-string) (cdr global-mode-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (defvar vip-vi-state-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 "*Hooks run just before the switch to Vi mode is completed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (defvar vip-insert-state-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 "*Hooks run just before the switch to Insert mode is completed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (defvar vip-replace-state-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 "*Hooks run just before the switch to Replace mode is completed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (defvar vip-emacs-state-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 "*Hooks run just before the switch to Emacs mode is completed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (defvar vip-load-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 "Hooks run just after loading Viper.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 ;; Generic predicates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 ;; generate test functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 ;; given symbol foo, foo-p is the test function, foos is the set of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 ;; Viper command keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 ;; (macroexpand '(vip-test-com-defun foo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (defmacro vip-test-com-defun (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (let* ((snm (symbol-name name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (nm-p (intern (concat snm "-p")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (nms (intern (concat snm "s"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (` (defun (, nm-p) (com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (consp (memq (if (< com 0) (- com) com) (, nms)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ;; Variables for defining VI commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 ;; Modifying commands that can be prefixes to movement commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (vip-test-com-defun vip-prefix-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ;; Commands that are pairs eg. dd. r and R here are a hack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (vip-test-com-defun vip-charpair-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 ?H ?M ?n ?t ?T ?w ?W ?$ ?%
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?`
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 ?; ?, ?0 ?? ?/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 "Movement commands")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (vip-test-com-defun vip-movement-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 ;; Commands that can be repeated by .(dotted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (defconst vip-dotable-commands '(?c ?d ?C ?D ?> ?<))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (vip-test-com-defun vip-dotable-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 ;; Commands that can follow a #
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (defconst vip-hash-cmds '(?c ?C ?g ?q ?S))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (vip-test-com-defun vip-hash-cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 ;; Commands that may have registers as prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (vip-test-com-defun vip-regsuffix-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 ;;; Arrange the keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (require 'viper-keym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 ;;; CODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 ;; sentinels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ;; Runs vip-after-change-functions inside after-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (defun vip-after-change-sentinel (beg end len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (let ((list vip-after-change-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (funcall (car list) beg end len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (setq list (cdr list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ;; Runs vip-before-change-functions inside before-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (defun vip-before-change-sentinel (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (let ((list vip-before-change-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (funcall (car list) beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (setq list (cdr list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (defsubst vip-post-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (run-hooks 'vip-post-command-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (defsubst vip-pre-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (run-hooks 'vip-pre-command-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ;; Needed so that Viper will be able to figure the last inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 ;; chunk of text with reasonable accuracy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (defsubst vip-insert-state-post-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (if (and (memq vip-current-state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 vip-insert-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (>= (point) vip-insert-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (setq vip-last-posn-while-in-insert-state (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (if (and (eq this-command 'dabbrev-expand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (integerp vip-pre-command-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (> vip-insert-point vip-pre-command-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (move-marker vip-insert-point vip-pre-command-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (defsubst vip-insert-state-pre-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (if (and (eq this-command 'dabbrev-expand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (markerp vip-insert-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (marker-position vip-insert-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (setq vip-pre-command-point (marker-position vip-insert-point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (defsubst vip-R-state-post-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ;; Restoring cursor color is needed despite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 ;; vip-replace-state-pre-command-sentinel: When you jump to another buffer in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 ;; another frame, the pre-command hook won't change cursor color to default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 ;; in that other frame. So, if the second frame cursor was red and we set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 ;; the point outside the replacement region, then the cursor color will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 ;; remain red. Restoring the default, below, prevents this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (if (and (<= (vip-replace-start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (<= (point) (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (vip-change-cursor-color vip-replace-overlay-cursor-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (vip-restore-cursor-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 ;; to speed up, don't change cursor color before self-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 ;; and common move commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (defsubst vip-replace-state-pre-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (or (memq this-command '(self-insert-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (memq (vip-event-key last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 '(up down left right (meta f) (meta b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (control n) (control p) (control f) (control b)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (vip-restore-cursor-color)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (defun vip-replace-state-post-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 ;; Restoring cursor color is needed despite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 ;; in another frame, the pre-command hook won't change cursor color to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ;; default in that other frame. So, if the second frame cursor was red and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 ;; we set the point outside the replacement region, then the cursor color
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 ;; will remain red. Restoring the default, below, fixes this problem.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 ;; We optimize for self-insert-command's here, since they either don't change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 ;; cursor color or, if they terminate replace mode, the color will be changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 ;; in vip-finish-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (or (memq this-command '(self-insert-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (vip-restore-cursor-color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 ((eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ;; delete characters to compensate for inserted chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (let ((replace-boundary (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 (goto-char vip-last-posn-in-replace-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (delete-char vip-replace-chars-to-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (setq vip-replace-chars-to-delete 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 vip-replace-chars-deleted 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 ;; terminate replace mode if reached replace limit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (if (= vip-last-posn-in-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (vip-replace-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (vip-finish-change vip-last-posn-in-replace-region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (if (and (<= (vip-replace-start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (<= (point) replace-boundary))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ;; the state may have changed in vip-finish-change above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (if (eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (vip-change-cursor-color vip-replace-overlay-cursor-color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (setq vip-last-posn-in-replace-region (point-marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (t ;; terminate replace mode if changed Viper states.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (vip-finish-change vip-last-posn-in-replace-region))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 ;; changing mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (defun vip-change-state (new-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 ;; Keep vip-post/pre-command-hooks fresh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 ;; We remove then add vip-post/pre-command-sentinel since it is very
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 ;; desirable that vip-pre-command-sentinel is the last hook and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 ;; vip-post-command-sentinel is the first hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (remove-hook 'post-command-hook 'vip-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (add-hook 'post-command-hook 'vip-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 ;; These hooks will be added back if switching to insert/replace mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 (vip-remove-hook 'vip-post-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 'vip-insert-state-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (vip-remove-hook 'vip-pre-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 'vip-insert-state-pre-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (cond ((eq new-state 'vi-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (cond ((member vip-current-state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ;; move vip-last-posn-while-in-insert-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 ;; This is a normal hook that is executed in insert/replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 ;; states after each command. In Vi/Emacs state, it does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 ;; nothing. We need to execute it here to make sure that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 ;; the last posn was recorded when we hit ESC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 ;; It may be left unrecorded if the last thing done in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 ;; insert/repl state was dabbrev-expansion or abbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 ;; expansion caused by hitting ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (vip-insert-state-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (vip-save-last-insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 vip-insert-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 vip-last-posn-while-in-insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (if vip-began-as-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (setq vip-began-as-replace nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 ;; repeat insert commands if numerical arg > 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (vip-repeat-insert-command))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (vip-message-conditions conds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (if (> (length vip-last-insertion) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (vip-push-onto-ring vip-last-insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 'vip-insertion-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (if vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (or (bolp) (backward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 ;; insert or replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 ((memq new-state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (if (memq vip-current-state '(emacs-state vi-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (vip-move-marker-locally 'vip-insert-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (vip-add-hook 'vip-post-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 'vip-insert-state-post-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (vip-add-hook 'vip-pre-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 'vip-insert-state-pre-command-sentinel t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 ) ; outermost cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 ;; Nothing needs to be done to switch to emacs mode! Just set some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 ;; variables, which is already done in vip-change-state-to-emacs!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (setq vip-current-state new-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (vip-normalize-minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (vip-adjust-keys-for new-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (vip-set-mode-vars-for new-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (vip-refresh-mode-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (defun vip-adjust-keys-for (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 "Make necessary adjustments to keymaps before entering STATE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (cond ((memq state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (if vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 ;; expert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (define-key vip-insert-basic-map "\C-j" nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 ;; novice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (setq vip-insert-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (not vip-want-emacs-keys-in-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (if vip-want-ctl-h-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (define-key vip-insert-basic-map "\C-h" 'help-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (define-key vip-replace-map "\C-h" 'help-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (define-key vip-insert-basic-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 "\C-h" 'vip-del-backward-char-in-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (define-key vip-replace-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 "\C-h" 'vip-del-backward-char-in-replace)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (if vip-want-ctl-h-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (define-key vip-vi-basic-map "\C-h" 'help-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (define-key vip-vi-basic-map "\C-h" 'vip-backward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 ;; This ensures that Viper bindings are in effect, regardless of which minor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 ;; modes were turned on by the user or by other packages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (defun vip-normalize-minor-mode-map-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (setq minor-mode-map-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (vip-append-filter-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (cons 'vip-vi-intercept-minor-mode vip-vi-intercept-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (cons 'vip-vi-minibuffer-minor-mode vip-minibuffer-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (cons 'vip-vi-local-user-minor-mode vip-vi-local-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (cons 'vip-vi-kbd-minor-mode vip-vi-kbd-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (cons 'vip-vi-global-user-minor-mode vip-vi-global-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (cons 'vip-vi-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (if (keymapp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (cdr (assoc major-mode vip-vi-state-modifier-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (cdr (assoc major-mode vip-vi-state-modifier-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 vip-empty-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (cons 'vip-vi-basic-minor-mode vip-vi-basic-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (cons 'vip-replace-minor-mode vip-replace-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 ;; vip-insert-minibuffer-minor-mode must come after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 ;; vip-replace-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (cons 'vip-insert-minibuffer-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 vip-minibuffer-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (cons 'vip-insert-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 vip-insert-local-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (cons 'vip-insert-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 vip-insert-global-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (cons 'vip-insert-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (if (keymapp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (assoc major-mode vip-insert-state-modifier-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (assoc major-mode vip-insert-state-modifier-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 vip-empty-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (cons 'vip-insert-basic-minor-mode vip-insert-basic-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (cons 'vip-emacs-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 vip-emacs-intercept-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (cons 'vip-emacs-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 vip-emacs-local-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (cons 'vip-emacs-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 vip-emacs-global-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (cons 'vip-emacs-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (if (keymapp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (assoc major-mode vip-emacs-state-modifier-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (assoc major-mode vip-emacs-state-modifier-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 vip-empty-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 minor-mode-map-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 ;; Viper mode-changing commands and utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 ;; Modifies mode-line-buffer-identification.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (defun vip-refresh-mode-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (setq vip-mode-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 ((eq vip-current-state 'vi-state) vip-vi-state-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 ((eq vip-current-state 'replace-state) vip-replace-state-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ((eq vip-current-state 'insert-state) vip-insert-state-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 ;; Sets Viper mode string in global-mode-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (force-mode-line-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (defun viper-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 "Turn on Viper emulation of Vi."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 (if (not noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (if vip-first-time ; This check is important. Without it, startup and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (progn ; expert-level msgs mix up when viper-mode recurses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (setq vip-first-time nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (if (not vip-inhibit-startup-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (setq vip-inhibit-startup-message t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (delete-other-windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (switch-to-buffer "Viper Startup Message")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 "Viper Is a Package for Emacs Rebels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 It is also a VI Plan for Emacs Rescue and a venomous VI PERil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 XEmacs 19. It supports virtually all of Vi and Ex functionality, extending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 and improving upon much of it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 1. Viper supports Vi at several levels. Level 1 is the closest to Vi,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 level 5 provides the most flexibility to depart from many Vi conventions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 You will be asked to specify your user level in a following screen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 If you select user level 1 then the keys ^X, ^C, ^Z, and ^G will behave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 as in VI, to smooth transition to Viper for the beginners. However, to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 use Emacs productively, you are advised to reach user level 3 or higher.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 If your user level is 2 or higher, ^X and ^C will invoke Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 functions,as usual in Emacs; ^Z will toggle vi/emacs modes, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 ^G will be the usual Emacs's keyboard-quit (something like ^C in VI).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 do not cause Emacs to quit, except at user level 1 (a novice).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 3. ^X^C EXITS EMACS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 undo. Another `u' changes direction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 6. Emacs Meta functions are invoked by typing `_' or `\\ ESC'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 On a window system, the best way is to use the Meta-key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 something funny happens. This would abort the current editing command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 You can get more information on Viper by:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 a. Typing `:help' in Vi state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 b. Printing Viper manual, found in ./etc/viper.dvi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 c. Printing ViperCard, the Quick Reference, found in ./etc/viperCard.dvi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 This startup message appears whenever you load Viper, unless you type `y' now."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (if (y-or-n-p "Inhibit Viper startup message? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (vip-save-setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 'vip-inhibit-startup-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 "Viper startup message inhibited"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 vip-custom-file-name t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 ;;(kill-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 "The last message is in buffer `Viper Startup Message'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (sit-for 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (vip-set-expert-level 'dont-change-unless)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (vip-change-state-to-vi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (defalias 'vip-mode 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 ;; Switch from Insert state to Vi state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (defun vip-exit-insert-state ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (vip-change-state-to-vi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (defun vip-set-mode-vars-for (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 "Sets Viper minor mode variables to put Viper's state STATE in effect."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 ;; Emacs state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (setq vip-vi-minibuffer-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 vip-insert-minibuffer-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 vip-vi-intercept-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 vip-insert-intercept-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 vip-vi-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 vip-vi-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 vip-vi-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 vip-vi-state-modifier-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 vip-vi-diehard-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 vip-vi-basic-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 vip-replace-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 vip-insert-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 vip-insert-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 vip-insert-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 vip-insert-state-modifier-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 vip-insert-diehard-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 vip-insert-basic-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 vip-emacs-intercept-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 vip-emacs-local-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 vip-emacs-global-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 vip-emacs-state-modifier-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 ;; Vi state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (if (eq state 'vi-state) ; adjust for vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 vip-vi-intercept-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 vip-vi-local-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 vip-vi-global-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 vip-vi-state-modifier-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 ;; don't let the diehard keymap block command completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 ;; and other things in the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 vip-vi-diehard-minor-mode (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (or vip-want-emacs-keys-in-vi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (vip-is-in-minibuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 vip-vi-basic-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 vip-emacs-intercept-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 vip-emacs-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 vip-emacs-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 vip-emacs-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 vip-emacs-state-modifier-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 ;; Insert and Replace states
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (if (member state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 vip-insert-intercept-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 vip-replace-minor-mode (eq state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 vip-insert-local-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 vip-insert-global-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 vip-insert-state-modifier-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 ;; don't let the diehard keymap block command completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 ;; and other things in the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 vip-insert-diehard-minor-mode (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (or vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (vip-is-in-minibuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 vip-insert-basic-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 vip-emacs-intercept-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 vip-emacs-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 vip-emacs-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 vip-emacs-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 vip-emacs-state-modifier-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 ;; minibuffer faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (setq vip-minibuffer-current-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 ((eq state 'vi-state) vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 ((memq state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 vip-minibuffer-insert-face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (if (vip-is-in-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (vip-set-minibuffer-overlay))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 ;; This also takes care of the annoying incomplete lines in files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 ;; Also, this fixes `undo' to work vi-style for complex commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (defun vip-change-state-to-vi ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 "Change Viper state to Vi."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (if (and vip-first-time (not (vip-is-in-minibuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (if overwrite-mode (overwrite-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (if abbrev-mode (expand-abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (if (and auto-fill-function (> (current-column) fill-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (funcall auto-fill-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 ;; don't leave whitespace lines around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (if (and (memq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 '(vip-autoindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 vip-open-line vip-Open-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 vip-replace-state-exit-cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (vip-over-whitespace-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (indent-to-left-margin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (vip-add-newline-at-eob-if-necessary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (if vip-undo-needs-adjustment (vip-adjust-undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (vip-change-state 'vi-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 ;; always turn off iso-accents-mode, or else we won't be able to use the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (iso-accents-mode -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 ;; Protection against user errors in hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (run-hooks 'vip-vi-state-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (vip-message-conditions conds)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (defun vip-change-state-to-insert ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 "Change Viper state to Insert."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (vip-change-state 'insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (iso-accents-mode 1)) ; turn iso accents on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 ;; Protection against user errors in hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (run-hooks 'vip-insert-state-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (vip-message-conditions conds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (defsubst vip-downgrade-to-insert ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (setq vip-current-state 'insert-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 vip-replace-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 ;; Change to replace state. When the end of replacement region is reached,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 ;; replace state changes to insert state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (defun vip-change-state-to-replace (&optional non-R-cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 (vip-change-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (iso-accents-mode 1)) ; turn iso accents on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 ;; Run insert-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (run-hooks 'vip-insert-state-hook 'vip-replace-state-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (vip-message-conditions conds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 (if non-R-cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (vip-start-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 ;; 'R' is implemented using Emacs's overwrite-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (vip-start-R-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (defun vip-change-state-to-emacs ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 "Change Viper state to Emacs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (vip-change-state 'emacs-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (iso-accents-mode 1)) ; turn iso accents on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 ;; Protection agains user errors in hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 (run-hooks 'vip-emacs-state-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (vip-message-conditions conds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 ;; escape to emacs mode termporarily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (defun vip-escape-to-emacs (arg &optional events)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 "Escape to Emacs state from Vi state for one Emacs command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 ARG is used as the prefix value for the executed command. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 EVENTS is a list of events, which become the beginning of the command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (vip-escape-to-state arg events 'emacs-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 ;; escape to Vi mode termporarily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (defun vip-escape-to-vi ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 "Escape from Emacs state to Vi state for one Vi 1-character command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 This doesn't work with prefix arguments or most complex commands like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 cw, dw, etc. But it does work with some 2-character commands,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 like dd or dr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (vip-escape-to-state nil nil 'vi-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 ;; Escape to STATE mode for one Emacs command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (defun vip-escape-to-state (arg events state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (let (com key prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 ;; this temporarily turns off Viper's minor mode keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (vip-set-mode-vars-for state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (vip-normalize-minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 (if events (vip-set-unread-command-events events))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 ;; protect against keyboard quit and other errors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (setq com (key-binding (setq key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (if vip-xemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (read-key-sequence nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (read-key-sequence nil t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 ;; In case of indirection--chase definitions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 ;; Have to do it here because we execute this command under
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 ;; different keymaps, so command-execute may not do the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 ;; right thing there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (while (vectorp com) (setq com (key-binding com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 ;; exec command in the right Viper state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 ;; otherwise, if we switch buffers in the escaped command,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 ;; Viper's mode vars will remain those of `state'. When we return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 ;; to the orig buffer, the bindings will be screwed up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (vip-set-mode-vars-for vip-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 ;; this-command, last-command-char, last-command-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (setq this-command com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (if vip-xemacs-p ; XEmacs represents key sequences as vectors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (setq last-command-event (vip-seq-last-elt key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 last-command-char (event-to-character last-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 ;; Emacs represents them as sequences (str or vec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 (setq last-command-event (vip-seq-last-elt key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 last-command-char last-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (if (commandp com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (setq prefix-arg arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (command-execute com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (quit (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (error (beep 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (vip-set-mode-vars-for vip-current-state)) ; set state in new buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (defun vip-exec-form-in-emacs (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (let ((buff (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 (vip-set-mode-vars-for 'emacs-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (setq result (eval form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 (if (not (equal buff (current-buffer))) ; cmd switched buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 (set-buffer buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (vip-set-mode-vars-for vip-current-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (vip-set-mode-vars-for vip-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 ;; This is needed because minor modes sometimes override essential Viper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 ;; bindings. By letting Viper know which files these modes are in, it will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 ;; arrange to reorganize minor-mode-map-alist so that things will work right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (defun vip-harness-minor-mode (load-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 "Familiarize Viper with a minor mode defined in LOAD_FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 Minor modes that have their own keymaps may overshadow Viper keymaps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 This function is designed to make Viper aware of the packages that define
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 such minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 Usage:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (vip-harness-minor-mode load-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 LOAD-FILE is a name of the file where the specific minor mode is defined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 Suffixes such as .el or .elc should be stripped."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (interactive "sEnter name of the load file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 ;; Change the default for minor-mode-map-alist each time a harnessed minor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 ;; mode adds its own keymap to the a-list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (defun vip-ESC (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 "Emulate ESC key in Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true. In that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 case \@ will be bound to ESC. If vip-no-multiple-ESC is 'twice double ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 would dings in vi-state. Other ESC sequences are emulated via the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 Emacs's major mode keymap. This is more convenient on dumb terminals and in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 Emacs -nw, since this won't block functional keys such as up,down,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 etc. Meta key also will work. When vip-no-multiple-ESC is nil, ESC key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 behaves as in Emacs, any number of multiple escapes is allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (let (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 (setq char (vip-read-char-exclusive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 (vip-escape-to-emacs arg (list ?\e char) ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 ((and (eq vip-no-multiple-ESC 'twice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (eq vip-current-state 'vi-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (setq char (vip-read-char-exclusive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (if (= char (string-to-char vip-ESC-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (vip-escape-to-emacs arg (list ?\e char) )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (t (ding)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 (defun vip-alternate-ESC (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 "ESC key without checking for multiple keystrokes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (vip-escape-to-emacs arg '(?\e)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 ;; Intercept ESC sequences on dumb terminals.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 ;; Check if last key was ESC and if so try to reread it as a function key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 ;; But only if there are characters to read during a very short time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 ;; Returns the last event, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (defun vip-envelop-ESC-key ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (let ((event last-input-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (keyseq [nil])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 inhibit-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (if (vip-ESC-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (if (vip-fast-keysequence-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (let (minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (vip-set-unread-command-events event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (setq keyseq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (funcall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (ad-get-orig-definition 'read-key-sequence) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 ) ; let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 ;; If keyseq translates into something that still has ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 ;; at the beginning, separate ESC from the rest of the seq.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 ;; In XEmacs we check for events that are keypress meta-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 ;; and convert them into [escape key]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 ;; This is needed for the following reason:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 ;; If ESC is the first symbol, we interpret it as if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 ;; user typed ESC and then quickly some other symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 ;; If ESC is not the first one, then the key sequence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 ;; entered was apparently translated into a function key or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 ;; something (e.g., one may have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 ;; (define-key function-key-map "\e[192z" [f11])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 ;; which would translate the escape-sequence generated by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 ;; f11 in an xterm window into the symbolic key f11.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 ;; If `first-key' is not an ESC event, we make it into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 ;; last-command-event in order to pretend that this key was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 ;; pressed. This is needed to allow arrow keys to be bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 ;; macros. Otherwise, vip-exec-mapped-kbd-macro will think that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ;; the last event was ESC and so it'll execute whatever is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 ;; bound to ESC. (Viper macros can't be bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 ;; ESC-sequences).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 (let* ((first-key (elt keyseq 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (key-mod (event-modifiers first-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (cond ((vip-ESC-event-p first-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 ;; put keys following ESC on the unread list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 ;; and return ESC as the key-sequence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (vip-set-unread-command-events (subseq keyseq 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (setq last-input-event event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 keyseq (if vip-emacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 "\e"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (vector (character-to-event ?\e)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 ((and vip-xemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (key-press-event-p first-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 (equal '(meta) key-mod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (vip-set-unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 (vconcat (vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (character-to-event (event-key first-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (subseq keyseq 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 (setq last-input-event event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 keyseq (vector (character-to-event ?\e))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 ((eventp first-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (setq last-command-event first-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 ) ; end progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 ;; this is escape event with nothing after it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 ;; put in unread-command-event and then re-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 (vip-set-unread-command-events event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (setq keyseq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 (funcall (ad-get-orig-definition 'read-key-sequence) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 ;; not an escape event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 (setq keyseq (vector event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 keyseq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (defadvice read-key-sequence (around vip-read-keyseq-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 "Harness to work for Viper. This advice is harmless---don't worry!"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 (let (inhibit-quit event keyseq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (setq keyseq ad-do-it)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (setq event (if vip-xemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 (elt keyseq 0) ; XEmacs returns vector of events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (elt (listify-key-sequence keyseq) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 (if (vip-ESC-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (let (unread-command-events)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 (vip-set-unread-command-events keyseq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 (if (vip-fast-keysequence-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 (let ((vip-vi-global-user-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 (vip-vi-local-user-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 (vip-replace-minor-mode nil) ; actually unnecessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (vip-insert-global-user-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (vip-insert-local-user-minor-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (setq keyseq ad-do-it))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (setq keyseq ad-do-it))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 keyseq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (defadvice describe-key (before vip-read-keyseq-ad protect activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 "Force to read key via `read-key-sequence'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 (interactive (list (vip-events-to-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 (read-key-sequence "Describe key: ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 (defadvice describe-key-briefly (before vip-read-keyseq-ad protect activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 "Force to read key via `read-key-sequence'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (interactive (list (vip-events-to-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (read-key-sequence "Describe key briefly: ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 ;; Listen to ESC key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 ;; If a sequence of keys starting with ESC is issued with very short delays,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (defun vip-intercept-ESC-key ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 "Function that implements ESC key in Viper emulation of Vi."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 (let ((cmd (or (key-binding (vip-envelop-ESC-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 '(lambda () (interactive) (error "")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 ;; call the actual function to execute ESC (if no other symbols followed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 ;; or the key bound to the ESC sequence (if the sequence was issued
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 ;; with very short delay between characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (if (eq cmd 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (setq cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (cond ((eq vip-current-state 'vi-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 'vip-ESC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 ((eq vip-current-state 'insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 'vip-exit-insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 ((eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 'vip-replace-state-exit-cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 (t 'vip-change-state-to-vi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (call-interactively cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 ;; prefix argument for Vi mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 ;; represents the numeric value of the prefix argument and COM represents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 ;; command prefix such as "c", "d", "m" and "y".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 ;; Get value part of prefix-argument ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (defsubst vip-p-val (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (cond ((null arg) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 ((consp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (if (or (null (car arg)) (equal (car arg) '(nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 1 (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 (t arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 ;; Get raw value part of prefix-argument ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (defsubst vip-P-val (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 (cond ((consp arg) (car arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (t arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 ;; Get com part of prefix-argument ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (defsubst vip-getcom (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (cond ((null arg) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 ((consp arg) (cdr arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 ;; Get com part of prefix-argument ARG and modify it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (defun vip-getCom (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (let ((com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (cond ((equal com ?c) ?C)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 ((equal com ?d) ?D)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 ((equal com ?y) ?Y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (t com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 ;; Compute numeric prefix arg value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 ;; Invoked by CHAR. COM is the command part obtained so far.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (defun vip-prefix-arg-value (event com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (let (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 ;; read while number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (while (and (vip-characterp event) (>= event ?0) (<= event ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (setq value (+ (* (if (vip-characterp value) value 0) 10) (- event ?0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (setq event (vip-read-event-convert-to-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (setq prefix-arg value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 (if com (setq prefix-arg (cons prefix-arg com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (while (eq event ?U)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (vip-describe-arg prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (setq event (vip-read-event-convert-to-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (vip-set-unread-command-events event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 ;; Vi operator as prefix argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 (defun vip-prefix-arg-com (char value com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (let ((cont t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 (while (and cont
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (memq char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 vip-buffer-search-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 ;; this means that we already have a command character, so we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 ;; construct a com list and exit while. however, if char is "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 ;; it is an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 ;; new com is (CHAR . OLDCOM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 (if (memq char '(?# ?\")) (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 (setq com (cons char com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 (setq cont nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 ;; If com is nil we set com as char, and read more. Again, if char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 ;; is ", we read the name of register and store it in vip-use-register.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 ;; if char is !, =, or #, a complete com is formed so we exit the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 ;; while loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (cond ((memq char '(?! ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (setq com char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (setq char (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 (setq cont nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 ((= char ?#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 ;; read a char and encode it as com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 (setq com (+ 128 (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (setq char (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 ((= char ?\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 (let ((reg (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 (if (vip-valid-register reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (setq vip-use-register reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 (setq char (read-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (setq com char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (setq char (vip-read-char-exclusive)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (if (atom com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 ;; com is a single char, so we construct prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 ;; and if char is ?, describe prefix arg, otherwise exit by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 ;; pushing the char back into vip-set-unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 ;; Since char is a command, the command will execute with the prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 ;; argument that we just constructed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (setq prefix-arg (cons value com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (while (= char ?U)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (vip-describe-arg prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (setq char (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (vip-set-unread-command-events char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 ;; as com is non-nil, this means that we have a command to execute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 (if (memq (car com) '(?r ?R))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 ;; execute apropriate region command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (let ((char (car com)) (com (cdr com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (setq prefix-arg (cons value com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (if (= char ?r) (vip-region prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (vip-Region prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 ;; reset prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (setq prefix-arg nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 ;; otherwise, reset prefix arg and call appropriate command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (setq value (if (null value) 1 value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (setq prefix-arg nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 ((equal com '(?d . ?d)) (vip-line (cons value ?D)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 ((equal com '(?d . ?y)) (vip-yank-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 ((equal com '(?y . ?y)) (vip-line (cons value ?Y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 ((equal com '(?< . ?<)) (vip-line (cons value ?<)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 ((equal com '(?> . ?>)) (vip-line (cons value ?>)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 ((equal com '(?! . ?!)) (vip-line (cons value ?!)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 ((equal com '(?= . ?=)) (vip-line (cons value ?=)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (t (error ""))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 (defun vip-describe-arg (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (let (val com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 (setq val (vip-P-val arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (if (null val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 (if (null com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 (message "Value is nil, and command is nil")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (message "Value is nil, and command is `%c'" com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (if (null com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (message "Value is `%d', and command is nil" val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 (message "Value is `%d', and command is `%c'" val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (defun vip-digit-argument (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 "Begin numeric argument for the next command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (vip-prefix-arg-value last-command-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (if (consp arg) (cdr arg) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (defun vip-command-argument (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 "Accept a motion command as an argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 (vip-prefix-arg-com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 last-command-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (cond ((null arg) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 ((consp arg) (car arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 ((integerp arg) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (t (error vip-InvalidCommandArgument)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 (cond ((null arg) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 ((consp arg) (cdr arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 ((integerp arg) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (t (error vip-InvalidCommandArgument))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 (quit (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (signal 'quit nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (vip-deactivate-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 ;; repeat last destructive command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 ;; Append region to text in register REG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 ;; START and END are buffer positions indicating what to append.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 (defsubst vip-append-to-register (reg start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (set-register reg (concat (if (stringp (get-register reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (get-register reg) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (buffer-substring start end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 ;; Saves last inserted text for possible use by vip-repeat command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 (defun vip-save-last-insertion (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 (setq vip-last-insertion (buffer-substring beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 (or (< (length vip-d-com) 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 (setcar (nthcdr 4 vip-d-com) vip-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 (or (null vip-command-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (ring-empty-p vip-command-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 vip-last-insertion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 ;; del most recent elt, if identical to the second most-recent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 (vip-cleanup-ring vip-command-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (defsubst vip-yank-last-insertion ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 "Inserts the text saved by the previous vip-save-last-insertion command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 (insert vip-last-insertion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 ;; define functions to be executed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 ;; invoked by the `C' command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (defun vip-exec-change (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 ;; handle C cmd at the eol and at eob.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 (if (or (and (eolp) (= vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (= vip-com-point (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (insert " ")(backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (if (= vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 (vip-forward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (if (= com ?c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (vip-change vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (vip-change-subr vip-com-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 ;; this is invoked by vip-substitute-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 (defun vip-exec-Change (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 ;;(vip-valid-register vip-use-register '(letter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 vip-use-register (mark t) (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (downcase vip-use-register) (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 (delete-region (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (defun vip-exec-delete (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 ;;(vip-valid-register vip-use-register '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 vip-use-register vip-com-point (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 (downcase vip-use-register) vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 (setq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (if (eq last-command 'd-command) 'kill-region nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (kill-region vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (setq this-command 'd-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (if (and (eolp) (not (bolp))) (backward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 (defun vip-exec-Delete (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 ;;(vip-valid-register vip-use-register '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 vip-use-register (mark t) (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 (downcase vip-use-register) (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (setq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (if (eq last-command 'D-command) 'kill-region nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (kill-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (if (eq m-com 'vip-line) (setq this-command 'D-command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (defun vip-exec-yank (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 ;; (vip-valid-register vip-use-register '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 vip-use-register vip-com-point (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 (downcase vip-use-register) vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 (setq last-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 (copy-region-as-kill vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 (goto-char vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (defun vip-exec-Yank (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 vip-use-register (mark t) (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 (downcase vip-use-register) (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (setq last-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 (copy-region-as-kill (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (goto-char vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (defun vip-exec-bang (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (shell-command-on-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (mark t) (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (if (= com ?!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (setq vip-last-shell-com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 "!"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 'vip-shell-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (car vip-shell-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 vip-last-shell-com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (defun vip-exec-equals (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 (if (> (mark t) (point)) (exchange-point-and-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (indent-region (mark t) (point) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (defun vip-exec-shift (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 (if (> (mark t) (point)) (exchange-point-and-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (indent-rigidly (mark t) (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (if (= com ?>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 vip-shift-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 (- vip-shift-width))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 ;; return point to where it was before shift
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 (goto-char vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 ;; this is needed because some commands fake com by setting it to ?r, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 ;; denotes repeated insert command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 (defsubst vip-exec-dummy (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 (defun vip-exec-buffer-search (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (setq vip-s-string (buffer-substring (point) vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 (setq vip-s-forward t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (setq vip-search-history (cons vip-s-string vip-search-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 (vip-search vip-s-string vip-s-forward 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (defvar vip-exec-array (make-vector 128 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 ;; Using a dispatch array allows adding functions like buffer search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 ;; without affecting other functions. Buffer search can now be bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 ;; to any character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (aset vip-exec-array ?c 'vip-exec-change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (aset vip-exec-array ?C 'vip-exec-Change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (aset vip-exec-array ?d 'vip-exec-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (aset vip-exec-array ?D 'vip-exec-Delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (aset vip-exec-array ?y 'vip-exec-yank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (aset vip-exec-array ?Y 'vip-exec-Yank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 (aset vip-exec-array ?r 'vip-exec-dummy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (aset vip-exec-array ?! 'vip-exec-bang)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 (aset vip-exec-array ?< 'vip-exec-shift)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (aset vip-exec-array ?> 'vip-exec-shift)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (aset vip-exec-array ?= 'vip-exec-equals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 ;; This function is called by various movement commands to execute a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 ;; destructive command on the region specified by the movement command. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 ;; instance, if the user types cw, then the command vip-forward-word will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 ;; call vip-execute-com to execute vip-exec-change, which eventually will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 ;; call vip-change to invoke the replace mode on the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 ;; The list (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) is set to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 ;; vip-d-com for later use by vip-repeat.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (defun vip-execute-com (m-com val com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (let ((reg vip-use-register))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 ;; this is the special command `#'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 (if (> com 128)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 (vip-special-prefix-com (- com 128))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 (let ((fn (aref vip-exec-array (if (< com 0) (- com) com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (if (null fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (error "%c: %s" com vip-InvalidViCommand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 (funcall fn m-com com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (if (vip-dotable-command-p com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (list m-com val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (if (memq com (list ?c ?C ?!)) (- com) com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 reg nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 (defun vip-repeat (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 "Re-execute last destructive command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 Use the info in vip-d-com, which has the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 \(com val ch reg inserted-text command-keys\),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 where `com' is the command to be re-executed, `val' is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 argument to `com', `ch' is a flag for repeat, and `reg' is optional;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 if it exists, it is the name of the register for `com'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 If the prefix argument, ARG, is non-nil, it is used instead of `val'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (let ((save-point (point)) ; save point before repeating prev cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 ;; Pass along that we are repeating a destructive command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 ;; This tells vip-set-destructive-command not to update
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 ;; vip-command-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 (vip-intermediate-command 'vip-repeat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (if (eq last-command 'vip-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 ;; if the last command was vip-undo, then undo-more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (vip-undo-more)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 ;; otherwise execute the command stored in vip-d-com. if arg is non-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 ;; its prefix value is used as new prefix value for the command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (let ((m-com (car vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 (com (nth 2 vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (reg (nth 3 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (if (null val) (setq val (nth 1 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 (if (null m-com) (error "No previous command to repeat."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (setq vip-use-register reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (if (nth 4 vip-d-com) ; text inserted by command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (setq vip-last-insertion (nth 4 vip-d-com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 vip-d-char (nth 4 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 (funcall m-com (cons val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 (if (and vip-keep-point-on-repeat (< save-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (goto-char save-point)) ; go back to before repeat.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (if (and (eolp) (not (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 ;; If the prev cmd was rotating the command ring, this means that `.' has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 ;; just executed a command from that ring. So, push it on the ring again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 ;; If we are just executing previous command , then don't push vip-d-com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 ;; because vip-d-com is not fully constructed in this case (its keys and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 ;; the inserted text may be nil). Besides, in this case, the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 ;; executed by `.' is already on the ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 (if (eq last-command 'vip-display-current-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (vip-push-onto-ring vip-d-com 'vip-command-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (defun vip-repeat-from-history ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 "Repeat a destructive command from history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 Doesn't change vip-command-ring in any way, so `.' will work as before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 executing this command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 This command is supposed to be bound to a two-character Vi macro where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 the second character is a digit 0 to 9. The digit indicates which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 history command to execute. `<char>0' is equivalent to `.', `<char>1'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 invokes the command before that, etc."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (let* ((vip-intermediate-command 'repeating-display-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 (idx (cond (vip-this-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (string-to-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (symbol-name (elt vip-this-kbd-macro 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (t 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (num idx)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (vip-d-com vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 (or (and (numberp num) (<= 0 num) (<= num 9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (setq idx 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 num 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 (while (< 0 num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (setq num (1- num)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (vip-repeat nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (while (> idx num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (vip-special-ring-rotate1 vip-command-ring 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (setq num (1+ num)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 ;; This command is invoked interactively by the key sequence #<char>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (defun vip-special-prefix-com (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (cond ((= char ?c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 (downcase-region (min vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 (max vip-com-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 ((= char ?C)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (upcase-region (min vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (max vip-com-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 ((= char ?g)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (push-mark vip-com-point t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (vip-global-execute))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 ((= char ?q)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (push-mark vip-com-point t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (vip-quote-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 ((= char ?s) (funcall vip-spell-function vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (t (error "#%c: %s" char vip-InvalidViCommand))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 ;; undoing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (defun vip-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 "Undo previous change."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (message "undo!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 (let ((modified (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (before-undo-pt (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (after-change-functions after-change-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 undo-beg-posn undo-end-posn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 ;; no need to remove this hook, since this var has scope inside a let.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 (add-hook 'after-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 '(lambda (beg end len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 (setq undo-beg-posn beg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 undo-end-posn (or end beg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 (undo-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 (undo-more 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 (setq undo-beg-posn (or undo-beg-posn before-undo-pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 undo-end-posn (or undo-end-posn undo-beg-posn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (goto-char undo-beg-posn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 (if (and vip-keep-point-on-undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 (pos-visible-in-window-p before-undo-pt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (push-mark (point-marker) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 (vip-sit-for-short 300)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 (goto-char undo-end-posn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 (vip-sit-for-short 300)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (> (abs (- undo-end-posn before-undo-pt)) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (goto-char before-undo-pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (goto-char undo-beg-posn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (push-mark before-undo-pt t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (if (and (eolp) (not (bolp))) (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (if (not modified) (set-buffer-modified-p t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (setq this-command 'vip-undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 ;; Continue undoing previous changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 (defun vip-undo-more ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 (message "undo more!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 (undo-more 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (error (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (message "No further undo information in this buffer")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (if (and (eolp) (not (bolp))) (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (setq this-command 'vip-undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 ;; The following two functions are used to set up undo properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 ;; they are undone all at once.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (defun vip-adjust-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 (let ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 tmp tmp2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 (setq vip-undo-needs-adjustment nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (if (listp buffer-undo-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 (setq tmp2 (cdr tmp)) ; the part after mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 ;; cut tail from buffer-undo-list temporarily by direct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 ;; manipulation with pointers in buffer-undo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 (setcdr tmp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (setq buffer-undo-list (delq nil buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (setq buffer-undo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (delq vip-buffer-undo-list-mark buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 ;; restore tail of buffer-undo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (setq buffer-undo-list (delq nil buffer-undo-list))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (defun vip-set-complex-command-for-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (if (listp buffer-undo-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (if (not vip-undo-needs-adjustment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 (setq buffer-undo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (cons vip-buffer-undo-list-mark buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 (setq vip-undo-needs-adjustment t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 (defun vip-display-current-destructive-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (let ((text (nth 4 vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (keys (nth 5 vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (max-text-len 30))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 (setq this-command 'vip-display-current-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 (message " `.' runs %s%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 (concat "`" (vip-array-to-string keys) "'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 (vip-abbreviate-string text max-text-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 " inserting `" "'" " ......."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 ;; don't change vip-d-com if it was vip-repeat command invoked with `.'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 ;; or in some other way (non-interactively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (defun vip-set-destructive-command (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (or (eq vip-intermediate-command 'vip-repeat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (setq vip-d-com list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (setcar (nthcdr 5 vip-d-com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (vip-array-to-string (this-command-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (vip-push-onto-ring vip-d-com 'vip-command-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (defun vip-prev-destructive-command (next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 "Find previous destructive command in the history of destructive commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 With prefix argument, find next destructive command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 (let (cmd vip-intermediate-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 (if (eq last-command 'vip-display-current-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 ;; repeated search through command history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 (setq vip-intermediate-command 'repeating-display-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 ;; first search through command history--set temp ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 (setq vip-temp-command-ring (copy-list vip-command-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (setq cmd (if next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (vip-special-ring-rotate1 vip-temp-command-ring 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (vip-special-ring-rotate1 vip-temp-command-ring -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (if (null cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 (setq vip-d-com cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 (vip-display-current-destructive-command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (defun vip-next-destructive-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 "Find next destructive command in the history of destructive commands."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (vip-prev-destructive-command 'next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (defun vip-insert-prev-from-insertion-ring (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 "Cycle through insertion ring in the direction of older insertions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 Undoes previous insertion and inserts new.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 With prefix argument, cycles in the direction of newer elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 In minibuffer, this command executes whatever the invocation key is bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 to in the global map, instead of cycling through the insertion ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 (let (vip-intermediate-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 (if (eq last-command 'vip-insert-from-insertion-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (progn ; repeated search through insertion history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (setq vip-intermediate-command 'repeating-insertion-from-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 (if (eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 (undo 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (if vip-last-inserted-string-from-insertion-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 (backward-delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 (length vip-last-inserted-string-from-insertion-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 ;;first search through insertion history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (setq vip-temp-insertion-ring (copy-list vip-insertion-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (setq this-command 'vip-insert-from-insertion-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 ;; so that things will be undone properly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 (setq buffer-undo-list (cons nil buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 (setq vip-last-inserted-string-from-insertion-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 ;; this change of vip-intermediate-command must come after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 ;; vip-special-ring-rotate1, so that the ring will rotate, but before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 ;; insertion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 (setq vip-intermediate-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (if vip-last-inserted-string-from-insertion-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 (insert vip-last-inserted-string-from-insertion-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 (defun vip-insert-next-from-insertion-ring ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 "Cycle through insertion ring in the direction of older insertions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 Undo previous insertion and inserts new."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 (vip-insert-prev-from-insertion-ring 'next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 ;; some region utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 ;; If at the last line of buffer, add \\n before eob, if newline is missing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 (defun vip-add-newline-at-eob-if-necessary ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 ;; make sure all lines end with newline, unless in the minibuffer or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 ;; when requested otherwise (require-final-newline is nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 (if (and (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 (not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 require-final-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (not (vip-is-in-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (not buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 (insert "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 (defun vip-yank-defun ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 (mark-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 (copy-region-as-kill (point) (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 ;; Enlarge region between BEG and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 (defun vip-enlarge-region (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (or beg (setq beg end)) ; if beg is nil, set to end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (or end (setq end beg)) ; if end is nil, set to beg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 (if (< beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (progn (goto-char beg) (set-mark end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 (set-mark beg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 (if (or (not (eobp)) (not (bolp))) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (if (not (eobp)) (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 (if (> beg end) (exchange-point-and-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 ;; Quote region by each line with a user supplied string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 (defun vip-quote-region ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (setq vip-quote-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 "Quote string: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 'vip-quote-region-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 vip-quote-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (vip-enlarge-region (point) (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (if (> (point) (mark t)) (exchange-point-and-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (insert vip-quote-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (while (and (< (point) (mark t)) (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (insert vip-quote-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 ;; Tells whether BEG is on the same line as END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 ;; If one of the args is nil, it'll return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 (defun vip-same-line (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 (let ((selective-display nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 (cond ((and beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 ;; This 'if' is needed because Emacs treats the next empty line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 ;; as part of the previous line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 (if (or (> beg (point-max)) (> end (point-max))) ; out of range
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 (if (and (> end beg) (= (vip-line-pos 'start) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 (setq end (min (1+ end) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (if (and (> beg end) (= (vip-line-pos 'start) beg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (setq beg (min (1+ beg) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (<= (count-lines beg end) 1) ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 (t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 ;; Check if the string ends with a newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (defun vip-end-with-a-newline-p (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 (or (string= string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (= (vip-seq-last-elt string) ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 (defun vip-tmp-insert-at-eob (msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 (let ((savemax (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 (goto-char savemax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 (insert msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (sit-for 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 (goto-char savemax) (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 ;;; Minibuffer business
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 (defsubst vip-set-minibuffer-style ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 (defun vip-minibuffer-setup-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 (let ((hook (if vip-vi-style-in-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 'vip-change-state-to-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 'vip-change-state-to-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (funcall hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 ;; Interpret last event in the local map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 (defun vip-exit-minibuffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 (let (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 (setq command (local-key-binding (char-to-string last-command-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (if command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 (command-execute command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 (exit-minibuffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 (defun vip-set-search-face ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 (defvar vip-search-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 (make-face 'vip-search-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 (vip-hide-face 'vip-search-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 (or (face-differs-from-default-p 'vip-search-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 ;; face wasn't set in .vip or .Xdefaults
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 (if (vip-can-use-colors "Black" "khaki")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 (set-face-background 'vip-search-face "khaki")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 (set-face-foreground 'vip-search-face "Black"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 (copy-face 'italic 'vip-search-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (set-face-underline-p 'vip-search-face t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 'vip-search-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 "*Face used to flash out the search pattern.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 (defun vip-set-minibuffer-faces ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (if (not (vip-has-face-support-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 (defvar vip-minibuffer-emacs-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 (make-face 'vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (vip-hide-face 'vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 (or (face-differs-from-default-p 'vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 ;; face wasn't set in .vip or .Xdefaults
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (if vip-vi-style-in-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 ;; emacs state is an exception in the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (if (vip-can-use-colors "darkseagreen2" "Black")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 (set-face-background
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 'vip-minibuffer-emacs-face "darkseagreen2")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 (set-face-foreground
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 'vip-minibuffer-emacs-face "Black"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 (copy-face 'modeline 'vip-minibuffer-emacs-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 ;; emacs state is the main state in the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (if (vip-can-use-colors "Black" "pink")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 (set-face-background 'vip-minibuffer-emacs-face "pink")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (set-face-foreground
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 'vip-minibuffer-emacs-face "Black"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (copy-face 'italic 'vip-minibuffer-emacs-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 'vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 "Face used in the Minibuffer when it is in Emacs state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (defvar vip-minibuffer-insert-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (make-face 'vip-minibuffer-insert-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (vip-hide-face 'vip-minibuffer-insert-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (or (face-differs-from-default-p 'vip-minibuffer-insert-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 (if vip-vi-style-in-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (if (vip-can-use-colors "Black" "pink")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 (set-face-background 'vip-minibuffer-insert-face "pink")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 (set-face-foreground
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 'vip-minibuffer-insert-face "Black"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 (copy-face 'italic 'vip-minibuffer-insert-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 ;; If Insert state is an exception
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (if (vip-can-use-colors "darkseagreen2" "Black")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (set-face-background
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 'vip-minibuffer-insert-face "darkseagreen2")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (set-face-foreground
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 'vip-minibuffer-insert-face "Black"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (copy-face 'modeline 'vip-minibuffer-insert-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (vip-italicize-face 'vip-minibuffer-insert-face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 'vip-minibuffer-insert-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 "Face used in the Minibuffer when it is in Insert state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (defvar vip-minibuffer-vi-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (make-face 'vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (vip-hide-face 'vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (or (face-differs-from-default-p 'vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (if vip-vi-style-in-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (if (vip-can-use-colors "Black" "grey")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (set-face-background 'vip-minibuffer-vi-face "grey")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (set-face-foreground 'vip-minibuffer-vi-face "Black"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (copy-face 'bold 'vip-minibuffer-vi-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (copy-face 'bold 'vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 (invert-face 'vip-minibuffer-vi-face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 'vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 "Face used in the Minibuffer when it is in Vi state.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 ;; the current face used in the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 (vip-deflocalvar vip-minibuffer-current-face vip-minibuffer-emacs-face "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 ;;; Reading string with history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 (defun vip-read-string-with-history (prompt &optional initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 history-var default keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 ;; Read string, prompting with PROMPT and inserting the INITIAL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 ;; input is an empty string. Use KEYMAP, if given, or the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 ;; minibuffer-local-map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 ;; Default value is displayed until the user types something in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 ;; minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 (let ((minibuffer-setup-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 (if (stringp initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 ;; don't wait if we have unread events or in kbd macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 (or unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 executing-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 (sit-for 840))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 (insert initial)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 (vip-minibuffer-setup-sentinel)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (val "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 (padding "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 temp-msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (setq keymap (or keymap minibuffer-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 initial (or initial "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 temp-msg (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (format "(default: %s) " default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (setq vip-incomplete-ex-cmd nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (setq val (read-from-minibuffer prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (concat temp-msg initial val padding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 keymap nil history-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (setq minibuffer-setup-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 padding (vip-array-to-string (this-command-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 temp-msg "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 ;; the following tries to be smart about what to put in history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (if (not (string= val (car (eval history-var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (set history-var (cons val (eval history-var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (string= (nth 0 (eval history-var)) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (set history-var (cdr (eval history-var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 ;; If the user enters nothing but the prev cmd wasn't vip-ex,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 ;; vip-command-argument, or `! shell-command', this probably means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 ;; that the user typed something then erased. Return "" in this case, not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 ;; the default---the default is too confusing in this case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (cond ((and (string= val "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (not (string= prompt "!")) ; was a `! shell-command'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 (not (memq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 '(vip-ex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 vip-command-argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 ((string= val "") (or default ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 (t val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 ;; insertion commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 ;; Called when state changes from Insert Vi command mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 ;; Repeats the insertion command if Insert state was entered with prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 ;; argument > 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 (defun vip-repeat-insert-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 (let ((i-com (car vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 (val (nth 1 vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 (char (nth 2 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 (if (and val (> val 1)) ; first check that val is non-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (setq vip-d-com (list i-com (1- val) ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 (vip-repeat nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (setq vip-d-com (list i-com val char nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (defun vip-insert (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 "Insert before point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 (vip-loop val (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 (defun vip-append (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 "Append after point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 (vip-set-destructive-command (list 'vip-append val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (if (not (eolp)) (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (vip-loop val (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (defun vip-Append (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 "Append at end of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 (vip-loop val (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 (defun vip-Insert (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 "Insert before first non-white."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 (vip-loop val (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 (defun vip-open-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 "Open line below."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 (vip-set-destructive-command (list 'vip-open-line val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 (let ((col (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 (newline 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 (indent-according-to-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 (indent-to col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 (newline 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 (indent-according-to-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 (indent-to col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 (vip-change-state-to-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 (defun vip-Open-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 "Open line above."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 (let ((col (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 (indent-according-to-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 (indent-to col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (indent-according-to-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 (indent-to col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 (vip-change-state-to-insert)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 (defun vip-open-line-at-point (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 "Open line at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (list 'vip-open-line-at-point val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 (defun vip-substitute (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 "Substitute characters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 (forward-char val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 (vip-change-subr (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 (vip-change (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 (defun vip-substitute-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 "Substitute lines."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (vip-line (cons arg ?C)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 ;; Prepare for replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (defun vip-start-replace ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 (setq vip-began-as-replace t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 vip-sitting-in-replace t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 vip-replace-chars-to-delete 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 vip-replace-chars-deleted 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 (vip-add-hook 'vip-after-change-functions 'vip-replace-mode-spy-after t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 ;; this will get added repeatedly, but no harm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 (add-hook 'after-change-functions 'vip-after-change-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (add-hook 'before-change-functions 'vip-before-change-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 (vip-move-marker-locally 'vip-last-posn-in-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 (vip-add-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 (vip-add-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 ;; checks how many chars were deleted by the last change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 (defun vip-replace-mode-spy-before (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 (setq vip-replace-chars-deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 (- end beg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 (max 0 (- end (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 (max 0 (- (vip-replace-start) beg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 ;; Invoked as an after-change-function to set up parameters of the last change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 (defun vip-replace-mode-spy-after (beg end length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 (if (memq vip-intermediate-command '(repeating-insertion-from-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 (setq vip-replace-chars-to-delete 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 (vip-move-marker-locally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 'vip-last-posn-in-replace-region (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 (let (beg-col end-col real-end chars-to-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 (setq real-end (min end (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 (setq beg-col (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 (goto-char real-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 (setq end-col (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 ;; If beg of change is outside the replacement region, then don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 ;; delete anything in the repl region (set chars-to-delete to 0).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 ;; This works fine except that we have to take special care of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 ;; sometimes simply shifts the repl region rightwards, without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 ;; deleting an equal amount of characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 ;; The reason why new-dabbrev.el causes this are this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 ;; if one dinamically completes a partial word that starts before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 ;; replacement region (but ends inside) then new-dabbrev.el first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 ;; moves cursor backwards, to the beginning of the word to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 ;; completed (say, pt A). Then it inserts the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 ;; completed word and then deletes the old, incomplete part.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 ;; Since the complete word is inserted at position before the repl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 ;; region, the next If-statement would have set chars-to-delete to 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 ;; unless we check for the current command, which must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 ;; dabbrev-expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 ;; In fact, it might be also useful to have overlays for insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 ;; regions as well, since this will let us capture the situation when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 ;; dabbrev-expand goes back past the insertion point to find the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 ;; beginning of the word to be expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 (if (or (and (<= (vip-replace-start) beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 (<= beg (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 (and (= length 0) (eq this-command 'dabbrev-expand)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 (setq chars-to-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 (max (- end-col beg-col) (- real-end beg) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 (setq chars-to-delete 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 ;; if beg = last change position, it means that we are within the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 ;; same command that does multiple changes. Moreover, it means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 ;; that we have two subsequent changes (insert/delete) that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 ;; complement each other.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 (if (= beg (marker-position vip-last-posn-in-replace-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 (setq vip-replace-chars-to-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 (- (+ chars-to-delete vip-replace-chars-to-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 vip-replace-chars-deleted))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 (setq vip-replace-chars-to-delete chars-to-delete))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 (vip-move-marker-locally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 'vip-last-posn-in-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 (max (if (> end (vip-replace-end)) (vip-replace-start) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 (or (marker-position vip-last-posn-in-replace-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 (setq vip-replace-chars-to-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 (max 0 (min vip-replace-chars-to-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 (- (vip-replace-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 vip-last-posn-in-replace-region))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 ;; posn is within the overlay.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 (defun vip-finish-change (posn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 (vip-remove-hook 'vip-after-change-functions 'vip-replace-mode-spy-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 (vip-remove-hook 'vip-before-change-functions 'vip-replace-mode-spy-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 (vip-remove-hook 'vip-post-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 'vip-replace-state-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 (vip-remove-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 (vip-restore-cursor-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 (setq vip-sitting-in-replace nil) ; just in case we'll need to know it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 (if (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 vip-replace-overlay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 (>= posn (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 (< posn (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 (delete-region posn (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 (if (eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 (vip-downgrade-to-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 ;; replace mode ended => nullify vip-last-posn-in-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 (vip-hide-replace-overlay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 (vip-refresh-mode-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 (vip-put-string-on-kill-ring vip-last-replace-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 ;; Make STRING be the first element of the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 (defun vip-put-string-on-kill-ring (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 (setq kill-ring (cons string kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 (if (> (length kill-ring) kill-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 (setq kill-ring-yank-pointer kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 (defun vip-finish-R-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 (vip-remove-hook 'vip-post-command-hooks 'vip-R-state-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 (vip-remove-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 (vip-downgrade-to-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 (defun vip-start-R-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 (overwrite-mode 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 (vip-add-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 (vip-add-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 (defun vip-replace-state-exit-cmd ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 "Binding for keys that cause Replace state to switch to Vi or to Insert.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 These keys are ESC, RET, and LineFeed"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 (if overwrite-mode ;; If you are in replace mode invoked via 'R'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 (vip-finish-R-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 (vip-finish-change vip-last-posn-in-replace-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 (let (com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 (if (eq this-command 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 (setq com 'vip-exit-insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 (vip-set-unread-command-events last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 (setq com (key-binding (read-key-sequence nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 (command-execute com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 (vip-message-conditions conds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 (vip-hide-replace-overlay))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 ;; This is the function bound to 'R'---unlimited replace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 ;; Similar to Emacs's own overwrite-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 (defun vip-overwrite (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 "Begin overwrite mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 (com (vip-getcom arg)) (len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 ;; Viper saves inserted text in vip-last-insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 (setq len (length vip-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 (delete-char len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 (vip-loop val (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 (setq last-command 'vip-overwrite)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 (vip-set-replace-overlay (point) (vip-line-pos 'end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 (vip-change-state-to-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 ;; line commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 (defun vip-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 (let ((val (car arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 (com (cdr arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 (vip-next-line-carefully (1- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 ;; this ensures that dd, cc, D, yy will do the right thing on the last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 ;; line of buffer when this line has no \n.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 (vip-add-newline-at-eob-if-necessary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 (vip-execute-com 'vip-line val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 (if (and (eobp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 (defun vip-yank-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 "Yank ARG lines (in Vi's sense)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 (let ((val (vip-p-val arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 (vip-line (cons val ?Y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 ;; region commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 (defun vip-region (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 "Execute command on a region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 (vip-execute-com 'vip-region val com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 (defun vip-Region (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 "Execute command on a Region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 (vip-execute-com 'vip-Region val com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 (defun vip-replace-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 "Replace the following ARG chars by the character read."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 (if (and (eolp) (bolp)) (error "No character to replace here"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 (vip-replace-char-subr com val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 (if (and (eolp) (not (bolp))) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 (list 'vip-replace-char val ?r nil vip-d-char nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 (defun vip-replace-char-subr (com arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (let ((take-care-of-iso-accents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (and (boundp 'iso-accents-mode) vip-automatic-iso-accents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 (setq char (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 vip-d-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 ;; get European characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 (iso-accents-mode 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 (vip-set-unread-command-events char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 (setq char (aref (read-key-sequence nil) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 (iso-accents-mode -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 (delete-char arg t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 (setq vip-d-char char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 (vip-loop (if (> arg 0) arg (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 (if (eq char ?\C-m) (insert "\n") (insert char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 (backward-char arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 ;; basic cursor movement. j, k, l, h commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 (defun vip-forward-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 "Move point right ARG characters (left if ARG negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 On reaching end of line, stop and signal error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 ;; the boundary condition check gets weird here because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 ;; forward-char may be the parameter of a delete, and 'dl' works
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 ;; just like 'x' for the last char on a line, so we have to allow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 ;; the forward motion before the 'vip-execute-com', but, of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 ;; course, 'dl' doesn't work on an empty line, so we have to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 ;; catch that condition before 'vip-execute-com'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 (if (and (eolp) (bolp)) (error "") (forward-char val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 (if com (vip-execute-com 'vip-forward-char val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 (if (eolp) (progn (backward-char 1) (error ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 (forward-char val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 (if com (vip-execute-com 'vip-forward-char val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 (defun vip-backward-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 "Move point left ARG characters (right if ARG negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 On reaching beginning of line, stop and signal error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 (if (bolp) (error "") (backward-char val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 (if com (vip-execute-com 'vip-backward-char val com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 (backward-char val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 (if com (vip-execute-com 'vip-backward-char val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 ;; Like forward-char, but doesn't move at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 (defun vip-forward-char-carefully (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 (setq arg (or arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 (if (>= (point-max) (+ (point) arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 (forward-char arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 (goto-char (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 ;; Like backward-char, but doesn't move at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 (defun vip-backward-char-carefully (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 (setq arg (or arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 (if (<= (point-min) (- (point) arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 (backward-char arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 (goto-char (point-min))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 (defun vip-next-line-carefully (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 (next-line arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 ;;; Word command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 ;; for word movement. When executed with a destructive command, \n is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 ;; usually left untouched for the last word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 ;; Viper uses syntax table to determine what is a word and what is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 ;; separator. However, \n is always a separator. Also, if vip-syntax-preference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 ;; is 'vi, then `_' is part of the word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 ;; skip only one \n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 (defun vip-skip-separators (forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 (if forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 (vip-skip-all-separators-forward 'within-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 (if (looking-at "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 (vip-skip-all-separators-forward 'within-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 (vip-skip-all-separators-backward 'within-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 (if (looking-at "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 (vip-skip-all-separators-backward 'within-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 (forward-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 (defun vip-forward-word-kernel (val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 (while (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 (cond ((vip-looking-at-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 (vip-skip-alpha-forward "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 (vip-skip-separators t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 ((vip-looking-at-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 (vip-skip-separators t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 ((not (vip-looking-at-alphasep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 (vip-skip-nonalphasep-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 (vip-skip-separators t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 (setq val (1- val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 ;; first search backward for pat. Then skip chars backwards using aux-pat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 (defun vip-fwd-skip (pat aux-pat lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 (if (and (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 (re-search-backward pat lim t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 (= (point) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 (goto-char (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 (skip-chars-backward aux-pat lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 (if (= (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 (vip-forward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 (defun vip-forward-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 "Forward word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 (vip-forward-word-kernel val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 (if com (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 (cond ((memq com (list ?c (- ?c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 ;; Yank words including the whitespace, but not newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 ((memq com (list ?y (- ?y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 ((vip-dotable-command-p com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 (vip-execute-com 'vip-forward-word val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 (defun vip-forward-Word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 "Forward word delimited by white characters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 (vip-skip-nonseparators 'forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 (vip-skip-separators t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 (if com (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 (cond ((memq com (list ?c (- ?c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 ;; Yank words including the whitespace, but not newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 ((memq com (list ?y (- ?y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 ((vip-dotable-command-p com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 (vip-execute-com 'vip-forward-Word val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 ;; this is a bit different from Vi, but Vi's end of word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 ;; makes no sense whatsoever
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 (defun vip-end-of-word-kernel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 (if (vip-end-of-word-p) (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 (if (vip-looking-at-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 (vip-skip-all-separators-forward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 (cond ((vip-looking-at-alpha) (vip-skip-alpha-forward "_"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 (vip-backward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 (defun vip-end-of-word-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 (or (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 (cond ((vip-looking-at-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 (not (vip-looking-at-alpha)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 ((not (vip-looking-at-alphasep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 (vip-looking-at-alphasep))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 (defun vip-end-of-word (arg &optional careful)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 "Move point to end of current word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 (vip-loop val (vip-end-of-word-kernel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 (vip-execute-com 'vip-end-of-word val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 (defun vip-end-of-Word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 "Forward to end of word delimited by white character."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 (vip-end-of-word-kernel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 (vip-skip-nonseparators 'forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 (backward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 (vip-execute-com 'vip-end-of-Word val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 (defun vip-backward-word-kernel (val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 (while (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 (cond ((vip-looking-at-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 (vip-skip-alpha-backward "_"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 ((vip-looking-at-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 (vip-skip-separators nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 (cond ((vip-looking-at-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 (vip-skip-alpha-backward "_"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 ((not (vip-looking-at-alphasep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 (vip-skip-nonalphasep-backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 (t (forward-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 ((not (vip-looking-at-alphasep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 (vip-skip-nonalphasep-backward)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 (setq val (1- val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 (defun vip-backward-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 "Backward word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 (let (i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351 (backward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 (if i (forward-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 (vip-backward-word-kernel val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 (if com (vip-execute-com 'vip-backward-word val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 (defun vip-backward-Word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 "Backward word delimited by white character."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364 (let (i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 (backward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 (if i (forward-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 (vip-skip-separators nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 (vip-skip-nonseparators 'backward)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 (if com (vip-execute-com 'vip-backward-Word val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377 ;; line commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379 (defun vip-beginning-of-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 "Go to beginning of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 (beginning-of-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 (if com (vip-execute-com 'vip-beginning-of-line val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 (defun vip-bol-and-skip-white (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 "Beginning of line at first non-white character."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 (forward-to-indentation (1- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 (if com (vip-execute-com 'vip-bol-and-skip-white val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399 (defun vip-goto-eol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 "Go to end of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 (end-of-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 (if com (vip-execute-com 'vip-goto-eol val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 (if (and (eolp) (not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 ;; a fix for vip-change-to-eol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 (not (equal vip-current-state 'insert-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 (defun vip-goto-col (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 "Go to ARG's column."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424 (if (> val (1+ (current-column))) (error "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 (forward-char (1- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 (if com (vip-execute-com 'vip-goto-col val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 (defun vip-next-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432 "Go to next line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 (next-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440 (if (and (eolp) (not (bolp))) (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 (setq this-command 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 (if com (vip-execute-com 'vip-next-line val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 (defun vip-next-line-at-bol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 "Next line at beginning of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450 (if (eobp) (error "Last line in buffer")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 (forward-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 (if com (vip-execute-com 'vip-next-line-at-bol val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 (defun vip-previous-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459 "Go to previous line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 (previous-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467 (if (and (eolp) (not (bolp))) (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 (setq this-command 'previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 (if com (vip-execute-com 'vip-previous-line val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 (defun vip-previous-line-at-bol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 "Previous line at beginning of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 (if (bobp) (error "First line in buffer")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482 (forward-line (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 (if com (vip-execute-com 'vip-previous-line val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 (defun vip-change-to-eol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 "Change to end of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 (vip-goto-eol (cons arg ?c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 (defun vip-kill-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 "Delete line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 (vip-goto-eol (cons arg ?d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 (defun vip-erase-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 "Erase line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 (vip-beginning-of-line (cons arg ?d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 ;;; Moving around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 (defun vip-goto-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 "Go to ARG's line. Without ARG go to end of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 (if (null val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 (forward-line (1- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517 ;; positioning is done twice: before and after command execution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 (if com (vip-execute-com 'vip-goto-line val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 ;; Find ARG's occurrence of CHAR on the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 ;; adjust point after search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 (defun vip-find-char (arg char forward offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 (or (char-or-string-p char) (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 (let ((arg (if forward arg (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533 (cmd (if (eq vip-intermediate-command 'vip-repeat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534 (nth 5 vip-d-com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 (vip-array-to-string (this-command-keys))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 ;; forward search begins here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 (if (eolp) (error "Command `%s': At end of line" cmd) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 ;; forward search ends here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 (progn (end-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 ;; backward search begins from here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 (error "Command `%s': At beginning of line" cmd) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 ;; backward search ends here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 (progn (beginning-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 ;; if arg > 0, point is forwarded before search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 (if (> arg 0) (goto-char (1+ (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 (if (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 (search-forward (char-to-string char) nil 0 arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 (setq point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 (error "Command `%s': `%c' not found" cmd char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 (defun vip-find-char-forward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 "Find char on the line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 If called interactively read the char to find from the terminal, and if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 called from vip-repeat, the char last used is used. This behaviour is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 controlled by the sign of prefix numeric value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 (cmd-representation (nth 5 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 (if (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 ;; this means that the function was called interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 (setq vip-f-char (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 vip-f-forward t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 vip-f-offset nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 ;; vip-repeat --- set vip-F-char from command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 (setq vip-F-char (if (stringp cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 (vip-seq-last-elt cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 vip-f-char vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 (setq val (- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 (setq val (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 (setq vip-F-char vip-f-char) ; set new vip-F-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 (vip-execute-com 'vip-find-char-forward val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 (defun vip-goto-char-forward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 "Go up to char ARG forward on line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 (cmd-representation (nth 5 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 (if (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 ;; this means that the function was called interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 (setq vip-f-char (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 vip-f-forward t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 vip-f-offset t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 ;; vip-repeat --- set vip-F-char from command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 (setq vip-F-char (if (stringp cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602 (vip-seq-last-elt cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604 vip-f-char vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3605 (setq val (- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 (setq val (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 (setq vip-F-char vip-f-char) ; set new vip-F-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 (vip-execute-com 'vip-goto-char-forward val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615 (defun vip-find-char-backward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 "Find char ARG on line backward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 (cmd-representation (nth 5 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 (if (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 ;; this means that the function was called interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 (setq vip-f-char (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 vip-f-forward nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 vip-f-offset nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626 ;; vip-repeat --- set vip-F-char from command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 (setq vip-F-char (if (stringp cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 (vip-seq-last-elt cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629 vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 vip-f-char vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 (setq val (- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633 (vip-find-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635 (setq val (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 (setq vip-F-char vip-f-char) ; set new vip-F-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 (vip-execute-com 'vip-find-char-backward val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 (defun vip-goto-char-backward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 "Go up to char ARG backward on line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646 (cmd-representation (nth 5 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 (if (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 ;; this means that the function was called interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649 (setq vip-f-char (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 vip-f-forward nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651 vip-f-offset t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652 ;; vip-repeat --- set vip-F-char from command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653 (setq vip-F-char (if (stringp cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654 (vip-seq-last-elt cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655 vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 vip-f-char vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657 (setq val (- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 (setq val (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663 (setq vip-F-char vip-f-char) ; set new vip-F-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 (vip-execute-com 'vip-goto-char-backward val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 (defun vip-repeat-find (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 "Repeat previous find command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 (vip-find-char val vip-f-char vip-f-forward vip-f-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676 (if vip-f-forward (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 (vip-execute-com 'vip-repeat-find val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 (defun vip-repeat-find-opposite (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 "Repeat previous find command in the opposite direction."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689 (if vip-f-forward (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 (vip-execute-com 'vip-repeat-find-opposite val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 ;; window scrolling etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 (defun vip-other-window (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 "Switch to other window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 (other-window arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 (or (not (eq vip-current-state 'emacs-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 (string= (buffer-name (current-buffer)) " *Minibuf-1*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 (vip-change-state-to-vi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 (defun vip-window-top (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 "Go to home window line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 (move-to-window-line (1- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712 ;; positioning is done twice: before and after command execution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 (if com (vip-execute-com 'vip-window-top val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 (defun vip-window-middle (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 "Go to middle window line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 (com (vip-getCom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 (if (not (pos-visible-in-window-p (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 (setq lines (count-lines (window-start) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 (move-to-window-line (+ (/ lines 2) (1- val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 ;; positioning is done twice: before and after command execution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 (if com (vip-execute-com 'vip-window-middle val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 (defun vip-window-bottom (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 "Go to last window line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 (move-to-window-line (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 ;; positioning is done twice: before and after command execution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 (if com (vip-execute-com 'vip-window-bottom val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 (defun vip-line-to-top (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 "Put current line on the home line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 (recenter (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 (defun vip-line-to-middle (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770 "Put current line on the middle line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 (defun vip-line-to-bottom (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 "Put current line on the last line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 (recenter (- (window-height) (1+ arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 ;; paren match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 ;; must correct this to only match ( to ) etc. On the other hand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782 ;; it is good that paren match gets confused, because that way you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 ;; catch _all_ imbalances.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 (defun vip-paren-match (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786 "Go to the matching parenthesis."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 (let ((com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789 anchor-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790 (if (integerp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791 (if (or (> arg 99) (< arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792 (error "Prefix must be between 1 and 99")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 (goto-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794 (if (> (point-max) 80000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 (* (/ (point-max) 100) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796 (/ (* (point-max) arg) 100)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3798 (let (beg-lim end-lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3799 (if (and (eolp) (not (bolp))) (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3800 (if (not (looking-at "[][(){}]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801 (setq anchor-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3803 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3804 (setq beg-lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3805 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3806 (setq end-lim (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3807 (cond ((re-search-forward "[][(){}]" end-lim t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3808 (backward-char) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3809 ((re-search-backward "[][(){}]" beg-lim t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811 (error "No matching character on line"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812 (cond ((looking-at "[\(\[{]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3816 (vip-execute-com 'vip-paren-match nil com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 (backward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 (anchor-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3819 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821 (vip-move-marker-locally 'vip-com-point anchor-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823 (vip-execute-com 'vip-paren-match nil com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825 ((looking-at "[])}]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3826 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3828 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3829 (if com (vip-execute-com 'vip-paren-match nil com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830 (t (error ""))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 ;; sentence ,paragraph and heading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835 (defun vip-forward-sentence (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836 "Forward sentence."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 (forward-sentence val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 (if com (vip-execute-com 'vip-forward-sentence nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845 (defun vip-backward-sentence (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3846 "Backward sentence."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3847 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3849 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3850 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 (backward-sentence val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3853 (if com (vip-execute-com 'vip-backward-sentence nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855 (defun vip-forward-paragraph (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3856 "Forward paragraph."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 (forward-paragraph val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 (vip-execute-com 'vip-forward-paragraph nil com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 (defun vip-backward-paragraph (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3869 "Backward paragraph."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3872 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3873 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875 (backward-paragraph val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3876 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3878 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 (vip-execute-com 'vip-backward-paragraph nil com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880 (backward-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882 ;; should be mode-specific etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884 (defun vip-prev-heading (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889 (re-search-backward vip-heading-start nil t val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891 (if com (vip-execute-com 'vip-prev-heading nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893 (defun vip-heading-end (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3896 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898 (re-search-forward vip-heading-end nil t val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3900 (if com (vip-execute-com 'vip-heading-end nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3901
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3902 (defun vip-next-heading (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3903 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3904 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3905 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3906 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3907 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3908 (re-search-forward vip-heading-start nil t val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3909 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3910 (if com (vip-execute-com 'vip-next-heading nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3913 ;; scrolling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915 (setq scroll-step 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3916
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3917 (defun vip-scroll (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3918 "Scroll to next screen."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3919 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3920 (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3921 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3922 (scroll-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3923 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3924 (while (> 0 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925 (scroll-down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 (setq arg (1+ arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3927
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3928 (defun vip-scroll-back (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3929 "Scroll to previous screen."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3930 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3931 (vip-scroll (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3933 (defun vip-scroll-down (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3934 "Pull down half screen."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3935 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3936 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938 (scroll-down (/ (window-height) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939 (scroll-down arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940 (error (beep 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3941 (message "Beginning of buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3942 (goto-char (point-min)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944 (defun vip-scroll-down-one (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 "Scroll up one line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 (scroll-down arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3948
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3949 (defun vip-scroll-up (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950 "Pull up half screen."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3952 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3953 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3954 (scroll-up (/ (window-height) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955 (scroll-up arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 (error (beep 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3957 (message "End of buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3958 (goto-char (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3960 (defun vip-scroll-up-one (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3961 "Scroll down one line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3962 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3963 (scroll-up arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3965
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3966 ;; searching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3968 (defun vip-if-string (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3969 (let ((s (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3970 prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3971 nil ; no initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3972 'vip-search-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3973 (car vip-search-history))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3974 (if (not (string= s ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3975 (setq vip-s-string s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3976
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3978 (defun vip-toggle-search-style (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3979 "Toggle the value of vip-case-fold-search/vip-re-search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3980 Without prefix argument, will ask which search style to toggle. With prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3981 arg 1,toggles vip-case-fold-search; with arg 2 toggles vip-re-search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3983 Although this function is bound to \\[vip-toggle-search-style], the most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3984 convenient way to use it is to bind `//' to the macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3985 `1 M-x vip-toggle-search-style' and `///' to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3986 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3987 toggle case-fold-search and hitting `/' three times witth toggle regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3988 search. Macros are more convenient in this case because they don't affect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3989 the Emacs binding of `/'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3990 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3991 (let (msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3992 (cond ((or (eq arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3993 (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3994 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3995 (if vip-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3996 "case-insensitive" "case-sensitive")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3997 (if vip-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3998 "case-sensitive"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3999 "case-insensitive")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4000 (setq vip-case-fold-search (null vip-case-fold-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4001 (if vip-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4002 (setq msg "Search becomes case-insensitive")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4003 (setq msg "Search becomes case-sensitive")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4004 ((or (eq arg 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4005 (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4006 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4007 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4008 "regexp-search" "vanilla-search")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4009 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4010 "vanilla-search"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4011 "regexp-search")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4012 (setq vip-re-search (null vip-re-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4013 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4014 (setq msg "Search becomes regexp-style")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4015 (setq msg "Search becomes vanilla-style")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4016 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4017 (setq msg "Search style remains unchanged")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4018 (prin1 msg t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4021 (defun vip-search-forward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4022 "Search a string forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4023 ARG is used to find the ARG's occurrence of the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4024 Null string will repeat previous search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4025 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4026 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4027 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4028 (old-str vip-s-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4029 (setq vip-s-forward t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4030 (vip-if-string "/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4031 ;; this is not used at present, but may be used later
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4032 (if (or (not (equal old-str vip-s-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4033 (not (markerp vip-local-search-start-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4034 (not (marker-buffer vip-local-search-start-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4035 (setq vip-local-search-start-marker (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4036 (vip-search vip-s-string t val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4037 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4038 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4039 (vip-move-marker-locally 'vip-com-point (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4040 (vip-execute-com 'vip-search-next val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4041
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4042 (defun vip-search-backward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4043 "Search a string backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4044 ARG is used to find the ARG's occurrence of the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4045 Null string will repeat previous search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4046 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4047 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4048 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4049 (old-str vip-s-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4050 (setq vip-s-forward nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4051 (vip-if-string "?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4052 ;; this is not used at present, but may be used later
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4053 (if (or (not (equal old-str vip-s-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4054 (not (markerp vip-local-search-start-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4055 (not (marker-buffer vip-local-search-start-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4056 (setq vip-local-search-start-marker (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4057 (vip-search vip-s-string nil val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4058 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4059 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4060 (vip-move-marker-locally 'vip-com-point (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4061 (vip-execute-com 'vip-search-next val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4062
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4064 ;; Search for COUNT's occurrence of STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4065 ;; Search is forward if FORWARD is non-nil, otherwise backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4066 ;; INIT-POINT is the position where search is to start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4067 ;; Arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4068 ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4069 (defun vip-search (string forward arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4070 &optional no-offset init-point fail-if-not-found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4071 (if (not (equal string ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4072 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4073 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4074 (offset (not no-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4075 (case-fold-search vip-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4076 (start-point (or init-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4077 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4078 (if forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4079 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4080 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4081 (if offset (vip-forward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4082 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4083 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4084 (re-search-forward string nil nil val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4085 (re-search-backward string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4086 (search-forward string nil nil val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4087 (search-backward string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4088 ;; don't wait and don't flash in macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4089 (or executing-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4090 (vip-flash-search-pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4091 (if (not (equal start-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4092 (push-mark start-point t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4093 (search-failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4094 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4095 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4096 (message "Search wrapped around end of buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4097 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4098 (vip-search string forward (cons 1 com) t start-point 'fail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4099 ;; don't wait in macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4100 (or executing-kbd-macro (sit-for 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4101 ;; delete the wrap-around message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4102 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4103 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4104 (goto-char start-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4105 (error "`%s': %s not found"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4106 string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4107 (if vip-re-search "Pattern" "String"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4108 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4109 ;; backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4110 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4111 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4112 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4113 (re-search-backward string nil nil val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4114 (search-backward string nil nil val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4115 ;; don't wait and don't flash in macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4116 (or executing-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4117 (vip-flash-search-pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4118 (if (not (equal start-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4119 (push-mark start-point t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4120 (search-failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4121 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4122 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4123 (message "Search wrapped around beginning of buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4124 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4125 (vip-search string forward (cons 1 com) t start-point 'fail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4126 ;; don't wait in macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4127 (or executing-kbd-macro (sit-for 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4128 ;; delete the wrap-around message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4129 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4130 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4131 (goto-char start-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4132 (error "`%s': %s not found"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4133 string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4134 (if vip-re-search "Pattern" "String"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4135 )))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4137 (defun vip-search-next (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4138 "Repeat previous search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4139 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4140 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4141 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4142 (if (null vip-s-string) (error vip-NoPrevSearch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4143 (vip-search vip-s-string vip-s-forward arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4144 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4145 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4146 (vip-move-marker-locally 'vip-com-point (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4147 (vip-execute-com 'vip-search-next val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4149 (defun vip-search-Next (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4150 "Repeat previous search in the reverse direction."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4151 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4152 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4153 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4154 (if (null vip-s-string) (error vip-NoPrevSearch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4155 (vip-search vip-s-string (not vip-s-forward) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4156 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4157 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4158 (vip-move-marker-locally 'vip-com-point (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4159 (vip-execute-com 'vip-search-Next val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4162 ;; Search contents of buffer defined by one of Viper's motion commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4163 ;; Repeatable via `n' and `N'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4164 (defun vip-buffer-search-enable (&optional c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4165 (cond (c (setq vip-buffer-search-char c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4166 ((null vip-buffer-search-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4167 (setq vip-buffer-search-char ?g)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4168 (define-key vip-vi-basic-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4169 (char-to-string vip-buffer-search-char) 'vip-command-argument)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4170 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4171 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4173 ;; This is a Viper wraper for isearch-forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4174 (defun vip-isearch-forward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4175 "Do incremental search forward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4176 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4177 ;; emacs bug workaround
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4178 (if (listp arg) (setq arg (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4179 (vip-exec-form-in-emacs (list 'isearch-forward arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4181 ;; This is a Viper wraper for isearch-backward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4182 (defun vip-isearch-backward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4183 "Do incremental search backward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4184 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4185 ;; emacs bug workaround
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4186 (if (listp arg) (setq arg (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4187 (vip-exec-form-in-emacs (list 'isearch-backward arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4190 ;; visiting and killing files, buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4192 (defun vip-switch-to-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4193 "Switch to buffer in the current window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4194 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4195 (let (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4196 (setq buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4197 (read-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4198 (format "Switch to buffer in this window \(%s\): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4199 (buffer-name (other-buffer (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4200 (switch-to-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4201 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4203 (defun vip-switch-to-buffer-other-window ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4204 "Switch to buffer in another window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4205 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4206 (let (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4207 (setq buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4208 (read-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4209 (format "Switch to buffer in another window \(%s\): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4210 (buffer-name (other-buffer (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4211 (switch-to-buffer-other-window buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4212 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4214 (defun vip-kill-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4215 "Kill a buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4216 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4217 (let (buffer buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4218 (setq buffer-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4219 (read-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4220 (format "Kill buffer \(%s\): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4221 (buffer-name (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4222 (setq buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4223 (if (null buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4224 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4225 (get-buffer buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4226 (if (null buffer) (error "`%s': No such buffer" buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4227 (if (or (not (buffer-modified-p buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4228 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4229 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4230 "Buffer `%s' is modified, are you sure you want to kill it? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4231 buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4232 (kill-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4233 (error "Buffer not killed"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4236 (defvar vip-smart-suffix-list '("" "tex" "c" "cc" "el" "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4237 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4238 This is useful when you the current directory contains files with the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4239 prefix and many different suffixes. Usually, only one of the suffixes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4240 represents an editable file. However, file completion will stop at the `.'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4241 The smart suffix feature lets you hit RET in such a case, and Viper will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4242 select the appropriate suffix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4244 Suffixes are tried in the order given and the first suffix for which a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4245 corresponding file exists is selected. If no file exists for any of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4246 suffixes, the user is asked to confirm.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4248 To turn this feature off, set this variable to nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4250 ;; Try to add suffix to files ending with a `.'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4251 ;; Useful when the user hits RET on a non-completed file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4252 (defun vip-file-add-suffix ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4253 (let ((count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4254 (len (length vip-smart-suffix-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4255 (file (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4256 found key cmd suff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4257 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4258 (if (and vip-smart-suffix-list (string-match "\\.$" file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4259 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4260 (while (and (not found) (< count len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4261 (setq suff (nth count vip-smart-suffix-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4262 count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4263 (if (file-exists-p (format "%s%s" file suff))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4264 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4265 (setq found t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4266 (insert suff))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4268 (if found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4269 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4270 (vip-tmp-insert-at-eob " [Please complete file name]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4271 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4272 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4273 (setq cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4274 (key-binding (setq key (read-key-sequence nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4275 (cond ((eq cmd 'self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4276 (if vip-xemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4277 (insert (events-to-keys key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4278 (insert key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4279 ((memq cmd '(exit-minibuffer vip-exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4280 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4281 (t (command-execute cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4282 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4283 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4284 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4287 ;; Advice for use in find-file and read-file-name commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4288 (defadvice exit-minibuffer (before vip-exit-minibuffer-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4289 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4290 (run-hooks 'vip-minibuffer-exit-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4292 (defadvice find-file (before vip-add-suffix-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4293 "Use `read-file-name' for reading arguments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4294 (interactive (list (read-file-name "Find file: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4295 nil default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4297 (defadvice find-file-other-window (before vip-add-suffix-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4298 "Use `read-file-name' for reading arguments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4299 (interactive (list (read-file-name "Find file in other window: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4300 nil default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4302 (defadvice find-file-other-frame (before vip-add-suffix-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4303 "Use `read-file-name' for reading arguments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4304 (interactive (list (read-file-name "Find file in other frame: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4305 nil default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4307 (defadvice read-file-name (around vip-suffix-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4308 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4309 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4310 ad-do-it))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4314 ;; yank and pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4316 (defsubst vip-yank (text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4317 "Yank TEXT silently. This works correctly with Emacs's yank-pop command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4318 (insert text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4319 (setq this-command 'yank))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4321 (defun vip-put-back (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4322 "Put back after point/below line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4323 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4324 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4325 (text (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4326 (cond ((vip-valid-register vip-use-register '(digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4327 (current-kill (- vip-use-register ?1) 'do-not-rotate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4328 ((vip-valid-register vip-use-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4329 (get-register (downcase vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4330 (t (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4331 (current-kill 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4332 (if (null text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4333 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4334 (let ((reg vip-use-register))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4335 (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4336 (error vip-EmptyRegister reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4337 (error "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4338 (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4339 (if (vip-end-with-a-newline-p text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4340 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4341 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4342 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4343 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4344 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4345 (if (not (eolp)) (vip-forward-char-carefully)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4346 (set-marker (vip-mark-marker) (point) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4347 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4348 (list 'vip-put-back val nil vip-use-register nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4349 (vip-loop val (vip-yank text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4350 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4351 ;; newline; it leaves the cursor at the beginning when the text contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4352 ;; a newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4353 (if (vip-same-line (point) (mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4354 (or (= (point) (mark)) (vip-backward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4355 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4356 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4357 (back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4358 (vip-deactivate-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4360 (defun vip-Put-back (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4361 "Put back at point/above line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4362 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4363 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4364 (text (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4365 (cond ((vip-valid-register vip-use-register '(digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4366 (current-kill (- vip-use-register ?1) 'do-not-rotate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4367 ((vip-valid-register vip-use-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4368 (get-register (downcase vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4369 (t (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4370 (current-kill 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4371 (if (null text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4372 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4373 (let ((reg vip-use-register))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4374 (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4375 (error vip-EmptyRegister reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4376 (error "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4377 (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4378 (if (vip-end-with-a-newline-p text) (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4379 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4380 (list 'vip-Put-back val nil vip-use-register nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4381 (set-marker (vip-mark-marker) (point) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4382 (vip-loop val (vip-yank text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4383 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4384 ;; newline; it leaves the cursor at the beginning when the text contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4385 ;; a newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4386 (if (vip-same-line (point) (mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4387 (or (= (point) (mark)) (vip-backward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4388 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4389 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4390 (back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4391 (vip-deactivate-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4394 ;; Copy region to kill-ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4395 ;; If BEG and END do not belong to the same buffer, copy empty region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4396 (defun vip-copy-region-as-kill (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4397 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4398 (copy-region-as-kill beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4399 (error (copy-region-as-kill beg beg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4402 (defun vip-delete-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4403 "Delete character."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4404 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4405 (let ((val (vip-p-val arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4406 (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4407 (if (> val 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4408 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4409 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4410 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4411 (if (> val (- (point) here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4412 (setq val (- (point) here))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4413 (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4414 (if (and vip-ex-style-motion (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4415 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4416 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4417 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4418 (cond ((vip-valid-register vip-use-register '((Letter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4419 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4420 (downcase vip-use-register) (point) (- (point) val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4421 ((vip-valid-register vip-use-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4422 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4423 vip-use-register (point) (- (point) val) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4424 (t (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4425 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4426 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4427 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4428 (delete-char val t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4429 (if (and (eolp) (not (bolp))) (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4430 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4431 (delete-backward-char val t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4432 (delete-char val t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4434 (defun vip-delete-backward-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4435 "Delete previous character. On reaching beginning of line, stop and beep."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4436 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4437 (let ((val (vip-p-val arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4438 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4439 (list 'vip-delete-backward-char val nil nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4440 (if (> val 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4441 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4442 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4443 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4444 (if (> val (- here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4445 (setq val (- here (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4446 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4447 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4448 (cond ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4449 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4450 (downcase vip-use-register) (point) (+ (point) val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4451 ((vip-valid-register vip-use-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4452 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4453 vip-use-register (point) (+ (point) val) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4454 (t (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4455 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4456 (if (bolp) (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4457 (delete-backward-char val t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4459 (defun vip-del-backward-char-in-insert ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4460 "Delete 1 char backwards while in insert mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4461 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4462 (if (and vip-ex-style-editing-in-insert (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4463 (beep 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4464 (delete-backward-char 1 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4466 (defun vip-del-backward-char-in-replace ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4467 "Delete one character in replace mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4468 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4469 charecters. If it is nil, then the cursor just moves backwards, similarly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4470 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4471 cursor move past the beginning of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4472 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4473 (cond (vip-delete-backwards-in-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4474 (cond ((not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4475 (delete-backward-char 1 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4476 (vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4477 (beep 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4478 ((bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4479 (beep 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4480 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4481 (delete-backward-char 1 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4482 (vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4483 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4484 (beep 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4485 (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4486 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4487 (backward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4491 ;; join lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4493 (defun vip-join-lines (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4494 "Join this line to next, if ARG is nil. Otherwise, join ARG lines."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4495 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4496 (let ((val (vip-P-val arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4497 (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4498 (vip-loop (if (null val) 1 (1- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4499 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4500 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4501 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4502 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4503 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4504 (delete-region (point) (1- (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4505 (fixup-whitespace)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4508 ;; Replace state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4510 (defun vip-change (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4511 (if (markerp beg) (setq beg (marker-position beg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4512 (if (markerp end) (setq end (marker-position end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4513 ;; beg is sometimes (mark t), which may be nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4514 (or beg (setq beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4516 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4517 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4518 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4519 (copy-to-register vip-use-register beg end nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4520 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4521 (vip-set-replace-overlay beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4522 (setq last-command nil) ; separate repl text from prev kills
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4524 (if (= (vip-replace-start) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4525 (error "End of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4527 (setq vip-last-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4528 (buffer-substring (vip-replace-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4529 (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4531 ;; protect against error while inserting "@" and other disasters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4532 ;; (e.g., read-only buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4533 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4534 (if (vip-same-line (vip-replace-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4535 (vip-replace-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4536 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4537 ;; tabs cause problems in replace, so untabify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4538 (goto-char (vip-replace-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4539 (insert-before-markers "@") ; put placeholder after the TAB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4540 (untabify (vip-replace-start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4541 ;; del @, don't put on kill ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4542 (delete-backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4544 (vip-set-replace-overlay-glyphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4545 vip-replace-region-start-delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4546 vip-replace-region-end-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4547 ;; this move takes care of the last posn in the overlay, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4548 ;; has to be shifted because of insert. We can't simply insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4549 ;; "$" before-markers because then overlay-start will shift the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4550 ;; beginning of the overlay in case we are replacing a single
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4551 ;; character. This fixes the bug with `s' and `cl' commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4552 (vip-move-replace-overlay (vip-replace-start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4553 (goto-char (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4554 (vip-change-state-to-replace t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4555 (kill-region (vip-replace-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4556 (vip-replace-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4557 (vip-hide-replace-overlay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4558 (vip-change-state-to-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4559 (error ;; make sure that the overlay doesn't stay.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4560 ;; go back to the original point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4561 (goto-char (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4562 (vip-hide-replace-overlay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4563 (vip-message-conditions conds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4566 (defun vip-change-subr (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4567 ;; beg is sometimes (mark t), which may be nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4568 (or beg (setq beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4570 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4571 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4572 (copy-to-register vip-use-register beg end nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4573 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4574 (kill-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4575 (setq this-command 'vip-change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4576 (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4578 (defun vip-toggle-case (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4579 "Toggle character case."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4580 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4581 (let ((val (vip-p-val arg)) (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4582 (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4583 (while (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4584 (setq c (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4585 (delete-char 1 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4586 (if (eq c (upcase c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4587 (insert-char (downcase c) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4588 (insert-char (upcase c) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4589 (if (eolp) (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4590 (setq val (1- val)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4593 ;; query replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4595 (defun vip-query-replace ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4596 "Query replace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4597 If a null string is suplied as the string to be replaced,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4598 the query replace mode will toggle between string replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4599 and regexp replace."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4600 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4601 (let (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4602 (setq str (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4603 (if vip-re-query-replace "Query replace regexp: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4604 "Query replace: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4605 nil ; no initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4606 'vip-replace1-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4607 (car vip-replace1-history) ; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4608 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4609 (if (string= str "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4610 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4611 (setq vip-re-query-replace (not vip-re-query-replace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4612 (message "Query replace mode changed to %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4613 (if vip-re-query-replace "regexp replace"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4614 "string replace")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4615 (if vip-re-query-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4616 (query-replace-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4617 str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4618 (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4619 (format "Query replace regexp `%s' with: " str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4620 nil ; no initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4621 'vip-replace1-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4622 (car vip-replace1-history) ; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4623 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4624 (query-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4625 str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4626 (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4627 (format "Query replace `%s' with: " str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4628 nil ; no initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4629 'vip-replace1-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4630 (car vip-replace1-history) ; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4631 ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4634 ;; marking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4636 (defun vip-mark-beginning-of-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4637 "Mark beginning of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4638 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4639 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4640 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4641 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4642 (message "Mark set at the beginning of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4644 (defun vip-mark-end-of-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4645 "Mark end of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4646 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4647 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4648 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4649 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4650 (message "Mark set at the end of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4652 (defun vip-mark-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4653 "Set mark at point of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4654 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4655 (let ((char (vip-read-char-exclusive)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4656 (cond ((and (<= ?a char) (<= char ?z))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4657 (point-to-register (1+ (- char ?a))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4658 ((= char ?<) (vip-mark-beginning-of-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4659 ((= char ?>) (vip-mark-end-of-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4660 ((= char ?.) (vip-set-mark-if-necessary))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4661 ((= char ?,) (vip-cycle-through-mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4662 ((= char ?D) (mark-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4663 (t (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4664 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4666 ;; Algorithm: If first invocation of this command save mark on ring, goto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4667 ;; mark, M0, and pop the most recent elt from the mark ring into mark,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4668 ;; making it into the new mark, M1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4669 ;; Push this mark back and set mark to the original point position, p1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4670 ;; So, if you hit '' or `` then you can return to p1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4671 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4672 ;; If repeated command, pop top elt from the ring into mark and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4673 ;; jump there. This forgets the position, p1, and puts M1 back into mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4674 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4675 ;; the ring into mark. Push M2 back on the ring and set mark to M0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4676 ;; etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4677 (defun vip-cycle-through-mark-ring ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4678 "Visit previous locations on the mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4679 One can use `` and '' to temporarily jump 1 step back."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4680 (let* ((sv-pt (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4681 ;; if repeated `m,' command, pop the previously saved mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4682 ;; Prev saved mark is actually prev saved point. It is used if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4683 ;; user types `` or '' and is discarded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4684 ;; from the mark ring by the next `m,' command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4685 ;; In any case, go to the previous or previously saved mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4686 ;; Then push the current mark (popped off the ring) and set current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4687 ;; point to be the mark. Current pt as mark is discarded by the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4688 ;; m, command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4689 (if (eq last-command 'vip-cycle-through-mark-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4690 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4691 ;; save current mark if the first iteration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4692 (setq mark-ring (delete (vip-mark-marker) mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4693 (if (mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4694 (push-mark (mark t) t)) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4695 (pop-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4696 (set-mark-command 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4697 ;; don't duplicate mark on the ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4698 (setq mark-ring (delete (vip-mark-marker) mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4699 (push-mark sv-pt t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4700 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4701 (setq this-command 'vip-cycle-through-mark-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4702 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4705 (defun vip-goto-mark (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4706 "Go to mark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4707 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4708 (let ((char (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4709 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4710 (vip-goto-mark-subr char com nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4712 (defun vip-goto-mark-and-skip-white (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4713 "Go to mark and skip to first non-white character on line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4714 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4715 (let ((char (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4716 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4717 (vip-goto-mark-subr char com t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4719 (defun vip-goto-mark-subr (char com skip-white)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4720 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4721 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4722 (error "Empty buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4723 (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4724 (cond ((vip-valid-register char '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4725 (let* ((buff (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4726 (reg (1+ (- char ?a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4727 (text-marker (get-register reg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4728 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4729 (if (not (vip-valid-marker text-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4730 (error vip-EmptyTextmarker char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4731 (if (and (vip-same-line (point) vip-last-jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4732 (= (point) vip-last-jump-ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4733 (push-mark vip-last-jump t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4734 (push-mark nil t)) ; no msg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4735 (vip-register-to-point reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4736 (setq vip-last-jump (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4737 (cond (skip-white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4738 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4739 (setq vip-last-jump-ignore (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4740 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4741 (if (equal buff (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4742 (vip-execute-com (if skip-white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4743 'vip-goto-mark-and-skip-white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4744 'vip-goto-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4745 nil com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4746 (switch-to-buffer buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4747 (goto-char vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4748 (vip-change-state-to-vi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4749 (error "")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4750 ((and (not skip-white) (= char ?`))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4751 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4752 (if (and (vip-same-line (point) vip-last-jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4753 (= (point) vip-last-jump-ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4754 (goto-char vip-last-jump))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4755 (if (= (point) (mark t)) (pop-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4756 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4757 (setq vip-last-jump (point-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4758 vip-last-jump-ignore 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4759 (if com (vip-execute-com 'vip-goto-mark nil com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4760 ((and skip-white (= char ?'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4761 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4762 (if (and (vip-same-line (point) vip-last-jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4763 (= (point) vip-last-jump-ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4764 (goto-char vip-last-jump))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4765 (if (= (point) (mark t)) (pop-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4766 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4767 (setq vip-last-jump (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4768 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4769 (setq vip-last-jump-ignore (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4770 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4771 (t (error vip-InvalidTextmarker char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4773 (defun vip-insert-tab ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4774 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4775 (insert-tab))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4777 (defun vip-exchange-point-and-mark ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4778 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4779 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4780 (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4782 ;; Input Mode Indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4784 ;; Returns t, if the string before point matches the regexp STR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4785 (defsubst vip-looking-back (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4786 (and (save-excursion (re-search-backward str nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4787 (= (point) (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4790 (defun vip-forward-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4791 "Indent forward -- `C-t' in Vi."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4792 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4793 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4794 (indent-to (+ (current-column) vip-shift-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4796 (defun vip-backward-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4797 "Backtab, C-d in VI"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4798 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4799 (if vip-cted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4800 (let ((p (point)) (c (current-column)) bol (indent t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4801 (if (vip-looking-back "[0^]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4802 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4803 (if (eq ?^ (preceding-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4804 (setq vip-preserve-indent t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4805 (delete-backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4806 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4807 (setq indent nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4808 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4809 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4810 (setq bol (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4811 (if (re-search-backward "[^ \t]" bol 1) (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4812 (delete-region (point) p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4813 (if indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4814 (indent-to (- c vip-shift-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4815 (if (or (bolp) (vip-looking-back "[^ \t]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4816 (setq vip-cted nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4818 (defun vip-autoindent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4819 "Auto Indentation, Vi-style."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4820 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4821 (let ((col (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4822 (if vip-preserve-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4823 (setq vip-preserve-indent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4824 (setq vip-current-indent col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4825 ;; don't leave whitespace lines around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4826 (if (memq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4827 '(vip-autoindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4828 vip-open-line vip-Open-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4829 vip-replace-state-exit-cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4830 (indent-to-left-margin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4831 (newline 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4832 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4833 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4834 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4835 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4836 (indent-according-to-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4837 (indent-to vip-current-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4838 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4839 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4842 ;; Viewing registers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4843
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4844 (defun vip-ket-function (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4845 "Function called by \], the ket. View registers and call \]\]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4846 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4847 (let ((reg (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4848 (cond ((vip-valid-register reg '(letter Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4849 (view-register (downcase reg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4850 ((vip-valid-register reg '(digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4851 (let ((text (current-kill (- reg ?1) 'do-not-rotate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4852 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4853 (set-buffer (get-buffer-create "*Output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4854 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4855 (insert (format "Register %c contains the string:\n" reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4856 (insert text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4857 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4858 (display-buffer "*Output*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4859 ((= ?\] reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4860 (vip-next-heading arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4861 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4862 vip-InvalidRegister reg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4863
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4864 (defun vip-brac-function (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4865 "Function called by \[, the brac. View textmarkers and call \[\["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4866 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4867 (let ((reg (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4868 (cond ((= ?\[ reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4869 (vip-prev-heading arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4870 ((= ?\] reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4871 (vip-heading-end arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4872 ((vip-valid-register reg '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4873 (let* ((val (get-register (1+ (- reg ?a))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4874 (buf (if (not val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4875 (error vip-EmptyTextmarker reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4876 (marker-buffer val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4877 (pos (marker-position val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4878 line-no text (s pos) (e pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4879 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4880 (set-buffer (get-buffer-create "*Output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4881 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4882 (if (and buf pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4883 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4884 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4885 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4886 (setq line-no (1+ (count-lines (point-min) val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4887 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4888 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4889 (if (re-search-backward "[^ \t]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4890 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4891 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4892 (setq s (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4893 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4894 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4895 (if (re-search-forward "[^ \t]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4896 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4897 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4898 (setq e (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4899 (setq text (buffer-substring s e))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4900 (setq text (format "%s<%c>%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4901 (substring text 0 (- pos s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4902 reg (substring text (- pos s)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4903 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4904 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4905 "Textmarker `%c' is in buffer `%s' at line %d.\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4906 reg (buffer-name buf) line-no))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4907 (insert (format "Here is some text around %c:\n\n %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4908 reg text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4909 (insert (format vip-EmptyTextmarker reg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4910 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4911 (display-buffer "*Output*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4912 (t (error vip-InvalidTextmarker reg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4916 ;; commands in insertion mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4918 (defun vip-delete-backward-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4919 "Delete previous word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4920 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4921 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4922 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4923 (backward-word arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4924 (delete-region (point) (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4925 (pop-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4927
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4928 (defun vip-set-expert-level (&optional dont-change-unless)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4929 "Sets the expert level for a Viper user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4930 Can be called interactively to change (temporarily or permanently) the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4931 current expert level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4933 The optional argument DONT-CHANGE-UNLESS if not nil, says that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4934 the level should not be changed, unless its current value is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4935 meaningless (i.e., not one of 1,2,3,4,5).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4937 User level determines the setting of Viper variables that are most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4938 sensitive for VI-style look-and-feel."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4940 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4942 (if (not (natnump vip-expert-level)) (setq vip-expert-level 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4944 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4945 (delete-other-windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4946 ;; if 0 < vip-expert-level < vip-max-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4947 ;; & dont-change-unless = t -- use it; else ask
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4948 (vip-ask-level dont-change-unless))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4950 (setq vip-always t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4951 vip-ex-style-motion t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4952 vip-ex-style-editing-in-insert t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4953 vip-want-ctl-h-help nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4955 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4956 ;; a novice or a beginner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4957 ((eq vip-expert-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4958 (global-set-key vip-toggle-key ;; in emacs-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4959 (if (vip-window-display-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4960 'vip-iconify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4961 'suspend-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4962 (setq vip-no-multiple-ESC t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4963 vip-re-search t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4964 vip-vi-style-in-minibuffer t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4965 vip-search-wrap-around-t t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4966 vip-want-emacs-keys-in-vi nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4967 vip-want-emacs-keys-in-insert nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4969 ;; an intermediate to guru
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4970 ((and (> vip-expert-level 1) (< vip-expert-level 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4971 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4972 vip-want-emacs-keys-in-vi t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4973 vip-want-emacs-keys-in-insert (> vip-expert-level 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4975 (if (eq vip-expert-level 4) ; respect user's ex-style motions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4976 ; and vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4977 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4978 (setq-default vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4979 (cdr (assoc 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4980 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4981 vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4982 (cdr (assoc 'vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4983 vip-saved-user-settings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4984 (setq vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4985 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4986 vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4987 (cdr (assoc 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4988 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4989 vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4990 (cdr (assoc 'vip-re-search vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4991 vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4992 (cdr (assoc 'vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4993 vip-saved-user-settings))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4995 ;; A wizard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4996 ;; Ideally, if 5 is selected, a buffer should pop up to let the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4997 ;; user toggle variable values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4998 (t (setq-default vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4999 (cdr (assoc 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5000 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5001 vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5002 (cdr (assoc 'vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5003 vip-saved-user-settings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5004 (setq vip-want-ctl-h-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5005 (cdr (assoc 'vip-want-ctl-h-help vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5006 vip-always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5007 (cdr (assoc 'vip-always vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5008 vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5009 (cdr (assoc 'vip-no-multiple-ESC vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5010 vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5011 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5012 vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5013 (cdr (assoc 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5014 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5015 vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5016 (cdr (assoc 'vip-re-search vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5017 vip-want-emacs-keys-in-vi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5018 (cdr (assoc 'vip-want-emacs-keys-in-vi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5019 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5020 vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5021 (cdr (assoc 'vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5022 vip-saved-user-settings)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5023 (vip-set-mode-vars-for vip-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5024 (if (or vip-always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5025 (and (> vip-expert-level 0) (> 5 vip-expert-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5026 (vip-set-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5027
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5028 ;; Ask user expert level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5029 (defun vip-ask-level (dont-change-unless)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5030 (let ((ask-buffer " *vip-ask-level*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5031 level-changed repeated)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5032 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5033 (switch-to-buffer ask-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5035 (or (eq this-command 'vip-set-expert-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5036 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5037 (<= vip-expert-level vip-max-expert-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5038 (>= vip-expert-level 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5039 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5040 (insert "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5041
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5042 *** Important Notice for VIP users***
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5044 This is VIPER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5046 @joke
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5047 Viper Is a Package for Emacs Rebels,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5048 a VI Plan for Emacs Rescue,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5049 and a venomous VI PERil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5050 @end joke
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5052 Technically speaking, Viper is a new Vi emulator that replaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5053 the old VIP package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5054
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5055 Viper emulates Vi much better than VIP. It also significantly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5056 extends and improves upon Vi in many useful ways.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5058 Although many VIP settings in your ~/.vip are compatible with Viper,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5059 you may have to change some of them. Please refer to the documentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5060 which can be obtained by executing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5062 :help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5064 when Viper is in Vi state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5065
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5066 If you will be so lucky as to find a bug, report it via the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5067
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5068 :submitReport
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5070 Type any key to continue... ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5072 (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5073 (erase-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5074
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5075 (while (or (> vip-expert-level vip-max-expert-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5076 (< vip-expert-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5077 (null dont-change-unless))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5078 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5079 (if repeated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5080 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5081 (message "Invalid user level")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5082 (beep 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5083 (setq repeated t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5084 (setq dont-change-unless t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5085 level-changed t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5086 (insert "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5087 Please specify your level of familiarity with the venomous VI PERil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5088 (and the VI Plan for Emacs Rescue).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5089 You can change it at any time by typing `M-x vip-set-expert-level RET'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5091 1 -- BEGINNER: Almost all Emacs features are suppressed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5092 Feels almost like straight Vi. File name completion and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5093 command history in the minibuffer are thrown in as a bonus.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5094 To use Emacs productively, you must reach level 3 or higher.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5095 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5096 so most Emacs commands can be used when Viper is in Vi state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5097 Good progress---you are well on the way to level 3!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5098 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5099 in Viper's insert state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5100 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5101 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5102 variables. Adjust these settings to your taste.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5103 5 -- WIZARD: Like 4, but user settings are also respected for vip-always,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5104 vip-want-ctl-h-help, vip-want-emacs-keys-in-vi, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5105 vip-want-emacs-keys-in-insert. Adjust these to your taste.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5107 Please, specify your level now: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5109 (setq vip-expert-level (- (vip-read-char-exclusive) ?0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5110 ) ; end while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5112 ;; tell the user if level was changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5113 (and level-changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5114 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5115 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5116 (format "\n\n\n\n\n\t\tYou have selected user level %d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5117 vip-expert-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5118 (if (y-or-n-p "Do you wish to make this change permanent? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5119 ;; save the setting for vip-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5120 (vip-save-setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5121 'vip-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5122 (format "Saving user level %d ..." vip-expert-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5123 vip-custom-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5124 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5125 (bury-buffer) ; remove ask-buffer from screen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5126 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5127 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5130 (defun viper-version ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5131 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5132 (message "Viper version is %s" viper-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5134 (defalias 'vip-version 'viper-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5136 (defun vip-nil ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5137 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5138 (beep 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5141 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5142 (defun vip-register-to-point (char &optional enforce-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5143 "Like jump-to-register, but switches to another buffer in another window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5144 (interactive "cViper register to point: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5145 (let ((val (get-register char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5146 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5147 ((and (fboundp 'frame-configuration-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5148 (frame-configuration-p val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5149 (set-frame-configuration val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5150 ((window-configuration-p val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5151 (set-window-configuration val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5152 ((vip-valid-marker val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5153 (if (and enforce-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5154 (not (equal (current-buffer) (marker-buffer val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5155 (error (concat vip-EmptyTextmarker " in this buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5156 (1- (+ char ?a))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5157 (pop-to-buffer (marker-buffer val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5158 (goto-char val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5159 ((and (consp val) (eq (car val) 'file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5160 (find-file (cdr val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5161 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5162 (error vip-EmptyTextmarker (1- (+ char ?a)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5165 (defun vip-save-kill-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5166 "Save then kill current buffer. "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5167 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5168 (if (< vip-expert-level 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5169 (save-buffers-kill-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5170 (save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5171 (kill-buffer (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5175 ;;; Bug Report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5177 (defun vip-submit-report ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5178 "Submit bug report on Viper."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5179 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5180 (let ((reporter-prompt-for-summary-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5181 (vip-device-type (vip-device-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5182 color-display-p frame-parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5183 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5184 varlist salutation window-config)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5186 ;; If mode info is needed, add variable to `let' and then set it below,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5187 ;; like we did with color-display-p.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5188 (setq color-display-p (if (vip-window-display-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5189 (vip-color-display-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5190 'non-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5191 minibuffer-vi-face (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5192 (vip-get-face vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5193 'non-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5194 minibuffer-insert-face (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5195 (vip-get-face vip-minibuffer-insert-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5196 'non-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5197 minibuffer-emacs-face (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5198 (vip-get-face vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5199 'non-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5200 frame-parameters (if (fboundp 'frame-parameters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5201 (frame-parameters (selected-frame))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5203 (setq varlist (list 'vip-vi-minibuffer-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5204 'vip-insert-minibuffer-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5205 'vip-vi-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5206 'vip-vi-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5207 'vip-vi-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5208 'vip-vi-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5209 'vip-vi-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5210 'vip-vi-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5211 'vip-vi-basic-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5212 'vip-replace-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5213 'vip-insert-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5214 'vip-insert-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5215 'vip-insert-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5216 'vip-insert-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5217 'vip-insert-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5218 'vip-insert-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5219 'vip-insert-basic-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5220 'vip-emacs-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5221 'vip-emacs-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5222 'vip-emacs-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5223 'vip-emacs-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5224 'vip-emacs-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5225 'vip-automatic-iso-accents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5226 'vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5227 'vip-want-emacs-keys-in-vi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5228 'vip-keep-point-on-undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5229 'vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5230 'vip-ESC-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5231 'vip-want-ctl-h-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5232 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5233 'vip-delete-backwards-in-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5234 'vip-vi-style-in-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5235 'vip-vi-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5236 'vip-insert-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5237 'vip-replace-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5238 'vip-emacs-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5239 'ex-cycle-other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5240 'ex-cycle-through-non-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5241 'vip-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5242 'major-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5243 'vip-device-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5244 'color-display-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5245 'frame-parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5246 'minibuffer-vi-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5247 'minibuffer-insert-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5248 'minibuffer-emacs-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5249 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5250 (setq salutation "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5251 Congratulations! You may have unearthed a bug in Viper!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5252 Please mail a concise, accurate summary of the problem to the address above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5254 -------------------------------------------------------------------")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5255 (setq window-config (current-window-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5256 (with-output-to-temp-buffer " *vip-info*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5257 (switch-to-buffer " *vip-info*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5258 (delete-other-windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5259 (princ "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5260 PLEASE FOLLOW THESE PROCEDURES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5261 ------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5263 Before reporting a bug, please verify that it is related to Viper, and is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5264 not cause by other packages you are using.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5266 Don't report compilation warnings, unless you are certain that there is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5267 problem. These warnings are normal and unavoidable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5269 Please note that users should not modify variables and keymaps other than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5270 those advertised in the manual. Such `customization' is likely to crash
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5271 Viper, as it would any other improperly customized Emacs package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5273 If you are reporting an error message received while executing one of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5274 Viper commands, type:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5276 M-x set-variable <Return> debug-on-error <Return> t <Return>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5278 Then reproduce the error. The above command will cause Emacs to produce a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5279 back trace of the execution that leads to the error. Please include this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5280 trace in your bug report.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5282 If you believe that one of Viper's commands goes into an infinite loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5283 \(e.g., Emacs freezes\), type:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5285 M-x set-variable <Return> debug-on-quit <Return> t <Return>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5287 Then reproduce the problem. Wait for a few seconds, then type C-g to abort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5288 the current command. Include the resulting back trace in the bug report.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5290 Mail anyway (y or n)? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5291 (if (y-or-n-p "Mail anyway? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5292 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5293 (set-window-configuration window-config)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5294 (error "Bug report aborted")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5296 (require 'reporter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5297 (set-window-configuration window-config)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5299 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5300 (vip-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5301 varlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5302 nil 'delete-other-windows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5303 salutation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5304 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5309 ;; Smoothes out the difference between Emacs' unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5310 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5311 ;; events or a sequence of keys.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5312 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5313 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5314 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5315 ;; into an event. Below, we delete nil from event lists, since nil is the most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5316 ;; common symbol that might appear in this wrong context.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5317 (defun vip-set-unread-command-events (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5318 (if vip-emacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5319 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5320 unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5321 (let ((new-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5322 (cond ((eventp arg) (list arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5323 ((listp arg) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5324 ((sequencep arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5325 (listify-key-sequence arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5326 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5327 "vip-set-unread-command-events: Invalid argument, %S"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5328 arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5329 (if (not (eventp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5330 (setq new-events (delq nil new-events)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5331 (append new-events unread-command-events)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5332 ;; XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5333 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5334 unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5335 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5336 (cond ((vip-characterp arg) (list (character-to-event arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5337 ((eventp arg) (list arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5338 ((stringp arg) (mapcar 'character-to-event arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5339 ((vectorp arg) (append arg nil)) ; turn into list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5340 ((listp arg) (vip-eventify-list-xemacs arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5341 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5342 "vip-set-unread-command-events: Invalid argument, %S" arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5343 unread-command-events))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5345 ;; list is assumed to be a list of events of characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5346 (defun vip-eventify-list-xemacs (lis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5347 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5348 (function (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5349 (cond ((vip-characterp elt) (character-to-event elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5350 ((eventp elt) elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5351 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5352 "vip-eventify-list-xemacs: can't convert to event, %S"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5353 elt)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5354 lis))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5358 ;;; Bring in the rest of the files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5359 (require 'viper-mous)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5360 (require 'viper-macs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5361 (require 'viper-ex)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5365 ;; The following is provided for compatibility with older VIP's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5367 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5368 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5369 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5373 ;;; Load .vip and set up hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5375 ;; This hook designed to enable Vi-style editing in comint-based modes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5376 (defun vip-comint-mode-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5377 (setq require-final-newline nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5378 (setq vip-ex-style-editing-in-insert nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5379 vip-ex-style-motion nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5380 (vip-add-local-keys 'vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5381 '(("\C-m" . comint-send-input) ; return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5382 ("\C-d" . comint-delchar-or-maybe-eof))) ; \C-d
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5383 (vip-add-local-keys 'insert-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5384 '(("\C-m" . comint-send-input) ; return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5385 ("\C-d" . comint-delchar-or-maybe-eof))) ; \C-d
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5386 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5389 ;; This sets major mode hooks to make them come up in vi-state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5390 (defun vip-set-hooks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5392 ;; It is of course a misnomer to call viper-mode a `major mode'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5393 ;; However, this has the effect that if the user didn't specify the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5394 ;; default mode, new buffers that fall back on the default will come up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5395 ;; in Fundamental Mode and Vi state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5396 (setq default-major-mode 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5398 ;; The following major modes should come up in vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5399 (defadvice fundamental-mode (after vip-fundamental-mode-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5400 "Run `vip-change-state-to-vi' on entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5401 (vip-change-state-to-vi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5403 (defvar makefile-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5404 (add-hook 'makefile-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5406 (defvar help-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5407 (add-hook 'help-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5409 (defvar awk-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5410 (add-hook 'awk-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5412 (defvar html-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5413 (add-hook 'html-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5414 (defvar html-helper-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5415 (add-hook 'html-helper-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5417 (defvar emacs-lisp-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5418 (add-hook 'emacs-lisp-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5420 (defvar lisp-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5421 (add-hook 'lisp-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5423 (defvar bibtex-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5424 (add-hook 'bibtex-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5426 (defvar cc-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5427 (add-hook 'cc-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5429 (defvar c-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5430 (add-hook 'c-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5432 (defvar c++-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5433 (add-hook 'c++-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5435 (defvar lisp-interaction-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5436 (add-hook 'lisp-interaction-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5438 (defvar fortran-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5439 (add-hook 'fortran-mode-hook 'vip-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5441 (defvar text-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5442 (add-hook 'text-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5444 (add-hook 'completion-list-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5445 (add-hook 'compilation-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5447 (add-hook 'perl-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5448 (add-hook 'tcl-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5450 (defvar emerge-startup-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5451 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5452 ;; Run vip-change-state-to-vi after quitting emerge.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5453 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5454 "emerge"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5455 '(defadvice emerge-quit (after vip-emerge-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5456 "Run `vip-change-state-to-vi' after quitting emerge."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5457 (vip-change-state-to-vi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5458 ;; In case Emerge was loaded before Viper.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5459 (defadvice emerge-quit (after vip-emerge-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5460 "Run `vip-change-state-to-vi' after quitting emerge."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5461 (vip-change-state-to-vi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5463 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5464 "asm-mode"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5465 '(defadvice asm-mode (after vip-asm-mode-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5466 "Run `vip-change-state-to-vi' on entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5467 (vip-change-state-to-vi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5469 ;; passwd.el sets up its own buffer, which turns up in Vi mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5470 ;; thus overriding the local map. We don't need Vi mode here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5471 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5472 "passwd"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5473 '(defadvice read-passwd-1 (before vip-passwd-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5474 "Switch to emacs state while reading password."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5475 (vip-change-state-to-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5477 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5478 "prolog"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5479 '(defadvice prolog-mode (after vip-prolog-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5480 "Switch to Vi state in Prolog mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5481 (vip-change-state-to-vi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5483 ;; Emacs shell, ange-ftp, and comint-based modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5484 (defvar comint-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5485 (add-hook 'comint-mode-hook 'vip-change-state-to-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5486 (add-hook 'comint-mode-hook 'vip-comint-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5488 ;; Shell scripts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5489 (defvar sh-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5490 (add-hook 'sh-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5491 (defvar ksh-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5492 (add-hook 'ksh-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5494 ;; Dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5495 ;; This is only necessary when the user uses vip-modify-major-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5496 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5498 (if vip-emacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5499 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5500 (defvar view-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5501 (add-hook 'view-mode-hook 'vip-change-state-to-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5502 (defadvice view-minor-mode (after vip-view-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5503 "Switch to Emacs state in View mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5504 (vip-change-state-to-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5505 (defvar view-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5506 (add-hook 'view-hook 'vip-change-state-to-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5508 ;; For VM users.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5509 ;; Put summary and other VM buffers in Emacs state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5510 (defvar vm-mode-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5511 (defvar vm-summary-mode-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5512 (add-hook 'vm-mode-hooks 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5513 (add-hook 'vm-summary-mode-hooks 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5515 ;; For RMAIL users.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5516 ;; Put buf in Emacs state after edit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5517 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5518 "rmailedit"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5519 '(defadvice rmail-cease-edit (after vip-rmail-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5520 "Switch to emacs state when done editing message."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5521 (vip-change-state-to-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5522 ;; In case RMAIL was loaded before Viper.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5523 (defadvice rmail-cease-edit (after vip-rmail-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5524 "Switch to emacs state when done editing message."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5525 (vip-change-state-to-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5526 ) ; vip-set-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5528 ;; Set some useful macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5529 ;; These must be before we load .vip, so the user can unrecord them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5531 ;; repeat the 2nd previous command without rotating the command history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5532 (vip-record-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5533 (vector vip-repeat-from-history-key '\1) 'vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5534 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5535 ;; repeat the 3d previous command without rotating the command history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5536 (vip-record-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5537 (vector vip-repeat-from-history-key '\2) 'vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5538 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5540 ;; toggle case sensitivity in search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5541 (vip-record-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5542 "//" 'vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5543 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5544 ;; toggle regexp/vanila search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5545 (vip-record-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5546 "///" 'vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5547 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5550 ;; ~/.vip is loaded if it exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5551 (if (and (file-exists-p vip-custom-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5552 (not noninteractive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5553 (load vip-custom-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5555 ;; VIP compatibility: merge whatever the user has in vip-mode-map into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5556 ;; Viper's basic map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5557 (vip-add-keymap vip-mode-map vip-vi-global-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5560 ;; Applying Viper customization -- runs after (load .vip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5562 ;; Save user settings or Viper defaults for vars controled by vip-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5563 (setq vip-saved-user-settings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5564 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5565 (cons 'vip-always vip-always)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5566 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5567 (cons 'vip-ex-style-motion vip-ex-style-motion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5568 (cons 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5569 vip-ex-style-editing-in-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5570 (cons 'vip-want-emacs-keys-in-vi vip-want-emacs-keys-in-vi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5571 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5572 (cons 'vip-re-search vip-re-search)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5575 (vip-set-minibuffer-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5576 (vip-set-minibuffer-faces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5577 (vip-set-search-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5578 (if vip-buffer-search-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5579 (vip-buffer-search-enable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5580 (vip-update-alphanumeric-class)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5582 ;;; Familiarize Viper with some minor modes that have their own keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5583 (vip-harness-minor-mode "compile")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5584 (vip-harness-minor-mode "outline")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5585 (vip-harness-minor-mode "allout")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5586 (vip-harness-minor-mode "xref")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5587 (vip-harness-minor-mode "lmenu")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5588 (vip-harness-minor-mode "vc")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5589 (vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5590 (vip-harness-minor-mode "latex") ; which is in one of these two files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5591 (vip-harness-minor-mode "cyrillic")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5592 (vip-harness-minor-mode "russian")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5593 (vip-harness-minor-mode "view-less")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5594 (vip-harness-minor-mode "view")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5597 ;; Intercept maps could go in viper-keym.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5598 ;; We keep them here in case someone redefines them in ~/.vip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5600 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5601 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5603 ;; This is taken care of by vip-insert-global-user-map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5604 ;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5606 (define-key vip-insert-intercept-map vip-toggle-key 'vip-alternate-ESC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5607 ;; The default vip-toggle-key is \C-z; for the novice, it suspends or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5608 ;; iconifies Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5609 (define-key vip-vi-intercept-map vip-toggle-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5610 '(lambda () (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5611 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5612 (if (vip-window-display-p) (vip-iconify) (suspend-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5613 (vip-change-state-to-emacs))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5615 (define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5618 (if (or vip-always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5619 (and (< vip-expert-level 5) (> vip-expert-level 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5620 (vip-set-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5622 ;; Let all minor modes take effect after loading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5623 ;; this may not be enough, so we also set default minor-mode-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5624 ;; Without setting the default, new buffers that come up in emacs mode have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5625 ;; minor-mode-map-alist = nil, unless we call vip-change-state-*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5626 (if (eq vip-current-state 'emacs-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5627 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5628 (vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5629 (setq-default minor-mode-map-alist minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5630 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5633 (run-hooks 'vip-load-hook) ; the last chance to change something
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5635 (provide 'viper)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5636 (provide 'vip19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5637 (provide 'vip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5639 ;;; viper.el ends here