viper-init.el 35.6 KB
Newer Older
Michael Kifer's avatar
Michael Kifer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
;;; viper-init.el --- some common definitions for Viper

;; Copyright (C) 1997 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;; Code

(provide 'viper-init)

;; compiler pacifier
(defvar mark-even-if-inactive)
Michael Kifer's avatar
Michael Kifer committed
28 29 30
(defvar quail-mode)
(defvar iso-accents-mode)
(defvar viper-current-state)
Michael Kifer's avatar
Michael Kifer committed
31
(defvar viper-version)
Michael Kifer's avatar
Michael Kifer committed
32
(defvar viper-expert-level)
Michael Kifer's avatar
Michael Kifer committed
33 34 35
(defvar current-input-method)
(defvar default-input-method)
(defvar describe-current-input-method-function)
Michael Kifer's avatar
Michael Kifer committed
36 37
;; end pacifier

Michael Kifer's avatar
Michael Kifer committed
38 39 40 41

;; Viper version
(defun viper-version ()
  (interactive)
42
  (message "Viper version is %s" viper-version))
Michael Kifer's avatar
Michael Kifer committed
43

Michael Kifer's avatar
Michael Kifer committed
44
;; Is it XEmacs?
Michael Kifer's avatar
Michael Kifer committed
45
(defconst viper-xemacs-p (string-match "XEmacs" emacs-version))
Michael Kifer's avatar
Michael Kifer committed
46
;; Is it Emacs?
Michael Kifer's avatar
Michael Kifer committed
47
(defconst viper-emacs-p (not viper-xemacs-p))
Michael Kifer's avatar
Michael Kifer committed
48
;; Tell whether we are running as a window application or on a TTY
Michael Kifer's avatar
Michael Kifer committed
49 50
(defsubst viper-device-type ()
  (if viper-emacs-p
Michael Kifer's avatar
Michael Kifer committed
51 52 53
      window-system
    (device-type (selected-device))))
;; in XEmacs: device-type is tty on tty and stream in batch.
Michael Kifer's avatar
Michael Kifer committed
54 55
(defun viper-window-display-p ()
  (and (viper-device-type) (not (memq (viper-device-type) '(tty stream pc)))))
Michael Kifer's avatar
Michael Kifer committed
56

Michael Kifer's avatar
Michael Kifer committed
57 58
(defcustom viper-ms-style-os-p (memq system-type
				     '(ms-dos windows-nt windows-95))
Michael Kifer's avatar
Michael Kifer committed
59 60 61
  "Tells if Emacs is running under an MS-style OS: ms-dos, windows-nt, W95."
  :type 'boolean
  :tag "Is it Microsoft-made OS?"
Michael Kifer's avatar
Michael Kifer committed
62
  :group 'viper-misc)
Michael Kifer's avatar
Michael Kifer committed
63
(defcustom viper-vms-os-p (memq system-type '(vax-vms axp-vms))
Michael Kifer's avatar
Michael Kifer committed
64 65 66
  "Tells if Emacs is running under VMS."
  :type 'boolean
  :tag "Is it VMS?"
Michael Kifer's avatar
Michael Kifer committed
67
  :group 'viper-misc)
Michael Kifer's avatar
Michael Kifer committed
68

Michael Kifer's avatar
Michael Kifer committed
69
(defcustom viper-force-faces nil
Michael Kifer's avatar
Michael Kifer committed
70
  "If t, Viper will think that it is running on a display that supports faces.
Michael Kifer's avatar
Michael Kifer committed
71 72 73 74
This is provided as a temporary relief for users of graphics-capable terminals
that Viper doesn't know about.
In all likelihood, you don't need to bother with this setting."
  :type 'boolean
Michael Kifer's avatar
Michael Kifer committed
75
  :group 'viper-highlighting)
Michael Kifer's avatar
Michael Kifer committed
76

Michael Kifer's avatar
Michael Kifer committed
77 78 79 80 81
(defun viper-has-face-support-p ()
  (cond ((viper-window-display-p))
	(viper-force-faces)
	(viper-emacs-p (memq (viper-device-type) '(pc)))
	(viper-xemacs-p (memq (viper-device-type) '(tty pc)))))
Michael Kifer's avatar
Michael Kifer committed
82 83 84 85


;;; Macros

Michael Kifer's avatar
Michael Kifer committed
86
(defmacro viper-deflocalvar (var default-value &optional documentation)
87 88 89 90
  `(progn
    (defvar ,var ,default-value
      ,(format "%s\n\(buffer local\)" documentation))
    (make-variable-buffer-local ',var)))
Michael Kifer's avatar
Michael Kifer committed
91

Michael Kifer's avatar
Michael Kifer committed
92 93
;; (viper-loop COUNT BODY) Execute BODY COUNT times.
(defmacro viper-loop (count &rest body)
94 95 96 97
  `(let ((count ,count))
    (while (> count 0)
      ,@body
      (setq count (1- count)))))
Michael Kifer's avatar
Michael Kifer committed
98

Michael Kifer's avatar
Michael Kifer committed
99
(defmacro viper-buffer-live-p (buf)
100 101
  `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))

Michael Kifer's avatar
Michael Kifer committed
102
;; return buffer-specific macro definition, given a full macro definition
Michael Kifer's avatar
Michael Kifer committed
103
(defmacro viper-kbd-buf-alist (macro-elt)
104
  `(nth 1 ,macro-elt))
Michael Kifer's avatar
Michael Kifer committed
105
;; get a pair: (curr-buffer . macro-definition)
Michael Kifer's avatar
Michael Kifer committed
106
(defmacro viper-kbd-buf-pair (macro-elt)
107
  `(assoc (buffer-name) (viper-kbd-buf-alist ,macro-elt)))
Michael Kifer's avatar
Michael Kifer committed
108
;; get macro definition for current buffer
Michael Kifer's avatar
Michael Kifer committed
109
(defmacro viper-kbd-buf-definition (macro-elt)
110 111
  `(cdr (viper-kbd-buf-pair ,macro-elt)))

Michael Kifer's avatar
Michael Kifer committed
112
;; return mode-specific macro definitions, given a full macro definition
Michael Kifer's avatar
Michael Kifer committed
113
(defmacro viper-kbd-mode-alist (macro-elt)
114
  `(nth 2 ,macro-elt))
Michael Kifer's avatar
Michael Kifer committed
115
;; get a pair: (major-mode . macro-definition)
Michael Kifer's avatar
Michael Kifer committed
116
(defmacro viper-kbd-mode-pair (macro-elt)
117
  `(assoc major-mode (viper-kbd-mode-alist ,macro-elt)))
Michael Kifer's avatar
Michael Kifer committed
118
;; get macro definition for the current major mode
Michael Kifer's avatar
Michael Kifer committed
119
(defmacro viper-kbd-mode-definition (macro-elt)
120 121
  `(cdr (viper-kbd-mode-pair ,macro-elt)))

Michael Kifer's avatar
Michael Kifer committed
122
;; return global macro definition, given a full macro definition
Michael Kifer's avatar
Michael Kifer committed
123
(defmacro viper-kbd-global-pair (macro-elt)
124
  `(nth 3 ,macro-elt))
Michael Kifer's avatar
Michael Kifer committed
125
;; get global macro definition from an elt of macro-alist
Michael Kifer's avatar
Michael Kifer committed
126
(defmacro viper-kbd-global-definition (macro-elt)
127 128
  `(cdr (viper-kbd-global-pair ,macro-elt)))

Michael Kifer's avatar
Michael Kifer committed
129
;; last elt of a sequence
Michael Kifer's avatar
Michael Kifer committed
130
(defsubst viper-seq-last-elt (seq)
Michael Kifer's avatar
Michael Kifer committed
131
  (elt seq (1- (length seq))))
Michael Kifer's avatar
Michael Kifer committed
132 133 134 135 136 137 138 139 140 141 142 143 144

(defsubst viper-string-to-list (string)
  (append (vconcat string) nil))

(defsubst viper-charlist-to-string (list)
  (mapconcat 'char-to-string list ""))

;; like char-after/before, but saves typing
(defun viper-char-at-pos (direction &optional offset)
  (or (integerp offset) (setq offset 0))
  (if (eq direction 'forward)
      (char-after (+ (point) offset))
    (char-before (- (point) offset))))
145

Michael Kifer's avatar
Michael Kifer committed
146

Michael Kifer's avatar
Michael Kifer committed
147 148 149
(defvar viper-minibuffer-overlay-priority 300)
(defvar viper-replace-overlay-priority 400)
(defvar viper-search-overlay-priority 500)
150

Michael Kifer's avatar
Michael Kifer committed
151 152 153 154

;;; Viper minor modes

;; Mode for vital things like \e, C-z.
Michael Kifer's avatar
Michael Kifer committed
155
(viper-deflocalvar viper-vi-intercept-minor-mode nil)
Michael Kifer's avatar
Michael Kifer committed
156

Michael Kifer's avatar
Michael Kifer committed
157
(viper-deflocalvar viper-vi-basic-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
158
  "Viper's minor mode for Vi bindings.")
159

Michael Kifer's avatar
Michael Kifer committed
160
(viper-deflocalvar viper-vi-local-user-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
161 162
  "Auxiliary minor mode for user-defined local bindings in Vi state.")

Michael Kifer's avatar
Michael Kifer committed
163
(viper-deflocalvar viper-vi-global-user-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
164 165
  "Auxiliary minor mode for user-defined global bindings in Vi state.")

Michael Kifer's avatar
Michael Kifer committed
166
(viper-deflocalvar viper-vi-state-modifier-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
167 168
  "Minor mode used to make major-mode-specific modification to Vi state.")

Michael Kifer's avatar
Michael Kifer committed
169
(viper-deflocalvar viper-vi-diehard-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
170 171
  "This minor mode is in effect when the user wants Viper to be Vi.")

Michael Kifer's avatar
Michael Kifer committed
172
(viper-deflocalvar viper-vi-kbd-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
173 174 175 176 177
  "Minor mode for Ex command macros in Vi state.
The corresponding keymap stores key bindings of Vi macros defined with
the Ex command :map.")

;; Mode for vital things like \e, C-z.
Michael Kifer's avatar
Michael Kifer committed
178
(viper-deflocalvar viper-insert-intercept-minor-mode nil)
Michael Kifer's avatar
Michael Kifer committed
179

Michael Kifer's avatar
Michael Kifer committed
180
(viper-deflocalvar viper-insert-basic-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
181 182
  "Viper's minor mode for bindings in Insert mode.")

Michael Kifer's avatar
Michael Kifer committed
183
(viper-deflocalvar viper-insert-local-user-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
184 185 186 187
  "Auxiliary minor mode for buffer-local user-defined bindings in Insert state.
This is a way to overshadow normal Insert mode bindings locally to certain
designated buffers.")

Michael Kifer's avatar
Michael Kifer committed
188
(viper-deflocalvar viper-insert-global-user-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
189 190
  "Auxiliary minor mode for global user-defined bindings in Insert state.")

Michael Kifer's avatar
Michael Kifer committed
191
(viper-deflocalvar viper-insert-state-modifier-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
192 193
  "Minor mode used to make major-mode-specific modification to Insert state.")

Michael Kifer's avatar
Michael Kifer committed
194
(viper-deflocalvar viper-insert-diehard-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
195 196 197
  "Minor mode that simulates Vi very closely.
Not recommened, except for the novice user.")

Michael Kifer's avatar
Michael Kifer committed
198
(viper-deflocalvar viper-insert-kbd-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
199 200 201 202
"Minor mode for Ex command macros Insert state.
The corresponding keymap stores key bindings of Vi macros defined with
the Ex command :map!.")

Michael Kifer's avatar
Michael Kifer committed
203
(viper-deflocalvar viper-replace-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
204 205
  "Minor mode in effect in replace state (cw, C, and the like commands).")

Michael Kifer's avatar
Michael Kifer committed
206
;; Mode for vital things like \C-z and \C-x) This is set to t, when viper-mode
Michael Kifer's avatar
Michael Kifer committed
207 208
;; is invoked.  So, any new buffer will have C-z defined as switch to Vi,
;; unless we switched states in this buffer
Michael Kifer's avatar
Michael Kifer committed
209
(viper-deflocalvar viper-emacs-intercept-minor-mode nil)
210

Michael Kifer's avatar
Michael Kifer committed
211
(viper-deflocalvar viper-emacs-local-user-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
212 213
  "Minor mode for local user bindings effective in Emacs state.
Users can use it to override Emacs bindings when Viper is in its Emacs
214 215
state.")

Michael Kifer's avatar
Michael Kifer committed
216
(viper-deflocalvar viper-emacs-global-user-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
217 218
  "Minor mode for global user bindings in effect in Emacs state.
Users can use it to override Emacs bindings when Viper is in its Emacs
219
state.")
Michael Kifer's avatar
Michael Kifer committed
220

Michael Kifer's avatar
Michael Kifer committed
221
(viper-deflocalvar viper-emacs-kbd-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
222 223
  "Minor mode for Vi style macros in Emacs state.
The corresponding keymap stores key bindings of Vi macros defined with
Michael Kifer's avatar
Michael Kifer committed
224
`viper-record-kbd-macro' command.  There is no Ex-level command to do this
Michael Kifer's avatar
Michael Kifer committed
225 226
interactively.")

Michael Kifer's avatar
Michael Kifer committed
227
(viper-deflocalvar viper-emacs-state-modifier-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
228 229 230 231
  "Minor mode used to make major-mode-specific modification to Emacs state.
For instance, a Vi purist may want to bind `dd' in Dired mode to a function
that deletes a file.")

Michael Kifer's avatar
Michael Kifer committed
232
(viper-deflocalvar viper-vi-minibuffer-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
233 234
   "Minor mode that forces Vi-style when the Minibuffer is in Vi state.")

Michael Kifer's avatar
Michael Kifer committed
235
(viper-deflocalvar viper-insert-minibuffer-minor-mode nil
Michael Kifer's avatar
Michael Kifer committed
236
   "Minor mode that forces Vi-style when the Minibuffer is in Insert state.")
237

Michael Kifer's avatar
Michael Kifer committed
238 239 240 241


;; Some common error messages

Michael Kifer's avatar
Michael Kifer committed
242 243 244 245 246 247 248 249 250 251 252 253
(defconst viper-SpuriousText "Spurious text after command"  "")
(defconst viper-BadExCommand "Not an editor command"   "")
(defconst viper-InvalidCommandArgument "Invalid command argument"   "")
(defconst viper-NoPrevSearch "No previous search string"   "")
(defconst viper-EmptyRegister "`%c': Nothing in this register"   "")
(defconst viper-InvalidRegister "`%c': Invalid register"   "")
(defconst viper-EmptyTextmarker "`%c': Text marker doesn't point anywhere"   "")
(defconst viper-InvalidTextmarker "`%c': Invalid text marker"   "")
(defconst viper-InvalidViCommand "Invalid command"   "")
(defconst viper-BadAddress "Ill-formed address"   "")
(defconst viper-FirstAddrExceedsSecond "First address exceeds second"   "")
(defconst viper-NoFileSpecified "No file specified"   "")
Michael Kifer's avatar
Michael Kifer committed
254

255
;; Is t until viper-mode executes for the very first time.
Michael Kifer's avatar
Michael Kifer committed
256
;; Prevents recursive descend into startup messages.
Michael Kifer's avatar
Michael Kifer committed
257
(defvar viper-first-time t)
Michael Kifer's avatar
Michael Kifer committed
258

Michael Kifer's avatar
Michael Kifer committed
259
(defvar viper-expert-level (if (boundp 'viper-expert-level) viper-expert-level 0)
Michael Kifer's avatar
Michael Kifer committed
260
  "User's expert level.
Michael Kifer's avatar
Michael Kifer committed
261 262 263 264
The minor mode viper-vi-diehard-minor-mode is in effect when
viper-expert-level is 1 or 2 or when viper-want-emacs-keys-in-vi is t.
The minor mode viper-insert-diehard-minor-mode is in effect when
viper-expert-level is 1 or 2 or if viper-want-emacs-keys-in-insert is t.
Michael Kifer's avatar
Michael Kifer committed
265
Use `M-x viper-set-expert-level' to change this.")
Michael Kifer's avatar
Michael Kifer committed
266

Michael Kifer's avatar
Michael Kifer committed
267
;; Max expert level supported by Viper.  This is NOT a user option.
Michael Kifer's avatar
Michael Kifer committed
268
;; It is here to make it hard for the user from resetting it.
Michael Kifer's avatar
Michael Kifer committed
269
(defconst viper-max-expert-level 5)
Michael Kifer's avatar
Michael Kifer committed
270 271


Michael Kifer's avatar
Michael Kifer committed
272 273 274 275
;;; ISO characters and MULE

;; If non-nil, ISO accents will be turned on in insert/replace emacs states and
;; turned off in vi-state.  For some users, this behavior may be too
Michael Kifer's avatar
Michael Kifer committed
276
;; primitive.  In this case, use insert/emacs/vi state hooks.
Michael Kifer's avatar
Michael Kifer committed
277
(viper-deflocalvar viper-automatic-iso-accents nil "")
Michael Kifer's avatar
Michael Kifer committed
278
;; Set iso-accents-mode to ARG.  Check if it is bound first
Michael Kifer's avatar
Michael Kifer committed
279 280 281
(defsubst viper-set-iso-accents-mode (arg)
  (if (boundp 'iso-accents-mode)
      (setq iso-accents-mode arg)))
282

Michael Kifer's avatar
Michael Kifer committed
283 284 285
;; Internal flag used to control when viper mule hooks are run.
;; Don't change this!
(defvar viper-mule-hook-flag t)
Michael Kifer's avatar
Michael Kifer committed
286
;; If non-nil, the default intl.  input method is turned on.
Michael Kifer's avatar
Michael Kifer committed
287
(viper-deflocalvar viper-special-input-method nil "")
288

Michael Kifer's avatar
Michael Kifer committed
289 290 291 292 293 294 295 296 297 298 299
;; viper hook to run on input-method activation
(defun viper-activate-input-method-action ()
  (if (null viper-mule-hook-flag)
      ()
    (setq viper-special-input-method t)
    ;; turn off special input methods in vi-state
    (if (eq viper-current-state 'vi-state)
	(viper-set-input-method nil))
    (if (memq viper-current-state '(vi-state insert-state replace-state))
	(message "Viper special input method%s: on"
		 (if (or current-input-method default-input-method)
300
		     (format " %S"
Michael Kifer's avatar
Michael Kifer committed
301 302 303
			     (or current-input-method default-input-method))
		   "")))
    ))
Michael Kifer's avatar
Michael Kifer committed
304

Michael Kifer's avatar
Michael Kifer committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
;; viper hook to run on input-method deactivation
(defun viper-inactivate-input-method-action ()
  (if (null viper-mule-hook-flag)
      ()
    (setq viper-special-input-method nil)
    (if (memq viper-current-state '(vi-state insert-state replace-state))
	(message "Viper special input method%s: off"
		 (if (or current-input-method default-input-method)
		     (format " %S"
			     (or current-input-method default-input-method))
		   "")))))

(defun viper-inactivate-input-method ()
  (cond ((and viper-emacs-p (fboundp 'inactivate-input-method))
	 (inactivate-input-method))
	((and viper-xemacs-p (boundp 'current-input-method))
	 ;; XEmacs had broken quil-mode for some time, so we are working around
322
	 ;; it here
Michael Kifer's avatar
Michael Kifer committed
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
	 (setq quail-mode nil)
	 (if (featurep 'quail)
	     (quail-delete-overlays))
	 (setq describe-current-input-method-function nil)
	 (setq current-input-method nil)
	 (run-hooks 'input-method-inactivate-hook)
	 (force-mode-line-update))
	))
(defun viper-activate-input-method ()
  (cond ((and viper-emacs-p (fboundp 'activate-input-method))
	 (activate-input-method default-input-method))
	((and viper-xemacs-p (fboundp 'quail-mode))
	 (quail-mode 1))))

;; Set quail-mode to ARG
(defun viper-set-input-method (arg)
  (setq viper-mule-hook-flag t) ; just a precaution
  (let (viper-mule-hook-flag) ; temporarily inactivate viper mule hooks
    (cond ((and arg (> (prefix-numeric-value arg) 0) default-input-method)
	   ;; activate input method
	   (viper-activate-input-method))
	  (t ; deactivate input method
	   (viper-inactivate-input-method)))
    ))

Michael Kifer's avatar
Michael Kifer committed
348 349 350 351

;; VI-style Undo

;; Used to 'undo' complex commands, such as replace and insert commands.
Michael Kifer's avatar
Michael Kifer committed
352 353
(viper-deflocalvar viper-undo-needs-adjustment nil)
(put 'viper-undo-needs-adjustment 'permanent-local t)
Michael Kifer's avatar
Michael Kifer committed
354 355

;; A mark that Viper puts on buffer-undo-list.  Marks the beginning of a
Michael Kifer's avatar
Michael Kifer committed
356
;; complex command that must be undone atomically.  If inserted, it is
Michael Kifer's avatar
Michael Kifer committed
357 358
;; erased by viper-change-state-to-vi and viper-repeat.
(defconst viper-buffer-undo-list-mark 'viper)
Michael Kifer's avatar
Michael Kifer committed
359

Michael Kifer's avatar
Michael Kifer committed
360
(defcustom viper-keep-point-on-undo nil
Michael Kifer's avatar
Michael Kifer committed
361
  "*Non-nil means not to move point while undoing commands.
Michael Kifer's avatar
Michael Kifer committed
362
This style is different from Emacs and Vi.  Try it to see if
Michael Kifer's avatar
Michael Kifer committed
363 364 365
it better fits your working style."
  :type 'boolean
  :tag "Preserve Position of Point After Undo"
366
  :group 'viper)
Michael Kifer's avatar
Michael Kifer committed
367 368 369

;; Replace mode and changing text

Michael Kifer's avatar
Michael Kifer committed
370
;; Hack used to pass global states around for short period of time
Michael Kifer's avatar
Michael Kifer committed
371 372 373 374
(viper-deflocalvar viper-intermediate-command nil "")

;; This is used to pass the right Vi command key sequence to
;; viper-set-destructive-command whenever (this-command-keys) doesn't give the
Michael Kifer's avatar
Michael Kifer committed
375 376
;; right result.  For instance, in commands like c/bla<RET>,
;; (this-command-keys) will return ^M, which invoked exit-minibuffer, while we
377
;; need "c/"
Michael Kifer's avatar
Michael Kifer committed
378
(defconst viper-this-command-keys nil)
Michael Kifer's avatar
Michael Kifer committed
379 380

;; Indicates that the current destructive command has started in replace mode.
Michael Kifer's avatar
Michael Kifer committed
381
(viper-deflocalvar viper-began-as-replace nil "")
Michael Kifer's avatar
Michael Kifer committed
382

Michael Kifer's avatar
Michael Kifer committed
383
(defcustom viper-allow-multiline-replace-regions t
Michael Kifer's avatar
Michael Kifer committed
384 385 386
  "If non-nil, Viper will allow multi-line replace regions.
This is an extension to standard Vi.
If nil, commands that attempt to replace text spanning multiple lines first
Michael Kifer's avatar
Michael Kifer committed
387 388 389 390
delete the text being replaced, as in standard Vi."
  :type 'boolean
  :group 'viper)

Michael Kifer's avatar
Michael Kifer committed
391
(defcustom viper-replace-overlay-cursor-color "Red"
Michael Kifer's avatar
Michael Kifer committed
392 393 394
  "*Cursor color when Viper is in Replace state."
  :type 'string
  :group 'viper)
Michael Kifer's avatar
Michael Kifer committed
395
(defcustom viper-insert-state-cursor-color "Green"
Michael Kifer's avatar
Michael Kifer committed
396 397 398
  "Cursor color when Viper is in insert state."
  :type 'string
  :group 'viper)
Michael Kifer's avatar
Michael Kifer committed
399

Michael Kifer's avatar
Michael Kifer committed
400 401
;; internal var, used to remember the default cursor color of emacs frames
(defvar viper-vi-state-cursor-color nil)
402

Michael Kifer's avatar
Michael Kifer committed
403 404
(viper-deflocalvar viper-replace-overlay nil "")
(put 'viper-replace-overlay 'permanent-local t)
Michael Kifer's avatar
Michael Kifer committed
405

Michael Kifer's avatar
Michael Kifer committed
406
(defcustom viper-replace-region-end-delimiter "$"
Michael Kifer's avatar
Michael Kifer committed
407
  "A string marking the end of replacement regions.
Michael Kifer's avatar
Michael Kifer committed
408
It is used only with TTYs or if `viper-use-replace-region-delimiters'
Michael Kifer's avatar
Michael Kifer committed
409 410 411
is non-nil."
  :type 'string
  :group 'viper)
Michael Kifer's avatar
Michael Kifer committed
412
(defcustom viper-replace-region-start-delimiter ""
Michael Kifer's avatar
Michael Kifer committed
413
  "A string marking the beginning of replacement regions.
Michael Kifer's avatar
Michael Kifer committed
414
It is used only with TTYs or if `viper-use-replace-region-delimiters'
Michael Kifer's avatar
Michael Kifer committed
415 416 417
is non-nil."
  :type 'string
  :group 'viper)
418
(defcustom viper-use-replace-region-delimiters
Michael Kifer's avatar
Michael Kifer committed
419 420
  (or (not (viper-has-face-support-p))
      (and viper-xemacs-p (eq (viper-device-type) 'tty)))
Michael Kifer's avatar
Michael Kifer committed
421 422
  "*If non-nil, Viper will always use `viper-replace-region-end-delimiter' and
`viper-replace-region-start-delimiter' to delimit replacement regions, even on
Michael Kifer's avatar
Michael Kifer committed
423
color displays.  By default, the delimiters are used only on TTYs."
Michael Kifer's avatar
Michael Kifer committed
424 425
  :type 'boolean
  :group 'viper)
Michael Kifer's avatar
Michael Kifer committed
426 427 428 429 430

(defcustom viper-read-buffer-function 'read-buffer
  "Function to use for prompting the user for a buffer name."
  :type 'symbol
  :group 'viper)
431

Michael Kifer's avatar
Michael Kifer committed
432
;; XEmacs requires glyphs
Michael Kifer's avatar
Michael Kifer committed
433
(if viper-xemacs-p
Michael Kifer's avatar
Michael Kifer committed
434
    (progn
Michael Kifer's avatar
Michael Kifer committed
435 436 437 438 439 440
      (or (glyphp viper-replace-region-end-delimiter)
	  (setq viper-replace-region-end-delimiter
		(make-glyph viper-replace-region-end-delimiter)))
      (or (glyphp viper-replace-region-start-delimiter)
	  (setq viper-replace-region-start-delimiter
		(make-glyph viper-replace-region-start-delimiter)))
Michael Kifer's avatar
Michael Kifer committed
441
      ))
442 443


Michael Kifer's avatar
Michael Kifer committed
444
;; These are local marker that must be initialized to nil and moved with
Michael Kifer's avatar
Michael Kifer committed
445
;; `viper-move-marker-locally'
Michael Kifer's avatar
Michael Kifer committed
446 447
;;
;; Remember the last position inside the replace region.
Michael Kifer's avatar
Michael Kifer committed
448
(viper-deflocalvar viper-last-posn-in-replace-region nil)
Michael Kifer's avatar
Michael Kifer committed
449
;; Remember the last position while inserting
Michael Kifer's avatar
Michael Kifer committed
450 451 452
(viper-deflocalvar viper-last-posn-while-in-insert-state nil)
(put 'viper-last-posn-in-replace-region 'permanent-local t)
(put 'viper-last-posn-while-in-insert-state 'permanent-local t)
Michael Kifer's avatar
Michael Kifer committed
453

Michael Kifer's avatar
Michael Kifer committed
454 455
(viper-deflocalvar viper-sitting-in-replace nil "")
(put 'viper-sitting-in-replace 'permanent-local t)
456

Michael Kifer's avatar
Michael Kifer committed
457 458
;; Remember the number of characters that have to be deleted in replace
;; mode to compensate for the inserted characters.
Michael Kifer's avatar
Michael Kifer committed
459
(viper-deflocalvar viper-replace-chars-to-delete 0 "")
Michael Kifer's avatar
Michael Kifer committed
460
;; This variable is used internally by the before/after changed functions to
Michael Kifer's avatar
Michael Kifer committed
461
;; determine how many chars were deleted by the change.  This can't be
Michael Kifer's avatar
Michael Kifer committed
462 463 464 465
;; determined inside after-change-functions because those get the length of the
;; deleted region, not the number of chars deleted (which are two different
;; things under MULE).
(viper-deflocalvar viper-replace-region-chars-deleted 0 "")
Michael Kifer's avatar
Michael Kifer committed
466 467

;; Insertion ring and command ring
Michael Kifer's avatar
Michael Kifer committed
468
(defcustom viper-insertion-ring-size 14
Michael Kifer's avatar
Michael Kifer committed
469 470 471 472
  "The size of history of inserted text.
This is a list where Viper keeps the history of previously inserted pieces of
text."
  :type 'integer
Michael Kifer's avatar
Michael Kifer committed
473
  :group 'viper-misc)
Michael Kifer's avatar
Michael Kifer committed
474
;; The insertion ring.
Michael Kifer's avatar
Michael Kifer committed
475
(defvar viper-insertion-ring nil)
Michael Kifer's avatar
Michael Kifer committed
476
;; This is temp insertion ring.  Used to do rotation for display purposes.
Michael Kifer's avatar
Michael Kifer committed
477 478 479
;; When rotation just started, it is initialized to viper-insertion-ring.
(defvar viper-temp-insertion-ring nil)
(defvar viper-last-inserted-string-from-insertion-ring "")
Michael Kifer's avatar
Michael Kifer committed
480

Michael Kifer's avatar
Michael Kifer committed
481
(defcustom viper-command-ring-size 14
Michael Kifer's avatar
Michael Kifer committed
482 483
  "The size of history of Vi commands repeatable with dot."
  :type 'integer
Michael Kifer's avatar
Michael Kifer committed
484
  :group 'viper-misc)
Michael Kifer's avatar
Michael Kifer committed
485
;; The command ring.
Michael Kifer's avatar
Michael Kifer committed
486
(defvar viper-command-ring nil)
Michael Kifer's avatar
Michael Kifer committed
487
;; This is temp command ring.  Used to do rotation for display purposes.
Michael Kifer's avatar
Michael Kifer committed
488 489
;; When rotation just started, it is initialized to viper-command-ring.
(defvar viper-temp-command-ring nil)
Michael Kifer's avatar
Michael Kifer committed
490

Michael Kifer's avatar
Michael Kifer committed
491
;; Fast keyseq and ESC keyseq timeouts
Michael Kifer's avatar
Michael Kifer committed
492
(defcustom viper-fast-keyseq-timeout 200
Michael Kifer's avatar
Michael Kifer committed
493
  "*Key sequence separated by no more than this many milliseconds is viewed as a Vi-style macro, if such a macro is defined.
Michael Kifer's avatar
Michael Kifer committed
494
Setting this too high may slow down your typing.  Setting this value too low
495
will make it hard to use Vi-style timeout macros."
Michael Kifer's avatar
Michael Kifer committed
496
  :type 'integer
Michael Kifer's avatar
Michael Kifer committed
497
  :group 'viper-misc)
Michael Kifer's avatar
Michael Kifer committed
498

Michael Kifer's avatar
Michael Kifer committed
499 500
(defcustom viper-ESC-keyseq-timeout (if (viper-window-display-p)
				      0 viper-fast-keyseq-timeout)
Michael Kifer's avatar
Michael Kifer committed
501
  "*Key sequence beginning with ESC and separated by no more than this many milliseconds is considered to be generated by a keyboard function key.
Michael Kifer's avatar
Michael Kifer committed
502
Setting this too high may slow down switching from insert to vi state.  Setting
Michael Kifer's avatar
Michael Kifer committed
503 504 505
this value too low will make it impossible to use function keys in insert mode
on a dumb terminal."
  :type 'integer
Michael Kifer's avatar
Michael Kifer committed
506
  :group 'viper-misc)
Michael Kifer's avatar
Michael Kifer committed
507

508 509 510 511 512
(defcustom viper-translate-all-ESC-keysequences (not (viper-window-display-p))
  "Allow translation of all key sequences into commands.
Normally, Viper lets Emacs translate only those ESC key sequences that are
defined in the low-level key-translation-map or function-key-map, such as those
emitted by the arrow and function keys. Other sequences, e.g., \\e/, are
513
treated as ESC command followed by a `/'. This is done for people who type fast
514 515 516 517 518 519 520
and tend to hit other characters right after they hit ESC. Other people like
Emacs to translate ESC sequences all the time. 
The default is to translate all sequences only when using a dumb terminal.
This permits you to use ESC as a meta key in insert mode."
  :type 'boolean
  :group 'viper-misc)

Michael Kifer's avatar
Michael Kifer committed
521 522 523
;; Modes and related variables

;; Current mode.  One of: `emacs-state', `vi-state', `insert-state'
Michael Kifer's avatar
Michael Kifer committed
524
(viper-deflocalvar viper-current-state 'emacs-state)
Michael Kifer's avatar
Michael Kifer committed
525 526 527 528 529


;; Autoindent in insert

;; Variable that keeps track of whether C-t has been pressed.
Michael Kifer's avatar
Michael Kifer committed
530
(viper-deflocalvar viper-cted nil "")
Michael Kifer's avatar
Michael Kifer committed
531 532

;; Preserve the indent value, used by C-d in insert mode.
Michael Kifer's avatar
Michael Kifer committed
533
(viper-deflocalvar viper-current-indent 0)
Michael Kifer's avatar
Michael Kifer committed
534 535

;; Whether to preserve the indent, used by C-d in insert mode.
Michael Kifer's avatar
Michael Kifer committed
536
(viper-deflocalvar viper-preserve-indent nil)
Michael Kifer's avatar
Michael Kifer committed
537

Michael Kifer's avatar
Michael Kifer committed
538 539
(viper-deflocalvar viper-auto-indent nil "")
(defcustom viper-auto-indent nil
Michael Kifer's avatar
Michael Kifer committed
540 541 542 543 544
  "*Enable autoindent, if t.
This is a buffer-local variable."
  :type 'boolean
  :group 'viper)

Michael Kifer's avatar
Michael Kifer committed
545 546
(viper-deflocalvar viper-electric-mode t "")
(defcustom viper-electric-mode t
Michael Kifer's avatar
Michael Kifer committed
547 548 549 550
  "*If t, electrify Viper.
Currently, this only electrifies auto-indentation, making it appropriate to the
mode of the buffer.
This means that auto-indentation will depart from standard Vi and will indent
Michael Kifer's avatar
Michael Kifer committed
551
appropriate to the mode of the buffer.  This is especially useful for editing
Michael Kifer's avatar
Michael Kifer committed
552 553 554 555
programs and LaTeX documents."
  :type 'boolean
  :group 'viper)

Michael Kifer's avatar
Michael Kifer committed
556
(defcustom viper-shift-width 8
Michael Kifer's avatar
Michael Kifer committed
557 558 559
  "*The value of the shiftwidth.
This determines the number of columns by which the Ctl-t moves the cursor in
the Insert state."
Michael Kifer's avatar
Michael Kifer committed
560 561
  :type 'integer
  :group 'viper)
Michael Kifer's avatar
Michael Kifer committed
562 563 564

;; Variables for repeating destructive commands

Michael Kifer's avatar
Michael Kifer committed
565
(defcustom viper-keep-point-on-repeat t
Michael Kifer's avatar
Michael Kifer committed
566 567 568
  "*If t, don't move point when repeating previous command.
This is useful for doing repeated changes with the '.' key.
The user can change this to nil, if she likes when the cursor moves
Michael Kifer's avatar
Michael Kifer committed
569 570
to a new place after repeating previous Vi command."
  :type 'boolean
571
  :group 'viper)
Michael Kifer's avatar
Michael Kifer committed
572 573

;; Remember insert point as a marker.  This is a local marker that must be
Michael Kifer's avatar
Michael Kifer committed
574 575 576
;; initialized to nil and moved with `viper-move-marker-locally'.
(viper-deflocalvar viper-insert-point nil)
(put 'viper-insert-point 'permanent-local t)
Michael Kifer's avatar
Michael Kifer committed
577 578

;; This remembers the point before dabbrev-expand was called.
Michael Kifer's avatar
Michael Kifer committed
579 580
;; If viper-insert-point turns out to be bigger than that, it is reset
;; back to viper-pre-command-point.
Michael Kifer's avatar
Michael Kifer committed
581 582
;; The reason this is needed is because dabbrev-expand (and possibly
;; others) may jump to before the insertion point, delete something and
Michael Kifer's avatar
Michael Kifer committed
583
;; then reinsert a bigger piece.  For instance:  bla^blo
Michael Kifer's avatar
Michael Kifer committed
584
;; If dabbrev-expand is called after `blo' and ^ undicates viper-insert-point,
Michael Kifer's avatar
Michael Kifer committed
585 586
;; then point jumps to the beginning of `blo'.  If expansion is found, `blablo'
;; is deleted, and we have |^, where | denotes point.  Next, dabbrev-expand
Michael Kifer's avatar
Michael Kifer committed
587 588
;; will insert the expansion, and we get: blablo^
;; Whatever we insert next goes before the ^, i.e., before the
Michael Kifer's avatar
Michael Kifer committed
589 590
;; viper-insert-point marker.  So, Viper will think that nothing was
;; inserted.  Remembering the orig position of the marker circumvents the
Michael Kifer's avatar
Michael Kifer committed
591 592
;; problem.
;; We don't know of any command, except dabbrev-expand, that has the same
Michael Kifer's avatar
Michael Kifer committed
593
;; problem.  However, the same trick can be used if such a command is
Michael Kifer's avatar
Michael Kifer committed
594 595
;; discovered later.
;;
Michael Kifer's avatar
Michael Kifer committed
596 597
(viper-deflocalvar viper-pre-command-point nil)
(put 'viper-pre-command-point 'permanent-local t) ; this is probably an overkill
Michael Kifer's avatar
Michael Kifer committed
598 599

;; This is used for saving inserted text.
Michael Kifer's avatar
Michael Kifer committed
600
(defvar viper-last-insertion  nil)
601

Michael Kifer's avatar
Michael Kifer committed
602
;; Remembers the last replaced region.
Michael Kifer's avatar
Michael Kifer committed
603
(defvar viper-last-replace-region "")
604

Michael Kifer's avatar
Michael Kifer committed
605
;; Remember com point as a marker.
Michael Kifer's avatar
Michael Kifer committed
606
;; This is a local marker.  Should be moved with `viper-move-marker-locally'
Michael Kifer's avatar
Michael Kifer committed
607
(viper-deflocalvar viper-com-point nil)
Michael Kifer's avatar
Michael Kifer committed
608 609 610 611 612 613 614 615 616 617 618

;; If non-nil, the value is a list (M-COM VAL COM REG inserted-text cmd-keys)
;; It is used to re-execute last destructive command.
;; M-COM is a Lisp symbol representing the function to be executed.
;; VAL is the prefix argument that was used with that command.
;; COM is an internal descriptor, such as ?r, ?c, ?C, which contains
;; additional information on how the function in M-COM is to be handled.
;; REG is the register used by command
;; INSERTED-TEXT is text inserted by that command (in case of o, c, C, i, r
;; commands).
;; COMMAND-KEYS are the keys that were typed to invoke the command.
Michael Kifer's avatar
Michael Kifer committed
619
(defvar viper-d-com nil)
Michael Kifer's avatar
Michael Kifer committed
620 621

;; The character remembered by the Vi `r' command.
Michael Kifer's avatar
Michael Kifer committed
622
(defvar viper-d-char nil)
Michael Kifer's avatar
Michael Kifer committed
623 624

;; Name of register to store deleted or yanked strings
Michael Kifer's avatar
Michael Kifer committed
625
(defvar viper-use-register nil)
Michael Kifer's avatar
Michael Kifer committed
626 627


Michael Kifer's avatar
Michael Kifer committed
628
;;; Variables for Moves and Searches
Michael Kifer's avatar
Michael Kifer committed
629

Michael Kifer's avatar
Michael Kifer committed
630 631 632 633 634
(defgroup viper-search nil
  "Variables that define the search and query-replace behavior of Viper."
  :prefix "viper-"
  :group 'viper)

Michael Kifer's avatar
Michael Kifer committed
635
;; For use by `;' command.
Michael Kifer's avatar
Michael Kifer committed
636
(defvar viper-f-char nil)
Michael Kifer's avatar
Michael Kifer committed
637 638

;; For use by `.' command.
Michael Kifer's avatar
Michael Kifer committed
639
(defvar viper-F-char nil)
Michael Kifer's avatar
Michael Kifer committed
640 641

;; For use by `;' command.
Michael Kifer's avatar
Michael Kifer committed
642
(defvar viper-f-forward nil)
Michael Kifer's avatar
Michael Kifer committed
643 644

;; For use by `;' command.
Michael Kifer's avatar
Michael Kifer committed
645
(defvar viper-f-offset nil)
Michael Kifer's avatar
Michael Kifer committed
646 647

;; Last search string
Michael Kifer's avatar
Michael Kifer committed
648
(defvar viper-s-string "")
Michael Kifer's avatar
Michael Kifer committed
649

Michael Kifer's avatar
Michael Kifer committed
650
(defcustom viper-quote-string "> "
Michael Kifer's avatar
Michael Kifer committed
651 652 653
  "String inserted at the beginning of quoted region."
  :type 'string
  :group 'viper)
Michael Kifer's avatar
Michael Kifer committed
654 655

;; If t, search is forward.
Michael Kifer's avatar
Michael Kifer committed
656
(defvar viper-s-forward nil)
Michael Kifer's avatar
Michael Kifer committed
657

Michael Kifer's avatar
Michael Kifer committed
658
(defcustom viper-case-fold-search nil
Michael Kifer's avatar
Michael Kifer committed
659 660
  "*If not nil, search ignores cases."
  :type 'boolean
Michael Kifer's avatar
Michael Kifer committed
661
  :group 'viper-search)
Michael Kifer's avatar
Michael Kifer committed
662

Michael Kifer's avatar
Michael Kifer committed
663
(defcustom viper-re-search t
Michael Kifer's avatar
Michael Kifer committed
664 665 666
  "*If not nil, search is regexp search, otherwise vanilla search."
  :type 'boolean
  :tag "Regexp Search"
Michael Kifer's avatar
Michael Kifer committed
667
  :group 'viper-search)
Michael Kifer's avatar
Michael Kifer committed
668

Michael Kifer's avatar
Michael Kifer committed
669
(defcustom viper-search-scroll-threshold 2
Michael Kifer's avatar
Michael Kifer committed
670 671 672
  "*If search lands within this threshnold from the window top/bottom,
the window will be scrolled up or down appropriately, to reveal context.
If you want Viper search to behave as usual in Vi, set this variable to a
Michael Kifer's avatar
Michael Kifer committed
673 674
negative number."
  :type 'boolean
Michael Kifer's avatar
Michael Kifer committed
675
  :group 'viper-search)
Michael Kifer's avatar
Michael Kifer committed
676

Michael Kifer's avatar
Michael Kifer committed
677
(defcustom viper-re-query-replace t
Michael Kifer's avatar
Michael Kifer committed
678 679 680
  "*If t then do regexp replace, if nil then do string replace."
  :type 'boolean
  :tag "Regexp Query Replace"
Michael Kifer's avatar
Michael Kifer committed
681
  :group 'viper-search)
Michael Kifer's avatar
Michael Kifer committed
682

Michael Kifer's avatar
Michael Kifer committed
683
(defcustom viper-re-replace t
Michael Kifer's avatar
Michael Kifer committed
684
  "*If t, do regexp replace.  nil means do string replace."
Michael Kifer's avatar
Michael Kifer committed
685 686
  :type 'boolean
  :tag "Regexp Replace"
Michael Kifer's avatar
Michael Kifer committed
687
  :group 'viper-search)
Michael Kifer's avatar
Michael Kifer committed
688

Michael Kifer's avatar
Michael Kifer committed
689
(defcustom viper-parse-sexp-ignore-comments t
Michael Kifer's avatar
Michael Kifer committed
690 691 692 693
  "*If t, `%' ignores the parentheses that occur inside comments."
  :type 'boolean
  :group 'viper)

Michael Kifer's avatar
Michael Kifer committed
694 695
(viper-deflocalvar viper-ex-style-motion t "")
(defcustom viper-ex-style-motion t
Michael Kifer's avatar
Michael Kifer committed
696 697 698 699 700
  "*If t, the commands l,h do not cross lines, etc (Ex-style).
If nil, these commands cross line boundaries."
  :type 'boolean
  :group 'viper)

Michael Kifer's avatar
Michael Kifer committed
701 702 703 704 705
(viper-deflocalvar viper-ex-style-editing t "")
(defcustom viper-ex-style-editing t
  "*If t, Ex-style behavior while editing in Vi command and insert states.
`Backspace' and `Delete' don't cross line boundaries in insert.
`X' and `x' can't delete characters across line boundary in Vi, etc.
Michael Kifer's avatar
Michael Kifer committed
706
Note: this doesn't preclude `Backspace' and `Delete' from deleting characters
Michael Kifer's avatar
Michael Kifer committed
707
by moving past the insertion point.  This is a feature, not a bug.
Michael Kifer's avatar
Michael Kifer committed
708 709

If nil, the above commands can work across lines."
Michael Kifer's avatar
Michael Kifer committed
710 711 712
  :type 'boolean
  :group 'viper)

Michael Kifer's avatar
Michael Kifer committed
713
(viper-deflocalvar viper-ESC-moves-cursor-back viper-ex-style-editing "")
Michael Kifer's avatar
Michael Kifer committed
714
(defcustom viper-ESC-moves-cursor-back nil
Michael Kifer's avatar
Michael Kifer committed
715
  "*If t, ESC moves cursor back when changing from insert to vi state.
Michael Kifer's avatar
Michael Kifer committed
716
If nil, the cursor stays where it was when ESC was hit."
Michael Kifer's avatar
Michael Kifer committed
717 718 719
  :type 'boolean
  :group 'viper)

Michael Kifer's avatar
Michael Kifer committed
720 721
(viper-deflocalvar viper-delete-backwards-in-replace nil "")
(defcustom viper-delete-backwards-in-replace nil
Michael Kifer's avatar
Michael Kifer committed
722
  "*If t, DEL key will delete characters while moving the cursor backwards.
Michael Kifer's avatar
Michael Kifer committed
723 724 725 726
If nil, the cursor will move backwards without deleting anything."
  :type 'boolean
  :group 'viper)

Michael Kifer's avatar
Michael Kifer committed
727
(defcustom viper-buffer-search-char nil
Michael Kifer's avatar
Michael Kifer committed
728
  "*Key used for buffer-searching.  Must be a character type, e.g., ?g."
Michael Kifer's avatar
Michael Kifer committed
729
  :type '(choice (const nil) character)
Michael Kifer's avatar
Michael Kifer committed
730
  :group 'viper-search)
Michael Kifer's avatar
Michael Kifer committed
731

Michael Kifer's avatar
Michael Kifer committed
732
(defcustom viper-search-wrap-around-t t
Michael Kifer's avatar
Michael Kifer committed
733 734 735
  "*If t, search wraps around."
  :type 'boolean
  :tag "Search Wraps Around"
Michael Kifer's avatar
Michael Kifer committed
736
  :group 'viper-search)
737

Michael Kifer's avatar
Michael Kifer committed
738 739
(viper-deflocalvar viper-related-files-and-buffers-ring nil "")
(defcustom viper-related-files-and-buffers-ring nil
Michael Kifer's avatar
Michael Kifer committed
740 741 742
  "*List of file and buffer names that are considered to be related to the current buffer.
Related buffers can be cycled through via :R and :P commands."
  :type 'boolean
Michael Kifer's avatar
Michael Kifer committed
743
  :group 'viper-misc)
Michael Kifer's avatar
Michael Kifer committed
744
(put 'viper-related-files-and-buffers-ring 'permanent-local t)
Michael Kifer's avatar
Michael Kifer committed
745 746

;; Used to find out if we are done with searching the current buffer.
Michael Kifer's avatar
Michael Kifer committed
747
(viper-deflocalvar viper-local-search-start-marker nil)
Michael Kifer's avatar
Michael Kifer committed
748
;; As above, but global
Michael Kifer's avatar
Michael Kifer committed
749
(defvar viper-search-start-marker (make-marker))
Michael Kifer's avatar
Michael Kifer committed
750 751

;; the search overlay
Michael Kifer's avatar
Michael Kifer committed
752
(viper-deflocalvar viper-search-overlay nil)
Michael Kifer's avatar
Michael Kifer committed
753 754


755
(defvar viper-heading-start
Michael Kifer's avatar
Michael Kifer committed
756 757 758 759 760 761
  (concat "^\\s-*(\\s-*defun\\s-\\|"			        ; lisp
	  "^{\\s-*$\\|^[_a-zA-Z][^()]*[()].*{\\s-*$\\|"	        ; C/C++
	  "^\\s-*class.*{\\|^\\s-*struct.*{\\|^\\s-*enum.*{\\|"
	  "^\\\\[sb][a-z]*{.*}\\s-*$\\|"	    		; latex
	  "^@node\\|@table\\|^@m?enu\\|^@itemize\\|^@if\\|"	; texinfo
	  "^.+:-")			                        ; prolog
Michael Kifer's avatar
Michael Kifer committed
762
  "*Regexps for Headings.  Used by \[\[ and \]\].")
Michael Kifer's avatar
Michael Kifer committed
763

764
(defvar viper-heading-end
Michael Kifer's avatar
Michael Kifer committed
765 766 767 768 769
  (concat "^}\\|"						; C/C++
	  "^\\\\end{\\|"					; latex
	  "^@end \\|"						; texinfo
	  ")\n\n[ \t\n]*\\|"					; lisp
	  "\\.\\s-*$")						; prolog
Michael Kifer's avatar
Michael Kifer committed
770
      "*Regexps to end Headings/Sections.  Used by \[\].")
Michael Kifer's avatar
Michael Kifer committed
771 772 773 774 775 776 777 778


;; These two vars control the interaction of jumps performed by ' and `.
;; In this new version, '' doesn't erase the marks set by ``, so one can
;; use both kinds of jumps interchangeably and without loosing positions
;; inside the lines.

;; Remembers position of the last jump done using ``'.
Michael Kifer's avatar
Michael Kifer committed
779
(viper-deflocalvar viper-last-jump  nil)
Michael Kifer's avatar
Michael Kifer committed
780
;; Remembers position of the last jump done using `''.
Michael Kifer's avatar
Michael Kifer committed
781
(viper-deflocalvar viper-last-jump-ignore 0)
Michael Kifer's avatar
Michael Kifer committed
782 783 784 785

;; History variables

;; History of search strings.
Michael Kifer's avatar
Michael Kifer committed
786
(defvar viper-search-history  (list ""))
Michael Kifer's avatar
Michael Kifer committed
787
;; History of query-replace strings used as a source.
Michael Kifer's avatar
Michael Kifer committed
788
(defvar viper-replace1-history nil)
Michael Kifer's avatar
Michael Kifer committed
789
;; History of query-replace strings used as replacement.
Michael Kifer's avatar
Michael Kifer committed
790
(defvar viper-replace2-history nil)
Michael Kifer's avatar
Michael Kifer committed
791
;; History of region quoting strings.
Michael Kifer's avatar
Michael Kifer committed
792
(defvar viper-quote-region-history (list viper-quote-string))
Michael Kifer's avatar
Michael Kifer committed
793
;; History of Ex-style commands.
Michael Kifer's avatar
Michael Kifer committed
794
(defvar viper-ex-history nil)
Michael Kifer's avatar
Michael Kifer committed
795
;; History of shell commands.
Michael Kifer's avatar
Michael Kifer committed
796
(defvar viper-shell-history nil)
Michael Kifer's avatar
Michael Kifer committed
797 798


Michael Kifer's avatar
Michael Kifer committed
799
;; Last shell command.  There are two of these, one for Ex (in viper-ex)
Michael Kifer's avatar
Michael Kifer committed
800 801 802
;; and one for Vi.

;; Last shell command executed with ! command.
Michael Kifer's avatar
Michael Kifer committed
803
(defvar viper-last-shell-com nil)
Michael Kifer's avatar
Michael Kifer committed
804

Michael Kifer's avatar
Michael Kifer committed
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820

;;; Face-saving tricks

(defun viper-hide-face (face)
  (if (and (viper-has-face-support-p) viper-emacs-p)
      (add-to-list 'facemenu-unlisted-faces face)))


(defgroup viper-highlighting nil
  "Hilighting of replace region, search pattern, minibuffer, etc."
  :prefix "viper-"
  :group 'viper)


(defface viper-search-face
  '((((class color)) (:foreground "Black" :background "khaki"))
821
    (t (:underline t :stipple "gray3")))
Michael Kifer's avatar
Michael Kifer committed
822 823
  "*Face used to flash out the search pattern."
  :group 'viper-highlighting)
Michael Kifer's avatar
Michael Kifer committed
824
;; An internal variable.  Viper takes the face from here.
Michael Kifer's avatar
Michael Kifer committed
825 826
(defvar viper-search-face 'viper-search-face
  "Face used to flash out the search pattern.
Michael Kifer's avatar
Michael Kifer committed
827
DO NOT CHANGE this variable.  Instead, use the customization widget
Michael Kifer's avatar
Michael Kifer committed
828 829
to customize the actual face object `viper-search-face'
this variable represents.")
Michael Kifer's avatar
Michael Kifer committed
830
(viper-hide-face 'viper-search-face)
831

Michael Kifer's avatar