annotate lisp/viper/viper.el @ 152:4c132ee2d62b

Added tag r20-3b2 for changeset 59463afc5666
author cvs
date Mon, 13 Aug 2007 09:37:21 +0200
parents 318232e2a3f0
children 43dd3413c7c7
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
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
9 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
10
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 104
diff changeset
11 (defconst viper-version "2.93 of March 9, 1997"
0
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
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
29 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; Viper is a full-featured Vi emulator for Emacs 19. It emulates and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; improves upon the standard features of Vi and, at the same time, allows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; full access to all Emacs facilities. Viper supports multiple undo,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; file name completion, command, file, and search history and it extends
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; Vi in many other ways. Viper is highly customizable through the various
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; hooks, user variables, and keymaps. It is implemented as a collection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; 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
40 ;; major and minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; History
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; Viper is a new name for a package formerly known as VIP-19,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; which was a successor of VIP version 3.5 by Masahiko Sato
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; <ms@sail.stanford.edu> and VIP version 4.2 by Aamod Sane
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; <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
48 ;; were also shamelessly plagiarized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; Viper maintains some degree of compatibility with these older
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; packages. See the documentation for customization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; The main difference between Viper and these older packages are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; 1. Viper emulates Vi at several levels, from almost complete conformity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; to a rather loose Vi-compliance.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; 2. Viper provides full access to all major and minor modes of Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; without the need to type extra keys.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; The older versions of VIP (and other Vi emulators) do not work with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; some major and minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; 3. Viper supports vi-style undo.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; 4. Viper fully emulates (and improves upon) vi's replacement mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; 5. Viper has a better interface to ex, including command, variable, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; file name completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; 6. Viper uses native Emacs history and completion features; it doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; rely on other packages (such as gmhist.el and completer.el) to provide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; these features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; 7. Viper supports Vi-style editing in the minibuffer, by allowing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; user to switch from Insert state to Vi state to Replace state, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; 8. Viper keeps history of recently inserted pieces of text and recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; executed Vi-style destructive commands, such as `i', `d', etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; These pieces of text can be inserted in later insertion commands;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; the previous destructive commands can be re-executed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; 9. Viper has Vi-style keyboard macros, which enhances the similar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; facility in the original Vi.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; First, one can execute any Emacs command while defining a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; macro, not just the Vi commands. Second, macros are defined in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; WYSYWYG mode, using an interface to Emacs' WYSIWYG style of defining
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; macros. Third, in Viper, one can define macros that are specific to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; a given buffer, a given major mode, or macros defined for all buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; The same macro name can have several different definitions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; one global, several definitions for various major modes, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; definitions for specific buffers.
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
92 ;; Buffer-specific definitions override mode-specific
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; definitions, which, in turn, override global definitions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;; Installation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; -------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; (require 'viper)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;; Acknowledgements:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; -----------------
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
104 ;; Bug reports and ideas contributed by many users have helped
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
105 ;; improve Viper and the various versions of VIP.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; See the on-line manual for a complete list of contributors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;; Notes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; 1. Major modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; In most cases, Viper handles major modes correctly, i.e., they come up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; in the right state (either vi-state or emacs-state). For instance, text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; 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
115 ;; default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; However, some modes do not appear in the right mode in the beginning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; usually because they neglect to follow Emacs conventions (e.g., they don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; use kill-all-local-variables when they start). Some major modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; 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
120 ;; text-hook, for no good reason.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; 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
123 ;; 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
124 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; (add-hook 'your-favorite-mode 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; (add-hook 'your-favorite-mode 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; whichever applies. The right thing to do, however, is to complain to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; author of the respective package. (Sometimes they also neglect to equip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; their modes with hooks, which is one more reason for complaining.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; 2. Keymap handling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; Because Emacs 19 has an elegant mechanism for turning minor mode keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; on and off, implementation of Viper has been greatly simplified. Viper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; has several minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; Viper's Vi state consists of seven minor modes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; vip-vi-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; vip-vi-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; vip-vi-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; vip-vi-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; vip-vi-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; vip-vi-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; vip-vi-basic-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; Bindings done to the keymap of the first mode overshadow those done to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; the second, which, in turn, overshadows those done to the third, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; 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
152 ;; in its edit mode. This mode provides access to all Emacs facilities.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; Novice users, however, may want to set their vip-expert-level to 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; in their .vip file. This will enable vip-vi-diehard-minor-mode. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; minor mode's bindings make Viper simulate the usual Vi very closely.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; For instance, C-c will not have its standard Emacs binding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; and so many of the goodies of Emacs are not available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;;
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
159 ;; A skilled user should set vip-expert-level to at least 3. This will
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
160 ;; enable `C-c' and many Emacs facilities will become available.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; In this case, vip-vi-diehard-minor-mode is inactive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; Viper gurus should have at least
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; (setq vip-expert-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; in their ~/.vip files. This will unsuppress all Emacs keys that are not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;; essential for VI-style editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;; Pick-and-choose users may want to put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;; (setq vip-expert-level 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; 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
170 ;; vip-want-* See vip-set-expert-level for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; The very first minor mode, vip-vi-intercept-minor-mode, is of no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; 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
174 ;; ESC and C-z.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; The second mode, vip-vi-local-user-minor-mode, usually has an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; empty keymap. However, the user can set bindings in this keymap, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; will overshadow the corresponding bindings in the other two minor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; modes. This is useful, for example, for setting up ZZ in gnus,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; 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
181 ;; 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
182 ;; that would visit the next or the previous file in the Dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;; Setting local keys is tricky, so don't do it directly. Instead, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; vip-add-local-keys function (see its doc).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; The third minor mode, vip-vi-global-user-minor-mode, is also intended
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; for the users but, unlike vip-vi-local-user-minor-mode, its key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;; bindings are seen in all Viper buffers. This mode keys can be done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; with define-key command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; The fourth minor mode, vip-vi-kbd-minor-mode, is used by keyboard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; macros. Users are NOT supposed to modify this keymap directly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; 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
195 ;; key bindings that are visible in some major modes but not in others.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; Users are allowed to modify keymaps that belong to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; vip-vi-local-user-minor-mode, vip-vi-global-user-minor-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; and vip-vi-state-modifier-minor-mode only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;; Viper's Insert state also has seven minor modes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; vip-insert-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; vip-insert-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; vip-insert-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; vip-insert-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; vip-insert-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; vip-insert-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; vip-insert-basic-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; 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
212 ;; 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
213 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;; The next mode, vip-insert-local-user-minor-mode, is used to customize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;; bindings in the insert state of Viper. The third mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; vip-insert-global-user-minor-mode is like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;; vip-insert-local-user-minor-mode, except that its bindings are seen in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; all Viper buffers. As with vip-vi-local-user-minor-mode, its bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; should be done via the function vip-add-local-keys. Bindings for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;; 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
221 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; The next minor mode, vip-insert-kbd-minor-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; is used for keyboard VI-style macros defined with :map!.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;; The fifth minor mode, vip-insert-state-modifier-minor-mode, is like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; 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
227 ;; state; it can be used to modify keys in a mode-specific fashion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;; The minor mode vip-insert-diehard-minor-mode is in effect when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; the user wants a high degree of Vi compatibility (a bad idea, really!).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;; The last minor mode, vip-insert-basic-minor-mode, is always in effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;; 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
233 ;; Viper's operation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; Finally, Viper provides minor modes for overriding bindings set by Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; modes when Viper is in Emacs state:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; vip-emacs-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;; vip-emacs-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; vip-emacs-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ;; vip-emacs-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; 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
244 ;; associated with vip-emacs-global-user-minor-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; vip-emacs-global-user-map, overrides the global and local keymaps as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; well as the minor mode keymaps set by other modes. The keymap of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;; vip-emacs-local-user-minor-mode, vip-emacs-local-user-map, overrides
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;; everything, but it is used on a per buffer basis.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ;; The keymap associated with vip-emacs-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; overrides keys on a per-major-mode basis. The mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;; 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
252 ;; state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;; 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
255 ;; replace-state (used for commands like cw, C, etc.). This mode is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;; called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;; vip-replace-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; and its keymap is vip-replace-map. Replace minor mode is always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;; used in conjunction with the minor modes for insert-state, and its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; keymap overshadows the keymaps for insert minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; 4. Defining buffer-local bindings in Vi and Insert modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; As mentioned before, sometimes, it is convenient to have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; buffer-specific of mode-specific key bindings in Vi and insert modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; Viper provides a special function, vip-add-local-keys, to do precisely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;; this. For instance, is you need to add couple of mode-specific bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;; to Insert mode, you can put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; (vip-add-local-keys 'insert-state '((key1 . func1) (key2 .func2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; 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
274 ;; in your own elisp function, this will define bindings specific to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;; 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
276 ;; 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
277 ;; is written according to Emacs conventions, which includes a call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;; (kill-all-local-variables). See vip-add-local-keys for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; TO DO (volunteers?):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; 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
284 ;; convoluted. Instead of vip-command-argument, keymaps should bind the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; actual commands. E.g., "dw" should be bound to a generic command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; vip-delete that will delete things based on the value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;; last-command-char. This would greatly simplify the logic and the code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ;; 2. Somebody should venture to write a customization package a la
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ;; options.el that would allow the user to change values of variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;; that meet certain specs (e.g., match a regexp) and whose doc string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;; starts with a '*'. Then, the user should be offered to save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ;; variables that were changed. This will make user's customization job
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ;; much easier.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;; Code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (require 'advice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (require 'cl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (require 'ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
303 (provide 'viper)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;; Compiler pacifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (defvar vip-minibuffer-current-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (defvar vip-minibuffer-insert-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (defvar vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (defvar vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (defvar iso-accents-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (defvar zmacs-region-stays)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
312 (defvar mark-even-if-inactive)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
313
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
314 (eval-when-compile
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
315 (let ((load-path (cons (expand-file-name ".") load-path)))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
316 (or (featurep 'viper-util)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
317 (load "viper-util.el" nil nil 'nosuffix))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
318 (or (featurep 'viper-keym)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
319 (load "viper-keym.el" nil nil 'nosuffix))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
320 (or (featurep 'viper-mous)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
321 (load "viper-mous.el" nil nil 'nosuffix))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
322 (or (featurep 'viper-macs)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
323 (load "viper-macs.el" nil nil 'nosuffix))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
324 (or (featurep 'viper-ex)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
325 (load "viper-ex.el" nil nil 'nosuffix))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
326 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;; end pacifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
329
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
330 (require 'viper-util)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
331 (require 'viper-keym)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
332 (require 'viper-mous)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
333 (require 'viper-macs)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
334 (require 'viper-ex)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
335
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
336
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
337
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;; Generic predicates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;; 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
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; generate test functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;; 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
344 ;; Viper command keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; (macroexpand '(vip-test-com-defun foo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (defmacro vip-test-com-defun (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (let* ((snm (symbol-name name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (nm-p (intern (concat snm "-p")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (nms (intern (concat snm "s"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (` (defun (, nm-p) (com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (consp (memq (if (< com 0) (- com) com) (, nms)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ;; Variables for defining VI commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;; Modifying commands that can be prefixes to movement commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\"))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
359 ;; define vip-prefix-command-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (vip-test-com-defun vip-prefix-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ;; Commands that are pairs eg. dd. r and R here are a hack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
364 ;; define vip-charpair-command-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (vip-test-com-defun vip-charpair-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
368 ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?%
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?`
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ?; ?, ?0 ?? ?/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 "Movement commands")
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
373 ;; define vip-movement-command-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (vip-test-com-defun vip-movement-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
376 (defconst vip-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
377 "Digit commands")
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
378 ;; define vip-digit-command-p
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
379 (vip-test-com-defun vip-digit-command)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
380
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
381 ;; Commands that can be repeated by . (dotted)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
382 (defconst vip-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
383 ;; define vip-dotable-command-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (vip-test-com-defun vip-dotable-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; Commands that can follow a #
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
387 (defconst vip-hash-commands '(?c ?C ?g ?q ?s))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
388 ;; define vip-hash-command-p
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
389 (vip-test-com-defun vip-hash-command)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;; Commands that may have registers as prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
393 ;; define vip-regsuffix-command-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (vip-test-com-defun vip-regsuffix-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
396 (defconst vip-vi-commands (append vip-movement-commands
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
397 vip-digit-commands
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
398 vip-dotable-commands
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
399 vip-charpair-commands
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
400 vip-hash-commands
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
401 vip-prefix-commands
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
402 vip-regsuffix-commands)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
403 "The list of all commands in Vi-state.")
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
404 ;; define vip-vi-command-p
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
405 (vip-test-com-defun vip-vi-command)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;;; CODE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 ;; sentinels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ;; Runs vip-after-change-functions inside after-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (defun vip-after-change-sentinel (beg end len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (let ((list vip-after-change-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (funcall (car list) beg end len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (setq list (cdr list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 ;; Runs vip-before-change-functions inside before-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defun vip-before-change-sentinel (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (let ((list vip-before-change-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (funcall (car list) beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (setq list (cdr list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (defsubst vip-post-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (run-hooks 'vip-post-command-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 (defsubst vip-pre-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (run-hooks 'vip-pre-command-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; Needed so that Viper will be able to figure the last inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;; chunk of text with reasonable accuracy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (defsubst vip-insert-state-post-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (if (and (memq vip-current-state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 vip-insert-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (>= (point) vip-insert-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (setq vip-last-posn-while-in-insert-state (point-marker)))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
439 (if (eq vip-current-state 'insert-state)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
440 (progn
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
441 (or (stringp vip-saved-cursor-color)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
442 (string= (vip-get-cursor-color) vip-insert-state-cursor-color)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
443 (setq vip-saved-cursor-color (vip-get-cursor-color)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
444 (if (stringp vip-saved-cursor-color)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
445 (vip-change-cursor-color vip-insert-state-cursor-color))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
446 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (if (and (eq this-command 'dabbrev-expand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (integerp vip-pre-command-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (> vip-insert-point vip-pre-command-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (move-marker vip-insert-point vip-pre-command-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (defsubst vip-insert-state-pre-command-sentinel ()
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
454 (or (memq this-command '(self-insert-command))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
455 (memq (vip-event-key last-command-event)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
456 '(up down left right (meta f) (meta b)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
457 (control n) (control p) (control f) (control b)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
458 (vip-restore-cursor-color-after-insert))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (if (and (eq this-command 'dabbrev-expand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (markerp vip-insert-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (marker-position vip-insert-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (setq vip-pre-command-point (marker-position vip-insert-point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (defsubst vip-R-state-post-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;; Restoring cursor color is needed despite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; vip-replace-state-pre-command-sentinel: When you jump to another buffer in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; another frame, the pre-command hook won't change cursor color to default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ;; 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
469 ;; the point outside the replacement region, then the cursor color will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; remain red. Restoring the default, below, prevents this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (if (and (<= (vip-replace-start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (<= (point) (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (vip-change-cursor-color vip-replace-overlay-cursor-color)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
474 (vip-restore-cursor-color-after-replace)
0
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 ;; to speed up, don't change cursor color before self-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;; and common move commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (defsubst vip-replace-state-pre-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (or (memq this-command '(self-insert-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (memq (vip-event-key last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 '(up down left right (meta f) (meta b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (control n) (control p) (control f) (control b)))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
484 (vip-restore-cursor-color-after-replace)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (defun vip-replace-state-post-command-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; Restoring cursor color is needed despite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; in another frame, the pre-command hook won't change cursor color to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; 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
491 ;; we set the point outside the replacement region, then the cursor color
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 ;; will remain red. Restoring the default, below, fixes this problem.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 ;; 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
495 ;; cursor color or, if they terminate replace mode, the color will be changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ;; in vip-finish-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (or (memq this-command '(self-insert-command))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
498 (vip-restore-cursor-color-after-replace))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 ((eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ;; delete characters to compensate for inserted chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (let ((replace-boundary (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (goto-char vip-last-posn-in-replace-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (delete-char vip-replace-chars-to-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (setq vip-replace-chars-to-delete 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 vip-replace-chars-deleted 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;; terminate replace mode if reached replace limit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (if (= vip-last-posn-in-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (vip-replace-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (vip-finish-change vip-last-posn-in-replace-region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (if (and (<= (vip-replace-start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (<= (point) replace-boundary))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ;; the state may have changed in vip-finish-change above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (if (eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (vip-change-cursor-color vip-replace-overlay-cursor-color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (setq vip-last-posn-in-replace-region (point-marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (t ;; terminate replace mode if changed Viper states.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (vip-finish-change vip-last-posn-in-replace-region))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ;; changing mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (defun vip-change-state (new-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ;; Keep vip-post/pre-command-hooks fresh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; We remove then add vip-post/pre-command-sentinel since it is very
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ;; desirable that vip-pre-command-sentinel is the last hook and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; vip-post-command-sentinel is the first hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (remove-hook 'post-command-hook 'vip-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (add-hook 'post-command-hook 'vip-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;; These hooks will be added back if switching to insert/replace mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (vip-remove-hook 'vip-post-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 'vip-insert-state-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (vip-remove-hook 'vip-pre-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 'vip-insert-state-pre-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (cond ((eq new-state 'vi-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (cond ((member vip-current-state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;; move vip-last-posn-while-in-insert-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ;; This is a normal hook that is executed in insert/replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ;; states after each command. In Vi/Emacs state, it does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ;; nothing. We need to execute it here to make sure that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ;; the last posn was recorded when we hit ESC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 ;; It may be left unrecorded if the last thing done in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ;; insert/repl state was dabbrev-expansion or abbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;; expansion caused by hitting ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (vip-insert-state-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (vip-save-last-insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 vip-insert-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 vip-last-posn-while-in-insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (if vip-began-as-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (setq vip-began-as-replace nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;; repeat insert commands if numerical arg > 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (vip-repeat-insert-command))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (vip-message-conditions conds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (if (> (length vip-last-insertion) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (vip-push-onto-ring vip-last-insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 'vip-insertion-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (if vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (or (bolp) (backward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;; insert or replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ((memq new-state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (if (memq vip-current-state '(emacs-state vi-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (vip-move-marker-locally 'vip-insert-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (vip-add-hook 'vip-post-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 'vip-insert-state-post-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (vip-add-hook 'vip-pre-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 'vip-insert-state-pre-command-sentinel t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ) ; outermost cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 ;; Nothing needs to be done to switch to emacs mode! Just set some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 ;; variables, which is already done in vip-change-state-to-emacs!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (setq vip-current-state new-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (vip-normalize-minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (vip-adjust-keys-for new-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (vip-set-mode-vars-for new-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (vip-refresh-mode-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (defun vip-adjust-keys-for (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 "Make necessary adjustments to keymaps before entering STATE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (cond ((memq state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (if vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 ;; expert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (define-key vip-insert-basic-map "\C-j" nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 ;; novice
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 104
diff changeset
610 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 104
diff changeset
611 (define-key vip-insert-basic-map "\C-m" nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 104
diff changeset
612 (define-key vip-insert-basic-map "\C-j" nil))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (setq vip-insert-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (not vip-want-emacs-keys-in-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (if vip-want-ctl-h-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (progn
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
619 (define-key vip-insert-basic-map [(control h)] 'help-command)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
620 (define-key vip-replace-map [(control h)] 'help-command))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (define-key vip-insert-basic-map
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
622 [(control h)] 'vip-del-backward-char-in-insert)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (define-key vip-replace-map
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
624 [(control h)] 'vip-del-backward-char-in-replace)))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
625
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
626 (t ; Vi state
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (if vip-want-ctl-h-help
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
629 (define-key vip-vi-basic-map [(control h)] 'help-command)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
630 (define-key vip-vi-basic-map [(control h)] 'vip-backward-char)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ;; This ensures that Viper bindings are in effect, regardless of which minor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;; modes were turned on by the user or by other packages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (defun vip-normalize-minor-mode-map-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (setq minor-mode-map-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (vip-append-filter-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (cons 'vip-vi-intercept-minor-mode vip-vi-intercept-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (cons 'vip-vi-minibuffer-minor-mode vip-minibuffer-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (cons 'vip-vi-local-user-minor-mode vip-vi-local-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (cons 'vip-vi-kbd-minor-mode vip-vi-kbd-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (cons 'vip-vi-global-user-minor-mode vip-vi-global-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (cons 'vip-vi-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (if (keymapp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (cdr (assoc major-mode vip-vi-state-modifier-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (cdr (assoc major-mode vip-vi-state-modifier-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 vip-empty-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (cons 'vip-vi-basic-minor-mode vip-vi-basic-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (cons 'vip-replace-minor-mode vip-replace-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ;; vip-insert-minibuffer-minor-mode must come after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; vip-replace-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (cons 'vip-insert-minibuffer-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 vip-minibuffer-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (cons 'vip-insert-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 vip-insert-local-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (cons 'vip-insert-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 vip-insert-global-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (cons 'vip-insert-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (if (keymapp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (assoc major-mode vip-insert-state-modifier-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (assoc major-mode vip-insert-state-modifier-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 vip-empty-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (cons 'vip-insert-basic-minor-mode vip-insert-basic-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (cons 'vip-emacs-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 vip-emacs-intercept-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (cons 'vip-emacs-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 vip-emacs-local-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (cons 'vip-emacs-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 vip-emacs-global-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (cons 'vip-emacs-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (if (keymapp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (assoc major-mode vip-emacs-state-modifier-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (assoc major-mode vip-emacs-state-modifier-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 vip-empty-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 minor-mode-map-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ;; Viper mode-changing commands and utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 ;; Modifies mode-line-buffer-identification.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (defun vip-refresh-mode-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (setq vip-mode-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ((eq vip-current-state 'vi-state) vip-vi-state-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 ((eq vip-current-state 'replace-state) vip-replace-state-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 ((eq vip-current-state 'insert-state) vip-insert-state-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 ;; Sets Viper mode string in global-mode-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (force-mode-line-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (defun viper-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 "Turn on Viper emulation of Vi."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (if (not noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (if vip-first-time ; This check is important. Without it, startup and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (progn ; expert-level msgs mix up when viper-mode recurses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (setq vip-first-time nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (if (not vip-inhibit-startup-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (setq vip-inhibit-startup-message t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (delete-other-windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (switch-to-buffer "Viper Startup Message")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 "Viper Is a Package for Emacs Rebels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 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
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 XEmacs 19. It supports virtually all of Vi and Ex functionality, extending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 and improving upon much of it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 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
732 level 5 provides the most flexibility to depart from many Vi conventions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 You will be asked to specify your user level in a following screen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 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
737 as in VI, to smooth transition to Viper for the beginners. However, to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 use Emacs productively, you are advised to reach user level 3 or higher.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 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
741 functions,as usual in Emacs; ^Z will toggle vi/emacs modes, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 ^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
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 do not cause Emacs to quit, except at user level 1 (a novice).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 3. ^X^C EXITS EMACS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 undo. Another `u' changes direction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
750 6. Emacs Meta functions are invoked by typing `C-\\' or `\\ ESC'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 On a window system, the best way is to use the Meta-key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 something funny happens. This would abort the current editing command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 You can get more information on Viper by:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 a. Typing `:help' in Vi state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 b. Printing Viper manual, found in ./etc/viper.dvi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 c. Printing ViperCard, the Quick Reference, found in ./etc/viperCard.dvi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 This startup message appears whenever you load Viper, unless you type `y' now."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (if (y-or-n-p "Inhibit Viper startup message? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (vip-save-setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 'vip-inhibit-startup-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 "Viper startup message inhibited"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 vip-custom-file-name t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;;(kill-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 "The last message is in buffer `Viper Startup Message'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (sit-for 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (vip-set-expert-level 'dont-change-unless)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (vip-change-state-to-vi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (defalias 'vip-mode 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 ;; Switch from Insert state to Vi state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (defun vip-exit-insert-state ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (vip-change-state-to-vi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (defun vip-set-mode-vars-for (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 "Sets Viper minor mode variables to put Viper's state STATE in effect."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 ;; Emacs state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (setq vip-vi-minibuffer-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 vip-insert-minibuffer-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 vip-vi-intercept-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 vip-insert-intercept-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 vip-vi-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 vip-vi-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 vip-vi-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 vip-vi-state-modifier-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 vip-vi-diehard-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 vip-vi-basic-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 vip-replace-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 vip-insert-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 vip-insert-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 vip-insert-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 vip-insert-state-modifier-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 vip-insert-diehard-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 vip-insert-basic-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 vip-emacs-intercept-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 vip-emacs-local-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 vip-emacs-global-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 vip-emacs-state-modifier-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 ;; Vi state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (if (eq state 'vi-state) ; adjust for vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 vip-vi-intercept-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 vip-vi-local-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 vip-vi-global-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 vip-vi-state-modifier-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 ;; don't let the diehard keymap block command completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 ;; and other things in the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 vip-vi-diehard-minor-mode (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (or vip-want-emacs-keys-in-vi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (vip-is-in-minibuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 vip-vi-basic-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 vip-emacs-intercept-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 vip-emacs-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 vip-emacs-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 vip-emacs-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 vip-emacs-state-modifier-minor-mode nil
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 ;; Insert and Replace states
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (if (member state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 vip-insert-intercept-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 vip-replace-minor-mode (eq state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 vip-insert-local-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 vip-insert-global-user-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 vip-insert-state-modifier-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 ;; don't let the diehard keymap block command completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 ;; and other things in the minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 vip-insert-diehard-minor-mode (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (or vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (vip-is-in-minibuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 vip-insert-basic-minor-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 vip-emacs-intercept-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 vip-emacs-local-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 vip-emacs-kbd-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 vip-emacs-global-user-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 vip-emacs-state-modifier-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 ;; minibuffer faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (setq vip-minibuffer-current-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 ((eq state 'vi-state) vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 ((memq state '(insert-state replace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 vip-minibuffer-insert-face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (if (vip-is-in-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (vip-set-minibuffer-overlay))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 ;; This also takes care of the annoying incomplete lines in files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 ;; Also, this fixes `undo' to work vi-style for complex commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (defun vip-change-state-to-vi ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 "Change Viper state to Vi."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (if (and vip-first-time (not (vip-is-in-minibuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (if overwrite-mode (overwrite-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (if abbrev-mode (expand-abbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (if (and auto-fill-function (> (current-column) fill-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (funcall auto-fill-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 ;; don't leave whitespace lines around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (if (and (memq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 '(vip-autoindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 vip-open-line vip-Open-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 vip-replace-state-exit-cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (vip-over-whitespace-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (indent-to-left-margin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (vip-add-newline-at-eob-if-necessary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (if vip-undo-needs-adjustment (vip-adjust-undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (vip-change-state 'vi-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 ;; 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
897 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (iso-accents-mode -1))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
900
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
901 (vip-restore-cursor-color-after-insert)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
902
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 ;; Protection against user errors in hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (run-hooks 'vip-vi-state-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (vip-message-conditions conds)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (defun vip-change-state-to-insert ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 "Change Viper state to Insert."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (vip-change-state 'insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (iso-accents-mode 1)) ; turn iso accents on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
916 (or (stringp vip-saved-cursor-color)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
917 (string= (vip-get-cursor-color) vip-insert-state-cursor-color)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
918 (setq vip-saved-cursor-color (vip-get-cursor-color)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
919 ;; Commented out, because if vip-change-state-to-insert is executed
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
920 ;; non-interactively then the old cursor color may get lost. Same old Emacs
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
921 ;; bug related to local variables?
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
922 ;;;(if (stringp vip-saved-cursor-color)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
923 ;;; (vip-change-cursor-color vip-insert-state-cursor-color))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 ;; Protection against user errors in hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (run-hooks 'vip-insert-state-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (vip-message-conditions conds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (defsubst vip-downgrade-to-insert ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (setq vip-current-state 'insert-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 vip-replace-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 ;; Change to replace state. When the end of replacement region is reached,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 ;; replace state changes to insert state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (defun vip-change-state-to-replace (&optional non-R-cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (vip-change-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (iso-accents-mode 1)) ; turn iso accents on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 ;; Run insert-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (run-hooks 'vip-insert-state-hook 'vip-replace-state-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (vip-message-conditions conds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (if non-R-cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (vip-start-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 ;; 'R' is implemented using Emacs's overwrite-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (vip-start-R-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (defun vip-change-state-to-emacs ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 "Change Viper state to Emacs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (vip-change-state 'emacs-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (iso-accents-mode 1)) ; turn iso accents on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 ;; Protection agains user errors in hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (run-hooks 'vip-emacs-state-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (vip-message-conditions conds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 ;; escape to emacs mode termporarily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (defun vip-escape-to-emacs (arg &optional events)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 "Escape to Emacs state from Vi state for one Emacs command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ARG is used as the prefix value for the executed command. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 EVENTS is a list of events, which become the beginning of the command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (interactive "P")
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
975 (if (= last-command-char ?\\)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
976 (message "Switched to EMACS state for the next command..."))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (vip-escape-to-state arg events 'emacs-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 ;; escape to Vi mode termporarily
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
980 (defun vip-escape-to-vi (arg)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 "Escape from Emacs state to Vi state for one Vi 1-character command.
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
982 If the Vi command that the user types has a prefix argument, e.g., `d2w', then
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
983 Vi's prefix argument will be used. Otherwise, the prefix argument passed to
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
984 `vip-escape-to-vi' is used."
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
985 (interactive "P")
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
986 (message "Switched to VI state for the next command...")
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
987 (vip-escape-to-state arg nil 'vi-state))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
988
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 ;; Escape to STATE mode for one Emacs command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (defun vip-escape-to-state (arg events state)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
991 ;;(let (com key prefix-arg)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
992 (let (com key)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 ;; this temporarily turns off Viper's minor mode keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (vip-set-mode-vars-for state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (vip-normalize-minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (if events (vip-set-unread-command-events events))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 ;; protect against keyboard quit and other errors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (condition-case nil
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1000 (let (vip-vi-kbd-minor-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1001 vip-insert-kbd-minor-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1002 vip-emacs-kbd-minor-mode)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (setq com (key-binding (setq key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (if vip-xemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (read-key-sequence nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (read-key-sequence nil t)))))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1009 ;; In case of binding indirection--chase definitions.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 ;; Have to do it here because we execute this command under
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ;; different keymaps, so command-execute may not do the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ;; right thing there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (while (vectorp com) (setq com (key-binding com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 nil)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1015 ;; Execute command com in the original Viper state, not in state
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1016 ;; `state'. Otherwise, if we switch buffers while executing the
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1017 ;; escaped to command, Viper's mode vars will remain those of
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1018 ;; `state'. When we return to the orig buffer, the bindings will be
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1019 ;; screwed up.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (vip-set-mode-vars-for vip-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;; this-command, last-command-char, last-command-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (setq this-command com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (if vip-xemacs-p ; XEmacs represents key sequences as vectors
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1025 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 last-command-char (event-to-character last-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 ;; Emacs represents them as sequences (str or vec)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1028 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 last-command-char last-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (if (commandp com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (progn
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1033 (setq prefix-arg (or prefix-arg arg))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (command-execute com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (quit (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (error (beep 1))))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1038 ;; set state in the new buffer
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1039 (vip-set-mode-vars-for vip-current-state))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1041 (defun vip-exec-form-in-vi (form)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1042 "Execute FORM in Vi state, regardless of the Ccurrent Vi state."
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1043 (let ((buff (current-buffer))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1044 result)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1045 (vip-set-mode-vars-for 'vi-state)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1046
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1047 (condition-case nil
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1048 (setq result (eval form))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1049 (error
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1050 (signal 'quit nil)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1051
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1052 (if (not (equal buff (current-buffer))) ; cmd switched buffer
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1053 (save-excursion
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1054 (set-buffer buff)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1055 (vip-set-mode-vars-for vip-current-state)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1056 (vip-set-mode-vars-for vip-current-state)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1057 result))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1058
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (defun vip-exec-form-in-emacs (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (let ((buff (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (vip-set-mode-vars-for 'emacs-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (setq result (eval form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (if (not (equal buff (current-buffer))) ; cmd switched buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (set-buffer buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (vip-set-mode-vars-for vip-current-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (vip-set-mode-vars-for vip-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 ;; This is needed because minor modes sometimes override essential Viper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 ;; bindings. By letting Viper know which files these modes are in, it will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 ;; arrange to reorganize minor-mode-map-alist so that things will work right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (defun vip-harness-minor-mode (load-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 "Familiarize Viper with a minor mode defined in LOAD_FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 Minor modes that have their own keymaps may overshadow Viper keymaps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 This function is designed to make Viper aware of the packages that define
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 such minor modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 Usage:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (vip-harness-minor-mode load-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 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
1086 Suffixes such as .el or .elc should be stripped."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (interactive "sEnter name of the load file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 ;; Change the default for minor-mode-map-alist each time a harnessed minor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 ;; mode adds its own keymap to the a-list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (defun vip-ESC (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 "Emulate ESC key in Emacs.
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1101 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1102 If vip-no-multiple-ESC is 'twice double ESC would ding in vi-state.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1103 Other ESC sequences are emulated via the current Emacs's major mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1104 keymap. This is more convenient on TTYs, since this won't block
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1105 function keys such as up,down, etc. ESC will also will also work as
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1106 a Meta key in this case. When vip-no-multiple-ESC is nil, ESC functions
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1107 as a Meta key and any number of multiple escapes is allowed."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (let (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (setq char (vip-read-char-exclusive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (vip-escape-to-emacs arg (list ?\e char) ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 ((and (eq vip-no-multiple-ESC 'twice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (eq vip-current-state 'vi-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (setq char (vip-read-char-exclusive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (if (= char (string-to-char vip-ESC-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (vip-escape-to-emacs arg (list ?\e char) )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (t (ding)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1122 (defun vip-alternate-Meta-key (arg)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1123 "Simulate Emacs Meta key."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (interactive "P")
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1125 (sit-for 1) (message "ESC-")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (vip-escape-to-emacs arg '(?\e)))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1127
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1128 (defun vip-toggle-key-action ()
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1129 "Action bound to `vip-toggle-key'."
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1130 (interactive)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1131 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z"))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1132 (if (vip-window-display-p)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1133 (vip-iconify)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1134 (suspend-emacs))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1135 (vip-change-state-to-emacs)))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1136
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 ;; Intercept ESC sequences on dumb terminals.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 ;; 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
1142 ;; But only if there are characters to read during a very short time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 ;; Returns the last event, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (defun vip-envelop-ESC-key ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (let ((event last-input-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (keyseq [nil])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 inhibit-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (if (vip-ESC-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (if (vip-fast-keysequence-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (let (minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (vip-set-unread-command-events event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (setq keyseq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (funcall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (ad-get-orig-definition 'read-key-sequence) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 ) ; let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 ;; If keyseq translates into something that still has ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 ;; at the beginning, separate ESC from the rest of the seq.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 ;; In XEmacs we check for events that are keypress meta-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 ;; and convert them into [escape key]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 ;; This is needed for the following reason:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 ;; If ESC is the first symbol, we interpret it as if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 ;; user typed ESC and then quickly some other symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 ;; If ESC is not the first one, then the key sequence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 ;; entered was apparently translated into a function key or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 ;; something (e.g., one may have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 ;; (define-key function-key-map "\e[192z" [f11])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 ;; which would translate the escape-sequence generated by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 ;; f11 in an xterm window into the symbolic key f11.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;; If `first-key' is not an ESC event, we make it into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 ;; last-command-event in order to pretend that this key was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 ;; pressed. This is needed to allow arrow keys to be bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 ;; macros. Otherwise, vip-exec-mapped-kbd-macro will think that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 ;; the last event was ESC and so it'll execute whatever is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 ;; bound to ESC. (Viper macros can't be bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 ;; ESC-sequences).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (let* ((first-key (elt keyseq 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (key-mod (event-modifiers first-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (cond ((vip-ESC-event-p first-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 ;; put keys following ESC on the unread list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 ;; and return ESC as the key-sequence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (vip-set-unread-command-events (subseq keyseq 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (setq last-input-event event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 keyseq (if vip-emacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 "\e"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (vector (character-to-event ?\e)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 ((and vip-xemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (key-press-event-p first-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (equal '(meta) key-mod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (vip-set-unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (vconcat (vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (character-to-event (event-key first-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (subseq keyseq 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (setq last-input-event event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 keyseq (vector (character-to-event ?\e))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 ((eventp first-key)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1200 (setq last-command-event (vip-copy-event first-key)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 ) ; end progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 ;; this is escape event with nothing after it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 ;; put in unread-command-event and then re-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (vip-set-unread-command-events event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (setq keyseq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (funcall (ad-get-orig-definition 'read-key-sequence) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 ;; not an escape event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (setq keyseq (vector event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 keyseq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (defadvice read-key-sequence (around vip-read-keyseq-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 "Harness to work for Viper. This advice is harmless---don't worry!"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (let (inhibit-quit event keyseq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (setq keyseq ad-do-it)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (setq event (if vip-xemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (elt keyseq 0) ; XEmacs returns vector of events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (elt (listify-key-sequence keyseq) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (if (vip-ESC-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 (let (unread-command-events)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (vip-set-unread-command-events keyseq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (if (vip-fast-keysequence-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (let ((vip-vi-global-user-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (vip-vi-local-user-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (vip-replace-minor-mode nil) ; actually unnecessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (vip-insert-global-user-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (vip-insert-local-user-minor-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (setq keyseq ad-do-it))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (setq keyseq ad-do-it))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 keyseq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 (defadvice describe-key (before vip-read-keyseq-ad protect activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 "Force to read key via `read-key-sequence'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (interactive (list (vip-events-to-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (read-key-sequence "Describe key: ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (defadvice describe-key-briefly (before vip-read-keyseq-ad protect activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 "Force to read key via `read-key-sequence'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (interactive (list (vip-events-to-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (read-key-sequence "Describe key briefly: ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 ;; Listen to ESC key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 ;; 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
1248 ;; 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
1249 (defun vip-intercept-ESC-key ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 "Function that implements ESC key in Viper emulation of Vi."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (let ((cmd (or (key-binding (vip-envelop-ESC-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 '(lambda () (interactive) (error "")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 ;; call the actual function to execute ESC (if no other symbols followed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 ;; or the key bound to the ESC sequence (if the sequence was issued
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 ;; with very short delay between characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (if (eq cmd 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (setq cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (cond ((eq vip-current-state 'vi-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 'vip-ESC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 ((eq vip-current-state 'insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 'vip-exit-insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 ((eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 'vip-replace-state-exit-cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 (t 'vip-change-state-to-vi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (call-interactively cmd)))
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1269
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 ;; prefix argument for Vi mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 ;; represents the numeric value of the prefix argument and COM represents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 ;; command prefix such as "c", "d", "m" and "y".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 ;; Get value part of prefix-argument ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (defsubst vip-p-val (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (cond ((null arg) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 ((consp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (if (or (null (car arg)) (equal (car arg) '(nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 1 (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (t arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 ;; Get raw value part of prefix-argument ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (defsubst vip-P-val (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (cond ((consp arg) (car arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (t arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 ;; Get com part of prefix-argument ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (defsubst vip-getcom (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (cond ((null arg) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 ((consp arg) (cdr arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 ;; Get com part of prefix-argument ARG and modify it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (defun vip-getCom (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (let ((com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (cond ((equal com ?c) ?C)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 ((equal com ?d) ?D)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 ((equal com ?y) ?Y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (t com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 ;; Compute numeric prefix arg value.
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1308 ;; Invoked by EVENT. COM is the command part obtained so far.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (defun vip-prefix-arg-value (event com)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1310 (let (value func)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 ;; read while number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (while (and (vip-characterp event) (>= event ?0) (<= event ?9))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
1313 (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (setq event (vip-read-event-convert-to-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (setq prefix-arg value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (if com (setq prefix-arg (cons prefix-arg com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (while (eq event ?U)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (vip-describe-arg prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (setq event (vip-read-event-convert-to-char)))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1321
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1322 (if (or com (and (not (eq vip-current-state 'vi-state))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1323 ;; make sure it is a Vi command
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1324 (vip-characterp event) (vip-vi-command-p event)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1325 ))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1326 ;; If appears to be one of the vi commands,
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1327 ;; then execute it with funcall and clear prefix-arg in order to not
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1328 ;; confuse subsequent commands
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1329 (progn
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1330 ;; last-command-char is the char we want emacs to think was typed
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1331 ;; last. If com is not nil, the vip-digit-argument command was called
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1332 ;; from within vip-prefix-arg command, such as `d', `w', etc., i.e.,
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1333 ;; the user typed, say, d2. In this case, `com' would be `d', `w',
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1334 ;; etc.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1335 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
1336 ;; indicated by the fact that the current state is not vi-state),
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1337 ;; then `event' represents the vi command to be executed (e.g., `d',
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1338 ;; `w', etc). Again, last-command-char must make emacs believe that
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1339 ;; this is the command we typed.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1340 (setq last-command-char (or com event))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1341 (setq func (vip-exec-form-in-vi
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1342 (` (key-binding (char-to-string (, event))))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1343 (funcall func prefix-arg)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1344 (setq prefix-arg nil))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1345 ;; some other command -- let emacs do it in its own way
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1346 (vip-set-unread-command-events event))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1347 ))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1348
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 ;; Vi operator as prefix argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (defun vip-prefix-arg-com (char value com)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1352 (let ((cont t)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1353 cmd-info mv-or-digit-cmd)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (while (and cont
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 (memq char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 vip-buffer-search-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 ;; this means that we already have a command character, so we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 ;; construct a com list and exit while. however, if char is "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 ;; it is an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 ;; new com is (CHAR . OLDCOM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (if (memq char '(?# ?\")) (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (setq com (cons char com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (setq cont nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 ;; 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
1368 ;; 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
1369 ;; if char is !, =, or #, a complete com is formed so we exit the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 ;; while loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (cond ((memq char '(?! ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (setq com char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (setq char (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (setq cont nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 ((= char ?#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 ;; read a char and encode it as com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (setq com (+ 128 (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (setq char (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 ((= char ?\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (let ((reg (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (if (vip-valid-register reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 (setq vip-use-register reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (setq char (read-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (setq com char)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1387 (setq char (read-char))))))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1388
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (if (atom com)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1390 ;; `com' is a single char, so we construct the command argument
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1391 ;; and if `char' is `?', we describe the arg; otherwise
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1392 ;; we prepare the command that will be executed at the end.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (progn
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1394 (setq cmd-info (cons value com))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (while (= char ?U)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1396 (vip-describe-arg cmd-info)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (setq char (read-char)))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
1398 ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so we
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
1399 ;; execute it at the very end
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1400 (or (vip-movement-command-p char)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1401 (vip-digit-command-p char)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
1402 (vip-regsuffix-command-p char)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1403 (error ""))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1404 (setq mv-or-digit-cmd
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1405 (vip-exec-form-in-vi
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1406 (` (key-binding (char-to-string (, char)))))))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1407
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 ;; 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
1409 (if (memq (car com) '(?r ?R))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 ;; execute apropriate region command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (let ((char (car com)) (com (cdr com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (setq prefix-arg (cons value com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (if (= char ?r) (vip-region prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (vip-Region prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 ;; reset prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (setq prefix-arg nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 ;; otherwise, reset prefix arg and call appropriate command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (setq value (if (null value) 1 value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (setq prefix-arg nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 ((equal com '(?d . ?d)) (vip-line (cons value ?D)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 ((equal com '(?d . ?y)) (vip-yank-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 ((equal com '(?y . ?y)) (vip-line (cons value ?Y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 ((equal com '(?< . ?<)) (vip-line (cons value ?<)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 ((equal com '(?> . ?>)) (vip-line (cons value ?>)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 ((equal com '(?! . ?!)) (vip-line (cons value ?!)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 ((equal com '(?= . ?=)) (vip-line (cons value ?=)))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1428 (t (error "")))))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1429
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1430 (if mv-or-digit-cmd
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1431 (progn
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1432 (setq last-command-char char)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1433 (setq last-command-event
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1434 (vip-copy-event
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1435 (if vip-xemacs-p (character-to-event char) char)))
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1436 (condition-case nil
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1437 (funcall mv-or-digit-cmd cmd-info)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1438 (error
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1439 (error "")))))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1440 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (defun vip-describe-arg (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (let (val com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (setq val (vip-P-val arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (if (null val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 (if (null com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (message "Value is nil, and command is nil")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (message "Value is nil, and command is `%c'" com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (if (null com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (message "Value is `%d', and command is nil" val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (message "Value is `%d', and command is `%c'" val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (defun vip-digit-argument (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 "Begin numeric argument for the next command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (vip-leave-region-active)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1458 (vip-prefix-arg-value
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1459 last-command-char (if (consp arg) (cdr arg) nil)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (defun vip-command-argument (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 "Accept a motion command as an argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (interactive "P")
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1464 (let ((vip-inside-command-argument-action t))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1465 (condition-case nil
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1466 (vip-prefix-arg-com
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1467 last-command-char
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1468 (cond ((null arg) nil)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1469 ((consp arg) (car arg))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1470 ((integerp arg) arg)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1471 (t (error vip-InvalidCommandArgument)))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1472 (cond ((null arg) nil)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1473 ((consp arg) (cdr arg))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1474 ((integerp arg) nil)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1475 (t (error vip-InvalidCommandArgument))))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1476 (quit (setq vip-use-register nil)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1477 (signal 'quit nil)))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1478 (vip-deactivate-mark)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 ;; repeat last destructive command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 ;; Append region to text in register REG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 ;; START and END are buffer positions indicating what to append.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (defsubst vip-append-to-register (reg start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 (set-register reg (concat (if (stringp (get-register reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (get-register reg) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 (buffer-substring start end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 ;; Saves last inserted text for possible use by vip-repeat command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (defun vip-save-last-insertion (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (setq vip-last-insertion (buffer-substring beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (or (< (length vip-d-com) 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (setcar (nthcdr 4 vip-d-com) vip-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 (or (null vip-command-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 (ring-empty-p vip-command-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 vip-last-insertion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 ;; del most recent elt, if identical to the second most-recent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 (vip-cleanup-ring vip-command-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (defsubst vip-yank-last-insertion ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 "Inserts the text saved by the previous vip-save-last-insertion command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (insert vip-last-insertion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 ;; define functions to be executed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 ;; invoked by the `C' command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (defun vip-exec-change (m-com com)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1515 (or (and (markerp vip-com-point) (marker-position vip-com-point))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1516 (set-marker vip-com-point (point) (current-buffer)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 ;; handle C cmd at the eol and at eob.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 (if (or (and (eolp) (= vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (= vip-com-point (point-max)))
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 (insert " ")(backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 (if (= vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (vip-forward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (if (= com ?c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (vip-change vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (vip-change-subr vip-com-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 ;; this is invoked by vip-substitute-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (defun vip-exec-Change (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 ;;(vip-valid-register vip-use-register '(letter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 vip-use-register (mark t) (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (downcase vip-use-register) (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 (delete-region (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (defun vip-exec-delete (m-com com)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1550 (or (and (markerp vip-com-point) (marker-position vip-com-point))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1551 (set-marker vip-com-point (point) (current-buffer)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 ;;(vip-valid-register vip-use-register '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 vip-use-register vip-com-point (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (downcase vip-use-register) vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 (setq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (if (eq last-command 'd-command) 'kill-region nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 (kill-region vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (setq this-command 'd-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (if (and (eolp) (not (bolp))) (backward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (defun vip-exec-Delete (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 ;;(vip-valid-register vip-use-register '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 vip-use-register (mark t) (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (downcase vip-use-register) (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (setq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (if (eq last-command 'D-command) 'kill-region nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (kill-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (if (eq m-com 'vip-line) (setq this-command 'D-command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (defun vip-exec-yank (m-com com)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1594 (or (and (markerp vip-com-point) (marker-position vip-com-point))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1595 (set-marker vip-com-point (point) (current-buffer)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 ;; (vip-valid-register vip-use-register '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 vip-use-register vip-com-point (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (downcase vip-use-register) vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (setq last-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 (copy-region-as-kill vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 (goto-char vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (defun vip-exec-Yank (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (cond ((vip-valid-register vip-use-register '(letter digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 vip-use-register (mark t) (point) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (downcase vip-use-register) (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 (t (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 (setq last-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 (copy-region-as-kill (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (goto-char vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (defun vip-exec-bang (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (shell-command-on-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (mark t) (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (if (= com ?!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (setq vip-last-shell-com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 "!"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 'vip-shell-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (car vip-shell-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 vip-last-shell-com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 (defun vip-exec-equals (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (if (> (mark t) (point)) (exchange-point-and-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (indent-region (mark t) (point) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (defun vip-exec-shift (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 (set-mark vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (vip-enlarge-region (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (if (> (mark t) (point)) (exchange-point-and-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 (indent-rigidly (mark t) (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (if (= com ?>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 vip-shift-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (- vip-shift-width))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ;; return point to where it was before shift
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 (goto-char vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 ;; 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
1669 ;; denotes repeated insert command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (defsubst vip-exec-dummy (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (defun vip-exec-buffer-search (m-com com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (setq vip-s-string (buffer-substring (point) vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (setq vip-s-forward t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (setq vip-search-history (cons vip-s-string vip-search-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (vip-search vip-s-string vip-s-forward 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (defvar vip-exec-array (make-vector 128 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 ;; Using a dispatch array allows adding functions like buffer search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 ;; without affecting other functions. Buffer search can now be bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 ;; to any character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 (aset vip-exec-array ?c 'vip-exec-change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 (aset vip-exec-array ?C 'vip-exec-Change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (aset vip-exec-array ?d 'vip-exec-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (aset vip-exec-array ?D 'vip-exec-Delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (aset vip-exec-array ?y 'vip-exec-yank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (aset vip-exec-array ?Y 'vip-exec-Yank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 (aset vip-exec-array ?r 'vip-exec-dummy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 (aset vip-exec-array ?! 'vip-exec-bang)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 (aset vip-exec-array ?< 'vip-exec-shift)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 (aset vip-exec-array ?> 'vip-exec-shift)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (aset vip-exec-array ?= 'vip-exec-equals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 ;; This function is called by various movement commands to execute a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 ;; destructive command on the region specified by the movement command. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 ;; instance, if the user types cw, then the command vip-forward-word will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 ;; call vip-execute-com to execute vip-exec-change, which eventually will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 ;; call vip-change to invoke the replace mode on the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 ;; 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
1706 ;; vip-d-com for later use by vip-repeat.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (defun vip-execute-com (m-com val com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (let ((reg vip-use-register))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 ;; this is the special command `#'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (if (> com 128)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 (vip-special-prefix-com (- com 128))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (let ((fn (aref vip-exec-array (if (< com 0) (- com) com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 (if (null fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 (error "%c: %s" com vip-InvalidViCommand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 (funcall fn m-com com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 (if (vip-dotable-command-p com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (list m-com val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (if (memq com (list ?c ?C ?!)) (- com) com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 reg nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (defun vip-repeat (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 "Re-execute last destructive command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 Use the info in vip-d-com, which has the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 \(com val ch reg inserted-text command-keys\),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 where `com' is the command to be re-executed, `val' is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 argument to `com', `ch' is a flag for repeat, and `reg' is optional;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 if it exists, it is the name of the register for `com'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 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
1732 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 (let ((save-point (point)) ; save point before repeating prev cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 ;; Pass along that we are repeating a destructive command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 ;; This tells vip-set-destructive-command not to update
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 ;; vip-command-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (vip-intermediate-command 'vip-repeat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 (if (eq last-command 'vip-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 ;; if the last command was vip-undo, then undo-more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 (vip-undo-more)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 ;; 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
1742 ;; its prefix value is used as new prefix value for the command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 (let ((m-com (car vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 (com (nth 2 vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (reg (nth 3 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (if (null val) (setq val (nth 1 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (if (null m-com) (error "No previous command to repeat."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (setq vip-use-register reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (if (nth 4 vip-d-com) ; text inserted by command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 (setq vip-last-insertion (nth 4 vip-d-com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 vip-d-char (nth 4 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 (funcall m-com (cons val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 (if (and vip-keep-point-on-repeat (< save-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 (goto-char save-point)) ; go back to before repeat.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (if (and (eolp) (not (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 ;; If the prev cmd was rotating the command ring, this means that `.' has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 ;; 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
1762 ;; 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
1763 ;; 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
1764 ;; the inserted text may be nil). Besides, in this case, the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 ;; executed by `.' is already on the ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (if (eq last-command 'vip-display-current-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (vip-push-onto-ring vip-d-com 'vip-command-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 (defun vip-repeat-from-history ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 "Repeat a destructive command from history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 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
1774 executing this command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 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
1776 the second character is a digit 0 to 9. The digit indicates which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 history command to execute. `<char>0' is equivalent to `.', `<char>1'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 invokes the command before that, etc."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (let* ((vip-intermediate-command 'repeating-display-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (idx (cond (vip-this-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 (string-to-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (symbol-name (elt vip-this-kbd-macro 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (t 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 (num idx)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (vip-d-com vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (or (and (numberp num) (<= 0 num) (<= num 9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 (setq idx 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 num 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 "`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
1794 (while (< 0 num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (setq num (1- num)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (vip-repeat nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (while (> idx num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (vip-special-ring-rotate1 vip-command-ring 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (setq num (1+ num)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1804 ;; The hash-command. It is invoked interactively by the key sequence #<char>.
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1805 ;; The chars that can follow `#' are determined by vip-hash-command-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (defun vip-special-prefix-com (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (cond ((= char ?c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (downcase-region (min vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (max vip-com-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 ((= char ?C)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 (upcase-region (min vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (max vip-com-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 ((= char ?g)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (push-mark vip-com-point t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (vip-global-execute))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 ((= char ?q)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (push-mark vip-com-point t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (vip-quote-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 ((= char ?s) (funcall vip-spell-function vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (t (error "#%c: %s" char vip-InvalidViCommand))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 ;; undoing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 (defun vip-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 "Undo previous change."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 (message "undo!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 (let ((modified (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (before-undo-pt (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (after-change-functions after-change-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 undo-beg-posn undo-end-posn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 ;; 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
1835 (add-hook 'after-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 '(lambda (beg end len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (setq undo-beg-posn beg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 undo-end-posn (or end beg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 (undo-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (undo-more 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (setq undo-beg-posn (or undo-beg-posn before-undo-pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 undo-end-posn (or undo-end-posn undo-beg-posn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (goto-char undo-beg-posn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (if (and vip-keep-point-on-undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 (pos-visible-in-window-p before-undo-pt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 (push-mark (point-marker) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (vip-sit-for-short 300)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 (goto-char undo-end-posn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 (vip-sit-for-short 300)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (> (abs (- undo-end-posn before-undo-pt)) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (goto-char before-undo-pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (goto-char undo-beg-posn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (push-mark before-undo-pt t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 (if (and (eolp) (not (bolp))) (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (if (not modified) (set-buffer-modified-p t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 (setq this-command 'vip-undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 ;; Continue undoing previous changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (defun vip-undo-more ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (message "undo more!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (undo-more 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (error (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (message "No further undo information in this buffer")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (if (and (eolp) (not (bolp))) (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (setq this-command 'vip-undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 ;; The following two functions are used to set up undo properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 ;; 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
1875 ;; they are undone all at once.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 (defun vip-adjust-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (let ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 tmp tmp2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 (setq vip-undo-needs-adjustment nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (if (listp buffer-undo-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (setq tmp2 (cdr tmp)) ; the part after mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 ;; cut tail from buffer-undo-list temporarily by direct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 ;; manipulation with pointers in buffer-undo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 (setcdr tmp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (setq buffer-undo-list (delq nil buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (setq buffer-undo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (delq vip-buffer-undo-list-mark buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 ;; restore tail of buffer-undo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (setq buffer-undo-list (delq nil buffer-undo-list))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (defun vip-set-complex-command-for-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (if (listp buffer-undo-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (if (not vip-undo-needs-adjustment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (setq buffer-undo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (cons vip-buffer-undo-list-mark buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (setq vip-undo-needs-adjustment t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 (defun vip-display-current-destructive-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (let ((text (nth 4 vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (keys (nth 5 vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 (max-text-len 30))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 (setq this-command 'vip-display-current-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 (message " `.' runs %s%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (concat "`" (vip-array-to-string keys) "'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (vip-abbreviate-string text max-text-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 " inserting `" "'" " ......."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 ;; 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
1923 ;; or in some other way (non-interactively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 (defun vip-set-destructive-command (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (or (eq vip-intermediate-command 'vip-repeat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (setq vip-d-com list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 (setcar (nthcdr 5 vip-d-com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 (vip-array-to-string (this-command-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 (vip-push-onto-ring vip-d-com 'vip-command-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 (defun vip-prev-destructive-command (next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 "Find previous destructive command in the history of destructive commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 With prefix argument, find next destructive command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (let (cmd vip-intermediate-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (if (eq last-command 'vip-display-current-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 ;; repeated search through command history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 (setq vip-intermediate-command 'repeating-display-destructive-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 ;; first search through command history--set temp ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (setq vip-temp-command-ring (copy-list vip-command-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (setq cmd (if next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (vip-special-ring-rotate1 vip-temp-command-ring 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (vip-special-ring-rotate1 vip-temp-command-ring -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (if (null cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (setq vip-d-com cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 (vip-display-current-destructive-command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (defun vip-next-destructive-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 "Find next destructive command in the history of destructive commands."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (vip-prev-destructive-command 'next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 (defun vip-insert-prev-from-insertion-ring (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 "Cycle through insertion ring in the direction of older insertions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 Undoes previous insertion and inserts new.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 With prefix argument, cycles in the direction of newer elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 In minibuffer, this command executes whatever the invocation key is bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 to in the global map, instead of cycling through the insertion ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (let (vip-intermediate-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (if (eq last-command 'vip-insert-from-insertion-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 (progn ; repeated search through insertion history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 (setq vip-intermediate-command 'repeating-insertion-from-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 (if (eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 (undo 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 (if vip-last-inserted-string-from-insertion-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (backward-delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 (length vip-last-inserted-string-from-insertion-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 ;;first search through insertion history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (setq vip-temp-insertion-ring (copy-list vip-insertion-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (setq this-command 'vip-insert-from-insertion-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 ;; so that things will be undone properly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (setq buffer-undo-list (cons nil buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (setq vip-last-inserted-string-from-insertion-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 ;; this change of vip-intermediate-command must come after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 ;; vip-special-ring-rotate1, so that the ring will rotate, but before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 ;; insertion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (setq vip-intermediate-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (if vip-last-inserted-string-from-insertion-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (insert vip-last-inserted-string-from-insertion-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (defun vip-insert-next-from-insertion-ring ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 "Cycle through insertion ring in the direction of older insertions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 Undo previous insertion and inserts new."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 (vip-insert-prev-from-insertion-ring 'next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 ;; some region utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 ;; 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
1998 (defun vip-add-newline-at-eob-if-necessary ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 ;; make sure all lines end with newline, unless in the minibuffer or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 ;; when requested otherwise (require-final-newline is nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (if (and (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 require-final-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 (not (vip-is-in-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 (not buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 (insert "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (defun vip-yank-defun ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 (mark-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 (copy-region-as-kill (point) (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 ;; Enlarge region between BEG and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (defun vip-enlarge-region (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 (or beg (setq beg end)) ; if beg is nil, set to end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (or end (setq end beg)) ; if end is nil, set to beg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (if (< beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (progn (goto-char beg) (set-mark end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (set-mark beg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (if (or (not (eobp)) (not (bolp))) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (if (not (eobp)) (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (if (> beg end) (exchange-point-and-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 ;; Quote region by each line with a user supplied string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 (defun vip-quote-region ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (setq vip-quote-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 "Quote string: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 'vip-quote-region-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 vip-quote-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 (vip-enlarge-region (point) (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 (if (> (point) (mark t)) (exchange-point-and-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (insert vip-quote-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 (while (and (< (point) (mark t)) (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 (insert vip-quote-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 ;; Tells whether BEG is on the same line as END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 ;; If one of the args is nil, it'll return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (defun vip-same-line (beg end)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2051 (let ((selective-display nil)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2052 (incr 0)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2053 temp)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2054 (if (and beg end (> beg end))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2055 (setq temp beg
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2056 beg end
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2057 end temp))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2058 (if (and beg end)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2059 (cond ((or (> beg (point-max)) (> end (point-max))) ; out of range
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2060 nil)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2061 (t
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2062 ;; This 'if' is needed because Emacs treats the next empty line
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2063 ;; as part of the previous line.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2064 (if (= (vip-line-pos 'start) end)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2065 (setq incr 1))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2066 (<= (+ incr (count-lines beg end)) 1))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2067 ))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
2068
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
2069
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 ;; Check if the string ends with a newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (defun vip-end-with-a-newline-p (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (or (string= string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 (= (vip-seq-last-elt string) ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 (defun vip-tmp-insert-at-eob (msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 (let ((savemax (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (goto-char savemax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (insert msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 (sit-for 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (goto-char savemax) (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 ;;; Minibuffer business
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (defsubst vip-set-minibuffer-style ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (defun vip-minibuffer-setup-sentinel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (let ((hook (if vip-vi-style-in-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 'vip-change-state-to-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 'vip-change-state-to-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (funcall hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 ;; Interpret last event in the local map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 (defun vip-exit-minibuffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (let (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (setq command (local-key-binding (char-to-string last-command-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 (if command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 (command-execute command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 (exit-minibuffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 ;;; Reading string with history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 (defun vip-read-string-with-history (prompt &optional initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 history-var default keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 ;; Read string, prompting with PROMPT and inserting the INITIAL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 ;; input is an empty string. Use KEYMAP, if given, or the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 ;; minibuffer-local-map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 ;; Default value is displayed until the user types something in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 ;; minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (let ((minibuffer-setup-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (if (stringp initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 ;; don't wait if we have unread events or in kbd macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (or unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 executing-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (sit-for 840))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (insert initial)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (vip-minibuffer-setup-sentinel)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (val "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 (padding "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 temp-msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (setq keymap (or keymap minibuffer-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 initial (or initial "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 temp-msg (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (format "(default: %s) " default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (setq vip-incomplete-ex-cmd nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (setq val (read-from-minibuffer prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (concat temp-msg initial val padding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 keymap nil history-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 (setq minibuffer-setup-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 padding (vip-array-to-string (this-command-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 temp-msg "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 ;; the following tries to be smart about what to put in history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (if (not (string= val (car (eval history-var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 (set history-var (cons val (eval history-var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (string= (nth 0 (eval history-var)) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (set history-var (cdr (eval history-var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 ;; If the user enters nothing but the prev cmd wasn't vip-ex,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 ;; vip-command-argument, or `! shell-command', this probably means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 ;; that the user typed something then erased. Return "" in this case, not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 ;; the default---the default is too confusing in this case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (cond ((and (string= val "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 (not (string= prompt "!")) ; was a `! shell-command'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (not (memq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 '(vip-ex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 vip-command-argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 ((string= val "") (or default ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 (t val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 ;; insertion commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 ;; Called when state changes from Insert Vi command mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 ;; Repeats the insertion command if Insert state was entered with prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 ;; argument > 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 (defun vip-repeat-insert-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (let ((i-com (car vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (val (nth 1 vip-d-com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 (char (nth 2 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (if (and val (> val 1)) ; first check that val is non-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 (setq vip-d-com (list i-com (1- val) ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (vip-repeat nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (setq vip-d-com (list i-com val char nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 (defun vip-insert (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 "Insert before point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (vip-loop val (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (defun vip-append (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 "Append after point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 (vip-set-destructive-command (list 'vip-append val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (if (not (eolp)) (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (vip-loop val (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (defun vip-Append (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 "Append at end of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (vip-loop val (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 (defun vip-Insert (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 "Insert before first non-white."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (vip-loop val (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (defun vip-open-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 "Open line below."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (vip-set-destructive-command (list 'vip-open-line val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 (let ((col (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (newline 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (indent-according-to-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 (indent-to col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 (newline 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (indent-according-to-mode)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2261 (indent-to col))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2262 (vip-change-state-to-insert)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 (defun vip-Open-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 "Open line above."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 (let ((col (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 (indent-according-to-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (indent-to col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (indent-according-to-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (indent-to col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 (vip-change-state-to-insert)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 (defun vip-open-line-at-point (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 "Open line at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (list 'vip-open-line-at-point val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (vip-change-state-to-insert))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (defun vip-substitute (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 "Substitute characters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (forward-char val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 (vip-change-subr (mark t) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (vip-change (mark t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (defun vip-substitute-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 "Substitute lines."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (vip-line (cons arg ?C)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 ;; Prepare for replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (defun vip-start-replace ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 (setq vip-began-as-replace t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 vip-sitting-in-replace t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 vip-replace-chars-to-delete 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 vip-replace-chars-deleted 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 (vip-add-hook 'vip-after-change-functions 'vip-replace-mode-spy-after t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 ;; this will get added repeatedly, but no harm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 (add-hook 'after-change-functions 'vip-after-change-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (add-hook 'before-change-functions 'vip-before-change-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (vip-move-marker-locally 'vip-last-posn-in-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 (vip-add-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 (vip-add-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2348 ;; guard against a smartie who switched from R-replace to normal replace
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2349 (vip-remove-hook
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2350 'vip-post-command-hooks 'vip-R-state-post-command-sentinel)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2351 (if overwrite-mode (overwrite-mode nil))
0
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 ;; checks how many chars were deleted by the last change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (defun vip-replace-mode-spy-before (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (setq vip-replace-chars-deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (- end beg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (max 0 (- end (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (max 0 (- (vip-replace-start) beg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 ;; 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
2364 (defun vip-replace-mode-spy-after (beg end length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 (if (memq vip-intermediate-command '(repeating-insertion-from-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 (setq vip-replace-chars-to-delete 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 (vip-move-marker-locally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 'vip-last-posn-in-replace-region (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 (let (beg-col end-col real-end chars-to-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 (setq real-end (min end (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (setq beg-col (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (goto-char real-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (setq end-col (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 ;; If beg of change is outside the replacement region, then don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 ;; delete anything in the repl region (set chars-to-delete to 0).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 ;; This works fine except that we have to take special care of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 ;; sometimes simply shifts the repl region rightwards, without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 ;; deleting an equal amount of characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 ;; The reason why new-dabbrev.el causes this are this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 ;; if one dinamically completes a partial word that starts before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 ;; replacement region (but ends inside) then new-dabbrev.el first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 ;; moves cursor backwards, to the beginning of the word to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 ;; completed (say, pt A). Then it inserts the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 ;; completed word and then deletes the old, incomplete part.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 ;; Since the complete word is inserted at position before the repl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 ;; region, the next If-statement would have set chars-to-delete to 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 ;; unless we check for the current command, which must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 ;; dabbrev-expand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 ;; In fact, it might be also useful to have overlays for insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 ;; regions as well, since this will let us capture the situation when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 ;; dabbrev-expand goes back past the insertion point to find the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 ;; beginning of the word to be expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 (if (or (and (<= (vip-replace-start) beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 (<= beg (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (and (= length 0) (eq this-command 'dabbrev-expand)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (setq chars-to-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (max (- end-col beg-col) (- real-end beg) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 (setq chars-to-delete 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 ;; if beg = last change position, it means that we are within the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 ;; same command that does multiple changes. Moreover, it means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 ;; that we have two subsequent changes (insert/delete) that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 ;; complement each other.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (if (= beg (marker-position vip-last-posn-in-replace-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 (setq vip-replace-chars-to-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 (- (+ chars-to-delete vip-replace-chars-to-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 vip-replace-chars-deleted))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 (setq vip-replace-chars-to-delete chars-to-delete))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 (vip-move-marker-locally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 'vip-last-posn-in-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 (max (if (> end (vip-replace-end)) (vip-replace-start) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 (or (marker-position vip-last-posn-in-replace-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 (setq vip-replace-chars-to-delete
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2427 (max 0
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2428 (min vip-replace-chars-to-delete
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2429 (- (vip-replace-end) vip-last-posn-in-replace-region)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2430 (- (vip-line-pos 'end) vip-last-posn-in-replace-region)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2431 )))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 ;; posn is within the overlay.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 (defun vip-finish-change (posn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (vip-remove-hook 'vip-after-change-functions 'vip-replace-mode-spy-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (vip-remove-hook 'vip-before-change-functions 'vip-replace-mode-spy-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 (vip-remove-hook 'vip-post-command-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 'vip-replace-state-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 (vip-remove-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
2444 (vip-restore-cursor-color-after-replace)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 (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
2446 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 (if (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 vip-replace-overlay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (>= posn (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 (< posn (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 (delete-region posn (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 (if (eq vip-current-state 'replace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 (vip-downgrade-to-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 ;; replace mode ended => nullify vip-last-posn-in-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (vip-hide-replace-overlay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 (vip-refresh-mode-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 (vip-put-string-on-kill-ring vip-last-replace-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 ;; Make STRING be the first element of the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (defun vip-put-string-on-kill-ring (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (setq kill-ring (cons string kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (if (> (length kill-ring) kill-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (setq kill-ring-yank-pointer kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (defun vip-finish-R-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (vip-remove-hook 'vip-post-command-hooks 'vip-R-state-post-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (vip-remove-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (vip-downgrade-to-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (defun vip-start-R-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 ;; 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
2478 (overwrite-mode 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 (vip-add-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 (vip-add-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2483 ;; guard against a smartie who switched from R-replace to normal replace
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2484 (vip-remove-hook
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2485 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 (defun vip-replace-state-exit-cmd ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 "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
2492 These keys are ESC, RET, and LineFeed"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 (if overwrite-mode ;; If you are in replace mode invoked via 'R'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 (vip-finish-R-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 (vip-finish-change vip-last-posn-in-replace-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 (let (com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 (if (eq this-command 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 (setq com 'vip-exit-insert-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (vip-set-unread-command-events last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 (setq com (key-binding (read-key-sequence nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 (command-execute com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 (vip-message-conditions conds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (vip-hide-replace-overlay))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2510 (defun vip-replace-state-carriage-return ()
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2511 "Implements carriage return in Viper replace state."
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2512 (interactive)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2513 ;; If Emacs start supporting overlay maps, as it currently supports
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2514 ;; text-property maps, we could do away with vip-replace-minor-mode and
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2515 ;; just have keymap attached to replace overlay. Then the "if part" of this
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2516 ;; statement can be deleted.
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2517 (if (or (< (point) (vip-replace-start))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2518 (> (point) (vip-replace-end)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2519 (let (vip-replace-minor-mode com)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2520 (vip-set-unread-command-events last-input-char)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2521 (setq com (key-binding (read-key-sequence nil)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2522 (condition-case conds
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2523 (command-execute com)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2524 (error
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2525 (vip-message-conditions conds))))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2526 (if (not vip-allow-multiline-replace-regions)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2527 (vip-replace-state-exit-cmd)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2528 (if (vip-same-line (point) (vip-replace-end))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2529 (vip-replace-state-exit-cmd)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2530 (vip-kill-line nil)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2531 (vip-next-line-at-bol nil)))))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2532
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 ;; This is the function bound to 'R'---unlimited replace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 ;; Similar to Emacs's own overwrite-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 (defun vip-overwrite (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 "Begin overwrite mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 (com (vip-getcom arg)) (len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 ;; Viper saves inserted text in vip-last-insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 (setq len (length vip-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 (delete-char len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 (vip-loop val (vip-yank-last-insertion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 (setq last-command 'vip-overwrite)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (vip-set-replace-overlay (point) (vip-line-pos 'end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 (vip-change-state-to-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 )))
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 ;; line commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (defun vip-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 (let ((val (car arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 (com (cdr arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (vip-next-line-carefully (1- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 ;; 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
2564 ;; line of buffer when this line has no \n.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (vip-add-newline-at-eob-if-necessary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 (vip-execute-com 'vip-line val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (if (and (eobp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 (defun vip-yank-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 "Yank ARG lines (in Vi's sense)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 (let ((val (vip-p-val arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (vip-line (cons val ?Y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 ;; region commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (defun vip-region (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 "Execute command on a region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (vip-execute-com 'vip-region val com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (defun vip-Region (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 "Execute command on a Region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 (vip-execute-com 'vip-Region val com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (defun vip-replace-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 "Replace the following ARG chars by the character read."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (if (and (eolp) (bolp)) (error "No character to replace here"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (vip-replace-char-subr com val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (if (and (eolp) (not (bolp))) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (list 'vip-replace-char val ?r nil vip-d-char nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (defun vip-replace-char-subr (com arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (let ((take-care-of-iso-accents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (and (boundp 'iso-accents-mode) vip-automatic-iso-accents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (setq char (if (equal com ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 vip-d-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 ;; get European characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (iso-accents-mode 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (vip-set-unread-command-events char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 (setq char (aref (read-key-sequence nil) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (iso-accents-mode -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (delete-char arg t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 (setq vip-d-char char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 (vip-loop (if (> arg 0) arg (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 (if (eq char ?\C-m) (insert "\n") (insert char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 (backward-char arg)))
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 ;; basic cursor movement. j, k, l, h commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (defun vip-forward-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 "Move point right ARG characters (left if ARG negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 On reaching end of line, stop and signal error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 ;; the boundary condition check gets weird here because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 ;; forward-char may be the parameter of a delete, and 'dl' works
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 ;; 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
2645 ;; the forward motion before the 'vip-execute-com', but, of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 ;; course, 'dl' doesn't work on an empty line, so we have to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 ;; catch that condition before 'vip-execute-com'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 (if (and (eolp) (bolp)) (error "") (forward-char val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (if com (vip-execute-com 'vip-forward-char val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 (if (eolp) (progn (backward-char 1) (error ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 (forward-char val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (if com (vip-execute-com 'vip-forward-char val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 (defun vip-backward-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 "Move point left ARG characters (right if ARG negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 On reaching beginning of line, stop and signal error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (if (bolp) (error "") (backward-char val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 (if com (vip-execute-com 'vip-backward-char val com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (backward-char val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 (if com (vip-execute-com 'vip-backward-char val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 ;; Like forward-char, but doesn't move at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (defun vip-forward-char-carefully (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (setq arg (or arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (if (>= (point-max) (+ (point) arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (forward-char arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (goto-char (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 ;; Like backward-char, but doesn't move at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (defun vip-backward-char-carefully (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (setq arg (or arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (if (<= (point-min) (- (point) arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (backward-char arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 (goto-char (point-min))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 (defun vip-next-line-carefully (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 (next-line arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 ;;; Word command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 ;; for word movement. When executed with a destructive command, \n is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 ;; usually left untouched for the last word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 ;; 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
2696 ;; separator. However, \n is always a separator. Also, if vip-syntax-preference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 ;; is 'vi, then `_' is part of the word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 ;; skip only one \n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 (defun vip-skip-separators (forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 (if forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 (vip-skip-all-separators-forward 'within-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (if (looking-at "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 (vip-skip-all-separators-forward 'within-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (vip-skip-all-separators-backward 'within-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 (if (looking-at "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 (vip-skip-all-separators-backward 'within-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 (forward-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 (defun vip-forward-word-kernel (val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 (while (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 (cond ((vip-looking-at-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 (vip-skip-alpha-forward "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 (vip-skip-separators t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 ((vip-looking-at-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 (vip-skip-separators t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 ((not (vip-looking-at-alphasep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 (vip-skip-nonalphasep-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (vip-skip-separators t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 (setq val (1- val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 ;; first search backward for pat. Then skip chars backwards using aux-pat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (defun vip-fwd-skip (pat aux-pat lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (if (and (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (re-search-backward pat lim t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 (= (point) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 (goto-char (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (skip-chars-backward aux-pat lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (if (= (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (vip-forward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 (defun vip-forward-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 "Forward word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 (vip-forward-word-kernel val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 (if com (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 (cond ((memq com (list ?c (- ?c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 ;; Yank words including the whitespace, but not newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 ((memq com (list ?y (- ?y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 ((vip-dotable-command-p com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 (vip-execute-com 'vip-forward-word val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 (defun vip-forward-Word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 "Forward word delimited by white characters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 (vip-skip-nonseparators 'forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 (vip-skip-separators t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 (if com (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 (cond ((memq com (list ?c (- ?c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 ;; Yank words including the whitespace, but not newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 ((memq com (list ?y (- ?y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 ((vip-dotable-command-p com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (vip-execute-com 'vip-forward-Word val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 ;; this is a bit different from Vi, but Vi's end of word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 ;; makes no sense whatsoever
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 (defun vip-end-of-word-kernel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 (if (vip-end-of-word-p) (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 (if (vip-looking-at-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 (vip-skip-all-separators-forward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 (cond ((vip-looking-at-alpha) (vip-skip-alpha-forward "_"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 (vip-backward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 (defun vip-end-of-word-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 (or (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 (cond ((vip-looking-at-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 (not (vip-looking-at-alpha)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 ((not (vip-looking-at-alphasep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 (vip-looking-at-alphasep))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 (defun vip-end-of-word (arg &optional careful)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 "Move point to end of current word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 (vip-loop val (vip-end-of-word-kernel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 (vip-execute-com 'vip-end-of-word val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (defun vip-end-of-Word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 "Forward to end of word delimited by white character."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 (vip-end-of-word-kernel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 (vip-skip-nonseparators 'forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 (backward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (vip-execute-com 'vip-end-of-Word val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (defun vip-backward-word-kernel (val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 (while (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (cond ((vip-looking-at-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 (vip-skip-alpha-backward "_"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 ((vip-looking-at-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 (vip-skip-separators nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 (cond ((vip-looking-at-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 (vip-skip-alpha-backward "_"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 ((not (vip-looking-at-alphasep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 (vip-skip-nonalphasep-backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 (t (forward-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 ((not (vip-looking-at-alphasep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 (vip-skip-nonalphasep-backward)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (setq val (1- val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (defun vip-backward-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 "Backward word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 (let (i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 (backward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (if i (forward-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (vip-backward-word-kernel val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 (if com (vip-execute-com 'vip-backward-word val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 (defun vip-backward-Word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 "Backward word delimited by white character."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 (let (i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 (backward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 (if i (forward-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 (vip-loop val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 (vip-skip-separators nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 (vip-skip-nonseparators 'backward)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 (if com (vip-execute-com 'vip-backward-Word val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881
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 ;; line commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 (defun vip-beginning-of-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 "Go to beginning of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 (beginning-of-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 (if com (vip-execute-com 'vip-beginning-of-line val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 (defun vip-bol-and-skip-white (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 "Beginning of line at first non-white character."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 (forward-to-indentation (1- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 (if com (vip-execute-com 'vip-bol-and-skip-white val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 (defun vip-goto-eol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 "Go to end of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 (end-of-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 (if com (vip-execute-com 'vip-goto-eol val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 (if (and (eolp) (not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 ;; a fix for vip-change-to-eol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 (not (equal vip-current-state 'insert-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 (defun vip-goto-col (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 "Go to ARG's column."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 (let ((val (vip-p-val arg))
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2928 (com (vip-getcom arg))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2929 line-len)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2930 (setq line-len (- (vip-line-pos 'end) (vip-line-pos 'start)))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2931 (if com (vip-move-marker-locally 'vip-com-point (point)))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2932 (beginning-of-line)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2933 (forward-char (1- (min line-len val)))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2934 (while (> (current-column) (1- val))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2935 (backward-char 1))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2936 (if com (vip-execute-com 'vip-goto-col val com))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 (end-of-line)
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2939 (if (> val (current-column)) (error "")))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 110
diff changeset
2940 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 (defun vip-next-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 "Go to next line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 (next-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 (if (and (eolp) (not (bolp))) (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 (setq this-command 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 (if com (vip-execute-com 'vip-next-line val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 (defun vip-next-line-at-bol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 "Next line at beginning of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 (if (eobp) (error "Last line in buffer")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 (forward-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 (if com (vip-execute-com 'vip-next-line-at-bol val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 (defun vip-previous-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 "Go to previous line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 (previous-line val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 (if vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 (if (and (eolp) (not (bolp))) (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 (setq this-command 'previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 (if com (vip-execute-com 'vip-previous-line val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 (defun vip-previous-line-at-bol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 "Previous line at beginning of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 (vip-leave-region-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 (if (bobp) (error "First line in buffer")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 (forward-line (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 (if com (vip-execute-com 'vip-previous-line val com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 (defun vip-change-to-eol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 "Change to end of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 (vip-goto-eol (cons arg ?c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 (defun vip-kill-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 "Delete line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 (vip-goto-eol (cons arg ?d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 (defun vip-erase-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 "Erase line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 (vip-beginning-of-line (cons arg ?d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 ;;; Moving around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 (defun vip-goto-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 "Go to ARG's line. Without ARG go to end of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 (vip-move-marker-locally 'vip-com-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 (if (null val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 (forward-line (1- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 ;; positioning is done twice: before and after command execution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 (if com (vip-execute-com 'vip-goto-line val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 ;; Find ARG's occurrence of CHAR on the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 ;; adjust point after search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 (defun vip-find-char (arg char forward offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 (or (char-or-string-p char) (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 (let ((arg (if forward arg (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 (cmd (if (eq vip-intermediate-command 'vip-repeat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 (nth 5 vip-d-com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 (vip-array-to-string (this-command-keys))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 ;; forward search begins here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 (if (eolp) (error "Command `%s': At end of line" cmd) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 ;; forward search ends here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 (progn (end-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 ;; backward search begins from here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 (error "Command `%s': At beginning of line" cmd) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 ;; backward search ends here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 (progn (beginning-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 ;; if arg > 0, point is forwarded before search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 (if (> arg 0) (goto-char (1+ (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 (if (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 (search-forward (char-to-string char) nil 0 arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 (setq point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 (error "Command `%s': `%c' not found" cmd char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 (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
3071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 (defun vip-find-char-forward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 "Find char on the line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 If called interactively read the char to find from the terminal, and if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 called from vip-repeat, the char last used is used. This behaviour is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 controlled by the sign of prefix numeric value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 (cmd-representation (nth 5 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 (if (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 ;; this means that the function was called interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 (setq vip-f-char (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 vip-f-forward t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 vip-f-offset nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 ;; vip-repeat --- set vip-F-char from command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 (setq vip-F-char (if (stringp cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 (vip-seq-last-elt cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 vip-f-char vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 (setq val (- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 (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
3094 (setq val (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 (setq vip-F-char vip-f-char) ; set new vip-F-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 (vip-execute-com 'vip-find-char-forward val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 (defun vip-goto-char-forward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 "Go up to char ARG forward on line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 (cmd-representation (nth 5 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 (if (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 ;; this means that the function was called interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 (setq vip-f-char (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 vip-f-forward t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 vip-f-offset t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 ;; vip-repeat --- set vip-F-char from command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 (setq vip-F-char (if (stringp cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 (vip-seq-last-elt cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 vip-f-char vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 (setq val (- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 (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
3120 (setq val (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 (setq vip-F-char vip-f-char) ; set new vip-F-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 (vip-execute-com 'vip-goto-char-forward val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 (defun vip-find-char-backward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 "Find char ARG on line backward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 (interactive "P")
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 (cmd-representation (nth 5 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 (if (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 ;; this means that the function was called interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 (setq vip-f-char (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 vip-f-forward nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 vip-f-offset nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 ;; vip-repeat --- set vip-F-char from command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 (setq vip-F-char (if (stringp cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 (vip-seq-last-elt cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 vip-f-char vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 (setq val (- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 (vip-find-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 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
3147 (setq val (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 (setq vip-F-char vip-f-char) ; set new vip-F-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 (vip-execute-com 'vip-find-char-backward val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 (defun vip-goto-char-backward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 "Go up to char ARG backward on line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 (cmd-representation (nth 5 vip-d-com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 (if (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 ;; this means that the function was called interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 (setq vip-f-char (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 vip-f-forward nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 vip-f-offset t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 ;; vip-repeat --- set vip-F-char from command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 (setq vip-F-char (if (stringp cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 (vip-seq-last-elt cmd-representation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 vip-f-char vip-F-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 (setq val (- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 (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
3172 (setq val (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 (setq vip-F-char vip-f-char) ; set new vip-F-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 (vip-execute-com 'vip-goto-char-backward val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 (defun vip-repeat-find (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 "Repeat previous find command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 (vip-find-char val vip-f-char vip-f-forward vip-f-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 (if vip-f-forward (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 (vip-execute-com 'vip-repeat-find val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 (defun vip-repeat-find-opposite (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 "Repeat previous find command in the opposite direction."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 (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
3199 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 (if vip-f-forward (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 (vip-execute-com 'vip-repeat-find-opposite val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 ;; window scrolling etc.
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-other-window (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 "Switch to other window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 (other-window arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 (or (not (eq vip-current-state 'emacs-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 (string= (buffer-name (current-buffer)) " *Minibuf-1*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 (vip-change-state-to-vi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 (defun vip-window-top (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 "Go to home window line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 (move-to-window-line (1- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 ;; positioning is done twice: before and after command execution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 (if com (vip-execute-com 'vip-window-top val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 (defun vip-window-middle (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 "Go to middle window line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 (com (vip-getCom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 (if (not (pos-visible-in-window-p (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 (setq lines (count-lines (window-start) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 (move-to-window-line (+ (/ lines 2) (1- val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 ;; positioning is done twice: before and after command execution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 (if com (vip-execute-com 'vip-window-middle val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 (defun vip-window-bottom (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 "Go to last window line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 (move-to-window-line (- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 ;; positioning is done twice: before and after command execution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 (if com (vip-execute-com 'vip-window-bottom val com))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 (defun vip-line-to-top (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 "Put current line on the home line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 (recenter (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 (defun vip-line-to-middle (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 "Put current line on the middle line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 (defun vip-line-to-bottom (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 "Put current line on the last line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 (recenter (- (window-height) (1+ arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3291 ;; If point is within vip-search-scroll-threshold of window top or bottom,
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3292 ;; scroll up or down 1/7 of window height, depending on whether we are at the
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3293 ;; bottom or at the top of the window. This function is called by vip-search
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3294 ;; (which is called from vip-search-forward/backward/next). If the value of
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3295 ;; vip-search-scroll-threshold is negative - don't scroll.
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3296 (defun vip-adjust-window ()
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3297 (let ((win-height (if vip-emacs-p
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3298 (1- (window-height)) ; adjust for modeline
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3299 (window-displayed-height)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3300 (pt (point))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3301 at-top-p at-bottom-p
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3302 min-scroll direction)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3303 (save-excursion
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3304 (move-to-window-line 0) ; top
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3305 (setq at-top-p
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3306 (<= (count-lines pt (point))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3307 vip-search-scroll-threshold))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3308 (move-to-window-line -1) ; bottom
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3309 (setq at-bottom-p
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3310 (<= (count-lines pt (point)) vip-search-scroll-threshold))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3311 )
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3312 (cond (at-top-p (setq min-scroll (1- vip-search-scroll-threshold)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3313 direction 1))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3314 (at-bottom-p (setq min-scroll (1+ vip-search-scroll-threshold)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3315 direction -1)))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3316 (if min-scroll
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3317 (recenter
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3318 (* (max min-scroll (/ win-height 7)) direction)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3319 ))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3320
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 ;; paren match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 ;; must correct this to only match ( to ) etc. On the other hand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 ;; it is good that paren match gets confused, because that way you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 ;; catch _all_ imbalances.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 (defun vip-paren-match (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 "Go to the matching parenthesis."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 (interactive "P")
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3330 (vip-leave-region-active)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 (let ((com (vip-getcom arg))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3332 parse-sexp-ignore-comments anchor-point)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 (if (integerp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 (if (or (> arg 99) (< arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 (error "Prefix must be between 1 and 99")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 (goto-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 (if (> (point-max) 80000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 (* (/ (point-max) 100) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 (/ (* (point-max) arg) 100)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 (let (beg-lim end-lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 (if (and (eolp) (not (bolp))) (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 (if (not (looking-at "[][(){}]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 (setq anchor-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 (setq beg-lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 (setq end-lim (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 (cond ((re-search-forward "[][(){}]" end-lim t)
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 ((re-search-backward "[][(){}]" beg-lim t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 (error "No matching character on line"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 (cond ((looking-at "[\(\[{]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 (vip-execute-com 'vip-paren-match nil com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 (backward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361 (anchor-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364 (vip-move-marker-locally 'vip-com-point anchor-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 (vip-execute-com 'vip-paren-match nil com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 ((looking-at "[])}]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 (if com (vip-execute-com 'vip-paren-match nil com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 (t (error ""))))))
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 ;; sentence ,paragraph and heading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 (defun vip-forward-sentence (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379 "Forward sentence."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 (forward-sentence val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 (if com (vip-execute-com 'vip-forward-sentence nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 (defun vip-backward-sentence (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 "Backward sentence."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 (backward-sentence val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 (if com (vip-execute-com 'vip-backward-sentence nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398 (defun vip-forward-paragraph (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399 "Forward paragraph."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 (forward-paragraph val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 (vip-execute-com 'vip-forward-paragraph nil com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 (defun vip-backward-paragraph (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 "Backward paragraph."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 (backward-paragraph val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 (vip-execute-com 'vip-backward-paragraph nil com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 (backward-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 ;; should be mode-specific etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 (defun vip-prev-heading (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432 (re-search-backward vip-heading-start nil t val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 (if com (vip-execute-com 'vip-prev-heading nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 (defun vip-heading-end (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 (re-search-forward vip-heading-end nil t val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443 (if com (vip-execute-com 'vip-heading-end nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 (defun vip-next-heading (arg)
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 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 (re-search-forward vip-heading-start nil t val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 (if com (vip-execute-com 'vip-next-heading nil com))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 ;; scrolling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 (setq scroll-step 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3460 (defun vip-scroll-screen (arg)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 "Scroll to next screen."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 (interactive "p")
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3463 (condition-case nil
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3464 (if (> arg 0)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3465 (while (> arg 0)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3466 (scroll-up)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3467 (setq arg (1- arg)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3468 (while (> 0 arg)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3469 (scroll-down)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3470 (setq arg (1+ arg))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3471 (error (beep 1)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3472 (if (> arg 0)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3473 (progn
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3474 (message "End of buffer")
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3475 (goto-char (point-max)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3476 (message "Beginning of buffer")
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3477 (goto-char (point-min))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3478 ))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3479
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3480 (defun vip-scroll-screen-back (arg)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 "Scroll to previous screen."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482 (interactive "p")
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3483 (vip-scroll-screen (- arg)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 (defun vip-scroll-down (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 "Pull down half screen."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 (scroll-down (/ (window-height) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 (scroll-down arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 (error (beep 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 (message "Beginning of buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 (goto-char (point-min)))))
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-scroll-down-one (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 "Scroll up one 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 (scroll-down arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 (defun vip-scroll-up (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 "Pull up half screen."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 (scroll-up (/ (window-height) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 (scroll-up arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 (error (beep 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 (message "End of buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 (goto-char (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 (defun vip-scroll-up-one (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 "Scroll down one line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 (scroll-up arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518 ;; searching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520 (defun vip-if-string (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 (let ((s (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 nil ; no initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 'vip-search-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 (car vip-search-history))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 (if (not (string= s ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 (setq vip-s-string s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 (defun vip-toggle-search-style (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 "Toggle the value of vip-case-fold-search/vip-re-search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 Without prefix argument, will ask which search style to toggle. With prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533 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
3534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 Although this function is bound to \\[vip-toggle-search-style], the most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 convenient way to use it is to bind `//' to the macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 `1 M-x vip-toggle-search-style' and `///' to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 toggle case-fold-search and hitting `/' three times witth toggle regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 search. Macros are more convenient in this case because they don't affect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 the Emacs binding of `/'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 (let (msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 (cond ((or (eq arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 (if vip-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 "case-insensitive" "case-sensitive")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 (if vip-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 "case-sensitive"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 "case-insensitive")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 (setq vip-case-fold-search (null vip-case-fold-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 (if vip-case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 (setq msg "Search becomes case-insensitive")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 (setq msg "Search becomes case-sensitive")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 ((or (eq arg 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 "regexp-search" "vanilla-search")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 "vanilla-search"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 "regexp-search")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 (setq vip-re-search (null vip-re-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 (setq msg "Search becomes regexp-style")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 (setq msg "Search becomes vanilla-style")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 (setq msg "Search style remains unchanged")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 (prin1 msg t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3572 (defun vip-set-vi-search-style-macros (unset)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3573 "Set the macros for toggling the search style in Viper's vi-state.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3574 The macro that toggles case sensitivity is bound to `//', and the one that
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3575 toggles regexp search is bound to `///'.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3576 With a prefix argument, this function unsets the macros. "
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3577 (interactive "P")
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3578 (or noninteractive
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3579 (if (not unset)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3580 (progn
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3581 ;; toggle case sensitivity in search
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3582 (vip-record-kbd-macro
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3583 "//" 'vi-state
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3584 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3585 't)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3586 ;; toggle regexp/vanila search
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3587 (vip-record-kbd-macro
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3588 "///" 'vi-state
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3589 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3590 't)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3591 (if (interactive-p)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3592 (message
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3593 "// and /// now toggle case-sensitivity and regexp search.")))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3594 (vip-unrecord-kbd-macro "//" 'vi-state)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3595 (sit-for 2)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3596 (vip-unrecord-kbd-macro "///" 'vi-state))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3597
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3598 (defun vip-set-emacs-search-style-macros (unset &optional arg-majormode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3599 "Set the macros for toggling the search style in Viper's emacs-state.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3600 The macro that toggles case sensitivity is bound to `//', and the one that
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3601 toggles regexp search is bound to `///'.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3602 With a prefix argument, this function unsets the macros.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3603 If the optional prefix argument is non-nil and specifies a valid major mode,
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3604 this sets the macros only in the macros in that major mode. Otherwise,
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3605 the macros are set in the current major mode.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3606 \(When unsetting the macros, the second argument has no effect.\)"
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3607 (interactive "P")
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3608 (or noninteractive
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3609 (if (not unset)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3610 (progn
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3611 ;; toggle case sensitivity in search
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3612 (vip-record-kbd-macro
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3613 "//" 'emacs-state
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3614 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3615 (or arg-majormode major-mode))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3616 ;; toggle regexp/vanila search
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3617 (vip-record-kbd-macro
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3618 "///" 'emacs-state
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3619 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3620 (or arg-majormode major-mode))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3621 (if (interactive-p)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3622 (message
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3623 "// and /// now toggle case-sensitivity and regexp search.")))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3624 (vip-unrecord-kbd-macro "//" 'emacs-state)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3625 (sit-for 2)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3626 (vip-unrecord-kbd-macro "///" 'emacs-state))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3627
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629 (defun vip-search-forward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 "Search a string forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 ARG is used to find the ARG's occurrence of the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 Null string will repeat previous search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 (old-str vip-s-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 (setq vip-s-forward t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 (vip-if-string "/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 ;; this is not used at present, but may be used later
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640 (if (or (not (equal old-str vip-s-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 (not (markerp vip-local-search-start-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 (not (marker-buffer vip-local-search-start-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 (setq vip-local-search-start-marker (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644 (vip-search vip-s-string t val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 (vip-move-marker-locally 'vip-com-point (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 (vip-execute-com 'vip-search-next val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 (defun vip-search-backward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651 "Search a string backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652 ARG is used to find the ARG's occurrence of the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653 Null string will repeat previous search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655 (let ((val (vip-P-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657 (old-str vip-s-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 (setq vip-s-forward nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 (vip-if-string "?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 ;; this is not used at present, but may be used later
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 (if (or (not (equal old-str vip-s-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 (not (markerp vip-local-search-start-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663 (not (marker-buffer vip-local-search-start-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 (setq vip-local-search-start-marker (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 (vip-search vip-s-string nil val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 (vip-move-marker-locally 'vip-com-point (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 (vip-execute-com 'vip-search-next val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 ;; Search for COUNT's occurrence of STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 ;; Search is forward if FORWARD is non-nil, otherwise backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 ;; INIT-POINT is the position where search is to start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675 ;; Arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676 ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 (defun vip-search (string forward arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 &optional no-offset init-point fail-if-not-found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 (if (not (equal string ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 (com (vip-getcom arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 (offset (not no-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 (case-fold-search vip-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 (start-point (or init-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 (if forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 (condition-case nil
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 offset (vip-forward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 (re-search-forward string nil nil val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 (re-search-backward string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 (search-forward string nil nil val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 (search-backward string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 (if (not (equal start-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697 (push-mark start-point t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 (search-failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 (progn
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3701 (message "Search wrapped around BOTTOM of buffer")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 (vip-search string forward (cons 1 com) t start-point 'fail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 ;; don't wait in macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 (or executing-kbd-macro (sit-for 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 ;; delete the wrap-around message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 (goto-char start-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 (error "`%s': %s not found"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711 string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712 (if vip-re-search "Pattern" "String"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 ;; backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 (if vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 (re-search-backward string nil nil val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 (search-backward string nil nil val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720 (if (not (equal start-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721 (push-mark start-point t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 (search-failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 (progn
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3725 (message "Search wrapped around TOP of buffer")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 (vip-search string forward (cons 1 com) t start-point 'fail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 ;; don't wait in macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 (or executing-kbd-macro (sit-for 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 ;; delete the wrap-around message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 (goto-char start-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 (error "`%s': %s not found"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 (if vip-re-search "Pattern" "String"))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3737 ))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3738 ;; pull up or down if at top/bottom of window
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3739 (vip-adjust-window)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3740 ;; highlight the result of search
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3741 ;; don't wait and don't highlight in macros
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3742 (or executing-kbd-macro
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
3743 vip-inside-command-argument-action
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3744 (vip-flash-search-pattern))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3745 )))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 (defun vip-search-next (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 "Repeat previous search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 (if (null vip-s-string) (error vip-NoPrevSearch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 (vip-search vip-s-string vip-s-forward arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 (vip-move-marker-locally 'vip-com-point (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 (vip-execute-com 'vip-search-next val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 (defun vip-search-Next (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 "Repeat previous search in the reverse direction."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 (if (null vip-s-string) (error vip-NoPrevSearch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 (vip-search vip-s-string (not vip-s-forward) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 (vip-move-marker-locally 'vip-com-point (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 (vip-execute-com 'vip-search-Next val com)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 ;; Search contents of buffer defined by one of Viper's motion commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 ;; Repeatable via `n' and `N'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 (defun vip-buffer-search-enable (&optional c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 (cond (c (setq vip-buffer-search-char c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 ((null vip-buffer-search-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 (setq vip-buffer-search-char ?g)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778 (define-key vip-vi-basic-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 (char-to-string vip-buffer-search-char) 'vip-command-argument)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 ;; This is a Viper wraper for isearch-forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 (defun vip-isearch-forward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 "Do incremental search forward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 ;; emacs bug workaround
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 (if (listp arg) (setq arg (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789 (vip-exec-form-in-emacs (list 'isearch-forward arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791 ;; This is a Viper wraper for isearch-backward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792 (defun vip-isearch-backward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 "Do incremental search backward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 ;; emacs bug workaround
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796 (if (listp arg) (setq arg (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 (vip-exec-form-in-emacs (list 'isearch-backward arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3800 ;; visiting and killing files, buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802 (defun vip-switch-to-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3803 "Switch to buffer in the current window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3804 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3805 (let (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3806 (setq buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3807 (read-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3808 (format "Switch to buffer in this window \(%s\): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3809 (buffer-name (other-buffer (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 (switch-to-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 (defun vip-switch-to-buffer-other-window ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814 "Switch to buffer in another window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3816 (let (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 (setq buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 (read-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3819 (format "Switch to buffer in another window \(%s\): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820 (buffer-name (other-buffer (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821 (switch-to-buffer-other-window buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824 (defun vip-kill-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825 "Kill a buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3826 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827 (let (buffer buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3828 (setq buffer-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3829 (read-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830 (format "Kill buffer \(%s\): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831 (buffer-name (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832 (setq buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 (if (null buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835 (get-buffer buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836 (if (null buffer) (error "`%s': No such buffer" buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837 (if (or (not (buffer-modified-p buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840 "Buffer `%s' is modified, are you sure you want to kill it? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 (kill-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 (error "Buffer not killed"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
3846 (defvar vip-smart-suffix-list
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 104
diff changeset
3847 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 "*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
3849 This is useful when you the current directory contains files with the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3850 prefix and many different suffixes. Usually, only one of the suffixes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851 represents an editable file. However, file completion will stop at the `.'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 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
3853 select the appropriate suffix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855 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
3856 corresponding file exists is selected. If no file exists for any of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857 suffixes, the user is asked to confirm.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 To turn this feature off, set this variable to nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861 ;; Try to add suffix to files ending with a `.'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 ;; Useful when the user hits RET on a non-completed file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 (defun vip-file-add-suffix ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 (let ((count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 (len (length vip-smart-suffix-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 (file (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867 found key cmd suff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3869 (if (and vip-smart-suffix-list (string-match "\\.$" file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 (while (and (not found) (< count len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3872 (setq suff (nth count vip-smart-suffix-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3873 count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 (if (file-exists-p (format "%s%s" file suff))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3876 (setq found t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877 (insert suff))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3878
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 (if found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881 (vip-tmp-insert-at-eob " [Please complete file name]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884 (setq cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885 (key-binding (setq key (read-key-sequence nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886 (cond ((eq cmd 'self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887 (if vip-xemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888 (insert (events-to-keys key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889 (insert key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890 ((memq cmd '(exit-minibuffer vip-exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892 (t (command-execute cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898 ;; Advice for use in find-file and read-file-name commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899 (defadvice exit-minibuffer (before vip-exit-minibuffer-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3900 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3901 (run-hooks 'vip-minibuffer-exit-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3902
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3903 (defadvice find-file (before vip-add-suffix-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3904 "Use `read-file-name' for reading arguments."
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3905 (interactive (cons (read-file-name "Find file: " nil default-directory)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3906 ;; if Mule and prefix argument, ask for coding system
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3907 (if (or (boundp 'MULE) ; mule integrated Emacs 19
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3908 (featurep 'mule)) ; mule integrated XEmacs 20
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3909 (list
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3910 (and current-prefix-arg
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3911 (read-coding-system "Coding-system: "))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3912 )))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3914 (defadvice find-file-other-window (before vip-add-suffix-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915 "Use `read-file-name' for reading arguments."
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3916 (interactive (cons (read-file-name "Find file in other window: "
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3917 nil default-directory)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3918 ;; if Mule and prefix argument, ask for coding system
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3919 (if (or (boundp 'MULE) ; mule integrated Emacs 19
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3920 (featurep 'mule)) ; mule integrated XEmacs 20
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3921 (list
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3922 (and current-prefix-arg
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3923 (read-coding-system "Coding-system: "))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3924 )))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 (defadvice find-file-other-frame (before vip-add-suffix-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3927 "Use `read-file-name' for reading arguments."
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3928 (interactive (cons (read-file-name "Find file in other frame: "
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3929 nil default-directory)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3930 ;; if Mule and prefix argument, ask for coding system
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3931 (if (or (boundp 'MULE) ; mule integrated Emacs 19
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3932 (featurep 'mule)) ; mule integrated XEmacs 20
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3933 (list
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3934 (and current-prefix-arg
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3935 (read-coding-system "Coding-system: "))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3936 )))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938 (defadvice read-file-name (around vip-suffix-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3941 ad-do-it))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 ;; yank and pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 (defsubst vip-yank (text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3948 "Yank TEXT silently. This works correctly with Emacs's yank-pop command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3949 (insert text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950 (setq this-command 'yank))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3952 (defun vip-put-back (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3953 "Put back after point/below line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3954 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 (text (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3957 (cond ((vip-valid-register vip-use-register '(digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3958 (current-kill (- vip-use-register ?1) 'do-not-rotate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3959 ((vip-valid-register vip-use-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3960 (get-register (downcase vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3961 (t (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3962 (current-kill 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3963 (if (null text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3964 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3965 (let ((reg vip-use-register))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3966 (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3967 (error vip-EmptyRegister reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3968 (error "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3969 (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3970 (if (vip-end-with-a-newline-p text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3971 (progn
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
3972 (end-of-line)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3973 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3974 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3975 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3976 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3977 (if (not (eolp)) (vip-forward-char-carefully)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3978 (set-marker (vip-mark-marker) (point) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3979 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3980 (list 'vip-put-back val nil vip-use-register nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3981 (vip-loop val (vip-yank text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3982 ;; 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
3983 ;; newline; it leaves the cursor at the beginning when the text contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3984 ;; a newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3985 (if (vip-same-line (point) (mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3986 (or (= (point) (mark)) (vip-backward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3987 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3988 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3989 (back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3990 (vip-deactivate-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3992 (defun vip-Put-back (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3993 "Put back at point/above line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3994 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3995 (let ((val (vip-p-val arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3996 (text (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3997 (cond ((vip-valid-register vip-use-register '(digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3998 (current-kill (- vip-use-register ?1) 'do-not-rotate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3999 ((vip-valid-register vip-use-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4000 (get-register (downcase vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4001 (t (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4002 (current-kill 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4003 (if (null text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4004 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4005 (let ((reg vip-use-register))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4006 (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4007 (error vip-EmptyRegister reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4008 (error "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4009 (setq vip-use-register nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4010 (if (vip-end-with-a-newline-p text) (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4011 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4012 (list 'vip-Put-back val nil vip-use-register nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4013 (set-marker (vip-mark-marker) (point) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4014 (vip-loop val (vip-yank text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4015 ;; 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
4016 ;; newline; it leaves the cursor at the beginning when the text contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4017 ;; a newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4018 (if (vip-same-line (point) (mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4019 (or (= (point) (mark)) (vip-backward-char-carefully))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4020 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4021 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4022 (back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4023 (vip-deactivate-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4026 ;; Copy region to kill-ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4027 ;; 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
4028 (defun vip-copy-region-as-kill (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4029 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4030 (copy-region-as-kill beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4031 (error (copy-region-as-kill beg beg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4032
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4033
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4034 (defun vip-delete-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4035 "Delete character."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4036 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4037 (let ((val (vip-p-val arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4038 (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4039 (if (> val 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4040 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4041 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4042 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4043 (if (> val (- (point) here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4044 (setq val (- (point) here))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4045 (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4046 (if (and vip-ex-style-motion (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4047 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4048 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4049 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4050 (cond ((vip-valid-register vip-use-register '((Letter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4051 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4052 (downcase vip-use-register) (point) (- (point) val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4053 ((vip-valid-register vip-use-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4054 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4055 vip-use-register (point) (- (point) val) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4056 (t (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4057 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4058 (if vip-ex-style-motion
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 (delete-char val t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4061 (if (and (eolp) (not (bolp))) (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4062 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4063 (delete-backward-char val t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4064 (delete-char val t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4065
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4066 (defun vip-delete-backward-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4067 "Delete previous character. On reaching beginning of line, stop and beep."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4068 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4069 (let ((val (vip-p-val arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4070 (vip-set-destructive-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4071 (list 'vip-delete-backward-char val nil nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4072 (if (> val 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4073 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4074 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4075 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4076 (if (> val (- here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4077 (setq val (- here (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4078 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4079 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4080 (cond ((vip-valid-register vip-use-register '(Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4081 (vip-append-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4082 (downcase vip-use-register) (point) (+ (point) val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4083 ((vip-valid-register vip-use-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4084 (copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4085 vip-use-register (point) (+ (point) val) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4086 (t (error vip-InvalidRegister vip-use-register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4087 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4088 (if (bolp) (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4089 (delete-backward-char val t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4091 (defun vip-del-backward-char-in-insert ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4092 "Delete 1 char backwards while in insert mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4093 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4094 (if (and vip-ex-style-editing-in-insert (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4095 (beep 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4096 (delete-backward-char 1 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4098 (defun vip-del-backward-char-in-replace ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4099 "Delete one character in replace mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4100 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4101 charecters. If it is nil, then the cursor just moves backwards, similarly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4102 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
4103 cursor move past the beginning of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4104 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4105 (cond (vip-delete-backwards-in-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4106 (cond ((not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4107 (delete-backward-char 1 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4108 (vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4109 (beep 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4110 ((bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4111 (beep 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4112 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4113 (delete-backward-char 1 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4114 (vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4115 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4116 (beep 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4117 (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4118 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4119 (backward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4123 ;; join lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4125 (defun vip-join-lines (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4126 "Join this line to next, if ARG is nil. Otherwise, join ARG lines."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4127 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4128 (let ((val (vip-P-val arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4129 (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4130 (vip-loop (if (null val) 1 (1- val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4131 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4132 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4133 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4134 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4135 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4136 (delete-region (point) (1- (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4137 (fixup-whitespace)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4140 ;; Replace state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4142 (defun vip-change (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4143 (if (markerp beg) (setq beg (marker-position beg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4144 (if (markerp end) (setq end (marker-position end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4145 ;; beg is sometimes (mark t), which may be nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4146 (or beg (setq beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4148 (vip-set-complex-command-for-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4149 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4150 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4151 (copy-to-register vip-use-register beg end nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4152 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4153 (vip-set-replace-overlay beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4154 (setq last-command nil) ; separate repl text from prev kills
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4156 (if (= (vip-replace-start) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4157 (error "End of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4159 (setq vip-last-replace-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4160 (buffer-substring (vip-replace-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4161 (vip-replace-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4163 ;; protect against error while inserting "@" and other disasters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4164 ;; (e.g., read-only buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4165 (condition-case conds
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
4166 (if (or vip-allow-multiline-replace-regions
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
4167 (vip-same-line (vip-replace-start)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
4168 (vip-replace-end)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4169 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4170 ;; tabs cause problems in replace, so untabify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4171 (goto-char (vip-replace-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4172 (insert-before-markers "@") ; put placeholder after the TAB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4173 (untabify (vip-replace-start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4174 ;; del @, don't put on kill ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4175 (delete-backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4177 (vip-set-replace-overlay-glyphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4178 vip-replace-region-start-delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4179 vip-replace-region-end-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4180 ;; this move takes care of the last posn in the overlay, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4181 ;; has to be shifted because of insert. We can't simply insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4182 ;; "$" before-markers because then overlay-start will shift the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4183 ;; beginning of the overlay in case we are replacing a single
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4184 ;; character. This fixes the bug with `s' and `cl' commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4185 (vip-move-replace-overlay (vip-replace-start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4186 (goto-char (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4187 (vip-change-state-to-replace t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4188 (kill-region (vip-replace-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4189 (vip-replace-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4190 (vip-hide-replace-overlay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4191 (vip-change-state-to-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4192 (error ;; make sure that the overlay doesn't stay.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4193 ;; go back to the original point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4194 (goto-char (vip-replace-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4195 (vip-hide-replace-overlay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4196 (vip-message-conditions conds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4199 (defun vip-change-subr (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4200 ;; beg is sometimes (mark t), which may be nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4201 (or beg (setq beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4203 (if vip-use-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4204 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4205 (copy-to-register vip-use-register beg end nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4206 (setq vip-use-register nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4207 (kill-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4208 (setq this-command 'vip-change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4209 (vip-yank-last-insertion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4211 (defun vip-toggle-case (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4212 "Toggle character case."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4213 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4214 (let ((val (vip-p-val arg)) (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4215 (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4216 (while (> val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4217 (setq c (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4218 (delete-char 1 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4219 (if (eq c (upcase c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4220 (insert-char (downcase c) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4221 (insert-char (upcase c) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4222 (if (eolp) (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4223 (setq val (1- val)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4226 ;; query replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4228 (defun vip-query-replace ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4229 "Query replace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4230 If a null string is suplied as the string to be replaced,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4231 the query replace mode will toggle between string replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4232 and regexp replace."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4233 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4234 (let (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4235 (setq str (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4236 (if vip-re-query-replace "Query replace regexp: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4237 "Query replace: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4238 nil ; no initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4239 'vip-replace1-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4240 (car vip-replace1-history) ; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4241 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4242 (if (string= str "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4243 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4244 (setq vip-re-query-replace (not vip-re-query-replace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4245 (message "Query replace mode changed to %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4246 (if vip-re-query-replace "regexp replace"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4247 "string replace")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4248 (if vip-re-query-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4249 (query-replace-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4250 str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4251 (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4252 (format "Query replace regexp `%s' with: " str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4253 nil ; no initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4254 'vip-replace1-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4255 (car vip-replace1-history) ; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4256 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4257 (query-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4258 str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4259 (vip-read-string-with-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4260 (format "Query replace `%s' with: " str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4261 nil ; no initial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4262 'vip-replace1-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4263 (car vip-replace1-history) ; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4264 ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4267 ;; marking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4269 (defun vip-mark-beginning-of-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4270 "Mark beginning of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4271 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4272 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4273 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4274 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4275 (message "Mark set at the beginning of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4277 (defun vip-mark-end-of-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4278 "Mark end of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4279 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4280 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4281 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4282 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4283 (message "Mark set at the end of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4285 (defun vip-mark-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4286 "Set mark at point of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4287 (interactive)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4288 (let ((char (read-char)))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4289 (cond ((and (<= ?a char) (<= char ?z))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4290 (point-to-register (1+ (- char ?a))))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4291 ((= char ?<) (vip-mark-beginning-of-buffer))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4292 ((= char ?>) (vip-mark-end-of-buffer))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4293 ((= char ?.) (vip-set-mark-if-necessary))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4294 ((= char ?,) (vip-cycle-through-mark-ring))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4295 ((= char ?D) (mark-defun))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4296 (t (error ""))
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4297 )))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4299 ;; Algorithm: If first invocation of this command save mark on ring, goto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4300 ;; 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
4301 ;; making it into the new mark, M1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4302 ;; Push this mark back and set mark to the original point position, p1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4303 ;; So, if you hit '' or `` then you can return to p1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4304 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4305 ;; If repeated command, pop top elt from the ring into mark and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4306 ;; jump there. This forgets the position, p1, and puts M1 back into mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4307 ;; 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
4308 ;; 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
4309 ;; etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4310 (defun vip-cycle-through-mark-ring ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4311 "Visit previous locations on the mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4312 One can use `` and '' to temporarily jump 1 step back."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4313 (let* ((sv-pt (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4314 ;; if repeated `m,' command, pop the previously saved mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4315 ;; Prev saved mark is actually prev saved point. It is used if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4316 ;; user types `` or '' and is discarded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4317 ;; from the mark ring by the next `m,' command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4318 ;; In any case, go to the previous or previously saved mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4319 ;; Then push the current mark (popped off the ring) and set current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4320 ;; 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
4321 ;; m, command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4322 (if (eq last-command 'vip-cycle-through-mark-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4323 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4324 ;; save current mark if the first iteration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4325 (setq mark-ring (delete (vip-mark-marker) mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4326 (if (mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4327 (push-mark (mark t) t)) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4328 (pop-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4329 (set-mark-command 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4330 ;; don't duplicate mark on the ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4331 (setq mark-ring (delete (vip-mark-marker) mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4332 (push-mark sv-pt t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4333 (vip-deactivate-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4334 (setq this-command 'vip-cycle-through-mark-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4335 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4338 (defun vip-goto-mark (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4339 "Go to mark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4340 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4341 (let ((char (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4342 (com (vip-getcom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4343 (vip-goto-mark-subr char com nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4345 (defun vip-goto-mark-and-skip-white (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4346 "Go to mark and skip to first non-white character on line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4347 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4348 (let ((char (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4349 (com (vip-getCom arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4350 (vip-goto-mark-subr char com t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4352 (defun vip-goto-mark-subr (char com skip-white)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4353 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4354 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4355 (error "Empty buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4356 (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4357 (cond ((vip-valid-register char '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4358 (let* ((buff (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4359 (reg (1+ (- char ?a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4360 (text-marker (get-register reg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4361 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4362 (if (not (vip-valid-marker text-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4363 (error vip-EmptyTextmarker char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4364 (if (and (vip-same-line (point) vip-last-jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4365 (= (point) vip-last-jump-ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4366 (push-mark vip-last-jump t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4367 (push-mark nil t)) ; no msg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4368 (vip-register-to-point reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4369 (setq vip-last-jump (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4370 (cond (skip-white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4371 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4372 (setq vip-last-jump-ignore (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4373 (if com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4374 (if (equal buff (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4375 (vip-execute-com (if skip-white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4376 'vip-goto-mark-and-skip-white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4377 'vip-goto-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4378 nil com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4379 (switch-to-buffer buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4380 (goto-char vip-com-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4381 (vip-change-state-to-vi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4382 (error "")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4383 ((and (not skip-white) (= char ?`))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4384 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4385 (if (and (vip-same-line (point) vip-last-jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4386 (= (point) vip-last-jump-ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4387 (goto-char vip-last-jump))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4388 (if (null (mark t)) (error "Mark is not set in this buffer"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4389 (if (= (point) (mark t)) (pop-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4390 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4391 (setq vip-last-jump (point-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4392 vip-last-jump-ignore 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4393 (if com (vip-execute-com 'vip-goto-mark nil com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4394 ((and skip-white (= char ?'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4395 (if com (vip-move-marker-locally 'vip-com-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4396 (if (and (vip-same-line (point) vip-last-jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4397 (= (point) vip-last-jump-ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4398 (goto-char vip-last-jump))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4399 (if (= (point) (mark t)) (pop-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4400 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4401 (setq vip-last-jump (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4402 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4403 (setq vip-last-jump-ignore (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4404 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4405 (t (error vip-InvalidTextmarker char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4407 (defun vip-insert-tab ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4408 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4409 (insert-tab))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4411 (defun vip-exchange-point-and-mark ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4412 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4413 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4414 (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4416 ;; Input Mode Indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4418 ;; Returns t, if the string before point matches the regexp STR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4419 (defsubst vip-looking-back (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4420 (and (save-excursion (re-search-backward str nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4421 (= (point) (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4424 (defun vip-forward-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4425 "Indent forward -- `C-t' in Vi."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4426 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4427 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4428 (indent-to (+ (current-column) vip-shift-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4430 (defun vip-backward-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4431 "Backtab, C-d in VI"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4432 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4433 (if vip-cted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4434 (let ((p (point)) (c (current-column)) bol (indent t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4435 (if (vip-looking-back "[0^]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4436 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4437 (if (eq ?^ (preceding-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4438 (setq vip-preserve-indent t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4439 (delete-backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4440 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4441 (setq indent nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4442 (save-excursion
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 (setq bol (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4445 (if (re-search-backward "[^ \t]" bol 1) (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4446 (delete-region (point) p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4447 (if indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4448 (indent-to (- c vip-shift-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4449 (if (or (bolp) (vip-looking-back "[^ \t]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4450 (setq vip-cted nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4452 (defun vip-autoindent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4453 "Auto Indentation, Vi-style."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4454 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4455 (let ((col (current-indentation)))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 104
diff changeset
4456 (if abbrev-mode (expand-abbrev))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4457 (if vip-preserve-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4458 (setq vip-preserve-indent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4459 (setq vip-current-indent col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4460 ;; don't leave whitespace lines around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4461 (if (memq last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4462 '(vip-autoindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4463 vip-open-line vip-Open-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4464 vip-replace-state-exit-cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4465 (indent-to-left-margin))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4466 ;; use \n instead of newline, or else <Return> will move the insert point
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4467 ;;(newline 1)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4468 (insert "\n")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4469 (if vip-auto-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4470 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4471 (setq vip-cted t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4472 (if vip-electric-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4473 (indent-according-to-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4474 (indent-to vip-current-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4475 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4476 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4479 ;; Viewing registers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4481 (defun vip-ket-function (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4482 "Function called by \], the ket. View registers and call \]\]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4483 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4484 (let ((reg (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4485 (cond ((vip-valid-register reg '(letter Letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4486 (view-register (downcase reg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4487 ((vip-valid-register reg '(digit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4488 (let ((text (current-kill (- reg ?1) 'do-not-rotate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4489 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4490 (set-buffer (get-buffer-create "*Output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4491 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4492 (insert (format "Register %c contains the string:\n" reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4493 (insert text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4494 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4495 (display-buffer "*Output*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4496 ((= ?\] reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4497 (vip-next-heading arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4498 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4499 vip-InvalidRegister reg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4501 (defun vip-brac-function (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4502 "Function called by \[, the brac. View textmarkers and call \[\["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4503 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4504 (let ((reg (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4505 (cond ((= ?\[ reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4506 (vip-prev-heading arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4507 ((= ?\] reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4508 (vip-heading-end arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4509 ((vip-valid-register reg '(letter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4510 (let* ((val (get-register (1+ (- reg ?a))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4511 (buf (if (not val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4512 (error vip-EmptyTextmarker reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4513 (marker-buffer val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4514 (pos (marker-position val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4515 line-no text (s pos) (e pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4516 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4517 (set-buffer (get-buffer-create "*Output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4518 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4519 (if (and buf pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4520 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4521 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4522 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4523 (setq line-no (1+ (count-lines (point-min) val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4524 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4525 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4526 (if (re-search-backward "[^ \t]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4527 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4528 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4529 (setq s (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4530 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4531 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4532 (if (re-search-forward "[^ \t]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4533 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4534 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4535 (setq e (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4536 (setq text (buffer-substring s e))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4537 (setq text (format "%s<%c>%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4538 (substring text 0 (- pos s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4539 reg (substring text (- pos s)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4540 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4541 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4542 "Textmarker `%c' is in buffer `%s' at line %d.\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4543 reg (buffer-name buf) line-no))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4544 (insert (format "Here is some text around %c:\n\n %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4545 reg text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4546 (insert (format vip-EmptyTextmarker reg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4547 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4548 (display-buffer "*Output*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4549 (t (error vip-InvalidTextmarker reg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4553 ;; commands in insertion mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4555 (defun vip-delete-backward-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4556 "Delete previous word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4557 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4558 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4559 (push-mark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4560 (backward-word arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4561 (delete-region (point) (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4562 (pop-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4565 (defun vip-set-expert-level (&optional dont-change-unless)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4566 "Sets the expert level for a Viper user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4567 Can be called interactively to change (temporarily or permanently) the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4568 current expert level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4570 The optional argument DONT-CHANGE-UNLESS if not nil, says that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4571 the level should not be changed, unless its current value is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4572 meaningless (i.e., not one of 1,2,3,4,5).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4574 User level determines the setting of Viper variables that are most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4575 sensitive for VI-style look-and-feel."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4577 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4579 (if (not (natnump vip-expert-level)) (setq vip-expert-level 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4581 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4582 (delete-other-windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4583 ;; if 0 < vip-expert-level < vip-max-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4584 ;; & dont-change-unless = t -- use it; else ask
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4585 (vip-ask-level dont-change-unless))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4587 (setq vip-always t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4588 vip-ex-style-motion t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4589 vip-ex-style-editing-in-insert t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4590 vip-want-ctl-h-help nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4591
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4592 (cond ((eq vip-expert-level 1) ; novice or beginner
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4593 (global-set-key ; in emacs-state
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4594 vip-toggle-key
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4595 (if (vip-window-display-p) 'vip-iconify 'suspend-emacs))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4596 (setq vip-no-multiple-ESC t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4597 vip-re-search t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4598 vip-vi-style-in-minibuffer t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4599 vip-search-wrap-around-t t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4600 vip-want-emacs-keys-in-vi nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4601 vip-want-emacs-keys-in-insert nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4603 ((and (> vip-expert-level 1) (< vip-expert-level 5))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
4604 ;; intermediate to guru
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4605 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4606 vip-want-emacs-keys-in-vi t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4607 vip-want-emacs-keys-in-insert (> vip-expert-level 2))
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 (eq vip-expert-level 4) ; respect user's ex-style motions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4610 ; and vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4611 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4612 (setq-default vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4613 (cdr (assoc 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4614 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4615 vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4616 (cdr (assoc 'vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4617 vip-saved-user-settings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4618 (setq vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4619 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4620 vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4621 (cdr (assoc 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4622 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4623 vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4624 (cdr (assoc 'vip-re-search vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4625 vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4626 (cdr (assoc 'vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4627 vip-saved-user-settings))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4628
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4629 ;; A wizard!!
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4630 ;; Ideally, if 5 is selected, a buffer should pop up to let the
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
4631 ;; user toggle the values of variables.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4632 (t (setq-default vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4633 (cdr (assoc 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4634 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4635 vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4636 (cdr (assoc 'vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4637 vip-saved-user-settings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4638 (setq vip-want-ctl-h-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4639 (cdr (assoc 'vip-want-ctl-h-help vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4640 vip-always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4641 (cdr (assoc 'vip-always vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4642 vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4643 (cdr (assoc 'vip-no-multiple-ESC vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4644 vip-ex-style-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4645 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4646 vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4647 (cdr (assoc 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4648 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4649 vip-re-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4650 (cdr (assoc 'vip-re-search vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4651 vip-want-emacs-keys-in-vi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4652 (cdr (assoc 'vip-want-emacs-keys-in-vi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4653 vip-saved-user-settings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4654 vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4655 (cdr (assoc 'vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4656 vip-saved-user-settings)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4657 (vip-set-mode-vars-for vip-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4658 (if (or vip-always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4659 (and (> vip-expert-level 0) (> 5 vip-expert-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4660 (vip-set-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4662 ;; Ask user expert level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4663 (defun vip-ask-level (dont-change-unless)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4664 (let ((ask-buffer " *vip-ask-level*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4665 level-changed repeated)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4666 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4667 (switch-to-buffer ask-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4669 (or (eq this-command 'vip-set-expert-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4670 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4671 (<= vip-expert-level vip-max-expert-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4672 (>= vip-expert-level 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4673 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4674 (insert "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4676 *** Important Notice for VIP users***
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4678 This is VIPER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4680 @joke
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4681 Viper Is a Package for Emacs Rebels,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4682 a VI Plan for Emacs Rescue,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4683 and a venomous VI PERil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4684 @end joke
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4686 Technically speaking, Viper is a new Vi emulator that replaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4687 the old VIP package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4689 Viper emulates Vi much better than VIP. It also significantly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4690 extends and improves upon Vi in many useful ways.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4692 Although many VIP settings in your ~/.vip are compatible with Viper,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4693 you may have to change some of them. Please refer to the documentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4694 which can be obtained by executing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4696 :help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4698 when Viper is in Vi state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4700 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
4701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4702 :submitReport
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4704 Type any key to continue... ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4706 (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4707 (erase-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4709 (while (or (> vip-expert-level vip-max-expert-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4710 (< vip-expert-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4711 (null dont-change-unless))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4712 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4713 (if repeated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4714 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4715 (message "Invalid user level")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4716 (beep 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4717 (setq repeated t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4718 (setq dont-change-unless t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4719 level-changed t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4720 (insert "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4721 Please specify your level of familiarity with the venomous VI PERil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4722 (and the VI Plan for Emacs Rescue).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4723 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
4724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4725 1 -- BEGINNER: Almost all Emacs features are suppressed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4726 Feels almost like straight Vi. File name completion and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4727 command history in the minibuffer are thrown in as a bonus.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4728 To use Emacs productively, you must reach level 3 or higher.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4729 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
4730 so most Emacs commands can be used when Viper is in Vi state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4731 Good progress---you are well on the way to level 3!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4732 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4733 in Viper's insert state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4734 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
4735 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4736 variables. Adjust these settings to your taste.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4737 5 -- WIZARD: Like 4, but user settings are also respected for vip-always,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4738 vip-want-ctl-h-help, vip-want-emacs-keys-in-vi, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4739 vip-want-emacs-keys-in-insert. Adjust these to your taste.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4741 Please, specify your level now: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4743 (setq vip-expert-level (- (vip-read-char-exclusive) ?0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4744 ) ; end while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4746 ;; tell the user if level was changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4747 (and level-changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4748 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4749 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4750 (format "\n\n\n\n\n\t\tYou have selected user level %d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4751 vip-expert-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4752 (if (y-or-n-p "Do you wish to make this change permanent? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4753 ;; save the setting for vip-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4754 (vip-save-setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4755 'vip-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4756 (format "Saving user level %d ..." vip-expert-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4757 vip-custom-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4758 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4759 (bury-buffer) ; remove ask-buffer from screen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4760 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4761 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4764 (defun viper-version ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4765 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4766 (message "Viper version is %s" viper-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4768 (defalias 'vip-version 'viper-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4770 (defun vip-nil ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4771 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4772 (beep 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4775 ;; 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
4776 (defun vip-register-to-point (char &optional enforce-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4777 "Like jump-to-register, but switches to another buffer in another window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4778 (interactive "cViper register to point: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4779 (let ((val (get-register char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4780 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4781 ((and (fboundp 'frame-configuration-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4782 (frame-configuration-p val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4783 (set-frame-configuration val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4784 ((window-configuration-p val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4785 (set-window-configuration val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4786 ((vip-valid-marker val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4787 (if (and enforce-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4788 (not (equal (current-buffer) (marker-buffer val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4789 (error (concat vip-EmptyTextmarker " in this buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4790 (1- (+ char ?a))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4791 (pop-to-buffer (marker-buffer val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4792 (goto-char val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4793 ((and (consp val) (eq (car val) 'file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4794 (find-file (cdr val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4795 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4796 (error vip-EmptyTextmarker (1- (+ char ?a)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4799 (defun vip-save-kill-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4800 "Save then kill current buffer. "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4801 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4802 (if (< vip-expert-level 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4803 (save-buffers-kill-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4804 (save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4805 (kill-buffer (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4809 ;;; Bug Report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4811 (defun vip-submit-report ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4812 "Submit bug report on Viper."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4813 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4814 (let ((reporter-prompt-for-summary-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4815 (vip-device-type (vip-device-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4816 color-display-p frame-parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4817 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4818 varlist salutation window-config)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4820 ;; 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
4821 ;; like we did with color-display-p.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4822 (setq color-display-p (if (vip-window-display-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4823 (vip-color-display-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4824 'non-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4825 minibuffer-vi-face (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4826 (vip-get-face vip-minibuffer-vi-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4827 'non-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4828 minibuffer-insert-face (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4829 (vip-get-face vip-minibuffer-insert-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4830 'non-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4831 minibuffer-emacs-face (if (vip-has-face-support-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4832 (vip-get-face vip-minibuffer-emacs-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4833 'non-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4834 frame-parameters (if (fboundp 'frame-parameters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4835 (frame-parameters (selected-frame))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4836
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4837 (setq varlist (list 'vip-vi-minibuffer-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4838 'vip-insert-minibuffer-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4839 'vip-vi-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4840 'vip-vi-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4841 'vip-vi-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4842 'vip-vi-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4843 'vip-vi-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4844 'vip-vi-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4845 'vip-vi-basic-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4846 'vip-replace-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4847 'vip-insert-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4848 'vip-insert-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4849 'vip-insert-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4850 'vip-insert-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4851 'vip-insert-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4852 'vip-insert-diehard-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4853 'vip-insert-basic-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4854 'vip-emacs-intercept-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4855 'vip-emacs-local-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4856 'vip-emacs-kbd-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4857 'vip-emacs-global-user-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4858 'vip-emacs-state-modifier-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4859 'vip-automatic-iso-accents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4860 'vip-want-emacs-keys-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4861 'vip-want-emacs-keys-in-vi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4862 'vip-keep-point-on-undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4863 'vip-no-multiple-ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4864 'vip-ESC-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4865 'vip-want-ctl-h-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4866 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4867 'vip-delete-backwards-in-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4868 'vip-vi-style-in-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4869 'vip-vi-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4870 'vip-insert-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4871 'vip-replace-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4872 'vip-emacs-state-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4873 'ex-cycle-other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4874 'ex-cycle-through-non-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4875 'vip-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4876 'major-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4877 'vip-device-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4878 'color-display-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4879 'frame-parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4880 'minibuffer-vi-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4881 'minibuffer-insert-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4882 'minibuffer-emacs-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4883 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4884 (setq salutation "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4885 Congratulations! You may have unearthed a bug in Viper!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4886 Please mail a concise, accurate summary of the problem to the address above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4887
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4888 -------------------------------------------------------------------")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4889 (setq window-config (current-window-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4890 (with-output-to-temp-buffer " *vip-info*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4891 (switch-to-buffer " *vip-info*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4892 (delete-other-windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4893 (princ "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4894 PLEASE FOLLOW THESE PROCEDURES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4895 ------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4897 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
4898 not cause by other packages you are using.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4900 Don't report compilation warnings, unless you are certain that there is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4901 problem. These warnings are normal and unavoidable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4902
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4903 Please note that users should not modify variables and keymaps other than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4904 those advertised in the manual. Such `customization' is likely to crash
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4905 Viper, as it would any other improperly customized Emacs package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4907 If you are reporting an error message received while executing one of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4908 Viper commands, type:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4909
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4910 M-x set-variable <Return> debug-on-error <Return> t <Return>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4912 Then reproduce the error. The above command will cause Emacs to produce a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4913 back trace of the execution that leads to the error. Please include this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4914 trace in your bug report.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4916 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
4917 \(e.g., Emacs freezes\), type:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4919 M-x set-variable <Return> debug-on-quit <Return> t <Return>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4921 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
4922 the current command. Include the resulting back trace in the bug report.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4924 Mail anyway (y or n)? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4925 (if (y-or-n-p "Mail anyway? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4926 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4927 (set-window-configuration window-config)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4928 (error "Bug report aborted")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4930 (require 'reporter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4931 (set-window-configuration window-config)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4933 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4934 (vip-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4935 varlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4936 nil 'delete-other-windows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4937 salutation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4938 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4943 ;; Smoothes out the difference between Emacs' unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4944 ;; 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
4945 ;; events or a sequence of keys.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4946 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4947 ;; 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
4948 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4949 ;; 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
4950 ;; common symbol that might appear in this wrong context.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4951 (defun vip-set-unread-command-events (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4952 (if vip-emacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4953 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4954 unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4955 (let ((new-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4956 (cond ((eventp arg) (list arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4957 ((listp arg) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4958 ((sequencep arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4959 (listify-key-sequence arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4960 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4961 "vip-set-unread-command-events: Invalid argument, %S"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4962 arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4963 (if (not (eventp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4964 (setq new-events (delq nil new-events)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4965 (append new-events unread-command-events)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4966 ;; XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4967 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4968 unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4969 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4970 (cond ((vip-characterp arg) (list (character-to-event arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4971 ((eventp arg) (list arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4972 ((stringp arg) (mapcar 'character-to-event arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4973 ((vectorp arg) (append arg nil)) ; turn into list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4974 ((listp arg) (vip-eventify-list-xemacs arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4975 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4976 "vip-set-unread-command-events: Invalid argument, %S" arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4977 unread-command-events))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4979 ;; list is assumed to be a list of events of characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4980 (defun vip-eventify-list-xemacs (lis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4981 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4982 (function (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4983 (cond ((vip-characterp elt) (character-to-event elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4984 ((eventp elt) elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4985 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4986 "vip-eventify-list-xemacs: can't convert to event, %S"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4987 elt)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4988 lis))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4992 ;; The following is provided for compatibility with older VIP's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4994 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4995 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4996 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4998
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5000 ;;; Load .vip and set up hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5002 ;; This hook designed to enable Vi-style editing in comint-based modes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5003 (defun vip-comint-mode-hook ()
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5004 (setq require-final-newline nil
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5005 vip-ex-style-editing-in-insert nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5006 vip-ex-style-motion nil)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5007 (vip-change-state-to-insert))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5008
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5010 ;; This sets major mode hooks to make them come up in vi-state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5011 (defun vip-set-hooks ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5012
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5013 ;; It is of course a misnomer to call viper-mode a `major mode'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5014 ;; However, this has the effect that if the user didn't specify the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5015 ;; default mode, new buffers that fall back on the default will come up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5016 ;; in Fundamental Mode and Vi state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5017 (setq default-major-mode 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5018
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5019 ;; The following major modes should come up in vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5020 (defadvice fundamental-mode (after vip-fundamental-mode-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5021 "Run `vip-change-state-to-vi' on entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5022 (vip-change-state-to-vi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5024 (defvar makefile-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5025 (add-hook 'makefile-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5027 (defvar help-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5028 (add-hook 'help-mode-hook 'viper-mode)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
5029 (vip-modify-major-mode 'help-mode 'vi-state vip-help-modifier-map)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5031 (defvar awk-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5032 (add-hook 'awk-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5033
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5034 (defvar html-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5035 (add-hook 'html-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5036 (defvar html-helper-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5037 (add-hook 'html-helper-mode-hook 'viper-mode)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5038 (defvar java-mode-hook)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5039 (add-hook 'java-mode-hook 'viper-mode)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
5040
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5041 (defvar emacs-lisp-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5042 (add-hook 'emacs-lisp-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5044 (defvar lisp-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5045 (add-hook 'lisp-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5047 (defvar bibtex-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5048 (add-hook 'bibtex-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5050 (defvar cc-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5051 (add-hook 'cc-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5053 (defvar c-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5054 (add-hook 'c-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5056 (defvar c++-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5057 (add-hook 'c++-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5058
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5059 (defvar lisp-interaction-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5060 (add-hook 'lisp-interaction-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5062 (defvar fortran-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5063 (add-hook 'fortran-mode-hook 'vip-mode)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
5064
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5065 (defvar basic-mode-hook)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5066 (add-hook 'basic-mode-hook 'vip-mode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5067 (defvar bat-mode-hook)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5068 (add-hook 'bat-mode-hook 'vip-mode)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
5069
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5070 (defvar text-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5071 (add-hook 'text-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5073 (add-hook 'completion-list-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5074 (add-hook 'compilation-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5076 (add-hook 'perl-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5077 (add-hook 'tcl-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5078
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5079 (defvar emerge-startup-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5080 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5081
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5082 ;; Tell vc-diff to put *vc* in Vi mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5083 (if (featurep 'vc)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5084 (defadvice vc-diff (after vip-vc-ad activate)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5085 "Force Vi state in VC diff buffer."
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5086 (vip-change-state-to-vi))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5087 (vip-eval-after-load
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5088 "vc"
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5089 '(defadvice vc-diff (after vip-vc-ad activate)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5090 "Force Vi state in VC diff buffer."
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5091 (vip-change-state-to-vi))))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
5092
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5093 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5094 "emerge"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5095 '(defadvice emerge-quit (after vip-emerge-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5096 "Run `vip-change-state-to-vi' after quitting emerge."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5097 (vip-change-state-to-vi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5098 ;; In case Emerge was loaded before Viper.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5099 (defadvice emerge-quit (after vip-emerge-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5100 "Run `vip-change-state-to-vi' after quitting emerge."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5101 (vip-change-state-to-vi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5103 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5104 "asm-mode"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5105 '(defadvice asm-mode (after vip-asm-mode-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5106 "Run `vip-change-state-to-vi' on entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5107 (vip-change-state-to-vi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5109 ;; passwd.el sets up its own buffer, which turns up in Vi mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5110 ;; thus overriding the local map. We don't need Vi mode here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5111 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5112 "passwd"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5113 '(defadvice read-passwd-1 (before vip-passwd-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5114 "Switch to emacs state while reading password."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5115 (vip-change-state-to-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5117 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5118 "prolog"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5119 '(defadvice prolog-mode (after vip-prolog-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5120 "Switch to Vi state in Prolog mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5121 (vip-change-state-to-vi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5123 ;; Emacs shell, ange-ftp, and comint-based modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5124 (defvar comint-mode-hook)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5125 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5126 'comint-mode 'insert-state vip-comint-mode-modifier-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5127 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5128 'comint-mode 'vi-state vip-comint-mode-modifier-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5129 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5130 'shell-mode 'insert-state vip-comint-mode-modifier-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5131 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5132 'shell-mode 'vi-state vip-comint-mode-modifier-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5133 ;; ange-ftp in XEmacs
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5134 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5135 'ange-ftp-shell-mode 'insert-state vip-comint-mode-modifier-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5136 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5137 'ange-ftp-shell-mode 'vi-state vip-comint-mode-modifier-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5138 ;; ange-ftp in Emacs
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5139 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5140 'internal-ange-ftp-mode 'insert-state vip-comint-mode-modifier-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5141 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5142 'internal-ange-ftp-mode 'vi-state vip-comint-mode-modifier-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5143 ;; set hook
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5144 (add-hook 'comint-mode-hook 'vip-comint-mode-hook)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
5145
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5146 ;; Shell scripts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5147 (defvar sh-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5148 (add-hook 'sh-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5149 (defvar ksh-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5150 (add-hook 'ksh-mode-hook 'viper-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5152 ;; Dired
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5153 (vip-modify-major-mode 'dired-mode 'emacs-state vip-dired-modifier-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5154 (vip-set-emacs-search-style-macros nil 'dired-mode)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5155 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5156
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5157 ;; Tar
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5158 (vip-modify-major-mode 'tar-mode 'emacs-state vip-slash-and-colon-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5159 (vip-set-emacs-search-style-macros nil 'tar-mode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5160
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5161 ;; MH-E
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5162 (vip-modify-major-mode 'mh-folder-mode 'emacs-state vip-slash-and-colon-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5163 (vip-set-emacs-search-style-macros nil 'mh-folder-mode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5164 ;; changing state to emacs is needed so the preceding will take hold
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5165 (add-hook 'mh-folder-mode-hook 'vip-change-state-to-emacs)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5166 (add-hook 'mh-show-mode-hook 'viper-mode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5167
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5168 ;; Gnus
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5169 (vip-modify-major-mode 'gnus-group-mode 'emacs-state vip-slash-and-colon-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5170 (vip-set-emacs-search-style-macros nil 'gnus-group-mode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5171 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5172 'gnus-summary-mode 'emacs-state vip-slash-and-colon-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5173 (vip-set-emacs-search-style-macros nil 'gnus-summary-mode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5174 ;; changing state to emacs is needed so the preceding will take hold
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5175 (add-hook 'gnus-group-mode-hook 'vip-change-state-to-emacs)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5176 (add-hook 'gnus-summary-mode-hook 'vip-change-state-to-emacs)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5177 (add-hook 'gnus-article-mode-hook 'viper-mode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5178
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5179 ;; Info
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5180 (vip-modify-major-mode 'Info-mode 'emacs-state vip-slash-and-colon-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5181 (vip-set-emacs-search-style-macros nil 'Info-mode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5182 ;; Switching to emacs is needed so the above will take hold
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5183 (defadvice Info-mode (after vip-Info-ad activate)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5184 "Switch to emacs mode."
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5185 (vip-change-state-to-emacs))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5186
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5187 ;; Buffer menu
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5188 (vip-modify-major-mode
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5189 'Buffer-menu-mode 'emacs-state vip-slash-and-colon-map)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5190 (vip-set-emacs-search-style-macros nil 'Buffer-menu-mode)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5191 ;; Switching to emacs is needed so the above will take hold
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5192 (defadvice Buffer-menu-mode (after vip-Buffer-menu-ad activate)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5193 "Switch to emacs mode."
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5194 (vip-change-state-to-emacs))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5195
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5196 ;; View mode
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5197 (if vip-emacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5198 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5199 (defvar view-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5200 (add-hook 'view-mode-hook 'vip-change-state-to-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5201 (defadvice view-minor-mode (after vip-view-ad activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5202 "Switch to Emacs state in View mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5203 (vip-change-state-to-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5204 (defvar view-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5205 (add-hook 'view-hook 'vip-change-state-to-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5207 ;; For VM users.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5208 ;; Put summary and other VM buffers in Emacs state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5209 (defvar vm-mode-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5210 (defvar vm-summary-mode-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5211 (add-hook 'vm-mode-hooks 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5212 (add-hook 'vm-summary-mode-hooks 'vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5214 ;; For RMAIL users.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5215 ;; Put buf in Emacs state after edit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5216 (vip-eval-after-load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5217 "rmailedit"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5218 '(defadvice rmail-cease-edit (after vip-rmail-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5219 "Switch to emacs state when done editing message."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5220 (vip-change-state-to-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5221 ;; In case RMAIL was loaded before Viper.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5222 (defadvice rmail-cease-edit (after vip-rmail-advice activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5223 "Switch to emacs state when done editing message."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5224 (vip-change-state-to-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5225 ) ; vip-set-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5227 ;; Set some useful macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5228 ;; These must be before we load .vip, so the user can unrecord them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5230 ;; repeat the 2nd previous command without rotating the command history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5231 (vip-record-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5232 (vector vip-repeat-from-history-key '\1) 'vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5233 [(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
5234 ;; repeat the 3d previous command without rotating the command history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5235 (vip-record-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5236 (vector vip-repeat-from-history-key '\2) 'vi-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5237 [(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
5238
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5239 ;; set the toggle case sensitivity and regexp search macros
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5240 (vip-set-vi-search-style-macros nil)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
5241
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5243 ;; ~/.vip is loaded if it exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5244 (if (and (file-exists-p vip-custom-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5245 (not noninteractive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5246 (load vip-custom-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5248 ;; VIP compatibility: merge whatever the user has in vip-mode-map into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5249 ;; Viper's basic map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5250 (vip-add-keymap vip-mode-map vip-vi-global-user-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5253 ;; Applying Viper customization -- runs after (load .vip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5255 ;; Save user settings or Viper defaults for vars controled by vip-expert-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5256 (setq vip-saved-user-settings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5257 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5258 (cons 'vip-always vip-always)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5259 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5260 (cons 'vip-ex-style-motion vip-ex-style-motion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5261 (cons 'vip-ex-style-editing-in-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5262 vip-ex-style-editing-in-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5263 (cons 'vip-want-emacs-keys-in-vi vip-want-emacs-keys-in-vi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5264 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5265 (cons 'vip-re-search vip-re-search)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5268 (vip-set-minibuffer-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5269 (if vip-buffer-search-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5270 (vip-buffer-search-enable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5271 (vip-update-alphanumeric-class)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5273 ;;; Familiarize Viper with some minor modes that have their own keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5274 (vip-harness-minor-mode "compile")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5275 (vip-harness-minor-mode "outline")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5276 (vip-harness-minor-mode "allout")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5277 (vip-harness-minor-mode "xref")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5278 (vip-harness-minor-mode "lmenu")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5279 (vip-harness-minor-mode "vc")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5280 (vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5281 (vip-harness-minor-mode "latex") ; which is in one of these two files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5282 (vip-harness-minor-mode "cyrillic")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5283 (vip-harness-minor-mode "russian")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5284 (vip-harness-minor-mode "view-less")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5285 (vip-harness-minor-mode "view")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5288 ;; Intercept maps could go in viper-keym.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5289 ;; We keep them here in case someone redefines them in ~/.vip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5291 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5292 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5294 ;; This is taken care of by vip-insert-global-user-map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5295 ;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5296
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5297
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5298 ;; 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
5299 ;; iconifies Emacs
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
5300 (define-key vip-vi-intercept-map vip-toggle-key 'vip-toggle-key-action)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5301 (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
5302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5304 (if (or vip-always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5305 (and (< vip-expert-level 5) (> vip-expert-level 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5306 (vip-set-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5308 ;; Let all minor modes take effect after loading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5309 ;; this may not be enough, so we also set default minor-mode-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5310 ;; Without setting the default, new buffers that come up in emacs mode have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5311 ;; minor-mode-map-alist = nil, unless we call vip-change-state-*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5312 (if (eq vip-current-state 'emacs-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5313 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5314 (vip-change-state-to-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5315 (setq-default minor-mode-map-alist minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5316 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5319 (run-hooks 'vip-load-hook) ; the last chance to change something
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5321 (provide 'vip19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5322 (provide 'vip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5324 ;;; viper.el ends here