Mercurial > emacs
comparison lisp/emulation/viper.el @ 14232:aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
* viper.el (vip-auto-indent,vip-electric-mode): are now local
variables.
(vip-open-line,vip-Open-line,vip-autoindent):
are now electrified functions.
(vip-set-hooks): viperized awk, ksh, makefile, and html-helper modes.
(vip-custom-file-name): adapted to non-Unix systems.
(vip-move-minibuffer-overlay): removed.
(vip-read-string-with-history):
now accepts correct defaults when called to
read a shell command.
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Sat, 20 Jan 1996 03:10:57 +0000 |
parents | 83f275dcd93a |
children | 35aaddb9e959 |
comparison
equal
deleted
inserted
replaced
14231:069791dced1e | 14232:aa84e18af631 |
---|---|
1 ;;; viper.el --- A full-featured Vi emulator. | 1 ;;; viper.el --- A full-featured Vi emulator for GNU Emacs 19 and XEmacs 19, |
2 ;; a VI Plan for Emacs Rescue, | 2 ;; a VI Plan for Emacs Rescue, |
3 ;; and a venomous VI PERil. | 3 ;; and a venomous VI PERil. |
4 ;; Viper Is also a Package for Emacs Rebels. | 4 ;; Viper Is also a Package for Emacs Rebels. |
5 | 5 ;; |
6 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | |
7 | |
8 ;; Keywords: emulations | 6 ;; Keywords: emulations |
9 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | 7 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> |
10 | 8 |
11 (defconst viper-version "2.82 of October 12, 1995" | 9 (defconst viper-version "2.85 of January 15, 1996" |
12 "The current version of Viper") | 10 "The current version of Viper") |
11 | |
12 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | |
13 | 13 |
14 ;; This file is part of GNU Emacs. | 14 ;; This file is part of GNU Emacs. |
15 | 15 |
16 ;; GNU Emacs is free software; you can redistribute it and/or modify | 16 ;; GNU Emacs is free software; you can redistribute it and/or modify |
17 ;; it under the terms of the GNU General Public License as published by | 17 ;; it under the terms of the GNU General Public License as published by |
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 ;; GNU General Public License for more details. | 24 ;; GNU General Public License for more details. |
25 | 25 |
26 ;; You should have received a copy of the GNU General Public License | 26 ;; You should have received a copy of the GNU General Public License |
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 27 ;; along with GNU Emacs; see the file COPYING. If not, write to |
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 28 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
29 ;; Boston, MA 02111-1307, USA. | |
30 | 29 |
31 ;;; Commentary: | 30 ;;; Commentary: |
32 | 31 |
33 ;; Viper is a full-featured Vi emulator for Emacs 19. It emulates and | 32 ;; Viper is a full-featured Vi emulator for Emacs 19. It emulates and |
34 ;; improves upon the standard features of Vi and, at the same time, allows | 33 ;; improves upon the standard features of Vi and, at the same time, allows |
370 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil | 369 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil |
371 "Minor mode used to make major-mode-specific modification to Insert state.") | 370 "Minor mode used to make major-mode-specific modification to Insert state.") |
372 | 371 |
373 (vip-deflocalvar vip-insert-diehard-minor-mode nil | 372 (vip-deflocalvar vip-insert-diehard-minor-mode nil |
374 "Minor mode that simulates Vi very closely. | 373 "Minor mode that simulates Vi very closely. |
375 Not recommended, except for the novice user.") | 374 Not recommened, except for the novice user.") |
376 | 375 |
377 (vip-deflocalvar vip-insert-kbd-minor-mode nil | 376 (vip-deflocalvar vip-insert-kbd-minor-mode nil |
378 "Minor mode for Ex command macros Insert state. | 377 "Minor mode for Ex command macros Insert state. |
379 The corresponding keymap stores key bindings of Vi macros defined with | 378 The corresponding keymap stores key bindings of Vi macros defined with |
380 the Ex command :map!.") | 379 the Ex command :map!.") |
468 (vip-deflocalvar vip-replace-overlay nil "") | 467 (vip-deflocalvar vip-replace-overlay nil "") |
469 (put 'vip-replace-overlay 'permanent-local t) | 468 (put 'vip-replace-overlay 'permanent-local t) |
470 | 469 |
471 (if (vip-window-display-p) | 470 (if (vip-window-display-p) |
472 (progn | 471 (progn |
473 (add-to-list 'facemenu-unlisted-faces 'vip-replace-overlay-face) | |
474 (make-face 'vip-replace-overlay-face) | 472 (make-face 'vip-replace-overlay-face) |
473 (vip-hide-face 'vip-replace-overlay-face) | |
475 (or (face-differs-from-default-p 'vip-replace-overlay-face) | 474 (or (face-differs-from-default-p 'vip-replace-overlay-face) |
476 (progn | 475 (progn |
477 (if (vip-can-use-colors "darkseagreen2" "Black") | 476 (if (vip-can-use-colors "darkseagreen2" "Black") |
478 (progn | 477 (progn |
479 (set-face-background | 478 (set-face-background |
589 (vip-deflocalvar vip-current-indent 0) | 588 (vip-deflocalvar vip-current-indent 0) |
590 | 589 |
591 ;; Whether to preserve the indent, used by C-d in insert mode. | 590 ;; Whether to preserve the indent, used by C-d in insert mode. |
592 (vip-deflocalvar vip-preserve-indent nil) | 591 (vip-deflocalvar vip-preserve-indent nil) |
593 | 592 |
594 (defconst vip-auto-indent nil | 593 (vip-deflocalvar vip-auto-indent nil |
595 "*Autoindent if t.") | 594 "*Autoindent if t.") |
595 (vip-deflocalvar vip-electric-mode t | |
596 "*If t, enable electric behavior. | |
597 Currently only enables auto-indentation `according to mode'.") | |
596 | 598 |
597 (defconst vip-shift-width 8 | 599 (defconst vip-shift-width 8 |
598 "*The shiftwidth variable.") | 600 "*The shiftwidth variable.") |
599 | 601 |
600 ;; Variables for repeating destructive commands | 602 ;; Variables for repeating destructive commands |
614 ;; If vip-insert-point turns out to be bigger than that, it is reset | 616 ;; If vip-insert-point turns out to be bigger than that, it is reset |
615 ;; back to vip-pre-command-point. | 617 ;; back to vip-pre-command-point. |
616 ;; The reason this is needed is because dabbrev-expand (and possibly | 618 ;; The reason this is needed is because dabbrev-expand (and possibly |
617 ;; others) may jump to before the insertion point, delete something and | 619 ;; others) may jump to before the insertion point, delete something and |
618 ;; then reinsert a bigger piece. For instance: bla^blo | 620 ;; then reinsert a bigger piece. For instance: bla^blo |
619 ;; If dabbrev-expand is called after `blo' and ^ indicates vip-insert-point, | 621 ;; If dabbrev-expand is called after `blo' and ^ undicates vip-insert-point, |
620 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo' | 622 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo' |
621 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand | 623 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand |
622 ;; will insert the expansion, and we get: blablo^ | 624 ;; will insert the expansion, and we get: blablo^ |
623 ;; Whatever we insert next goes before the ^, i.e., before the | 625 ;; Whatever we insert next goes before the ^, i.e., before the |
624 ;; vip-insert-point marker. So, Viper will think that nothing was | 626 ;; vip-insert-point marker. So, Viper will think that nothing was |
806 "Whether Viper startup message should be inhibited.") | 808 "Whether Viper startup message should be inhibited.") |
807 | 809 |
808 (defvar vip-always t | 810 (defvar vip-always t |
809 "t means, arrange that vi-state will be a default.") | 811 "t means, arrange that vi-state will be a default.") |
810 | 812 |
811 (defvar vip-custom-file-name (convert-standard-filename "~/.vip") | 813 (defvar vip-custom-file-name (cond ((memq system-type '(vax-vms axp-vms)) |
814 "sys$login:.vip") | |
815 ((memq system-type '(emx ms-dos)) | |
816 "/_vip") | |
817 ((memq system-type '(windows-nt windows-95)) | |
818 "~/_vip") | |
819 (t ; Unix | |
820 "~/.vip")) | |
812 "Viper customisation file. | 821 "Viper customisation file. |
813 This variable must be set _before_ loading Viper.") | 822 This variable must be set _before_ loading Viper.") |
814 | 823 |
815 (defvar vip-spell-function 'ispell-region | 824 (defvar vip-spell-function 'ispell-region |
816 "Spell function used by #s<move> command to spell.") | 825 "Spell function used by #s<move> command to spell.") |
936 | 945 |
937 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. | 946 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. |
938 (defun vip-change-state (new-state) | 947 (defun vip-change-state (new-state) |
939 ;; Keep vip-post/pre-command-hooks fresh. | 948 ;; Keep vip-post/pre-command-hooks fresh. |
940 ;; We remove then add vip-post/pre-command-sentinel since it is very | 949 ;; We remove then add vip-post/pre-command-sentinel since it is very |
941 ;; desirable that no one gets in-between | 950 ;; desirable that noone gets in-between |
942 (remove-hook 'post-command-hook 'vip-post-command-sentinel) | 951 (remove-hook 'post-command-hook 'vip-post-command-sentinel) |
943 (add-hook 'post-command-hook 'vip-post-command-sentinel) | 952 (add-hook 'post-command-hook 'vip-post-command-sentinel) |
944 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel) | 953 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel) |
945 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t) | 954 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t) |
946 ;; These hooks will be added back if switching to insert/replace mode | 955 ;; These hooks will be added back if switching to insert/replace mode |
1360 (condition-case conds | 1369 (condition-case conds |
1361 (run-hooks 'vip-emacs-state-hook) | 1370 (run-hooks 'vip-emacs-state-hook) |
1362 (error | 1371 (error |
1363 (vip-message-conditions conds)))) | 1372 (vip-message-conditions conds)))) |
1364 | 1373 |
1365 ;; escape to emacs mode temporarily | 1374 ;; escape to emacs mode termporarily |
1366 (defun vip-escape-to-emacs (arg &optional events) | 1375 (defun vip-escape-to-emacs (arg &optional events) |
1367 "Escape to Emacs state from Vi state for one Emacs command. | 1376 "Escape to Emacs state from Vi state for one Emacs command. |
1368 ARG is used as the prefix value for the executed command. If | 1377 ARG is used as the prefix value for the executed command. If |
1369 EVENTS is a list of events, which become the beginning of the command." | 1378 EVENTS is a list of events, which become the beginning of the command." |
1370 (interactive "P") | 1379 (interactive "P") |
1371 (vip-escape-to-state arg events 'emacs-state)) | 1380 (vip-escape-to-state arg events 'emacs-state)) |
1372 | 1381 |
1373 ;; escape to Vi mode temporarily | 1382 ;; escape to Vi mode termporarily |
1374 (defun vip-escape-to-vi () | 1383 (defun vip-escape-to-vi () |
1375 "Escape from Emacs state to Vi state for one Vi 1-character command. | 1384 "Escape from Emacs state to Vi state for one Vi 1-character command. |
1376 This doesn't work with prefix arguments or most complex commands like | 1385 This doesn't work with prefix arguments or most complex commands like |
1377 cw, dw, etc. But it does work with some 2-character commands, | 1386 cw, dw, etc. But it does work with some 2-character commands, |
1378 like dd or dr." | 1387 like dd or dr." |
1462 ;; Change the default for minor-mode-map-alist each time a harnessed minor | 1471 ;; Change the default for minor-mode-map-alist each time a harnessed minor |
1463 ;; mode adds its own keymap to the a-list. | 1472 ;; mode adds its own keymap to the a-list. |
1464 (vip-eval-after-load | 1473 (vip-eval-after-load |
1465 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist)) | 1474 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist)) |
1466 ) | 1475 ) |
1467 | 1476 |
1468 | 1477 |
1469 (defun vip-ESC (arg) | 1478 (defun vip-ESC (arg) |
1470 "Emulate ESC key in Emacs. | 1479 "Emulate ESC key in Emacs. |
1471 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true. In that | 1480 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true. In that |
1472 case \@ will be bound to ESC. If vip-no-multiple-ESC is 'twice double ESC | 1481 case \@ will be bound to ESC. If vip-no-multiple-ESC is 'twice double ESC |
1699 (setq char (read-char))) | 1708 (setq char (read-char))) |
1700 (vip-set-unread-command-events char) | 1709 (vip-set-unread-command-events char) |
1701 ) | 1710 ) |
1702 ;; as com is non-nil, this means that we have a command to execute | 1711 ;; as com is non-nil, this means that we have a command to execute |
1703 (if (memq (car com) '(?r ?R)) | 1712 (if (memq (car com) '(?r ?R)) |
1704 ;; execute appropriate region command. | 1713 ;; execute apropriate region command. |
1705 (let ((char (car com)) (com (cdr com))) | 1714 (let ((char (car com)) (com (cdr com))) |
1706 (setq prefix-arg (cons value com)) | 1715 (setq prefix-arg (cons value com)) |
1707 (if (= char ?r) (vip-region prefix-arg) | 1716 (if (= char ?r) (vip-region prefix-arg) |
1708 (vip-Region prefix-arg)) | 1717 (vip-Region prefix-arg)) |
1709 ;; reset prefix-arg | 1718 ;; reset prefix-arg |
2065 (t 0))) | 2074 (t 0))) |
2066 (num idx) | 2075 (num idx) |
2067 (vip-d-com vip-d-com)) | 2076 (vip-d-com vip-d-com)) |
2068 | 2077 |
2069 (or (and (numberp num) (<= 0 num) (<= num 9)) | 2078 (or (and (numberp num) (<= 0 num) (<= num 9)) |
2070 (setq idx 0 | 2079 (progn |
2071 num 0) | 2080 (setq idx 0 |
2072 (message | 2081 num 0) |
2073 "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'")) | 2082 (message |
2083 "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'"))) | |
2074 (while (< 0 num) | 2084 (while (< 0 num) |
2075 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1)) | 2085 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1)) |
2076 (setq num (1- num))) | 2086 (setq num (1- num))) |
2077 (vip-repeat nil) | 2087 (vip-repeat nil) |
2078 (while (> idx num) | 2088 (while (> idx num) |
2367 (defun vip-minibuffer-setup-sentinel () | 2377 (defun vip-minibuffer-setup-sentinel () |
2368 (let ((hook (if vip-vi-style-in-minibuffer | 2378 (let ((hook (if vip-vi-style-in-minibuffer |
2369 'vip-change-state-to-insert | 2379 'vip-change-state-to-insert |
2370 'vip-change-state-to-emacs))) | 2380 'vip-change-state-to-emacs))) |
2371 (funcall hook) | 2381 (funcall hook) |
2372 | |
2373 ;; Make sure the minibuffer overlay is kept up-to-date. In XEmacs also | |
2374 ;; guards against the possibility of detaching this overlay. | |
2375 (vip-add-hook 'vip-post-command-hooks 'vip-move-minibuffer-overlay) | |
2376 )) | 2382 )) |
2377 | 2383 |
2378 ;; Interpret last event in the local map | 2384 ;; Interpret last event in the local map |
2379 (defun vip-exit-minibuffer () | 2385 (defun vip-exit-minibuffer () |
2380 (interactive) | 2386 (interactive) |
2388 (defun vip-set-search-face () | 2394 (defun vip-set-search-face () |
2389 (if (not (vip-window-display-p)) | 2395 (if (not (vip-window-display-p)) |
2390 () | 2396 () |
2391 (defvar vip-search-face | 2397 (defvar vip-search-face |
2392 (progn | 2398 (progn |
2393 (add-to-list 'facemenu-unlisted-faces 'vip-search-face) | |
2394 (make-face 'vip-search-face) | 2399 (make-face 'vip-search-face) |
2400 (vip-hide-face 'vip-search-face) | |
2395 (or (face-differs-from-default-p 'vip-search-face) | 2401 (or (face-differs-from-default-p 'vip-search-face) |
2396 ;; face wasn't set in .vip or .Xdefaults | 2402 ;; face wasn't set in .vip or .Xdefaults |
2397 (if (vip-can-use-colors "Black" "khaki") | 2403 (if (vip-can-use-colors "Black" "khaki") |
2398 (progn | 2404 (progn |
2399 (set-face-background 'vip-search-face "khaki") | 2405 (set-face-background 'vip-search-face "khaki") |
2408 (defun vip-set-minibuffer-faces () | 2414 (defun vip-set-minibuffer-faces () |
2409 (if (not (vip-window-display-p)) | 2415 (if (not (vip-window-display-p)) |
2410 () | 2416 () |
2411 (defvar vip-minibuffer-emacs-face | 2417 (defvar vip-minibuffer-emacs-face |
2412 (progn | 2418 (progn |
2413 (add-to-list 'facemenu-unlisted-faces 'vip-minibuffer-emacs-face) | |
2414 (make-face 'vip-minibuffer-emacs-face) | 2419 (make-face 'vip-minibuffer-emacs-face) |
2420 (vip-hide-face 'vip-minibuffer-emacs-face) | |
2415 (or (face-differs-from-default-p 'vip-minibuffer-emacs-face) | 2421 (or (face-differs-from-default-p 'vip-minibuffer-emacs-face) |
2416 ;; face wasn't set in .vip or .Xdefaults | 2422 ;; face wasn't set in .vip or .Xdefaults |
2417 (if vip-vi-style-in-minibuffer | 2423 (if vip-vi-style-in-minibuffer |
2418 ;; emacs state is an exception in the minibuffer | 2424 ;; emacs state is an exception in the minibuffer |
2419 (if (vip-can-use-colors "darkseagreen2" "Black") | 2425 (if (vip-can-use-colors "darkseagreen2" "Black") |
2434 'vip-minibuffer-emacs-face) | 2440 'vip-minibuffer-emacs-face) |
2435 "Face used in the Minibuffer when it is in Emacs state.") | 2441 "Face used in the Minibuffer when it is in Emacs state.") |
2436 | 2442 |
2437 (defvar vip-minibuffer-insert-face | 2443 (defvar vip-minibuffer-insert-face |
2438 (progn | 2444 (progn |
2439 (add-to-list 'facemenu-unlisted-faces 'vip-minibuffer-insert-face) | |
2440 (make-face 'vip-minibuffer-insert-face) | 2445 (make-face 'vip-minibuffer-insert-face) |
2446 (vip-hide-face 'vip-minibuffer-insert-face) | |
2441 (or (face-differs-from-default-p 'vip-minibuffer-insert-face) | 2447 (or (face-differs-from-default-p 'vip-minibuffer-insert-face) |
2442 (if vip-vi-style-in-minibuffer | 2448 (if vip-vi-style-in-minibuffer |
2443 (if (vip-can-use-colors "Black" "pink") | 2449 (if (vip-can-use-colors "Black" "pink") |
2444 (progn | 2450 (progn |
2445 (set-face-background 'vip-minibuffer-insert-face "pink") | 2451 (set-face-background 'vip-minibuffer-insert-face "pink") |
2458 'vip-minibuffer-insert-face) | 2464 'vip-minibuffer-insert-face) |
2459 "Face used in the Minibuffer when it is in Insert state.") | 2465 "Face used in the Minibuffer when it is in Insert state.") |
2460 | 2466 |
2461 (defvar vip-minibuffer-vi-face | 2467 (defvar vip-minibuffer-vi-face |
2462 (progn | 2468 (progn |
2463 (add-to-list 'facemenu-unlisted-faces 'vip-minibuffer-vi-face) | |
2464 (make-face 'vip-minibuffer-vi-face) | 2469 (make-face 'vip-minibuffer-vi-face) |
2470 (vip-hide-face 'vip-minibuffer-vi-face) | |
2465 (or (face-differs-from-default-p 'vip-minibuffer-vi-face) | 2471 (or (face-differs-from-default-p 'vip-minibuffer-vi-face) |
2466 (if vip-vi-style-in-minibuffer | 2472 (if vip-vi-style-in-minibuffer |
2467 (if (vip-can-use-colors "Black" "grey") | 2473 (if (vip-can-use-colors "Black" "grey") |
2468 (progn | 2474 (progn |
2469 (set-face-background 'vip-minibuffer-vi-face "grey") | 2475 (set-face-background 'vip-minibuffer-vi-face "grey") |
2482 | 2488 |
2483 ;;; Reading string with history | 2489 ;;; Reading string with history |
2484 | 2490 |
2485 (defun vip-read-string-with-history (prompt &optional initial | 2491 (defun vip-read-string-with-history (prompt &optional initial |
2486 history-var default keymap) | 2492 history-var default keymap) |
2487 ;; Reads string, prompting with PROMPT and inserting the INITIAL | 2493 ;; Read string, prompting with PROMPT and inserting the INITIAL |
2488 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the | 2494 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the |
2489 ;; input is an empty string. Uses KEYMAP, if given, or the | 2495 ;; input is an empty string. Use KEYMAP, if given, or the |
2490 ;; minibuffer-local-map. | 2496 ;; minibuffer-local-map. |
2491 ;; Default value is displayed until the user types something in the | 2497 ;; Default value is displayed until the user types something in the |
2492 ;; minibuffer. | 2498 ;; minibuffer. |
2493 (let ((minibuffer-setup-hook | 2499 (let ((minibuffer-setup-hook |
2494 '(lambda () | 2500 '(lambda () |
2522 (if (not (string= val (car (eval history-var)))) | 2528 (if (not (string= val (car (eval history-var)))) |
2523 (set history-var (cons val (eval history-var)))) | 2529 (set history-var (cons val (eval history-var)))) |
2524 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var))) | 2530 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var))) |
2525 (string= (nth 0 (eval history-var)) "")) | 2531 (string= (nth 0 (eval history-var)) "")) |
2526 (set history-var (cdr (eval history-var)))) | 2532 (set history-var (cdr (eval history-var)))) |
2527 ;; if the user enters nothing but the prev cmd wasn't vip-ex or | 2533 ;; If the user enters nothing but the prev cmd wasn't vip-ex, |
2528 ;; vip-command-argument, this means that the user typed something then | 2534 ;; vip-command-argument, or `! shell-command', this probably means |
2529 ;; erased. Return "" in this case, not the default---default is too | 2535 ;; that the user typed something then erased. Return "" in this case, not |
2530 ;; confusing in this case | 2536 ;; the default---the default is too confusing in this case. |
2531 (cond ((and (string= val "") | 2537 (cond ((and (string= val "") |
2538 (not (string= prompt "!")) ; was a `! shell-command' | |
2532 (not (memq last-command | 2539 (not (memq last-command |
2533 (list 'vip-ex 'vip-command-argument t)))) | 2540 '(vip-ex |
2541 vip-command-argument | |
2542 t) | |
2543 ))) | |
2534 "") | 2544 "") |
2535 ((string= val "") (or default "")) | 2545 ((string= val "") (or default "")) |
2536 (t val)) | 2546 (t val)) |
2537 )) | 2547 )) |
2538 | 2548 |
2613 (vip-loop val | 2623 (vip-loop val |
2614 (progn | 2624 (progn |
2615 (end-of-line) | 2625 (end-of-line) |
2616 (newline 1) | 2626 (newline 1) |
2617 (if vip-auto-indent | 2627 (if vip-auto-indent |
2618 (progn (setq vip-cted t) (indent-to col))) | 2628 (progn |
2629 (setq vip-cted t) | |
2630 (if vip-electric-mode | |
2631 (indent-according-to-mode) | |
2632 (indent-to col)) | |
2633 )) | |
2619 (vip-yank-last-insertion))) | 2634 (vip-yank-last-insertion))) |
2620 (end-of-line) | 2635 (end-of-line) |
2621 (newline 1) | 2636 (newline 1) |
2622 (if vip-auto-indent (progn (setq vip-cted t) (indent-to col))) | 2637 (if vip-auto-indent |
2638 (progn | |
2639 (setq vip-cted t) | |
2640 (if vip-electric-mode | |
2641 (indent-according-to-mode) | |
2642 (indent-to col)) | |
2643 )) | |
2623 (vip-change-state-to-insert) | 2644 (vip-change-state-to-insert) |
2624 )))) | 2645 )))) |
2625 | 2646 |
2626 (defun vip-Open-line (arg) | 2647 (defun vip-Open-line (arg) |
2627 "Open line above." | 2648 "Open line above." |
2635 (vip-loop val | 2656 (vip-loop val |
2636 (progn | 2657 (progn |
2637 (beginning-of-line) | 2658 (beginning-of-line) |
2638 (open-line 1) | 2659 (open-line 1) |
2639 (if vip-auto-indent | 2660 (if vip-auto-indent |
2640 (progn (setq vip-cted t) (indent-to col))) | 2661 (progn |
2662 (setq vip-cted t) | |
2663 (if vip-electric-mode | |
2664 (indent-according-to-mode) | |
2665 (indent-to col)) | |
2666 )) | |
2641 (vip-yank-last-insertion))) | 2667 (vip-yank-last-insertion))) |
2642 (beginning-of-line) | 2668 (beginning-of-line) |
2643 (open-line 1) | 2669 (open-line 1) |
2644 (if vip-auto-indent (progn (setq vip-cted t) (indent-to col))) | 2670 (if vip-auto-indent |
2671 (progn | |
2672 (setq vip-cted t) | |
2673 (if vip-electric-mode | |
2674 (indent-according-to-mode) | |
2675 (indent-to col)) | |
2676 )) | |
2645 (vip-change-state-to-insert))))) | 2677 (vip-change-state-to-insert))))) |
2646 | 2678 |
2647 (defun vip-open-line-at-point (arg) | 2679 (defun vip-open-line-at-point (arg) |
2648 "Open line at point." | 2680 "Open line at point." |
2649 (interactive "P") | 2681 (interactive "P") |
2830 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which | 2862 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which |
2831 ;; sometimes simply shifts the repl region rightwards, without | 2863 ;; sometimes simply shifts the repl region rightwards, without |
2832 ;; deleting an equal amount of characters. | 2864 ;; deleting an equal amount of characters. |
2833 ;; | 2865 ;; |
2834 ;; The reason why new-dabbrev.el causes this are this: | 2866 ;; The reason why new-dabbrev.el causes this are this: |
2835 ;; if one dynamically completes a partial word that starts before the | 2867 ;; if one dinamically completes a partial word that starts before the |
2836 ;; replacement region (but ends inside)then new-dabbrev.el first | 2868 ;; replacement region (but ends inside) then new-dabbrev.el first |
2837 ;; moves cursor backwards, to the beginning of the word to be | 2869 ;; moves cursor backwards, to the beginning of the word to be |
2838 ;; completed (say, pt A). Then it inserts the | 2870 ;; completed (say, pt A). Then it inserts the |
2839 ;; completed word and then deletes the old, incomplete part. | 2871 ;; completed word and then deletes the old, incomplete part. |
2840 ;; Since the complete word is inserted at position before the repl | 2872 ;; Since the complete word is inserted at position before the repl |
2841 ;; region, the next If-statement would have set chars-to-delete to 0 | 2873 ;; region, the next If-statement would have set chars-to-delete to 0 |
2842 ;; unless we check for the current command, which must be | 2874 ;; unless we check for the current command, which must be |
2843 ;; dabbrev-expand. | 2875 ;; dabbrev-expand. |
2844 ;; | 2876 ;; |
2845 ;; We should be able deal with these problems in a better way | 2877 ;; In fact, it might be also useful to have overlays for insert |
2846 ;; when emacs will have overlays with sticky back ends. | |
2847 ;; In fact, it would be also useful to add overlays for insert | |
2848 ;; regions as well, since this will let us capture the situation when | 2878 ;; regions as well, since this will let us capture the situation when |
2849 ;; dabbrev-expand goes back past the insertion point to find the | 2879 ;; dabbrev-expand goes back past the insertion point to find the |
2850 ;; beginning of the word to be expanded. | 2880 ;; beginning of the word to be expanded. |
2851 (if (or (and (<= (vip-replace-start) beg) | 2881 (if (or (and (<= (vip-replace-start) beg) |
2852 (<= beg (vip-replace-end))) | 2882 (<= beg (vip-replace-end))) |
3885 | 3915 |
3886 Although this function is bound to \\[vip-toggle-search-style], the most | 3916 Although this function is bound to \\[vip-toggle-search-style], the most |
3887 convenient way to use it is to bind `//' to the macro | 3917 convenient way to use it is to bind `//' to the macro |
3888 `1 M-x vip-toggle-search-style' and `///' to | 3918 `1 M-x vip-toggle-search-style' and `///' to |
3889 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will | 3919 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will |
3890 toggle case-fold-search and hitting `/' three times with toggle regexp | 3920 toggle case-fold-search and hitting `/' three times witth toggle regexp |
3891 search. Macros are more convenient in this case because they don't affect | 3921 search. Macros are more convenient in this case because they don't affect |
3892 the Emacs binding of `/'." | 3922 the Emacs binding of `/'." |
3893 (interactive "P") | 3923 (interactive "P") |
3894 (let (msg) | 3924 (let (msg) |
3895 (cond ((or (eq arg 1) | 3925 (cond ((or (eq arg 1) |
4071 (define-key vip-vi-basic-map | 4101 (define-key vip-vi-basic-map |
4072 (char-to-string vip-buffer-search-char) 'vip-command-argument) | 4102 (char-to-string vip-buffer-search-char) 'vip-command-argument) |
4073 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search) | 4103 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search) |
4074 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands))) | 4104 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands))) |
4075 | 4105 |
4076 ;; This is a Viper wrapper for isearch-forward. | 4106 ;; This is a Viper wraper for isearch-forward. |
4077 (defun vip-isearch-forward (arg) | 4107 (defun vip-isearch-forward (arg) |
4078 "Do incremental search forward." | 4108 "Do incremental search forward." |
4079 (interactive "P") | 4109 (interactive "P") |
4080 ;; emacs bug workaround | 4110 ;; emacs bug workaround |
4081 (if (listp arg) (setq arg (car arg))) | 4111 (if (listp arg) (setq arg (car arg))) |
4082 (vip-exec-form-in-emacs (list 'isearch-forward arg))) | 4112 (vip-exec-form-in-emacs (list 'isearch-forward arg))) |
4083 | 4113 |
4084 ;; This is a Viper wrapper for isearch-backward." | 4114 ;; This is a Viper wraper for isearch-backward." |
4085 (defun vip-isearch-backward (arg) | 4115 (defun vip-isearch-backward (arg) |
4086 "Do incremental search backward." | 4116 "Do incremental search backward." |
4087 (interactive "P") | 4117 (interactive "P") |
4088 ;; emacs bug workaround | 4118 ;; emacs bug workaround |
4089 (if (listp arg) (setq arg (car arg))) | 4119 (if (listp arg) (setq arg (car arg))) |
4387 (delete-backward-char 1 t))) | 4417 (delete-backward-char 1 t))) |
4388 | 4418 |
4389 (defun vip-del-backward-char-in-replace () | 4419 (defun vip-del-backward-char-in-replace () |
4390 "Delete one character in replace mode. | 4420 "Delete one character in replace mode. |
4391 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes | 4421 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes |
4392 characters. If it is nil, then the cursor just moves backwards, similarly | 4422 charecters. If it is nil, then the cursor just moves backwards, similarly |
4393 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the | 4423 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the |
4394 cursor move past the beginning of line." | 4424 cursor move past the beginning of line." |
4395 (interactive) | 4425 (interactive) |
4396 (cond (vip-delete-backwards-in-replace | 4426 (cond (vip-delete-backwards-in-replace |
4397 (cond ((not (bolp)) | 4427 (cond ((not (bolp)) |
4515 | 4545 |
4516 ;; query replace | 4546 ;; query replace |
4517 | 4547 |
4518 (defun vip-query-replace () | 4548 (defun vip-query-replace () |
4519 "Query replace. | 4549 "Query replace. |
4520 If a null string is supplied as the string to be replaced, | 4550 If a null string is suplied as the string to be replaced, |
4521 the query replace mode will toggle between string replace | 4551 the query replace mode will toggle between string replace |
4522 and regexp replace." | 4552 and regexp replace." |
4523 (interactive) | 4553 (interactive) |
4524 (let (str) | 4554 (let (str) |
4525 (setq str (vip-read-string-with-history | 4555 (setq str (vip-read-string-with-history |
4715 (interactive) | 4745 (interactive) |
4716 (if vip-cted | 4746 (if vip-cted |
4717 (let ((p (point)) (c (current-column)) bol (indent t)) | 4747 (let ((p (point)) (c (current-column)) bol (indent t)) |
4718 (if (vip-looking-back "[0^]") | 4748 (if (vip-looking-back "[0^]") |
4719 (progn | 4749 (progn |
4720 (if (= ?^ (preceding-char)) (setq vip-preserve-indent t)) | 4750 (if (eq ?^ (preceding-char)) |
4751 (setq vip-preserve-indent t)) | |
4721 (delete-backward-char 1) | 4752 (delete-backward-char 1) |
4722 (setq p (point)) | 4753 (setq p (point)) |
4723 (setq indent nil))) | 4754 (setq indent nil))) |
4724 (save-excursion | 4755 (save-excursion |
4725 (beginning-of-line) | 4756 (beginning-of-line) |
4733 | 4764 |
4734 (defun vip-autoindent () | 4765 (defun vip-autoindent () |
4735 "Auto Indentation, Vi-style." | 4766 "Auto Indentation, Vi-style." |
4736 (interactive) | 4767 (interactive) |
4737 (let ((col (current-indentation))) | 4768 (let ((col (current-indentation))) |
4738 (if (not vip-preserve-indent) | 4769 (if vip-preserve-indent |
4739 (setq vip-current-indent col) | 4770 (setq vip-preserve-indent nil) |
4740 (setq vip-preserve-indent nil)) | 4771 (setq vip-current-indent col)) |
4741 ;; don't leave whitespace lines around | 4772 ;; don't leave whitespace lines around |
4742 (if (memq last-command | 4773 (if (memq last-command |
4743 '(vip-autoindent | 4774 '(vip-autoindent |
4744 vip-open-line vip-Open-line | 4775 vip-open-line vip-Open-line |
4745 vip-replace-state-exit-cmd)) | 4776 vip-replace-state-exit-cmd)) |
4746 (indent-to-left-margin)) | 4777 (indent-to-left-margin)) |
4747 (newline 1) | 4778 (newline 1) |
4748 (if vip-auto-indent | 4779 (if vip-auto-indent |
4749 (progn | 4780 (progn |
4750 (setq vip-cted t) | 4781 (setq vip-cted t) |
4751 (indent-to vip-current-indent))))) | 4782 (if vip-electric-mode |
4783 (indent-according-to-mode) | |
4784 (indent-to vip-current-indent)) | |
4785 )) | |
4786 )) | |
4752 | 4787 |
4753 | 4788 |
4754 ;; Viewing registers | 4789 ;; Viewing registers |
4755 | 4790 |
4756 (defun vip-ket-function (arg) | 4791 (defun vip-ket-function (arg) |
4882 ;; an intermediate to guru | 4917 ;; an intermediate to guru |
4883 ((and (> vip-expert-level 1) (< vip-expert-level 5)) | 4918 ((and (> vip-expert-level 1) (< vip-expert-level 5)) |
4884 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice) | 4919 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice) |
4885 vip-want-emacs-keys-in-vi t | 4920 vip-want-emacs-keys-in-vi t |
4886 vip-want-emacs-keys-in-insert (> vip-expert-level 2)) | 4921 vip-want-emacs-keys-in-insert (> vip-expert-level 2)) |
4887 | 4922 |
4888 (if (eq vip-expert-level 4) ; respect user's ex-style motions | 4923 (if (eq vip-expert-level 4) ; respect user's ex-style motions |
4889 ; and vip-no-multiple-ESC | 4924 ; and vip-no-multiple-ESC |
4890 (progn | 4925 (progn |
4891 (setq-default vip-ex-style-editing-in-insert | 4926 (setq-default vip-ex-style-editing-in-insert |
4892 (cdr (assoc 'vip-ex-style-editing-in-insert | 4927 (cdr (assoc 'vip-ex-style-editing-in-insert |
5318 ;; The following major modes should come up in vi-state | 5353 ;; The following major modes should come up in vi-state |
5319 (defadvice fundamental-mode (after vip-fundamental-mode-ad activate) | 5354 (defadvice fundamental-mode (after vip-fundamental-mode-ad activate) |
5320 "Run `vip-change-state-to-vi' on entry." | 5355 "Run `vip-change-state-to-vi' on entry." |
5321 (vip-change-state-to-vi)) | 5356 (vip-change-state-to-vi)) |
5322 | 5357 |
5358 (defvar makefile-mode-hook nil) | |
5359 (add-hook 'makefile-mode-hook 'viper-mode) | |
5360 | |
5323 (defvar help-mode-hook nil) | 5361 (defvar help-mode-hook nil) |
5324 (add-hook 'help-mode-hook 'viper-mode) | 5362 (add-hook 'help-mode-hook 'viper-mode) |
5363 | |
5364 (defvar awk-mode-hook nil) | |
5365 (add-hook 'awk-mode-hook 'viper-mode) | |
5366 | |
5367 (defvar html-mode-hook nil) | |
5368 (add-hook 'html-mode-hook 'viper-mode) | |
5369 (defvar html-helper-mode-hook nil) | |
5370 (add-hook 'html-helper-mode-hook 'viper-mode) | |
5325 | 5371 |
5326 (defvar emacs-lisp-mode-hook nil) | 5372 (defvar emacs-lisp-mode-hook nil) |
5327 (add-hook 'emacs-lisp-mode-hook 'viper-mode) | 5373 (add-hook 'emacs-lisp-mode-hook 'viper-mode) |
5328 | |
5329 (defvar html-mode-hook nil) | |
5330 (add-hook 'html-mode-hook 'viper-mode) | |
5331 | 5374 |
5332 (defvar lisp-mode-hook nil) | 5375 (defvar lisp-mode-hook nil) |
5333 (add-hook 'lisp-mode-hook 'viper-mode) | 5376 (add-hook 'lisp-mode-hook 'viper-mode) |
5334 | 5377 |
5335 (defvar bibtex-mode-hook nil) | 5378 (defvar bibtex-mode-hook nil) |
5350 (defvar text-mode-hook nil) | 5393 (defvar text-mode-hook nil) |
5351 (add-hook 'text-mode-hook 'viper-mode) | 5394 (add-hook 'text-mode-hook 'viper-mode) |
5352 | 5395 |
5353 (add-hook 'completion-list-mode-hook 'viper-mode) | 5396 (add-hook 'completion-list-mode-hook 'viper-mode) |
5354 (add-hook 'compilation-mode-hook 'viper-mode) | 5397 (add-hook 'compilation-mode-hook 'viper-mode) |
5398 | |
5399 (add-hook 'perl-mode-hook 'viper-mode) | |
5355 | 5400 |
5356 (defvar emerge-startup-hook nil) | 5401 (defvar emerge-startup-hook nil) |
5357 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs) | 5402 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs) |
5358 ;; Run vip-change-state-to-vi after quitting emerge. | 5403 ;; Run vip-change-state-to-vi after quitting emerge. |
5359 (vip-eval-after-load | 5404 (vip-eval-after-load |
5377 (vip-eval-after-load | 5422 (vip-eval-after-load |
5378 "passwd" | 5423 "passwd" |
5379 '(defadvice read-passwd-1 (before vip-passwd-ad activate) | 5424 '(defadvice read-passwd-1 (before vip-passwd-ad activate) |
5380 "Switch to emacs state while reading password." | 5425 "Switch to emacs state while reading password." |
5381 (vip-change-state-to-emacs))) | 5426 (vip-change-state-to-emacs))) |
5427 | |
5428 (vip-eval-after-load | |
5429 "prolog" | |
5430 '(defadvice prolog-mode (after vip-prolog-ad activate) | |
5431 "Switch to Vi state in Prolog mode." | |
5432 (vip-change-state-to-vi))) | |
5382 | 5433 |
5383 ;; Emacs shell, ange-ftp, and comint-based modes | 5434 ;; Emacs shell, ange-ftp, and comint-based modes |
5384 (defvar comint-mode-hook nil) | 5435 (defvar comint-mode-hook nil) |
5385 (add-hook 'comint-mode-hook 'vip-change-state-to-insert) | 5436 (add-hook 'comint-mode-hook 'vip-change-state-to-insert) |
5386 (add-hook 'comint-mode-hook 'vip-comint-mode-hook) | 5437 (add-hook 'comint-mode-hook 'vip-comint-mode-hook) |
5387 | 5438 |
5388 ;; Shell scripts | 5439 ;; Shell scripts |
5389 (defvar sh-mode-hook nil) | 5440 (defvar sh-mode-hook nil) |
5390 (add-hook 'sh-mode-hook 'viper-mode) | 5441 (add-hook 'sh-mode-hook 'viper-mode) |
5442 (defvar ksh-mode-hook nil) | |
5443 (add-hook 'ksh-mode-hook 'viper-mode) | |
5391 | 5444 |
5392 ;; Dired | 5445 ;; Dired |
5393 ;; This is only necessary when the user uses vip-modify-major-mode | 5446 ;; This is only necessary when the user uses vip-modify-major-mode |
5394 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) | 5447 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) |
5395 | 5448 |
5441 | 5494 |
5442 ;; toggle case sensitivity in search | 5495 ;; toggle case sensitivity in search |
5443 (vip-record-kbd-macro | 5496 (vip-record-kbd-macro |
5444 "//" 'vi-state | 5497 "//" 'vi-state |
5445 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) | 5498 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) |
5446 ;; toggle regexp/vanilla search | 5499 ;; toggle regexp/vanila search |
5447 (vip-record-kbd-macro | 5500 (vip-record-kbd-macro |
5448 "///" 'vi-state | 5501 "///" 'vi-state |
5449 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) | 5502 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) |
5450 | 5503 |
5451 | 5504 |
5459 (vip-add-keymap vip-mode-map vip-vi-global-user-map) | 5512 (vip-add-keymap vip-mode-map vip-vi-global-user-map) |
5460 | 5513 |
5461 | 5514 |
5462 ;; Applying Viper customization -- runs after (load .vip) | 5515 ;; Applying Viper customization -- runs after (load .vip) |
5463 | 5516 |
5464 ;; Save user settings or Viper defaults for vars controlled by vip-expert-level | 5517 ;; Save user settings or Viper defaults for vars controled by vip-expert-level |
5465 (setq vip-saved-user-settings | 5518 (setq vip-saved-user-settings |
5466 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help) | 5519 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help) |
5467 (cons 'vip-always vip-always) | 5520 (cons 'vip-always vip-always) |
5468 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC) | 5521 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC) |
5469 (cons 'vip-ex-style-motion vip-ex-style-motion) | 5522 (cons 'vip-ex-style-motion vip-ex-style-motion) |
5491 (vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX | 5544 (vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX |
5492 (vip-harness-minor-mode "latex") ; which is in one of these two files | 5545 (vip-harness-minor-mode "latex") ; which is in one of these two files |
5493 (vip-harness-minor-mode "cyrillic") | 5546 (vip-harness-minor-mode "cyrillic") |
5494 (vip-harness-minor-mode "russian") | 5547 (vip-harness-minor-mode "russian") |
5495 (vip-harness-minor-mode "view-less") | 5548 (vip-harness-minor-mode "view-less") |
5549 (vip-harness-minor-mode "view") | |
5496 | 5550 |
5497 | 5551 |
5498 ;; Intercept maps could go in viper-keym.el | 5552 ;; Intercept maps could go in viper-keym.el |
5499 ;; We keep them here in case someone redefines them in ~/.vip | 5553 ;; We keep them here in case someone redefines them in ~/.vip |
5500 | 5554 |