comparison lisp/viper/viper-init.el @ 181:bfd6434d15b3 r20-3b17

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