comparison lisp/viper/viper-util.el @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents c7528f8e288d
children 6a378aca36af
comparison
equal deleted inserted replaced
79:5b0a5bbffab6 80:1ce6082ce73f
40 (defvar vip-replace-overlay-cursor-color) 40 (defvar vip-replace-overlay-cursor-color)
41 (defvar vip-intermediate-command) 41 (defvar vip-intermediate-command)
42 (defvar vip-use-replace-region-delimiters) 42 (defvar vip-use-replace-region-delimiters)
43 (defvar vip-fast-keyseq-timeout) 43 (defvar vip-fast-keyseq-timeout)
44 (defvar vip-related-files-and-buffers-ring) 44 (defvar vip-related-files-and-buffers-ring)
45 ;; end compiler pacifier 45 (defvar vip-saved-cursor-color)
46 (defvar ex-unix-type-shell)
47 (defvar ex-unix-type-shell-options)
48 (defvar vip-ex-tmp-buf-name)
49 ;; end pacifier
46 50
47 ;; Is it XEmacs? 51 ;; Is it XEmacs?
48 (defconst vip-xemacs-p (string-match "\\(Lucid\\|XEmacs\\)" emacs-version)) 52 (defconst vip-xemacs-p (string-match "\\(Lucid\\|XEmacs\\)" emacs-version))
49 ;; Is it Emacs? 53 ;; Is it Emacs?
50 (defconst vip-emacs-p (not vip-xemacs-p)) 54 (defconst vip-emacs-p (not vip-xemacs-p))
152 156
153 (defvar vip-minibuffer-overlay-priority 300) 157 (defvar vip-minibuffer-overlay-priority 300)
154 (defvar vip-replace-overlay-priority 400) 158 (defvar vip-replace-overlay-priority 400)
155 (defvar vip-search-overlay-priority 500) 159 (defvar vip-search-overlay-priority 500)
156 160
161
162 ;;; Viper minor modes
163
164 ;; This is not local in Emacs, so we make it local.
165 ;; This must be local because although the stack of minor modes can be the same
166 ;; for all buffers, the associated *keymaps* can be different. In Viper,
167 ;; vip-vi-local-user-map, vip-insert-local-user-map, and others can have
168 ;; different keymaps for different buffers.
169 ;; Also, the keymaps associated with vip-vi/insert-state-modifier-minor-mode
170 ;; can be different.
171 (make-variable-buffer-local 'minor-mode-map-alist)
172
173 ;; Mode for vital things like \e, C-z.
174 (vip-deflocalvar vip-vi-intercept-minor-mode nil)
175
176 (vip-deflocalvar vip-vi-basic-minor-mode nil
177 "Viper's minor mode for Vi bindings.")
178
179 (vip-deflocalvar vip-vi-local-user-minor-mode nil
180 "Auxiliary minor mode for user-defined local bindings in Vi state.")
181
182 (vip-deflocalvar vip-vi-global-user-minor-mode nil
183 "Auxiliary minor mode for user-defined global bindings in Vi state.")
184
185 (vip-deflocalvar vip-vi-state-modifier-minor-mode nil
186 "Minor mode used to make major-mode-specific modification to Vi state.")
187
188 (vip-deflocalvar vip-vi-diehard-minor-mode nil
189 "This minor mode is in effect when the user wants Viper to be Vi.")
190
191 (vip-deflocalvar vip-vi-kbd-minor-mode nil
192 "Minor mode for Ex command macros in Vi state.
193 The corresponding keymap stores key bindings of Vi macros defined with
194 the Ex command :map.")
195
196 ;; Mode for vital things like \e, C-z.
197 (vip-deflocalvar vip-insert-intercept-minor-mode nil)
198
199 (vip-deflocalvar vip-insert-basic-minor-mode nil
200 "Viper's minor mode for bindings in Insert mode.")
201
202 (vip-deflocalvar vip-insert-local-user-minor-mode nil
203 "Auxiliary minor mode for buffer-local user-defined bindings in Insert state.
204 This is a way to overshadow normal Insert mode bindings locally to certain
205 designated buffers.")
206
207 (vip-deflocalvar vip-insert-global-user-minor-mode nil
208 "Auxiliary minor mode for global user-defined bindings in Insert state.")
209
210 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil
211 "Minor mode used to make major-mode-specific modification to Insert state.")
212
213 (vip-deflocalvar vip-insert-diehard-minor-mode nil
214 "Minor mode that simulates Vi very closely.
215 Not recommened, except for the novice user.")
216
217 (vip-deflocalvar vip-insert-kbd-minor-mode nil
218 "Minor mode for Ex command macros Insert state.
219 The corresponding keymap stores key bindings of Vi macros defined with
220 the Ex command :map!.")
221
222 (vip-deflocalvar vip-replace-minor-mode nil
223 "Minor mode in effect in replace state (cw, C, and the like commands).")
224
225 ;; Mode for vital things like \C-z and \C-x)
226 ;; This is t, by default. So, any new buffer will have C-z defined as
227 ;; switch to Vi, unless we switched states in this buffer
228 (vip-deflocalvar vip-emacs-intercept-minor-mode t)
229
230 (vip-deflocalvar vip-emacs-local-user-minor-mode t
231 "Minor mode for local user bindings effective in Emacs state.
232 Users can use it to override Emacs bindings when Viper is in its Emacs
233 state.")
234
235 (vip-deflocalvar vip-emacs-global-user-minor-mode t
236 "Minor mode for global user bindings in effect in Emacs state.
237 Users can use it to override Emacs bindings when Viper is in its Emacs
238 state.")
239
240 (vip-deflocalvar vip-emacs-kbd-minor-mode t
241 "Minor mode for Vi style macros in Emacs state.
242 The corresponding keymap stores key bindings of Vi macros defined with
243 `vip-record-kbd-macro' command. There is no Ex-level command to do this
244 interactively.")
245
246 (vip-deflocalvar vip-emacs-state-modifier-minor-mode t
247 "Minor mode used to make major-mode-specific modification to Emacs state.
248 For instance, a Vi purist may want to bind `dd' in Dired mode to a function
249 that deletes a file.")
250
251 (vip-deflocalvar vip-vi-minibuffer-minor-mode nil
252 "Minor mode that forces Vi-style when the Minibuffer is in Vi state.")
253
254 (vip-deflocalvar vip-insert-minibuffer-minor-mode nil
255 "Minor mode that forces Vi-style when the Minibuffer is in Insert state.")
256
257
258
259 ;; Some common error messages
260
261 (defconst vip-SpuriousText "Spurious text after command" "")
262 (defconst vip-BadExCommand "Not an editor command" "")
263 (defconst vip-InvalidCommandArgument "Invalid command argument" "")
264 (defconst vip-NoPrevSearch "No previous search string" "")
265 (defconst vip-EmptyRegister "`%c': Nothing in this register" "")
266 (defconst vip-InvalidRegister "`%c': Invalid register" "")
267 (defconst vip-EmptyTextmarker "`%c': Text marker doesn't point anywhere" "")
268 (defconst vip-InvalidTextmarker "`%c': Invalid text marker" "")
269 (defconst vip-InvalidViCommand "Invalid command" "")
270 (defconst vip-BadAddress "Ill-formed address" "")
271 (defconst vip-FirstAddrExceedsSecond "First address exceeds second" "")
272 (defconst vip-NoFileSpecified "No file specified" "")
273
274
157 275
158 ;;; XEmacs support 276 ;;; XEmacs support
159 277
160 (if vip-xemacs-p 278 (if vip-xemacs-p
161 (progn 279 (progn
253 (defsubst vip-restore-cursor-color-after-replace () 371 (defsubst vip-restore-cursor-color-after-replace ()
254 (vip-change-cursor-color 372 (vip-change-cursor-color
255 (vip-overlay-get vip-replace-overlay 'vip-cursor-color))) 373 (vip-overlay-get vip-replace-overlay 'vip-cursor-color)))
256 (defsubst vip-restore-cursor-color-after-insert () 374 (defsubst vip-restore-cursor-color-after-insert ()
257 (vip-change-cursor-color vip-saved-cursor-color)) 375 (vip-change-cursor-color vip-saved-cursor-color))
258 376
259 377
260 ;; Check the current version against the major and minor version numbers 378 ;; Check the current version against the major and minor version numbers
261 ;; using op: cur-vers op major.minor If emacs-major-version or 379 ;; using op: cur-vers op major.minor If emacs-major-version or
262 ;; emacs-minor-version are not defined, we assume that the current version 380 ;; emacs-minor-version are not defined, we assume that the current version
263 ;; is hopelessly outdated. We assume that emacs-major-version and 381 ;; is hopelessly outdated. We assume that emacs-major-version and
945 (if (equal hook-value function) 1063 (if (equal hook-value function)
946 (setq hook-value nil))) 1064 (setq hook-value nil)))
947 (set hook hook-value)))) 1065 (set hook hook-value))))
948 1066
949 1067
1068 ;; it is suggested that an event must be copied before it is assigned to
1069 ;; last-command-event in XEmacs
1070 (defun vip-copy-event (event)
1071 (if vip-xemacs-p
1072 (copy-event event)
1073 event))
950 1074
951 ;; like read-event, but in XEmacs also try to convert to char, if possible 1075 ;; like read-event, but in XEmacs also try to convert to char, if possible
952 (defun vip-read-event-convert-to-char () 1076 (defun vip-read-event-convert-to-char ()
953 (let (event) 1077 (let (event)
954 (if vip-emacs-p 1078 (if vip-emacs-p
962 ;; keys. This does a better job than vip-read-event when it comes to kbd 1086 ;; keys. This does a better job than vip-read-event when it comes to kbd
963 ;; macros, since it enables certain macros to be shared between X and TTY modes 1087 ;; macros, since it enables certain macros to be shared between X and TTY modes
964 ;; by correctly mapping key sequences for Left/Right/... (one an ascii 1088 ;; by correctly mapping key sequences for Left/Right/... (one an ascii
965 ;; terminal) into logical keys left, right, etc. 1089 ;; terminal) into logical keys left, right, etc.
966 (defun vip-read-key () 1090 (defun vip-read-key ()
967 (let ((overriding-local-map vip-overriding-map) 1091 (let ((overriding-local-map vip-overriding-map)
968 (inhibit-quit t) 1092 (inhibit-quit t)
969 key) 1093 key)
970 (use-global-map vip-overriding-map) 1094 (use-global-map vip-overriding-map)
971 (setq key (elt (read-key-sequence nil) 0)) 1095 (setq key (elt (read-key-sequence nil) 0))
972 (use-global-map global-map) 1096 (use-global-map global-map)