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