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