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