16
|
1 ;;; viper-init.el --- some common definitions for Viper
|
|
2
|
|
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; This file is part of GNU Emacs.
|
|
6
|
|
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
8 ;; it under the terms of the GNU General Public License as published by
|
|
9 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
10 ;; any later version.
|
|
11
|
|
12 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 ;; GNU General Public License for more details.
|
|
16
|
|
17 ;; You should have received a copy of the GNU General Public License
|
|
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 ;; Boston, MA 02111-1307, USA.
|
|
21
|
|
22 ;; Code
|
|
23
|
|
24 (provide 'viper-init)
|
|
25
|
|
26 ;; compiler pacifier
|
|
27 (defvar mark-even-if-inactive)
|
|
28 ;; end pacifier
|
|
29
|
|
30 ;; Is it XEmacs?
|
|
31 (defconst vip-xemacs-p (string-match "\\(Lucid\\|XEmacs\\)" emacs-version))
|
|
32 ;; Is it Emacs?
|
|
33 (defconst vip-emacs-p (not vip-xemacs-p))
|
|
34 ;; Tell whether we are running as a window application or on a TTY
|
|
35 (defsubst vip-device-type ()
|
|
36 (if vip-emacs-p
|
|
37 window-system
|
|
38 (device-type (selected-device))))
|
|
39 ;; in XEmacs: device-type is tty on tty and stream in batch.
|
|
40 (defun vip-window-display-p ()
|
|
41 (and (vip-device-type) (not (memq (vip-device-type) '(tty stream pc)))))
|
|
42
|
|
43 (defvar vip-ms-style-os-p (memq system-type '(ms-dos windows-nt windows-95))
|
|
44 "Tells if Emacs is running under an MS-style OS: ms-dos, windows-nt, W95.")
|
|
45 (defvar vip-vms-os-p (memq system-type '(vax-vms axp-vms))
|
|
46 "Tells if Emacs is running under VMS.")
|
|
47
|
|
48 (defvar vip-force-faces nil
|
|
49 "If t, Viper will think that it is running on a display that supports faces.
|
|
50 This is provided as a temporary relief for users of face-capable displays
|
|
51 that Viper doesn't know about.")
|
|
52
|
|
53 (defun vip-has-face-support-p ()
|
|
54 (cond ((vip-window-display-p))
|
|
55 (vip-force-faces)
|
|
56 (vip-emacs-p (memq (vip-device-type) '(pc)))
|
|
57 (vip-xemacs-p (memq (vip-device-type) '(tty pc)))))
|
|
58
|
|
59 (defun vip-convert-standard-file-name (fname)
|
|
60 (if vip-emacs-p
|
|
61 (convert-standard-filename fname)
|
|
62 ;; hopefully, XEmacs adds this functionality
|
|
63 fname))
|
|
64
|
|
65
|
|
66 ;;; Macros
|
|
67
|
|
68 (defmacro vip-deflocalvar (var default-value &optional documentation)
|
|
69 (` (progn
|
|
70 (defvar (, var) (, default-value)
|
|
71 (, (format "%s\n\(buffer local\)" documentation)))
|
|
72 (make-variable-buffer-local '(, var))
|
|
73 )))
|
|
74
|
|
75 (defmacro vip-loop (count body)
|
|
76 "(vip-loop COUNT BODY) Execute BODY COUNT times."
|
|
77 (list 'let (list (list 'count count))
|
|
78 (list 'while '(> count 0)
|
|
79 body
|
|
80 '(setq count (1- count))
|
|
81 )))
|
|
82
|
|
83 (defmacro vip-buffer-live-p (buf)
|
|
84 (` (and (, buf) (get-buffer (, buf)) (buffer-name (get-buffer (, buf))))))
|
|
85
|
|
86 ;; return buffer-specific macro definition, given a full macro definition
|
|
87 (defmacro vip-kbd-buf-alist (macro-elt)
|
|
88 (` (nth 1 (, macro-elt))))
|
|
89 ;; get a pair: (curr-buffer . macro-definition)
|
|
90 (defmacro vip-kbd-buf-pair (macro-elt)
|
|
91 (` (assoc (buffer-name) (vip-kbd-buf-alist (, macro-elt)))))
|
|
92 ;; get macro definition for current buffer
|
|
93 (defmacro vip-kbd-buf-definition (macro-elt)
|
|
94 (` (cdr (vip-kbd-buf-pair (, macro-elt)))))
|
|
95
|
|
96 ;; return mode-specific macro definitions, given a full macro definition
|
|
97 (defmacro vip-kbd-mode-alist (macro-elt)
|
|
98 (` (nth 2 (, macro-elt))))
|
|
99 ;; get a pair: (major-mode . macro-definition)
|
|
100 (defmacro vip-kbd-mode-pair (macro-elt)
|
|
101 (` (assoc major-mode (vip-kbd-mode-alist (, macro-elt)))))
|
|
102 ;; get macro definition for the current major mode
|
|
103 (defmacro vip-kbd-mode-definition (macro-elt)
|
|
104 (` (cdr (vip-kbd-mode-pair (, macro-elt)))))
|
|
105
|
|
106 ;; return global macro definition, given a full macro definition
|
|
107 (defmacro vip-kbd-global-pair (macro-elt)
|
|
108 (` (nth 3 (, macro-elt))))
|
|
109 ;; get global macro definition from an elt of macro-alist
|
|
110 (defmacro vip-kbd-global-definition (macro-elt)
|
|
111 (` (cdr (vip-kbd-global-pair (, macro-elt)))))
|
|
112
|
|
113 ;; last elt of a sequence
|
|
114 (defsubst vip-seq-last-elt (seq)
|
|
115 (elt seq (1- (length seq))))
|
|
116
|
|
117
|
|
118 (defvar vip-minibuffer-overlay-priority 300)
|
|
119 (defvar vip-replace-overlay-priority 400)
|
|
120 (defvar vip-search-overlay-priority 500)
|
|
121
|
|
122
|
|
123 ;;; Viper minor modes
|
|
124
|
|
125 ;; This is not local in Emacs, so we make it local.
|
|
126 ;; This must be local because although the stack of minor modes can be the same
|
|
127 ;; for all buffers, the associated *keymaps* can be different. In Viper,
|
|
128 ;; vip-vi-local-user-map, vip-insert-local-user-map, and others can have
|
|
129 ;; different keymaps for different buffers.
|
|
130 ;; Also, the keymaps associated with vip-vi/insert-state-modifier-minor-mode
|
|
131 ;; can be different.
|
|
132 (make-variable-buffer-local 'minor-mode-map-alist)
|
|
133
|
|
134 ;; Mode for vital things like \e, C-z.
|
|
135 (vip-deflocalvar vip-vi-intercept-minor-mode nil)
|
|
136
|
|
137 (vip-deflocalvar vip-vi-basic-minor-mode nil
|
|
138 "Viper's minor mode for Vi bindings.")
|
|
139
|
|
140 (vip-deflocalvar vip-vi-local-user-minor-mode nil
|
|
141 "Auxiliary minor mode for user-defined local bindings in Vi state.")
|
|
142
|
|
143 (vip-deflocalvar vip-vi-global-user-minor-mode nil
|
|
144 "Auxiliary minor mode for user-defined global bindings in Vi state.")
|
|
145
|
|
146 (vip-deflocalvar vip-vi-state-modifier-minor-mode nil
|
|
147 "Minor mode used to make major-mode-specific modification to Vi state.")
|
|
148
|
|
149 (vip-deflocalvar vip-vi-diehard-minor-mode nil
|
|
150 "This minor mode is in effect when the user wants Viper to be Vi.")
|
|
151
|
|
152 (vip-deflocalvar vip-vi-kbd-minor-mode nil
|
|
153 "Minor mode for Ex command macros in Vi state.
|
|
154 The corresponding keymap stores key bindings of Vi macros defined with
|
|
155 the Ex command :map.")
|
|
156
|
|
157 ;; Mode for vital things like \e, C-z.
|
|
158 (vip-deflocalvar vip-insert-intercept-minor-mode nil)
|
|
159
|
|
160 (vip-deflocalvar vip-insert-basic-minor-mode nil
|
|
161 "Viper's minor mode for bindings in Insert mode.")
|
|
162
|
|
163 (vip-deflocalvar vip-insert-local-user-minor-mode nil
|
|
164 "Auxiliary minor mode for buffer-local user-defined bindings in Insert state.
|
|
165 This is a way to overshadow normal Insert mode bindings locally to certain
|
|
166 designated buffers.")
|
|
167
|
|
168 (vip-deflocalvar vip-insert-global-user-minor-mode nil
|
|
169 "Auxiliary minor mode for global user-defined bindings in Insert state.")
|
|
170
|
|
171 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil
|
|
172 "Minor mode used to make major-mode-specific modification to Insert state.")
|
|
173
|
|
174 (vip-deflocalvar vip-insert-diehard-minor-mode nil
|
|
175 "Minor mode that simulates Vi very closely.
|
|
176 Not recommened, except for the novice user.")
|
|
177
|
|
178 (vip-deflocalvar vip-insert-kbd-minor-mode nil
|
|
179 "Minor mode for Ex command macros Insert state.
|
|
180 The corresponding keymap stores key bindings of Vi macros defined with
|
|
181 the Ex command :map!.")
|
|
182
|
|
183 (vip-deflocalvar vip-replace-minor-mode nil
|
|
184 "Minor mode in effect in replace state (cw, C, and the like commands).")
|
|
185
|
|
186 ;; Mode for vital things like \C-z and \C-x)
|
|
187 ;; This is t, by default. So, any new buffer will have C-z defined as
|
|
188 ;; switch to Vi, unless we switched states in this buffer
|
|
189 (vip-deflocalvar vip-emacs-intercept-minor-mode t)
|
|
190
|
|
191 (vip-deflocalvar vip-emacs-local-user-minor-mode t
|
|
192 "Minor mode for local user bindings effective in Emacs state.
|
|
193 Users can use it to override Emacs bindings when Viper is in its Emacs
|
|
194 state.")
|
|
195
|
|
196 (vip-deflocalvar vip-emacs-global-user-minor-mode t
|
|
197 "Minor mode for global user bindings in effect in Emacs state.
|
|
198 Users can use it to override Emacs bindings when Viper is in its Emacs
|
|
199 state.")
|
|
200
|
|
201 (vip-deflocalvar vip-emacs-kbd-minor-mode t
|
|
202 "Minor mode for Vi style macros in Emacs state.
|
|
203 The corresponding keymap stores key bindings of Vi macros defined with
|
|
204 `vip-record-kbd-macro' command. There is no Ex-level command to do this
|
|
205 interactively.")
|
|
206
|
|
207 (vip-deflocalvar vip-emacs-state-modifier-minor-mode t
|
|
208 "Minor mode used to make major-mode-specific modification to Emacs state.
|
|
209 For instance, a Vi purist may want to bind `dd' in Dired mode to a function
|
|
210 that deletes a file.")
|
|
211
|
|
212 (vip-deflocalvar vip-vi-minibuffer-minor-mode nil
|
|
213 "Minor mode that forces Vi-style when the Minibuffer is in Vi state.")
|
|
214
|
|
215 (vip-deflocalvar vip-insert-minibuffer-minor-mode nil
|
|
216 "Minor mode that forces Vi-style when the Minibuffer is in Insert state.")
|
|
217
|
|
218
|
|
219
|
|
220 ;; Some common error messages
|
|
221
|
|
222 (defconst vip-SpuriousText "Spurious text after command" "")
|
|
223 (defconst vip-BadExCommand "Not an editor command" "")
|
|
224 (defconst vip-InvalidCommandArgument "Invalid command argument" "")
|
|
225 (defconst vip-NoPrevSearch "No previous search string" "")
|
|
226 (defconst vip-EmptyRegister "`%c': Nothing in this register" "")
|
|
227 (defconst vip-InvalidRegister "`%c': Invalid register" "")
|
|
228 (defconst vip-EmptyTextmarker "`%c': Text marker doesn't point anywhere" "")
|
|
229 (defconst vip-InvalidTextmarker "`%c': Invalid text marker" "")
|
|
230 (defconst vip-InvalidViCommand "Invalid command" "")
|
|
231 (defconst vip-BadAddress "Ill-formed address" "")
|
|
232 (defconst vip-FirstAddrExceedsSecond "First address exceeds second" "")
|
|
233 (defconst vip-NoFileSpecified "No file specified" "")
|
|
234
|
|
235 ;; Is t until viper-mode executes for the very first time.
|
|
236 ;; Prevents recursive descend into startup messages.
|
|
237 (defvar vip-first-time t)
|
|
238
|
|
239 (defvar vip-expert-level 0
|
|
240 "User's expert level.
|
|
241 The minor mode vip-vi-diehard-minor-mode is in effect when
|
|
242 vip-expert-level is 1 or 2 or when vip-want-emacs-keys-in-vi is t.
|
|
243 The minor mode vip-insert-diehard-minor-mode is in effect when
|
|
244 vip-expert-level is 1 or 2 or if vip-want-emacs-keys-in-insert is t.
|
|
245 Use `M-x vip-set-expert-level' to change this.")
|
|
246
|
|
247 ;; Max expert level supported by Viper. This is NOT a user option.
|
|
248 ;; It is here to make it hard for the user from resetting it.
|
|
249 (defconst vip-max-expert-level 5)
|
|
250
|
|
251 ;; Contains user settings for vars affected by vip-set-expert-level function.
|
|
252 ;; Not a user option.
|
|
253 (defvar vip-saved-user-settings nil)
|
|
254
|
|
255
|
|
256 ;;; ISO characters
|
|
257
|
|
258 (vip-deflocalvar vip-automatic-iso-accents nil
|
|
259 "*If non-nil, ISO accents will be turned on in insert/replace emacs states and turned off in vi-state.
|
|
260 For some users, this behavior may be too primitive. In this case, use
|
|
261 insert/emacs/vi state hooks.")
|
|
262
|
|
263
|
|
264 ;; VI-style Undo
|
|
265
|
|
266 ;; Used to 'undo' complex commands, such as replace and insert commands.
|
|
267 (vip-deflocalvar vip-undo-needs-adjustment nil)
|
|
268 (put 'vip-undo-needs-adjustment 'permanent-local t)
|
|
269
|
|
270 ;; A mark that Viper puts on buffer-undo-list. Marks the beginning of a
|
|
271 ;; complex command that must be undone atomically. If inserted, it is
|
|
272 ;; erased by vip-change-state-to-vi and vip-repeat.
|
|
273 (defconst vip-buffer-undo-list-mark 'viper)
|
|
274
|
|
275 (defvar vip-keep-point-on-undo nil
|
|
276 "*Non-nil means not to move point while undoing commands.
|
|
277 This style is different from Emacs and Vi. Try it to see if
|
|
278 it better fits your working style.")
|
|
279
|
|
280 ;; Replace mode and changing text
|
|
281
|
|
282 ;; Viper's own after/before change functions, which get vip-add-hook'ed to
|
|
283 ;; Emacs's
|
|
284 (vip-deflocalvar vip-after-change-functions nil "")
|
|
285 (vip-deflocalvar vip-before-change-functions nil "")
|
|
286 (vip-deflocalvar vip-post-command-hooks nil "")
|
|
287 (vip-deflocalvar vip-pre-command-hooks nil "")
|
|
288
|
|
289 ;; Can be used to pass global states around for short period of time
|
|
290 (vip-deflocalvar vip-intermediate-command nil "")
|
|
291
|
|
292 ;; Indicates that the current destructive command has started in replace mode.
|
|
293 (vip-deflocalvar vip-began-as-replace nil "")
|
|
294
|
|
295 (defvar vip-allow-multiline-replace-regions t
|
|
296 "If non-nil, Viper will allow multi-line replace regions.
|
|
297 This is an extension to standard Vi.
|
|
298 If nil, commands that attempt to replace text spanning multiple lines first
|
|
299 delete the text being replaced, as in standard Vi.")
|
|
300
|
|
301 (defvar vip-replace-overlay-cursor-color "Red"
|
|
302 "*Cursor color to use in Replace state")
|
|
303 (defvar vip-insert-state-cursor-color nil
|
|
304 "Cursor color for Viper insert state.")
|
|
305 (put 'vip-insert-state-cursor-color 'permanent-local t)
|
|
306 ;; place to save cursor colow when switching to insert mode
|
|
307 (vip-deflocalvar vip-saved-cursor-color nil "")
|
|
308
|
|
309 (vip-deflocalvar vip-replace-overlay nil "")
|
|
310 (put 'vip-replace-overlay 'permanent-local t)
|
|
311
|
|
312 (defvar vip-replace-overlay-pixmap "gray3"
|
|
313 "Pixmap to use for search face on non-color displays.")
|
|
314 (defvar vip-search-face-pixmap "gray3"
|
|
315 "Pixmap to use for search face on non-color displays.")
|
|
316
|
|
317
|
|
318 (defvar vip-replace-region-end-delimiter "$"
|
|
319 "A string marking the end of replacement regions.
|
|
320 It is used only with TTYs or if `vip-use-replace-region-delimiters'
|
|
321 is non-nil.")
|
|
322 (defvar vip-replace-region-start-delimiter ""
|
|
323 "A string marking the beginning of replacement regions.
|
|
324 It is used only with TTYs or if `vip-use-replace-region-delimiters'
|
|
325 is non-nil.")
|
|
326 (defvar vip-use-replace-region-delimiters (not (vip-has-face-support-p))
|
|
327 "*If non-nil, Viper will always use `vip-replace-region-end-delimiter' and
|
|
328 `vip-replace-region-start-delimiter' to delimit replacement regions, even on
|
|
329 color displays. By default, the delimiters are used only on TTYs.")
|
|
330
|
|
331 ;; XEmacs requires glyphs
|
|
332 (if vip-xemacs-p
|
|
333 (progn
|
|
334 (or (glyphp vip-replace-region-end-delimiter)
|
|
335 (setq vip-replace-region-end-delimiter
|
|
336 (make-glyph vip-replace-region-end-delimiter)))
|
|
337 (or (glyphp vip-replace-region-start-delimiter)
|
|
338 (setq vip-replace-region-start-delimiter
|
|
339 (make-glyph vip-replace-region-start-delimiter)))
|
|
340 ))
|
|
341
|
|
342
|
|
343 ;; These are local marker that must be initialized to nil and moved with
|
|
344 ;; `vip-move-marker-locally'
|
|
345 ;;
|
|
346 ;; Remember the last position inside the replace region.
|
|
347 (vip-deflocalvar vip-last-posn-in-replace-region nil)
|
|
348 ;; Remember the last position while inserting
|
|
349 (vip-deflocalvar vip-last-posn-while-in-insert-state nil)
|
|
350 (put 'vip-last-posn-in-replace-region 'permanent-local t)
|
|
351 (put 'vip-last-posn-while-in-insert-state 'permanent-local t)
|
|
352
|
|
353 (vip-deflocalvar vip-sitting-in-replace nil "")
|
|
354 (put 'vip-sitting-in-replace 'permanent-local t)
|
|
355
|
|
356 ;; Remember the number of characters that have to be deleted in replace
|
|
357 ;; mode to compensate for the inserted characters.
|
|
358 (vip-deflocalvar vip-replace-chars-to-delete 0 "")
|
|
359 (vip-deflocalvar vip-replace-chars-deleted 0 "")
|
|
360
|
|
361 ;; Insertion ring and command ring
|
|
362 (defvar vip-insertion-ring-size 14
|
|
363 "The size of the insertion ring.")
|
|
364 ;; The insertion ring.
|
|
365 (defvar vip-insertion-ring nil)
|
|
366 ;; This is temp insertion ring. Used to do rotation for display purposes.
|
|
367 ;; When rotation just started, it is initialized to vip-insertion-ring.
|
|
368 (defvar vip-temp-insertion-ring nil)
|
|
369 (defvar vip-last-inserted-string-from-insertion-ring "")
|
|
370
|
|
371 (defvar vip-command-ring-size 14
|
|
372 "The size of the command ring.")
|
|
373 ;; The command ring.
|
|
374 (defvar vip-command-ring nil)
|
|
375 ;; This is temp command ring. Used to do rotation for display purposes.
|
|
376 ;; When rotation just started, it is initialized to vip-command-ring.
|
|
377 (defvar vip-temp-command-ring nil)
|
|
378
|
|
379 ;; Modes and related variables
|
|
380
|
|
381 ;; Current mode. One of: `emacs-state', `vi-state', `insert-state'
|
|
382 (vip-deflocalvar vip-current-state 'emacs-state)
|
|
383
|
|
384
|
|
385 ;; Autoindent in insert
|
|
386
|
|
387 ;; Variable that keeps track of whether C-t has been pressed.
|
|
388 (vip-deflocalvar vip-cted nil "")
|
|
389
|
|
390 ;; Preserve the indent value, used by C-d in insert mode.
|
|
391 (vip-deflocalvar vip-current-indent 0)
|
|
392
|
|
393 ;; Whether to preserve the indent, used by C-d in insert mode.
|
|
394 (vip-deflocalvar vip-preserve-indent nil)
|
|
395
|
|
396 (vip-deflocalvar vip-auto-indent nil
|
|
397 "*Autoindent if t.")
|
|
398 (vip-deflocalvar vip-electric-mode t
|
|
399 "*If t, enable electric behavior.
|
|
400 Currently only enables auto-indentation `according to mode'.")
|
|
401
|
|
402 (defconst vip-shift-width 8
|
|
403 "*The shiftwidth variable.")
|
|
404
|
|
405 ;; Variables for repeating destructive commands
|
|
406
|
|
407 (defconst vip-keep-point-on-repeat t
|
|
408 "*If t, don't move point when repeating previous command.
|
|
409 This is useful for doing repeated changes with the '.' key.
|
|
410 The user can change this to nil, if she likes when the cursor moves
|
|
411 to a new place after repeating previous Vi command.")
|
|
412
|
|
413 ;; Remember insert point as a marker. This is a local marker that must be
|
|
414 ;; initialized to nil and moved with `vip-move-marker-locally'.
|
|
415 (vip-deflocalvar vip-insert-point nil)
|
|
416 (put 'vip-insert-point 'permanent-local t)
|
|
417
|
|
418 ;; This remembers the point before dabbrev-expand was called.
|
|
419 ;; If vip-insert-point turns out to be bigger than that, it is reset
|
|
420 ;; back to vip-pre-command-point.
|
|
421 ;; The reason this is needed is because dabbrev-expand (and possibly
|
|
422 ;; others) may jump to before the insertion point, delete something and
|
|
423 ;; then reinsert a bigger piece. For instance: bla^blo
|
|
424 ;; If dabbrev-expand is called after `blo' and ^ undicates vip-insert-point,
|
|
425 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo'
|
|
426 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand
|
|
427 ;; will insert the expansion, and we get: blablo^
|
|
428 ;; Whatever we insert next goes before the ^, i.e., before the
|
|
429 ;; vip-insert-point marker. So, Viper will think that nothing was
|
|
430 ;; inserted. Remembering the orig position of the marker circumvents the
|
|
431 ;; problem.
|
|
432 ;; We don't know of any command, except dabbrev-expand, that has the same
|
|
433 ;; problem. However, the same trick can be used if such a command is
|
|
434 ;; discovered later.
|
|
435 ;;
|
|
436 (vip-deflocalvar vip-pre-command-point nil)
|
|
437 (put 'vip-pre-command-point 'permanent-local t) ; this is probably an overkill
|
|
438
|
|
439 ;; This is used for saving inserted text.
|
|
440 (defvar vip-last-insertion nil)
|
|
441
|
|
442 ;; Remembers the last replaced region.
|
|
443 (defvar vip-last-replace-region "")
|
|
444
|
|
445 ;; Remember com point as a marker.
|
|
446 ;; This is a local marker. Should be moved with `vip-move-marker-locally'
|
|
447 (vip-deflocalvar vip-com-point nil)
|
|
448
|
|
449 ;; If non-nil, the value is a list (M-COM VAL COM REG inserted-text cmd-keys)
|
|
450 ;; It is used to re-execute last destructive command.
|
|
451 ;; M-COM is a Lisp symbol representing the function to be executed.
|
|
452 ;; VAL is the prefix argument that was used with that command.
|
|
453 ;; COM is an internal descriptor, such as ?r, ?c, ?C, which contains
|
|
454 ;; additional information on how the function in M-COM is to be handled.
|
|
455 ;; REG is the register used by command
|
|
456 ;; INSERTED-TEXT is text inserted by that command (in case of o, c, C, i, r
|
|
457 ;; commands).
|
|
458 ;; COMMAND-KEYS are the keys that were typed to invoke the command.
|
|
459 (defvar vip-d-com nil)
|
|
460
|
|
461 ;; The character remembered by the Vi `r' command.
|
|
462 (defvar vip-d-char nil)
|
|
463
|
|
464 ;; Name of register to store deleted or yanked strings
|
|
465 (defvar vip-use-register nil)
|
|
466
|
|
467
|
|
468
|
|
469 ;; Variables for Moves and Searches
|
|
470
|
|
471 ;; For use by `;' command.
|
|
472 (defvar vip-f-char nil)
|
|
473
|
|
474 ;; For use by `.' command.
|
|
475 (defvar vip-F-char nil)
|
|
476
|
|
477 ;; For use by `;' command.
|
|
478 (defvar vip-f-forward nil)
|
|
479
|
|
480 ;; For use by `;' command.
|
|
481 (defvar vip-f-offset nil)
|
|
482
|
|
483 ;; Last search string
|
|
484 (defvar vip-s-string "")
|
|
485
|
|
486 (defvar vip-quote-string "> "
|
|
487 "String inserted at the beginning of quoted region.")
|
|
488
|
|
489 ;; If t, search is forward.
|
|
490 (defvar vip-s-forward nil)
|
|
491
|
|
492 (defconst vip-case-fold-search nil
|
|
493 "*If not nil, search ignores cases.")
|
|
494
|
|
495 (defconst vip-re-search t
|
|
496 "*If not nil, search is reg-exp search, otherwise vanilla search.")
|
|
497
|
|
498 (defvar vip-search-scroll-threshold 2
|
|
499 "*If search lands within this threshnold from the window top/bottom,
|
|
500 the window will be scrolled up or down appropriately, to reveal context.
|
|
501 If you want Viper search to behave as usual in Vi, set this variable to a
|
|
502 negative number.")
|
|
503
|
|
504 (defconst vip-re-query-replace t
|
|
505 "*If t then do regexp replace, if nil then do string replace.")
|
|
506
|
|
507 (defconst vip-re-replace t
|
|
508 "*If t, do regexp replace. nil means do string replace.")
|
|
509
|
|
510 (vip-deflocalvar vip-ex-style-motion t
|
|
511 "*Ex-style: the commands l,h do not cross lines, etc.")
|
|
512
|
|
513 (vip-deflocalvar vip-ex-style-editing-in-insert t
|
|
514 "*The keys ^H, ^? don't jump lines in insert, ESC moves cursor back, etc.
|
|
515 Note: this doesn't preclude ^H and ^? from deleting characters by moving
|
|
516 past the insertion point. This is a feature, not a bug. ")
|
|
517
|
|
518 (vip-deflocalvar vip-delete-backwards-in-replace nil
|
|
519 "*If t, DEL key will delete characters while moving the cursor backwards.
|
|
520 If nil, the cursor will move backwards without deleting anything.")
|
|
521
|
|
522 (defconst vip-buffer-search-char nil
|
|
523 "*Key bound for buffer-searching.")
|
|
524
|
|
525 (defconst vip-search-wrap-around-t t
|
|
526 "*If t, search wraps around.")
|
|
527
|
|
528 (vip-deflocalvar vip-related-files-and-buffers-ring nil
|
|
529 "*Ring of file and buffer names that are considered to be related to the
|
|
530 current buffer.
|
|
531 These buffers can be cycled through via :R and :P commands.")
|
|
532 (put 'vip-related-files-and-buffers-ring 'permanent-local t)
|
|
533
|
|
534 ;; Used to find out if we are done with searching the current buffer.
|
|
535 (vip-deflocalvar vip-local-search-start-marker nil)
|
|
536 ;; As above, but global
|
|
537 (defvar vip-search-start-marker (make-marker))
|
|
538
|
|
539 ;; the search overlay
|
|
540 (vip-deflocalvar vip-search-overlay nil)
|
|
541
|
|
542
|
|
543 (defvar vip-heading-start
|
|
544 (concat "^\\s-*(\\s-*defun\\s-\\|" ; lisp
|
|
545 "^{\\s-*$\\|^[_a-zA-Z][^()]*[()].*{\\s-*$\\|" ; C/C++
|
|
546 "^\\s-*class.*{\\|^\\s-*struct.*{\\|^\\s-*enum.*{\\|"
|
|
547 "^\\\\[sb][a-z]*{.*}\\s-*$\\|" ; latex
|
|
548 "^@node\\|@table\\|^@m?enu\\|^@itemize\\|^@if\\|" ; texinfo
|
|
549 "^.+:-") ; prolog
|
|
550 "*Regexps for Headings. Used by \[\[ and \]\].")
|
|
551
|
|
552 (defvar vip-heading-end
|
|
553 (concat "^}\\|" ; C/C++
|
|
554 "^\\\\end{\\|" ; latex
|
|
555 "^@end \\|" ; texinfo
|
|
556 ")\n\n[ \t\n]*\\|" ; lisp
|
|
557 "\\.\\s-*$") ; prolog
|
|
558 "*Regexps to end Headings/Sections. Used by \[\].")
|
|
559
|
|
560
|
|
561 ;; These two vars control the interaction of jumps performed by ' and `.
|
|
562 ;; In this new version, '' doesn't erase the marks set by ``, so one can
|
|
563 ;; use both kinds of jumps interchangeably and without loosing positions
|
|
564 ;; inside the lines.
|
|
565
|
|
566 ;; Remembers position of the last jump done using ``'.
|
|
567 (vip-deflocalvar vip-last-jump nil)
|
|
568 ;; Remembers position of the last jump done using `''.
|
|
569 (vip-deflocalvar vip-last-jump-ignore 0)
|
|
570
|
|
571 ;; History variables
|
|
572
|
|
573 ;; History of search strings.
|
|
574 (defvar vip-search-history (list ""))
|
|
575 ;; History of query-replace strings used as a source.
|
|
576 (defvar vip-replace1-history nil)
|
|
577 ;; History of query-replace strings used as replacement.
|
|
578 (defvar vip-replace2-history nil)
|
|
579 ;; History of region quoting strings.
|
|
580 (defvar vip-quote-region-history (list vip-quote-string))
|
|
581 ;; History of Ex-style commands.
|
|
582 (defvar vip-ex-history nil)
|
|
583 ;; History of shell commands.
|
|
584 (defvar vip-shell-history nil)
|
|
585
|
|
586
|
|
587 ;; Last shell command. There are two of these, one for Ex (in viper-ex)
|
|
588 ;; and one for Vi.
|
|
589
|
|
590 ;; Last shell command executed with ! command.
|
|
591 (defvar vip-last-shell-com nil)
|
|
592
|
|
593
|
|
594
|
|
595 ;;; Miscellaneous
|
|
596
|
|
597 ;; don't bark when mark is inactive
|
|
598 (setq mark-even-if-inactive t)
|
|
599
|
|
600 (defvar vip-inhibit-startup-message nil
|
|
601 "Whether Viper startup message should be inhibited.")
|
|
602
|
|
603 (defvar vip-always t
|
|
604 "t means, arrange that vi-state will be a default.")
|
|
605
|
|
606 (defvar vip-custom-file-name (vip-convert-standard-file-name "~/.vip")
|
|
607 "Viper customisation file.
|
|
608 This variable must be set _before_ loading Viper.")
|
|
609
|
|
610
|
|
611 (defvar vip-spell-function 'ispell-region
|
|
612 "Spell function used by #s<move> command to spell.")
|
|
613
|
|
614 (defvar vip-tags-file-name "TAGS"
|
|
615 "The tags file used by Viper.")
|
|
616
|
|
617 ;; Indicates if we are in the middle of executing a command that takes another
|
|
618 ;; command as an argument, e.g., cw, dw, etc.
|
|
619 (defvar vip-inside-command-argument-action nil)
|
|
620
|
|
621 ;; Minibuffer
|
|
622
|
|
623 (defvar vip-vi-style-in-minibuffer t
|
|
624 "If t, use vi-style editing in minibuffer.
|
|
625 Should be set in `~/.vip' file.")
|
|
626
|
|
627 ;; overlay used in the minibuffer to indicate which state it is in
|
|
628 (vip-deflocalvar vip-minibuffer-overlay nil)
|
|
629
|
|
630 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer.
|
|
631 ;; Beginning with Emacs 19.26, the standard `minibuffer-exit-hook' is run
|
|
632 ;; *after* exiting the minibuffer
|
|
633 (defvar vip-minibuffer-exit-hook nil)
|
|
634
|
|
635 ;; setup emacs-supported vi-style feel
|
|
636 (setq next-line-add-newlines nil
|
|
637 require-final-newline t)
|
|
638
|
|
639 (make-variable-buffer-local 'require-final-newline)
|
|
640
|
|
641
|
|
642 ;; Mode line
|
|
643 (defconst vip-vi-state-id "<V> "
|
|
644 "Mode line tag identifying the Vi mode of Viper.")
|
|
645 (defconst vip-emacs-state-id "<E> "
|
|
646 "Mode line tag identifying the Emacs mode of Viper.")
|
|
647 (defconst vip-insert-state-id "<I> "
|
|
648 "Mode line tag identifying the Insert mode of Viper.")
|
|
649 (defconst vip-replace-state-id "<R> "
|
|
650 "Mode line tag identifying the Replace mode of Viper.")
|
|
651
|
|
652 ;; Viper changes the default mode-line-buffer-identification
|
|
653 (setq-default mode-line-buffer-identification '(" %b"))
|
|
654
|
|
655 ;; Variable displaying the current Viper state in the mode line.
|
|
656 (vip-deflocalvar vip-mode-string vip-emacs-state-id)
|
|
657 (or (memq 'vip-mode-string global-mode-string)
|
|
658 (setq global-mode-string
|
|
659 (append '("" vip-mode-string) (cdr global-mode-string))))
|
|
660
|
|
661
|
|
662 (defvar vip-vi-state-hook nil
|
|
663 "*Hooks run just before the switch to Vi mode is completed.")
|
|
664 (defvar vip-insert-state-hook nil
|
|
665 "*Hooks run just before the switch to Insert mode is completed.")
|
|
666 (defvar vip-replace-state-hook nil
|
|
667 "*Hooks run just before the switch to Replace mode is completed.")
|
|
668 (defvar vip-emacs-state-hook nil
|
|
669 "*Hooks run just before the switch to Emacs mode is completed.")
|
|
670
|
|
671 (defvar vip-load-hook nil
|
|
672 "Hooks run just after loading Viper.")
|
|
673
|
|
674 ;;; viper-ex.el ends here
|