aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kifer1996-09-06 01:17:30 +0000
committerMichael Kifer1996-09-06 01:17:30 +0000
commit34da0a2b03788d285b8e05e4885d9a5076811afd (patch)
treef7c520a7c5fa1f5e5f55b765bc17159b413cbf39
parent93b62e827874295bba86ee30a58c9d7c5b1ab3bb (diff)
downloademacs-34da0a2b03788d285b8e05e4885d9a5076811afd.tar.gz
emacs-34da0a2b03788d285b8e05e4885d9a5076811afd.zip
*** empty log message ***
-rw-r--r--lisp/emulation/viper.el375
1 files changed, 250 insertions, 125 deletions
diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el
index d017e4c7c4f..34e23efc644 100644
--- a/lisp/emulation/viper.el
+++ b/lisp/emulation/viper.el
@@ -8,7 +8,7 @@
8 8
9;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. 9;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
10 10
11(defconst viper-version "2.90 of June 19, 1996" 11(defconst viper-version "2.91 of August 5, 1996"
12 "The current version of Viper") 12 "The current version of Viper")
13 13
14;; This file is part of GNU Emacs. 14;; This file is part of GNU Emacs.
@@ -338,6 +338,12 @@ Use `M-x vip-set-expert-level' to change this.")
338;;; Viper minor modes 338;;; Viper minor modes
339 339
340;; This is not local in Emacs, so we make it local. 340;; This is not local in Emacs, so we make it local.
341;; This must be local because although the stack of minor modes can be the same
342;; for all buffers, the associated *keymaps* can be different. In Viper,
343;; vip-vi-local-user-map, vip-insert-local-user-map, and others can have
344;; different keymaps for different buffers.
345;; Also, the keymaps associated with vip-vi/insert-state-modifier-minor-mode
346;; can be different.
341(make-variable-buffer-local 'minor-mode-map-alist) 347(make-variable-buffer-local 'minor-mode-map-alist)
342 348
343;; Mode for vital things like \e, C-z. 349;; Mode for vital things like \e, C-z.
@@ -478,22 +484,31 @@ it better fits your working style.")
478(vip-deflocalvar vip-replace-overlay nil "") 484(vip-deflocalvar vip-replace-overlay nil "")
479(put 'vip-replace-overlay 'permanent-local t) 485(put 'vip-replace-overlay 'permanent-local t)
480 486
481(if (vip-has-face-support-p) 487(defvar vip-replace-overlay-pixmap "gray3"
482 (progn 488 "Pixmap to use for search face on non-color displays.")
483 (make-face 'vip-replace-overlay-face) 489(defvar vip-search-face-pixmap "gray3"
484 (vip-hide-face 'vip-replace-overlay-face) 490 "Pixmap to use for search face on non-color displays.")
485 (or (face-differs-from-default-p 'vip-replace-overlay-face) 491
486 (progn 492
487 (if (vip-can-use-colors "darkseagreen2" "Black") 493(defun vip-set-replace-overlay-face ()
488 (progn 494 (if (vip-has-face-support-p)
489 (set-face-background 495 (defvar vip-replace-overlay-face
490 'vip-replace-overlay-face "darkseagreen2") 496 (progn
491 (set-face-foreground 'vip-replace-overlay-face "Black"))) 497 (make-face 'vip-replace-overlay-face)
492 (set-face-underline-p 'vip-replace-overlay-face t)) 498 (vip-hide-face 'vip-replace-overlay-face)
493 ))) 499 (or (face-differs-from-default-p 'vip-replace-overlay-face)
494 500 (progn
495(defvar vip-replace-overlay-face 'vip-replace-overlay-face 501 (if (vip-can-use-colors "darkseagreen2" "Black")
496 "*Face for highlighting replace regions on a window display.") 502 (progn
503 (set-face-background
504 'vip-replace-overlay-face "darkseagreen2")
505 (set-face-foreground 'vip-replace-overlay-face "Black")))
506 (set-face-underline-p 'vip-replace-overlay-face t)
507 (vip-set-face-pixmap
508 'vip-replace-overlay-face vip-replace-overlay-pixmap)))
509 'vip-replace-overlay-face)
510 "*Face for highlighting replace regions on a window display.")
511 ))
497 512
498(defvar vip-replace-region-end-delimiter "$" 513(defvar vip-replace-region-end-delimiter "$"
499 "A string marking the end of replacement regions. 514 "A string marking the end of replacement regions.
@@ -503,12 +518,10 @@ is non-nil.")
503 "A string marking the beginning of replacement regions. 518 "A string marking the beginning of replacement regions.
504It is used only with TTYs or if `vip-use-replace-region-delimiters' 519It is used only with TTYs or if `vip-use-replace-region-delimiters'
505is non-nil.") 520is non-nil.")
506(defvar vip-use-replace-region-delimiters 521(defvar vip-use-replace-region-delimiters (not (vip-has-face-support-p))
507 (or (not (vip-has-face-support-p)) (not (vip-color-display-p)))
508 "*If non-nil, Viper will always use `vip-replace-region-end-delimiter' and 522 "*If non-nil, Viper will always use `vip-replace-region-end-delimiter' and
509`vip-replace-region-start-delimiter' to delimit replacement regions, even on 523`vip-replace-region-start-delimiter' to delimit replacement regions, even on
510color displays. By default, the delimiters are used only on TTYs or 524color displays. By default, the delimiters are used only on TTYs.")
511monochrome displays.")
512 525
513;; XEmacs requires glyphs 526;; XEmacs requires glyphs
514(if vip-xemacs-p 527(if vip-xemacs-p
@@ -563,21 +576,8 @@ monochrome displays.")
563;; Current mode. One of: `emacs-state', `vi-state', `insert-state' 576;; Current mode. One of: `emacs-state', `vi-state', `insert-state'
564(vip-deflocalvar vip-current-state 'emacs-state) 577(vip-deflocalvar vip-current-state 'emacs-state)
565 578
566
567(defvar vip-toggle-key "\C-z"
568 "The key used to change states from emacs to Vi and back.
569In insert mode, this key also functions as Meta.
570Must be set in .vip file or prior to loading Viper.
571This setting cannot be changed interactively.")
572
573(defvar vip-ESC-key "\e"
574 "Key used to ESC.
575Must be set in .vip file or prior to loading Viper.
576This setting cannot be changed interactively.")
577
578(defvar vip-no-multiple-ESC t 579(defvar vip-no-multiple-ESC t
579 "*If true, multiple ESC in Vi mode will cause bell to ring. 580 "*If true, multiple ESC in Vi mode will cause bell to ring.
580\_ is then mapped to Meta.
581This is set to t on a windowing terminal and to 'twice on a dumb 581This is set to t on a windowing terminal and to 'twice on a dumb
582terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this 582terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this
583enables cursor keys and is generally more convenient, as terminals usually 583enables cursor keys and is generally more convenient, as terminals usually
@@ -821,8 +821,13 @@ These buffers can be cycled through via :R and :P commands.")
821(defvar vip-always t 821(defvar vip-always t
822 "t means, arrange that vi-state will be a default.") 822 "t means, arrange that vi-state will be a default.")
823 823
824(defvar vip-custom-file-name 824(defvar vip-custom-file-name (cond (vip-vms-os-p "sys$login:.vip")
825 (convert-standard-filename "~/.vip") 825 ((memq system-type '(emx ms-dos))
826 "/_vip")
827 ((memq system-type '(windows-nt windows-95))
828 "~/_vip")
829 (t ; Unix
830 "~/.vip"))
826 "Viper customisation file. 831 "Viper customisation file.
827This variable must be set _before_ loading Viper.") 832This variable must be set _before_ loading Viper.")
828 833
@@ -927,7 +932,7 @@ Should be set in `~/.vip' file.")
927 "Movement commands") 932 "Movement commands")
928(vip-test-com-defun vip-movement-command) 933(vip-test-com-defun vip-movement-command)
929 934
930;; Commands that can be repeated by .(dotted) 935;; Commands that can be repeated by . (dotted)
931(defconst vip-dotable-commands '(?c ?d ?C ?D ?> ?<)) 936(defconst vip-dotable-commands '(?c ?d ?C ?D ?> ?<))
932(vip-test-com-defun vip-dotable-command) 937(vip-test-com-defun vip-dotable-command)
933 938
@@ -939,6 +944,14 @@ Should be set in `~/.vip' file.")
939(defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X)) 944(defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
940(vip-test-com-defun vip-regsuffix-command) 945(vip-test-com-defun vip-regsuffix-command)
941 946
947(defconst vip-vi-commands (append vip-movement-commands
948 vip-dotable-commands
949 vip-charpair-commands
950 vip-hash-cmds
951 vip-prefix-commands
952 vip-regsuffix-commands)
953 "The list of all commands in Vi-state.")
954(vip-test-com-defun vip-vi-command)
942 955
943 956
944;;; Arrange the keymaps 957;;; Arrange the keymaps
@@ -1272,7 +1285,7 @@ and improving upon much of it.
1272 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat 1285 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat
1273 undo. Another `u' changes direction. 1286 undo. Another `u' changes direction.
1274 1287
1275 6. Emacs Meta functions are invoked by typing `_' or `\\ ESC'. 1288 6. Emacs Meta functions are invoked by typing `C-\\' or `\\ ESC'.
1276 On a window system, the best way is to use the Meta-key. 1289 On a window system, the best way is to use the Meta-key.
1277 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if 1290 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if
1278 something funny happens. This would abort the current editing command. 1291 something funny happens. This would abort the current editing command.
@@ -1487,20 +1500,24 @@ This startup message appears whenever you load Viper, unless you type `y' now."
1487ARG is used as the prefix value for the executed command. If 1500ARG is used as the prefix value for the executed command. If
1488EVENTS is a list of events, which become the beginning of the command." 1501EVENTS is a list of events, which become the beginning of the command."
1489 (interactive "P") 1502 (interactive "P")
1503 (if (= last-command-char ?\\)
1504 (message "Switched to EMACS state for the next command..."))
1490 (vip-escape-to-state arg events 'emacs-state)) 1505 (vip-escape-to-state arg events 'emacs-state))
1491 1506
1492;; escape to Vi mode termporarily 1507;; escape to Vi mode termporarily
1493(defun vip-escape-to-vi () 1508(defun vip-escape-to-vi (arg)
1494 "Escape from Emacs state to Vi state for one Vi 1-character command. 1509 "Escape from Emacs state to Vi state for one Vi 1-character command.
1495This doesn't work with prefix arguments or most complex commands like 1510If the Vi command that the user types has a prefix argument, e.g., `d2w', then
1496cw, dw, etc. But it does work with some 2-character commands, 1511Vi's prefix argument will be used. Otherwise, the prefix argument passed to
1497like dd or dr." 1512`vip-escape-to-vi' is used."
1498 (interactive) 1513 (interactive "P")
1499 (vip-escape-to-state nil nil 'vi-state)) 1514 (message "Switched to VI state for the next command...")
1515 (vip-escape-to-state arg nil 'vi-state))
1500 1516
1501;; Escape to STATE mode for one Emacs command. 1517;; Escape to STATE mode for one Emacs command.
1502(defun vip-escape-to-state (arg events state) 1518(defun vip-escape-to-state (arg events state)
1503 (let (com key prefix-arg) 1519 ;;(let (com key prefix-arg)
1520 (let (com key)
1504 ;; this temporarily turns off Viper's minor mode keymaps 1521 ;; this temporarily turns off Viper's minor mode keymaps
1505 (vip-set-mode-vars-for state) 1522 (vip-set-mode-vars-for state)
1506 (vip-normalize-minor-mode-map-alist) 1523 (vip-normalize-minor-mode-map-alist)
@@ -1508,23 +1525,26 @@ like dd or dr."
1508 1525
1509 ;; protect against keyboard quit and other errors 1526 ;; protect against keyboard quit and other errors
1510 (condition-case nil 1527 (condition-case nil
1511 (progn 1528 (let (vip-vi-kbd-minor-mode
1529 vip-insert-kbd-minor-mode
1530 vip-emacs-kbd-minor-mode)
1512 (unwind-protect 1531 (unwind-protect
1513 (progn 1532 (progn
1514 (setq com (key-binding (setq key 1533 (setq com (key-binding (setq key
1515 (if vip-xemacs-p 1534 (if vip-xemacs-p
1516 (read-key-sequence nil) 1535 (read-key-sequence nil)
1517 (read-key-sequence nil t))))) 1536 (read-key-sequence nil t)))))
1518 ;; In case of indirection--chase definitions. 1537 ;; In case of binding indirection--chase definitions.
1519 ;; Have to do it here because we execute this command under 1538 ;; Have to do it here because we execute this command under
1520 ;; different keymaps, so command-execute may not do the 1539 ;; different keymaps, so command-execute may not do the
1521 ;; right thing there 1540 ;; right thing there
1522 (while (vectorp com) (setq com (key-binding com)))) 1541 (while (vectorp com) (setq com (key-binding com))))
1523 nil) 1542 nil)
1524 ;; exec command in the right Viper state 1543 ;; Execute command com in the original Viper state, not in state
1525 ;; otherwise, if we switch buffers in the escaped command, 1544 ;; `state'. Otherwise, if we switch buffers while executing the
1526 ;; Viper's mode vars will remain those of `state'. When we return 1545 ;; escaped to command, Viper's mode vars will remain those of
1527 ;; to the orig buffer, the bindings will be screwed up. 1546 ;; `state'. When we return to the orig buffer, the bindings will be
1547 ;; screwed up.
1528 (vip-set-mode-vars-for vip-current-state) 1548 (vip-set-mode-vars-for vip-current-state)
1529 1549
1530 ;; this-command, last-command-char, last-command-event 1550 ;; this-command, last-command-char, last-command-event
@@ -1538,13 +1558,27 @@ like dd or dr."
1538 1558
1539 (if (commandp com) 1559 (if (commandp com)
1540 (progn 1560 (progn
1541 (setq prefix-arg arg) 1561 (setq prefix-arg (or prefix-arg arg))
1542 (command-execute com))) 1562 (command-execute com)))
1543 ) 1563 )
1544 (quit (ding)) 1564 (quit (ding))
1545 (error (beep 1)))) 1565 (error (beep 1))))
1546 (vip-set-mode-vars-for vip-current-state)) ; set state in new buffer 1566 ;; set state in the new buffer
1567 (vip-set-mode-vars-for vip-current-state))
1547 1568
1569(defun vip-exec-form-in-vi (form)
1570 "Execute FORM in Vi state, regardless of the Ccurrent Vi state."
1571 (let ((buff (current-buffer))
1572 result)
1573 (vip-set-mode-vars-for 'vi-state)
1574 (setq result (eval form))
1575 (if (not (equal buff (current-buffer))) ; cmd switched buffer
1576 (save-excursion
1577 (set-buffer buff)
1578 (vip-set-mode-vars-for vip-current-state)))
1579 (vip-set-mode-vars-for vip-current-state)
1580 result))
1581
1548(defun vip-exec-form-in-emacs (form) 1582(defun vip-exec-form-in-emacs (form)
1549 "Execute FORM in Emacs, temporarily disabling Viper's minor modes. 1583 "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
1550Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes." 1584Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes."
@@ -1587,13 +1621,13 @@ Suffixes such as .el or .elc should be stripped."
1587 1621
1588(defun vip-ESC (arg) 1622(defun vip-ESC (arg)
1589 "Emulate ESC key in Emacs. 1623 "Emulate ESC key in Emacs.
1590Prevents multiple escape keystrokes if vip-no-multiple-ESC is true. In that 1624Prevents multiple escape keystrokes if vip-no-multiple-ESC is true.
1591case \@ will be bound to ESC. If vip-no-multiple-ESC is 'twice double ESC 1625If vip-no-multiple-ESC is 'twice double ESC would ding in vi-state.
1592would dings in vi-state. Other ESC sequences are emulated via the current 1626Other ESC sequences are emulated via the current Emacs's major mode
1593Emacs's major mode keymap. This is more convenient on dumb terminals and in 1627keymap. This is more convenient on TTYs, since this won't block
1594Emacs -nw, since this won't block functional keys such as up,down, 1628function keys such as up,down, etc. ESC will also will also work as
1595etc. Meta key also will work. When vip-no-multiple-ESC is nil, ESC key 1629a Meta key in this case. When vip-no-multiple-ESC is nil, ESC functions
1596behaves as in Emacs, any number of multiple escapes is allowed." 1630as a Meta key and any number of multiple escapes is allowed."
1597 (interactive "P") 1631 (interactive "P")
1598 (let (char) 1632 (let (char)
1599 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state)) 1633 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state))
@@ -1608,11 +1642,21 @@ behaves as in Emacs, any number of multiple escapes is allowed."
1608 (t (ding))) 1642 (t (ding)))
1609 )) 1643 ))
1610 1644
1611(defun vip-alternate-ESC (arg) 1645(defun vip-alternate-Meta-key (arg)
1612 "ESC key without checking for multiple keystrokes." 1646 "Simulate Emacs Meta key."
1613 (interactive "P") 1647 (interactive "P")
1648 (sit-for 1) (message "ESC-")
1614 (vip-escape-to-emacs arg '(?\e))) 1649 (vip-escape-to-emacs arg '(?\e)))
1615 1650
1651(defun vip-toggle-key-action ()
1652 "Action bound to `vip-toggle-key'."
1653 (interactive)
1654 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z"))
1655 (if (vip-window-display-p)
1656 (vip-iconify)
1657 (suspend-emacs))
1658 (vip-change-state-to-emacs)))
1659
1616 1660
1617;; Intercept ESC sequences on dumb terminals. 1661;; Intercept ESC sequences on dumb terminals.
1618;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es> 1662;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
@@ -1783,9 +1827,9 @@ behaves as in Emacs, any number of multiple escapes is allowed."
1783 1827
1784 1828
1785;; Compute numeric prefix arg value. 1829;; Compute numeric prefix arg value.
1786;; Invoked by CHAR. COM is the command part obtained so far. 1830;; Invoked by EVENT. COM is the command part obtained so far.
1787(defun vip-prefix-arg-value (event com) 1831(defun vip-prefix-arg-value (event com)
1788 (let (value) 1832 (let (value func)
1789 ;; read while number 1833 ;; read while number
1790 (while (and (vip-characterp event) (>= event ?0) (<= event ?9)) 1834 (while (and (vip-characterp event) (>= event ?0) (<= event ?9))
1791 (setq value (+ (* (if (vip-characterp value) value 0) 10) (- event ?0))) 1835 (setq value (+ (* (if (vip-characterp value) value 0) 10) (- event ?0)))
@@ -1796,11 +1840,39 @@ behaves as in Emacs, any number of multiple escapes is allowed."
1796 (while (eq event ?U) 1840 (while (eq event ?U)
1797 (vip-describe-arg prefix-arg) 1841 (vip-describe-arg prefix-arg)
1798 (setq event (vip-read-event-convert-to-char))) 1842 (setq event (vip-read-event-convert-to-char)))
1799 (vip-set-unread-command-events event))) 1843
1844 (if (or com (and (not (eq vip-current-state 'vi-state))
1845 ;; make sure it is a Vi command
1846 (vip-characterp event) (vip-vi-command-p event)
1847 ))
1848 ;; If appears to be one of the vi commands,
1849 ;; then execute it with funcall and clear prefix-arg in order to not
1850 ;; confuse subsequent commands
1851 (progn
1852 ;; last-command-char is the char we want emacs to think was typed
1853 ;; last. If com is not nil, the vip-digit-argument command was called
1854 ;; from within vip-prefix-arg command, such as `d', `w', etc., i.e.,
1855 ;; the user typed, say, d2. In this case, `com' would be `d', `w',
1856 ;; etc.
1857 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is
1858 ;; indicated by the fact that the current state is not vi-state,
1859 ;; then `event' represents the vi command to be executed (e.g., `d',
1860 ;; `w', etc. Again, last-command-char must make emacs believe that
1861 ;; this is the command we typed.
1862 (setq last-command-char (or com event))
1863 (setq func (vip-exec-form-in-vi
1864 (` (key-binding (char-to-string (, event))))))
1865 (funcall func prefix-arg)
1866 (setq prefix-arg nil))
1867 ;; some other command -- let emacs do it in its own way
1868 (vip-set-unread-command-events event))
1869 ))
1870
1800 1871
1801;; Vi operator as prefix argument." 1872;; Vi operator as prefix argument."
1802(defun vip-prefix-arg-com (char value com) 1873(defun vip-prefix-arg-com (char value com)
1803 (let ((cont t)) 1874 (let ((cont t)
1875 cmd-info mv-or-digit-cmd)
1804 (while (and cont 1876 (while (and cont
1805 (memq char 1877 (memq char
1806 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\" 1878 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
@@ -1834,20 +1906,23 @@ behaves as in Emacs, any number of multiple escapes is allowed."
1834 (setq char (read-char)))) 1906 (setq char (read-char))))
1835 (t 1907 (t
1836 (setq com char) 1908 (setq com char)
1837 (setq char (vip-read-char-exclusive))))))) 1909 (setq char (vip-read-char-exclusive))))))
1910
1838 (if (atom com) 1911 (if (atom com)
1839 ;; com is a single char, so we construct prefix-arg 1912 ;; `com' is a single char, so we construct the command argument
1840 ;; and if char is ?, describe prefix arg, otherwise exit by 1913 ;; and if `char' is `?', we describe the arg; otherwise
1841 ;; pushing the char back into vip-set-unread-command-events 1914 ;; we prepare the command that will be executed at the end.
1842 ;; Since char is a command, the command will execute with the prefix
1843 ;; argument that we just constructed.
1844 (progn 1915 (progn
1845 (setq prefix-arg (cons value com)) 1916 (setq cmd-info (cons value com))
1846 (while (= char ?U) 1917 (while (= char ?U)
1847 (vip-describe-arg prefix-arg) 1918 (vip-describe-arg cmd-info)
1848 (setq char (read-char))) 1919 (setq char (read-char)))
1849 (vip-set-unread-command-events char) 1920 ;; `char' is a movement command or a digit arg command---so we execute
1850 ) 1921 ;; it at the very end
1922 (setq mv-or-digit-cmd
1923 (vip-exec-form-in-vi
1924 (` (key-binding (char-to-string (, char)))))))
1925
1851 ;; as com is non-nil, this means that we have a command to execute 1926 ;; as com is non-nil, this means that we have a command to execute
1852 (if (memq (car com) '(?r ?R)) 1927 (if (memq (car com) '(?r ?R))
1853 ;; execute apropriate region command. 1928 ;; execute apropriate region command.
@@ -1868,7 +1943,13 @@ behaves as in Emacs, any number of multiple escapes is allowed."
1868 ((equal com '(?> . ?>)) (vip-line (cons value ?>))) 1943 ((equal com '(?> . ?>)) (vip-line (cons value ?>)))
1869 ((equal com '(?! . ?!)) (vip-line (cons value ?!))) 1944 ((equal com '(?! . ?!)) (vip-line (cons value ?!)))
1870 ((equal com '(?= . ?=)) (vip-line (cons value ?=))) 1945 ((equal com '(?= . ?=)) (vip-line (cons value ?=)))
1871 (t (error "")))))) 1946 (t (error "")))))
1947
1948 (if mv-or-digit-cmd
1949 (progn
1950 (setq last-command-char char)
1951 (funcall mv-or-digit-cmd cmd-info)))
1952 ))
1872 1953
1873(defun vip-describe-arg (arg) 1954(defun vip-describe-arg (arg)
1874 (let (val com) 1955 (let (val com)
@@ -1886,8 +1967,8 @@ behaves as in Emacs, any number of multiple escapes is allowed."
1886 "Begin numeric argument for the next command." 1967 "Begin numeric argument for the next command."
1887 (interactive "P") 1968 (interactive "P")
1888 (vip-leave-region-active) 1969 (vip-leave-region-active)
1889 (vip-prefix-arg-value last-command-char 1970 (vip-prefix-arg-value
1890 (if (consp arg) (cdr arg) nil))) 1971 last-command-char (if (consp arg) (cdr arg) nil)))
1891 1972
1892(defun vip-command-argument (arg) 1973(defun vip-command-argument (arg)
1893 "Accept a motion command as an argument." 1974 "Accept a motion command as an argument."
@@ -2537,8 +2618,8 @@ Undo previous insertion and inserts new."
2537 (progn 2618 (progn
2538 (set-face-background 'vip-search-face "khaki") 2619 (set-face-background 'vip-search-face "khaki")
2539 (set-face-foreground 'vip-search-face "Black")) 2620 (set-face-foreground 'vip-search-face "Black"))
2540 (copy-face 'italic 'vip-search-face) 2621 (set-face-underline-p 'vip-search-face t)
2541 (set-face-underline-p 'vip-search-face t))) 2622 (vip-set-face-pixmap 'vip-search-face vip-search-face-pixmap)))
2542 'vip-search-face) 2623 'vip-search-face)
2543 "*Face used to flash out the search pattern.") 2624 "*Face used to flash out the search pattern.")
2544 )) 2625 ))
@@ -3905,21 +3986,30 @@ controlled by the sign of prefix numeric value."
3905 3986
3906(setq scroll-step 1) 3987(setq scroll-step 1)
3907 3988
3908(defun vip-scroll (arg) 3989(defun vip-scroll-screen (arg)
3909 "Scroll to next screen." 3990 "Scroll to next screen."
3910 (interactive "p") 3991 (interactive "p")
3911 (if (> arg 0) 3992 (condition-case nil
3912 (while (> arg 0) 3993 (if (> arg 0)
3913 (scroll-up) 3994 (while (> arg 0)
3914 (setq arg (1- arg))) 3995 (scroll-up)
3915 (while (> 0 arg) 3996 (setq arg (1- arg)))
3916 (scroll-down) 3997 (while (> 0 arg)
3917 (setq arg (1+ arg))))) 3998 (scroll-down)
3918 3999 (setq arg (1+ arg))))
3919(defun vip-scroll-back (arg) 4000 (error (beep 1)
4001 (if (> arg 0)
4002 (progn
4003 (message "End of buffer")
4004 (goto-char (point-max)))
4005 (message "Beginning of buffer")
4006 (goto-char (point-min))))
4007 ))
4008
4009(defun vip-scroll-screen-back (arg)
3920 "Scroll to previous screen." 4010 "Scroll to previous screen."
3921 (interactive "p") 4011 (interactive "p")
3922 (vip-scroll (- arg))) 4012 (vip-scroll-screen (- arg)))
3923 4013
3924(defun vip-scroll-down (arg) 4014(defun vip-scroll-down (arg)
3925 "Pull down half screen." 4015 "Pull down half screen."
@@ -4084,7 +4174,7 @@ Null string will repeat previous search."
4084 (search-failed 4174 (search-failed
4085 (if (and (not fail-if-not-found) vip-search-wrap-around-t) 4175 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
4086 (progn 4176 (progn
4087 (message "Search wrapped around end of buffer") 4177 (message "Search wrapped around BOTTOM of buffer")
4088 (goto-char (point-min)) 4178 (goto-char (point-min))
4089 (vip-search string forward (cons 1 com) t start-point 'fail) 4179 (vip-search string forward (cons 1 com) t start-point 'fail)
4090 ;; don't wait in macros 4180 ;; don't wait in macros
@@ -4111,7 +4201,7 @@ Null string will repeat previous search."
4111 (search-failed 4201 (search-failed
4112 (if (and (not fail-if-not-found) vip-search-wrap-around-t) 4202 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
4113 (progn 4203 (progn
4114 (message "Search wrapped around beginning of buffer") 4204 (message "Search wrapped around TOP of buffer")
4115 (goto-char (point-max)) 4205 (goto-char (point-max))
4116 (vip-search string forward (cons 1 com) t start-point 'fail) 4206 (vip-search string forward (cons 1 com) t start-point 'fail)
4117 ;; don't wait in macros 4207 ;; don't wait in macros
@@ -4743,6 +4833,7 @@ One can use `` and '' to temporarily jump 1 step back."
4743 (if (and (vip-same-line (point) vip-last-jump) 4833 (if (and (vip-same-line (point) vip-last-jump)
4744 (= (point) vip-last-jump-ignore)) 4834 (= (point) vip-last-jump-ignore))
4745 (goto-char vip-last-jump)) 4835 (goto-char vip-last-jump))
4836 (if (null (mark t)) (error "Mark is not set in this buffer"))
4746 (if (= (point) (mark t)) (pop-mark)) 4837 (if (= (point) (mark t)) (pop-mark))
4747 (exchange-point-and-mark) 4838 (exchange-point-and-mark)
4748 (setq vip-last-jump (point-marker) 4839 (setq vip-last-jump (point-marker)
@@ -4943,13 +5034,10 @@ sensitive for VI-style look-and-feel."
4943 vip-ex-style-editing-in-insert t 5034 vip-ex-style-editing-in-insert t
4944 vip-want-ctl-h-help nil) 5035 vip-want-ctl-h-help nil)
4945 5036
4946 (cond 5037 (cond ((eq vip-expert-level 1) ; novice or beginner
4947 ;; a novice or a beginner 5038 (global-set-key ; in emacs-state
4948 ((eq vip-expert-level 1) 5039 vip-toggle-key
4949 (global-set-key vip-toggle-key ;; in emacs-state 5040 (if (vip-window-display-p) 'vip-iconify 'suspend-emacs))
4950 (if (vip-window-display-p)
4951 'vip-iconify
4952 'suspend-emacs))
4953 (setq vip-no-multiple-ESC t 5041 (setq vip-no-multiple-ESC t
4954 vip-re-search t 5042 vip-re-search t
4955 vip-vi-style-in-minibuffer t 5043 vip-vi-style-in-minibuffer t
@@ -4957,8 +5045,8 @@ sensitive for VI-style look-and-feel."
4957 vip-want-emacs-keys-in-vi nil 5045 vip-want-emacs-keys-in-vi nil
4958 vip-want-emacs-keys-in-insert nil)) 5046 vip-want-emacs-keys-in-insert nil))
4959 5047
4960 ;; an intermediate to guru
4961 ((and (> vip-expert-level 1) (< vip-expert-level 5)) 5048 ((and (> vip-expert-level 1) (< vip-expert-level 5))
5049 ;; intermediate to guru
4962 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice) 5050 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice)
4963 vip-want-emacs-keys-in-vi t 5051 vip-want-emacs-keys-in-vi t
4964 vip-want-emacs-keys-in-insert (> vip-expert-level 2)) 5052 vip-want-emacs-keys-in-insert (> vip-expert-level 2))
@@ -4983,9 +5071,9 @@ sensitive for VI-style look-and-feel."
4983 (cdr (assoc 'vip-no-multiple-ESC 5071 (cdr (assoc 'vip-no-multiple-ESC
4984 vip-saved-user-settings)))))) 5072 vip-saved-user-settings))))))
4985 5073
4986 ;; A wizard 5074 ;; A wizard!!
4987 ;; Ideally, if 5 is selected, a buffer should pop up to let the 5075 ;; Ideally, if 5 is selected, a buffer should pop up to let the
4988 ;; user toggle variable values. 5076 ;; user toggle the values of variables.
4989 (t (setq-default vip-ex-style-editing-in-insert 5077 (t (setq-default vip-ex-style-editing-in-insert
4990 (cdr (assoc 'vip-ex-style-editing-in-insert 5078 (cdr (assoc 'vip-ex-style-editing-in-insert
4991 vip-saved-user-settings)) 5079 vip-saved-user-settings))
@@ -5365,17 +5453,11 @@ Mail anyway (y or n)? ")
5365 5453
5366;; This hook designed to enable Vi-style editing in comint-based modes." 5454;; This hook designed to enable Vi-style editing in comint-based modes."
5367(defun vip-comint-mode-hook () 5455(defun vip-comint-mode-hook ()
5368 (setq require-final-newline nil) 5456 (setq require-final-newline nil
5369 (setq vip-ex-style-editing-in-insert nil 5457 vip-ex-style-editing-in-insert nil
5370 vip-ex-style-motion nil) 5458 vip-ex-style-motion nil)
5371 (vip-add-local-keys 'vi-state 5459 (vip-change-state-to-insert))
5372 '(("\C-m" . comint-send-input) ; return 5460
5373 ("\C-d" . comint-delchar-or-maybe-eof))) ; \C-d
5374 (vip-add-local-keys 'insert-state
5375 '(("\C-m" . comint-send-input) ; return
5376 ("\C-d" . comint-delchar-or-maybe-eof))) ; \C-d
5377 )
5378
5379 5461
5380;; This sets major mode hooks to make them come up in vi-state. 5462;; This sets major mode hooks to make them come up in vi-state.
5381(defun vip-set-hooks () 5463(defun vip-set-hooks ()
@@ -5404,6 +5486,8 @@ Mail anyway (y or n)? ")
5404 (add-hook 'html-mode-hook 'viper-mode) 5486 (add-hook 'html-mode-hook 'viper-mode)
5405 (defvar html-helper-mode-hook) 5487 (defvar html-helper-mode-hook)
5406 (add-hook 'html-helper-mode-hook 'viper-mode) 5488 (add-hook 'html-helper-mode-hook 'viper-mode)
5489 (defvar java-mode-hook)
5490 (add-hook 'java-mode-hook 'viper-mode)
5407 5491
5408 (defvar emacs-lisp-mode-hook) 5492 (defvar emacs-lisp-mode-hook)
5409 (add-hook 'emacs-lisp-mode-hook 'viper-mode) 5493 (add-hook 'emacs-lisp-mode-hook 'viper-mode)
@@ -5440,7 +5524,18 @@ Mail anyway (y or n)? ")
5440 5524
5441 (defvar emerge-startup-hook) 5525 (defvar emerge-startup-hook)
5442 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs) 5526 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs)
5443 ;; Run vip-change-state-to-vi after quitting emerge. 5527
5528 ;; Tell vc-diff to put *vc* in Vi mode
5529 (if (featurep 'vc)
5530 (defadvice vc-diff (after vip-vc-ad activate)
5531 "Force Vi state in VC diff buffer."
5532 (vip-change-state-to-vi))
5533 (vip-eval-after-load
5534 "vc"
5535 '(defadvice vc-diff (after vip-vc-ad activate)
5536 "Force Vi state in VC diff buffer."
5537 (vip-change-state-to-vi))))
5538
5444 (vip-eval-after-load 5539 (vip-eval-after-load
5445 "emerge" 5540 "emerge"
5446 '(defadvice emerge-quit (after vip-emerge-advice activate) 5541 '(defadvice emerge-quit (after vip-emerge-advice activate)
@@ -5473,7 +5568,10 @@ Mail anyway (y or n)? ")
5473 5568
5474 ;; Emacs shell, ange-ftp, and comint-based modes 5569 ;; Emacs shell, ange-ftp, and comint-based modes
5475 (defvar comint-mode-hook) 5570 (defvar comint-mode-hook)
5476 (add-hook 'comint-mode-hook 'vip-change-state-to-insert) 5571 (vip-modify-major-mode
5572 'comint-mode 'insert-state vip-comint-mode-modifier-map)
5573 (vip-modify-major-mode
5574 'comint-mode 'vi-state vip-comint-mode-modifier-map)
5477 (add-hook 'comint-mode-hook 'vip-comint-mode-hook) 5575 (add-hook 'comint-mode-hook 'vip-comint-mode-hook)
5478 5576
5479 ;; Shell scripts 5577 ;; Shell scripts
@@ -5483,9 +5581,40 @@ Mail anyway (y or n)? ")
5483 (add-hook 'ksh-mode-hook 'viper-mode) 5581 (add-hook 'ksh-mode-hook 'viper-mode)
5484 5582
5485 ;; Dired 5583 ;; Dired
5486 ;; This is only necessary when the user uses vip-modify-major-mode 5584 (vip-modify-major-mode 'dired-mode 'emacs-state vip-dired-modifier-map)
5487 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) 5585 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs)
5488 5586
5587 ;; MH-E
5588 (vip-modify-major-mode 'mh-folder-mode 'emacs-state vip-slash-and-colon-map)
5589 ;; changing state to emacs is needed so the preceding will take hold
5590 (add-hook 'mh-folder-mode-hook 'vip-change-state-to-emacs)
5591 (add-hook 'mh-show-mode-hook 'viper-mode)
5592
5593 ;; Gnus
5594 (vip-modify-major-mode 'gnus-group-mode 'emacs-state vip-slash-and-colon-map)
5595 (vip-modify-major-mode
5596 'gnus-summary-mode 'emacs-state vip-slash-and-colon-map)
5597 ;; changing state to emacs is needed so the preceding will take hold
5598 (add-hook 'gnus-group-mode-hook 'vip-change-state-to-emacs)
5599 (add-hook 'gnus-summary-mode-hook 'vip-change-state-to-emacs)
5600 (add-hook 'gnus-article-mode-hook 'viper-mode)
5601
5602 ;; Info
5603 (vip-modify-major-mode 'Info-mode 'emacs-state vip-slash-and-colon-map)
5604 ;; Switching to emacs is needed so the above will take hold
5605 (defadvice Info-mode (after vip-Info-ad activate)
5606 "Switch to emacs mode."
5607 (vip-change-state-to-emacs))
5608
5609 ;; Buffer menu
5610 (vip-modify-major-mode
5611 'Buffer-menu-mode 'emacs-state vip-slash-and-colon-map)
5612 ;; Switching to emacs is needed so the above will take hold
5613 (defadvice Buffer-menu-mode (after vip-Buffer-menu-ad activate)
5614 "Switch to emacs mode."
5615 (vip-change-state-to-emacs))
5616
5617 ;; View mode
5489 (if vip-emacs-p 5618 (if vip-emacs-p
5490 (progn 5619 (progn
5491 (defvar view-mode-hook) 5620 (defvar view-mode-hook)
@@ -5566,6 +5695,7 @@ Mail anyway (y or n)? ")
5566(vip-set-minibuffer-style) 5695(vip-set-minibuffer-style)
5567(vip-set-minibuffer-faces) 5696(vip-set-minibuffer-faces)
5568(vip-set-search-face) 5697(vip-set-search-face)
5698(vip-set-replace-overlay-face)
5569(if vip-buffer-search-char 5699(if vip-buffer-search-char
5570 (vip-buffer-search-enable)) 5700 (vip-buffer-search-enable))
5571(vip-update-alphanumeric-class) 5701(vip-update-alphanumeric-class)
@@ -5594,15 +5724,10 @@ Mail anyway (y or n)? ")
5594;; This is taken care of by vip-insert-global-user-map. 5724;; This is taken care of by vip-insert-global-user-map.
5595;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key) 5725;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key)
5596 5726
5597(define-key vip-insert-intercept-map vip-toggle-key 'vip-alternate-ESC) 5727
5598;; The default vip-toggle-key is \C-z; for the novice, it suspends or 5728;; The default vip-toggle-key is \C-z; for the novice, it suspends or
5599;; iconifies Emacs 5729;; iconifies Emacs
5600(define-key vip-vi-intercept-map vip-toggle-key 5730(define-key vip-vi-intercept-map vip-toggle-key 'vip-toggle-key-action)
5601 '(lambda () (interactive)
5602 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z"))
5603 (if (vip-window-display-p) (vip-iconify) (suspend-emacs))
5604 (vip-change-state-to-emacs))))
5605
5606(define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi) 5731(define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi)
5607 5732
5608 5733