comparison lisp/viper/viper.el @ 14:9ee227acff29 r19-15b90

Import from CVS: tag r19-15b90
author cvs
date Mon, 13 Aug 2007 08:48:42 +0200
parents bcdc7deadc19
children 0293115a14e9
comparison
equal deleted inserted replaced
13:13c6d0aaafe5 14:9ee227acff29
6 ;; Keywords: emulations 6 ;; Keywords: emulations
7 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> 7 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
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.91 of August 5, 1996" 11 (defconst viper-version "2.92 of January 3, 1997"
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.
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
298 298
299 (require 'advice) 299 (require 'advice)
300 (require 'cl) 300 (require 'cl)
301 (require 'ring) 301 (require 'ring)
302 302
303 (require 'viper-util) 303 (provide 'viper)
304 304
305 ;; Compiler pacifier 305 ;; Compiler pacifier
306 (defvar vip-minibuffer-current-face) 306 (defvar vip-minibuffer-current-face)
307 (defvar vip-minibuffer-insert-face) 307 (defvar vip-minibuffer-insert-face)
308 (defvar vip-minibuffer-vi-face) 308 (defvar vip-minibuffer-vi-face)
309 (defvar vip-minibuffer-emacs-face) 309 (defvar vip-minibuffer-emacs-face)
310 (defvar iso-accents-mode) 310 (defvar iso-accents-mode)
311 (defvar zmacs-region-stays) 311 (defvar zmacs-region-stays)
312 (defvar mark-even-if-inactive)
313
314 (eval-when-compile
315 (let ((load-path (cons "." load-path)))
316 (or (featurep 'viper-util)
317 (load "viper-util.el" nil nil 'nosuffix))
318 (or (featurep 'viper-keym)
319 (load "viper-keym.el" nil nil 'nosuffix))
320 (or (featurep 'viper-mous)
321 (load "viper-mous.el" nil nil 'nosuffix))
322 (or (featurep 'viper-macs)
323 (load "viper-macs.el" nil nil 'nosuffix))
324 (or (featurep 'viper-ex)
325 (load "viper-ex.el" nil nil 'nosuffix))
326 ))
312 ;; end pacifier 327 ;; end pacifier
328
329 (require 'viper-util)
330 (require 'viper-keym)
331 (require 'viper-mous)
332 (require 'viper-macs)
333 (require 'viper-ex)
334
313 335
314 336
315 ;;; Variables 337 ;;; Variables
316 338
317 ;; Is t until viper-mode executes for the very first time. 339 ;; Is t until viper-mode executes for the very first time.
333 ;; Contains user settings for vars affected by vip-set-expert-level function. 355 ;; Contains user settings for vars affected by vip-set-expert-level function.
334 ;; Not a user option. 356 ;; Not a user option.
335 (defvar vip-saved-user-settings nil) 357 (defvar vip-saved-user-settings nil)
336 358
337 359
338 ;;; Viper minor modes
339
340 ;; This must be local because although the stack of minor modes can be the same
341 ;; for all buffers, the associated *keymaps* can be different. In Viper,
342 ;; vip-vi-local-user-map, vip-insert-local-user-map, and others can have
343 ;; different keymaps for different buffers.
344 ;; Also, the keymaps associated with vip-vi/insert-state-modifier-minor-mode
345 ;; can be different.
346 (make-variable-buffer-local 'minor-mode-map-alist)
347
348 ;; Mode for vital things like \e, C-z.
349 (vip-deflocalvar vip-vi-intercept-minor-mode nil)
350
351 (vip-deflocalvar vip-vi-basic-minor-mode nil
352 "Viper's minor mode for Vi bindings.")
353
354 (vip-deflocalvar vip-vi-local-user-minor-mode nil
355 "Auxiliary minor mode for user-defined local bindings in Vi state.")
356
357 (vip-deflocalvar vip-vi-global-user-minor-mode nil
358 "Auxiliary minor mode for user-defined global bindings in Vi state.")
359
360 (vip-deflocalvar vip-vi-state-modifier-minor-mode nil
361 "Minor mode used to make major-mode-specific modification to Vi state.")
362
363 (vip-deflocalvar vip-vi-diehard-minor-mode nil
364 "This minor mode is in effect when the user wants Viper to be Vi.")
365
366 (vip-deflocalvar vip-vi-kbd-minor-mode nil
367 "Minor mode for Ex command macros in Vi state.
368 The corresponding keymap stores key bindings of Vi macros defined with
369 the Ex command :map.")
370
371 ;; Mode for vital things like \e, C-z.
372 (vip-deflocalvar vip-insert-intercept-minor-mode nil)
373
374 (vip-deflocalvar vip-insert-basic-minor-mode nil
375 "Viper's minor mode for bindings in Insert mode.")
376
377 (vip-deflocalvar vip-insert-local-user-minor-mode nil
378 "Auxiliary minor mode for buffer-local user-defined bindings in Insert state.
379 This is a way to overshadow normal Insert mode bindings locally to certain
380 designated buffers.")
381
382 (vip-deflocalvar vip-insert-global-user-minor-mode nil
383 "Auxiliary minor mode for global user-defined bindings in Insert state.")
384
385 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil
386 "Minor mode used to make major-mode-specific modification to Insert state.")
387
388 (vip-deflocalvar vip-insert-diehard-minor-mode nil
389 "Minor mode that simulates Vi very closely.
390 Not recommened, except for the novice user.")
391
392 (vip-deflocalvar vip-insert-kbd-minor-mode nil
393 "Minor mode for Ex command macros Insert state.
394 The corresponding keymap stores key bindings of Vi macros defined with
395 the Ex command :map!.")
396
397 (vip-deflocalvar vip-replace-minor-mode nil
398 "Minor mode in effect in replace state (cw, C, and the like commands).")
399
400 ;; Mode for vital things like \C-z and \C-x)
401 ;; This is t, by default. So, any new buffer will have C-z defined as
402 ;; switch to Vi, unless we switched states in this buffer
403 (vip-deflocalvar vip-emacs-intercept-minor-mode t)
404
405 (vip-deflocalvar vip-emacs-local-user-minor-mode t
406 "Minor mode for local user bindings effective in Emacs state.
407 Users can use it to override Emacs bindings when Viper is in its Emacs
408 state.")
409
410 (vip-deflocalvar vip-emacs-global-user-minor-mode t
411 "Minor mode for global user bindings in effect in Emacs state.
412 Users can use it to override Emacs bindings when Viper is in its Emacs
413 state.")
414
415 (vip-deflocalvar vip-emacs-kbd-minor-mode t
416 "Minor mode for Vi style macros in Emacs state.
417 The corresponding keymap stores key bindings of Vi macros defined with
418 `vip-record-kbd-macro' command. There is no Ex-level command to do this
419 interactively.")
420
421 (vip-deflocalvar vip-emacs-state-modifier-minor-mode t
422 "Minor mode used to make major-mode-specific modification to Emacs state.
423 For instance, a Vi purist may want to bind `dd' in Dired mode to a function
424 that deletes a file.")
425
426
427
428 ;;; ISO characters 360 ;;; ISO characters
429 361
430 (vip-deflocalvar vip-automatic-iso-accents nil 362 (vip-deflocalvar vip-automatic-iso-accents nil
431 "*If non-nil, ISO accents will be turned on in insert/replace emacs states and turned off in vi-state. 363 "*If non-nil, ISO accents will be turned on in insert/replace emacs states and turned off in vi-state.
432 For some users, this behavior may be too primitive. In this case, use 364 For some users, this behavior may be too primitive. In this case, use
433 insert/emacs/vi state hooks.") 365 insert/emacs/vi state hooks.")
434 366
435
436 ;;; Emacs keys in other states.
437
438 (defvar vip-want-emacs-keys-in-insert t
439 "*Set to nil if you want complete Vi compatibility in insert mode.
440 Complete compatibility with Vi is not recommended for power use of Viper.")
441
442 (defvar vip-want-emacs-keys-in-vi t
443 "*Set to nil if you want complete Vi compatibility in Vi mode.
444 Full Vi compatibility is not recommended for power use of Viper.")
445
446
447 367
448 ;; VI-style Undo 368 ;; VI-style Undo
449 369
450 ;; Used to 'undo' complex commands, such as replace and insert commands. 370 ;; Used to 'undo' complex commands, such as replace and insert commands.
451 (vip-deflocalvar vip-undo-needs-adjustment nil) 371 (vip-deflocalvar vip-undo-needs-adjustment nil)
476 ;; Indicates that the current destructive command has started in replace mode. 396 ;; Indicates that the current destructive command has started in replace mode.
477 (vip-deflocalvar vip-began-as-replace nil "") 397 (vip-deflocalvar vip-began-as-replace nil "")
478 398
479 (defvar vip-replace-overlay-cursor-color "Red" 399 (defvar vip-replace-overlay-cursor-color "Red"
480 "*Cursor color to use in Replace state") 400 "*Cursor color to use in Replace state")
481
482 (defvar vip-insert-state-cursor-color nil 401 (defvar vip-insert-state-cursor-color nil
483 "Cursor color for Viper insert state.") 402 "Cursor color for Viper insert state.")
484 (put 'vip-insert-state-cursor-color 'permanent-local t) 403 (put 'vip-insert-state-cursor-color 'permanent-local t)
485 ;; place to save cursor colow when switching to insert mode 404 ;; place to save cursor colow when switching to insert mode
486 (vip-deflocalvar vip-saved-cursor-color nil "") 405 (vip-deflocalvar vip-saved-cursor-color nil "")
487 406
488 (vip-deflocalvar vip-replace-overlay nil "") 407 (vip-deflocalvar vip-replace-overlay nil "")
489 (put 'vip-replace-overlay 'permanent-local t) 408 (put 'vip-replace-overlay 'permanent-local t)
490 409
491 (defvar vip-replace-overlay-pixmap "gray3" 410 (defvar vip-replace-overlay-pixmap "gray3"
492 "Pixmap to use for search face on non-color displays.") 411 "Pixmap to use for search face on non-color displays.")
578 ;; Modes and related variables 497 ;; Modes and related variables
579 498
580 ;; Current mode. One of: `emacs-state', `vi-state', `insert-state' 499 ;; Current mode. One of: `emacs-state', `vi-state', `insert-state'
581 (vip-deflocalvar vip-current-state 'emacs-state) 500 (vip-deflocalvar vip-current-state 'emacs-state)
582 501
583 (defvar vip-no-multiple-ESC t
584 "*If true, multiple ESC in Vi mode will cause bell to ring.
585 This is set to t on a windowing terminal and to 'twice on a dumb
586 terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this
587 enables cursor keys and is generally more convenient, as terminals usually
588 don't have a convenient Meta key.
589 Setting vip-no-multiple-ESC to nil will allow as many multiple ESC,
590 as is allowed by the major mode in effect.")
591
592
593 (defvar vip-want-ctl-h-help nil
594 "*If t then C-h is bound to help-command in insert mode, if nil then it is
595 bound to delete-backward-char.")
596 502
597 ;; Autoindent in insert 503 ;; Autoindent in insert
598 504
599 ;; Variable that keeps track of whether C-t has been pressed. 505 ;; Variable that keeps track of whether C-t has been pressed.
600 (vip-deflocalvar vip-cted nil "") 506 (vip-deflocalvar vip-cted nil "")
700 606
701 ;; If t, search is forward. 607 ;; If t, search is forward.
702 (defvar vip-s-forward nil) 608 (defvar vip-s-forward nil)
703 609
704 (defconst vip-case-fold-search nil 610 (defconst vip-case-fold-search nil
705 "*If not nil, search ignores case.") 611 "*If not nil, search ignores cases.")
706 612
707 (defconst vip-re-search t 613 (defconst vip-re-search t
708 "*If not nil, search is reg-exp search, otherwise vanilla search.") 614 "*If not nil, search is reg-exp search, otherwise vanilla search.")
709 615
710 (defvar vip-adjust-window-after-search t 616 (defvar vip-search-scroll-threshold 2
711 "*If not nil, pull the window up or down, depending on the direction of the 617 "*If search lands within this threshnold from the window top/bottom,
712 search, if search ends up near the bottom or near the top of the window.") 618 the window will be scrolled up or down appropriately, to reveal context.
619 If you want Viper search to behave as usual in Vi, set this variable to a
620 negative number.")
713 621
714 (defconst vip-re-query-replace t 622 (defconst vip-re-query-replace t
715 "*If t then do regexp replace, if nil then do string replace.") 623 "*If t then do regexp replace, if nil then do string replace.")
716 624
717 (defconst vip-re-replace t 625 (defconst vip-re-replace t
775 683
776 ;; Remembers position of the last jump done using ``'. 684 ;; Remembers position of the last jump done using ``'.
777 (vip-deflocalvar vip-last-jump nil) 685 (vip-deflocalvar vip-last-jump nil)
778 ;; Remembers position of the last jump done using `''. 686 ;; Remembers position of the last jump done using `''.
779 (vip-deflocalvar vip-last-jump-ignore 0) 687 (vip-deflocalvar vip-last-jump-ignore 0)
780
781 ;; Some common error messages
782
783 (defconst vip-SpuriousText "Spurious text after command" "")
784 (defconst vip-BadExCommand "Not an editor command" "")
785 (defconst vip-InvalidCommandArgument "Invalid command argument" "")
786 (defconst vip-NoPrevSearch "No previous search string" "")
787 (defconst vip-EmptyRegister "`%c': Nothing in this register" "")
788 (defconst vip-InvalidRegister "`%c': Invalid register" "")
789 (defconst vip-EmptyTextmarker "`%c': Text marker doesn't point anywhere" "")
790 (defconst vip-InvalidTextmarker "`%c': Invalid text marker" "")
791 (defconst vip-InvalidViCommand "Invalid command" "")
792 (defconst vip-BadAddress "Ill-formed address" "")
793 (defconst vip-FirstAddrExceedsSecond "First address exceeds second" "")
794 (defconst vip-NoFileSpecified "No file specified" "")
795
796 688
797 ;; History variables 689 ;; History variables
798 690
799 ;; History of search strings. 691 ;; History of search strings.
800 (defvar vip-search-history (list "")) 692 (defvar vip-search-history (list ""))
838 "Spell function used by #s<move> command to spell.") 730 "Spell function used by #s<move> command to spell.")
839 731
840 (defvar vip-tags-file-name "TAGS" 732 (defvar vip-tags-file-name "TAGS"
841 "The tags file used by Viper.") 733 "The tags file used by Viper.")
842 734
735 ;; Indicates if we are in the middle of executing a command that takes another
736 ;; command as an argument, e.g., cw, dw, etc.
737 (defvar vip-inside-command-argument-action nil)
738
843 ;; Minibuffer 739 ;; Minibuffer
844 740
845 (defvar vip-vi-style-in-minibuffer t 741 (defvar vip-vi-style-in-minibuffer t
846 "If t, use vi-style editing in minibuffer. 742 "If t, use vi-style editing in minibuffer.
847 Should be set in `~/.vip' file.") 743 Should be set in `~/.vip' file.")
852 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer. 748 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer.
853 ;; Beginning with Emacs 19.26, the standard `minibuffer-exit-hook' is run 749 ;; Beginning with Emacs 19.26, the standard `minibuffer-exit-hook' is run
854 ;; *after* exiting the minibuffer 750 ;; *after* exiting the minibuffer
855 (defvar vip-minibuffer-exit-hook nil) 751 (defvar vip-minibuffer-exit-hook nil)
856 752
857 (vip-deflocalvar vip-vi-minibuffer-minor-mode nil
858 "Minor mode that forces Vi-style when the Minibuffer is in Vi state.")
859 (vip-deflocalvar vip-insert-minibuffer-minor-mode nil
860 "Minor mode that forces Vi-style when the Minibuffer is in Insert state.")
861
862 ;; setup emacs-supported vi-style feel 753 ;; setup emacs-supported vi-style feel
863 (setq next-line-add-newlines nil 754 (setq next-line-add-newlines nil
864 require-final-newline t) 755 require-final-newline t)
865 756
866 (make-variable-buffer-local 'require-final-newline) 757 (make-variable-buffer-local 'require-final-newline)
918 809
919 ;; Variables for defining VI commands 810 ;; Variables for defining VI commands
920 811
921 ;; Modifying commands that can be prefixes to movement commands 812 ;; Modifying commands that can be prefixes to movement commands
922 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\")) 813 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\"))
814 ;; define vip-prefix-command-p
923 (vip-test-com-defun vip-prefix-command) 815 (vip-test-com-defun vip-prefix-command)
924 816
925 ;; Commands that are pairs eg. dd. r and R here are a hack 817 ;; Commands that are pairs eg. dd. r and R here are a hack
926 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R)) 818 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R))
819 ;; define vip-charpair-command-p
927 (vip-test-com-defun vip-charpair-command) 820 (vip-test-com-defun vip-charpair-command)
928 821
929 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l 822 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l
930 ?H ?M ?n ?t ?T ?w ?W ?$ ?% 823 ?H ?M ?n ?t ?T ?w ?W ?$ ?%
931 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?` 824 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?`
932 ?; ?, ?0 ?? ?/ 825 ?; ?, ?0 ?? ?/
933 ) 826 )
934 "Movement commands") 827 "Movement commands")
828 ;; define vip-movement-command-p
935 (vip-test-com-defun vip-movement-command) 829 (vip-test-com-defun vip-movement-command)
936 830
937 ;; Commands that can be repeated by . (dotted) 831 ;; Commands that can be repeated by . (dotted)
938 (defconst vip-dotable-commands '(?c ?d ?C ?D ?> ?<)) 832 (defconst vip-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<))
833 ;; define vip-dotable-command-p
939 (vip-test-com-defun vip-dotable-command) 834 (vip-test-com-defun vip-dotable-command)
940 835
941 ;; Commands that can follow a # 836 ;; Commands that can follow a #
942 (defconst vip-hash-cmds '(?c ?C ?g ?q ?S)) 837 (defconst vip-hash-commands '(?c ?C ?g ?q ?s))
943 (vip-test-com-defun vip-hash-cmd) 838 ;; define vip-hash-command-p
839 (vip-test-com-defun vip-hash-command)
944 840
945 ;; Commands that may have registers as prefix 841 ;; Commands that may have registers as prefix
946 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X)) 842 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
843 ;; define vip-regsuffix-command-p
947 (vip-test-com-defun vip-regsuffix-command) 844 (vip-test-com-defun vip-regsuffix-command)
948 845
949 (defconst vip-vi-commands (append vip-movement-commands 846 (defconst vip-vi-commands (append vip-movement-commands
950 vip-dotable-commands 847 vip-dotable-commands
951 vip-charpair-commands 848 vip-charpair-commands
952 vip-hash-cmds 849 vip-hash-commands
953 vip-prefix-commands 850 vip-prefix-commands
954 vip-regsuffix-commands) 851 vip-regsuffix-commands)
955 "The list of all commands in Vi-state.") 852 "The list of all commands in Vi-state.")
853 ;; define vip-vi-command-p
956 (vip-test-com-defun vip-vi-command) 854 (vip-test-com-defun vip-vi-command)
957
958 ;;; Arrange the keymaps
959 (require 'viper-keym)
960 855
961 856
962 ;;; CODE 857 ;;; CODE
963 858
964 ;; sentinels 859 ;; sentinels
1033 (defsubst vip-replace-state-pre-command-sentinel () 928 (defsubst vip-replace-state-pre-command-sentinel ()
1034 (or (memq this-command '(self-insert-command)) 929 (or (memq this-command '(self-insert-command))
1035 (memq (vip-event-key last-command-event) 930 (memq (vip-event-key last-command-event)
1036 '(up down left right (meta f) (meta b) 931 '(up down left right (meta f) (meta b)
1037 (control n) (control p) (control f) (control b))) 932 (control n) (control p) (control f) (control b)))
1038 (vip-restore-cursor-color))) 933 (vip-restore-cursor-color-after-replace)))
1039 934
1040 (defun vip-replace-state-post-command-sentinel () 935 (defun vip-replace-state-post-command-sentinel ()
1041 ;; Restoring cursor color is needed despite 936 ;; Restoring cursor color is needed despite
1042 ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer 937 ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer
1043 ;; in another frame, the pre-command hook won't change cursor color to 938 ;; in another frame, the pre-command hook won't change cursor color to
1172 (define-key vip-replace-map [(control h)] 'help-command)) 1067 (define-key vip-replace-map [(control h)] 'help-command))
1173 (define-key vip-insert-basic-map 1068 (define-key vip-insert-basic-map
1174 [(control h)] 'vip-del-backward-char-in-insert) 1069 [(control h)] 'vip-del-backward-char-in-insert)
1175 (define-key vip-replace-map 1070 (define-key vip-replace-map
1176 [(control h)] 'vip-del-backward-char-in-replace))) 1071 [(control h)] 'vip-del-backward-char-in-replace)))
1177 1072
1178 (t ; Vi state 1073 (t ; Vi state
1179 (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi)) 1074 (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi))
1180 (if vip-want-ctl-h-help 1075 (if vip-want-ctl-h-help
1181 (define-key vip-vi-basic-map [(control h)] 'help-command) 1076 (define-key vip-vi-basic-map [(control h)] 'help-command)
1182 (define-key vip-vi-basic-map [(control h)] 'vip-backward-char))) 1077 (define-key vip-vi-basic-map [(control h)] 'vip-backward-char)))
1449 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions. 1344 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions.
1450 (if (and (boundp 'iso-accents-mode) iso-accents-mode) 1345 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
1451 (iso-accents-mode -1)) 1346 (iso-accents-mode -1))
1452 1347
1453 (vip-restore-cursor-color-after-insert) 1348 (vip-restore-cursor-color-after-insert)
1454 1349
1455 ;; Protection against user errors in hooks 1350 ;; Protection against user errors in hooks
1456 (condition-case conds 1351 (condition-case conds
1457 (run-hooks 'vip-vi-state-hook) 1352 (run-hooks 'vip-vi-state-hook)
1458 (error 1353 (error
1459 (vip-message-conditions conds))))) 1354 (vip-message-conditions conds)))))
1535 Vi's prefix argument will be used. Otherwise, the prefix argument passed to 1430 Vi's prefix argument will be used. Otherwise, the prefix argument passed to
1536 `vip-escape-to-vi' is used." 1431 `vip-escape-to-vi' is used."
1537 (interactive "P") 1432 (interactive "P")
1538 (message "Switched to VI state for the next command...") 1433 (message "Switched to VI state for the next command...")
1539 (vip-escape-to-state arg nil 'vi-state)) 1434 (vip-escape-to-state arg nil 'vi-state))
1540 1435
1541 ;; Escape to STATE mode for one Emacs command. 1436 ;; Escape to STATE mode for one Emacs command.
1542 (defun vip-escape-to-state (arg events state) 1437 (defun vip-escape-to-state (arg events state)
1543 ;;(let (com key prefix-arg) 1438 ;;(let (com key prefix-arg)
1544 (let (com key) 1439 (let (com key)
1545 ;; this temporarily turns off Viper's minor mode keymaps 1440 ;; this temporarily turns off Viper's minor mode keymaps
1572 (vip-set-mode-vars-for vip-current-state) 1467 (vip-set-mode-vars-for vip-current-state)
1573 1468
1574 ;; this-command, last-command-char, last-command-event 1469 ;; this-command, last-command-char, last-command-event
1575 (setq this-command com) 1470 (setq this-command com)
1576 (if vip-xemacs-p ; XEmacs represents key sequences as vectors 1471 (if vip-xemacs-p ; XEmacs represents key sequences as vectors
1577 (setq last-command-event (vip-seq-last-elt key) 1472 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
1578 last-command-char (event-to-character last-command-event)) 1473 last-command-char (event-to-character last-command-event))
1579 ;; Emacs represents them as sequences (str or vec) 1474 ;; Emacs represents them as sequences (str or vec)
1580 (setq last-command-event (vip-seq-last-elt key) 1475 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
1581 last-command-char last-command-event)) 1476 last-command-char last-command-event))
1582 1477
1583 (if (commandp com) 1478 (if (commandp com)
1584 (progn 1479 (progn
1585 (setq prefix-arg (or prefix-arg arg)) 1480 (setq prefix-arg (or prefix-arg arg))
1667 )) 1562 ))
1668 1563
1669 (defun vip-alternate-Meta-key (arg) 1564 (defun vip-alternate-Meta-key (arg)
1670 "Simulate Emacs Meta key." 1565 "Simulate Emacs Meta key."
1671 (interactive "P") 1566 (interactive "P")
1567 (sit-for 1) (message "ESC-")
1672 (vip-escape-to-emacs arg '(?\e))) 1568 (vip-escape-to-emacs arg '(?\e)))
1673 1569
1674 (defun vip-toggle-key-action () 1570 (defun vip-toggle-key-action ()
1675 "Action bound to `vip-toggle-key'." 1571 "Action bound to `vip-toggle-key'."
1676 (interactive) 1572 (interactive)
1677 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z")) 1573 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z"))
1678 (if (vip-window-display-p) 1574 (if (vip-window-display-p)
1679 (vip-iconify) 1575 (vip-iconify)
1680 (suspend-emacs)) 1576 (suspend-emacs))
1681 (vip-change-state-to-emacs))) 1577 (vip-change-state-to-emacs)))
1578
1682 1579
1683 ;; Intercept ESC sequences on dumb terminals. 1580 ;; Intercept ESC sequences on dumb terminals.
1684 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es> 1581 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
1685 1582
1686 ;; Check if last key was ESC and if so try to reread it as a function key. 1583 ;; Check if last key was ESC and if so try to reread it as a function key.
1740 (character-to-event (event-key first-key))) 1637 (character-to-event (event-key first-key)))
1741 (subseq keyseq 1))) 1638 (subseq keyseq 1)))
1742 (setq last-input-event event 1639 (setq last-input-event event
1743 keyseq (vector (character-to-event ?\e)))) 1640 keyseq (vector (character-to-event ?\e))))
1744 ((eventp first-key) 1641 ((eventp first-key)
1745 (setq last-command-event first-key)) 1642 (setq last-command-event (vip-copy-event first-key)))
1746 )) 1643 ))
1747 ) ; end progn 1644 ) ; end progn
1748 1645
1749 ;; this is escape event with nothing after it 1646 ;; this is escape event with nothing after it
1750 ;; put in unread-command-event and then re-read 1647 ;; put in unread-command-event and then re-read
1860 (setq prefix-arg value) 1757 (setq prefix-arg value)
1861 (if com (setq prefix-arg (cons prefix-arg com))) 1758 (if com (setq prefix-arg (cons prefix-arg com)))
1862 (while (eq event ?U) 1759 (while (eq event ?U)
1863 (vip-describe-arg prefix-arg) 1760 (vip-describe-arg prefix-arg)
1864 (setq event (vip-read-event-convert-to-char))) 1761 (setq event (vip-read-event-convert-to-char)))
1865 1762
1866 (if (or com (and (not (eq vip-current-state 'vi-state)) 1763 (if (or com (and (not (eq vip-current-state 'vi-state))
1867 ;; make sure it is a Vi command 1764 ;; make sure it is a Vi command
1868 (vip-characterp event) (vip-vi-command-p event) 1765 (vip-characterp event) (vip-vi-command-p event)
1869 )) 1766 ))
1870 ;; If appears to be one of the vi commands, 1767 ;; If appears to be one of the vi commands,
1877 ;; the user typed, say, d2. In this case, `com' would be `d', `w', 1774 ;; the user typed, say, d2. In this case, `com' would be `d', `w',
1878 ;; etc. 1775 ;; etc.
1879 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is 1776 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is
1880 ;; indicated by the fact that the current state is not vi-state, 1777 ;; indicated by the fact that the current state is not vi-state,
1881 ;; then `event' represents the vi command to be executed (e.g., `d', 1778 ;; then `event' represents the vi command to be executed (e.g., `d',
1882 ;; `w', etc. Again, last-command-char must make emacs believe that 1779 ;; `w', etc). Again, last-command-char must make emacs believe that
1883 ;; this is the command we typed. 1780 ;; this is the command we typed.
1884 (setq last-command-char (or com event)) 1781 (setq last-command-char (or com event))
1885 (setq func (vip-exec-form-in-vi 1782 (setq func (vip-exec-form-in-vi
1886 (` (key-binding (char-to-string (, event)))))) 1783 (` (key-binding (char-to-string (, event))))))
1887 (funcall func prefix-arg) 1784 (funcall func prefix-arg)
1888 (setq prefix-arg nil)) 1785 (setq prefix-arg nil))
1889 ;; some other command -- let emacs do it in its own way 1786 ;; some other command -- let emacs do it in its own way
1890 (vip-set-unread-command-events event)) 1787 (vip-set-unread-command-events event))
1891 )) 1788 ))
1892 1789
1893 1790
1894 ;; Vi operator as prefix argument." 1791 ;; Vi operator as prefix argument."
1895 (defun vip-prefix-arg-com (char value com) 1792 (defun vip-prefix-arg-com (char value com)
1896 (let ((cont t) 1793 (let ((cont t)
1897 cmd-info mv-or-digit-cmd) 1794 cmd-info mv-or-digit-cmd)
1926 (setq vip-use-register reg) 1823 (setq vip-use-register reg)
1927 (error "")) 1824 (error ""))
1928 (setq char (read-char)))) 1825 (setq char (read-char))))
1929 (t 1826 (t
1930 (setq com char) 1827 (setq com char)
1931 (setq char (vip-read-char-exclusive)))))) 1828 (setq char (read-char))))))
1829
1932 (if (atom com) 1830 (if (atom com)
1933 ;; `com' is a single char, so we construct the command argument 1831 ;; `com' is a single char, so we construct the command argument
1934 ;; and if `char' is `?', we describe the arg; otherwise 1832 ;; and if `char' is `?', we describe the arg; otherwise
1935 ;; we prepare the command that will be executed at the end. 1833 ;; we prepare the command that will be executed at the end.
1936 (progn 1834 (progn
1941 ;; `char' is a movement command or a digit arg command---so we execute 1839 ;; `char' is a movement command or a digit arg command---so we execute
1942 ;; it at the very end 1840 ;; it at the very end
1943 (setq mv-or-digit-cmd 1841 (setq mv-or-digit-cmd
1944 (vip-exec-form-in-vi 1842 (vip-exec-form-in-vi
1945 (` (key-binding (char-to-string (, char))))))) 1843 (` (key-binding (char-to-string (, char)))))))
1844
1946 ;; as com is non-nil, this means that we have a command to execute 1845 ;; as com is non-nil, this means that we have a command to execute
1947 (if (memq (car com) '(?r ?R)) 1846 (if (memq (car com) '(?r ?R))
1948 ;; execute apropriate region command. 1847 ;; execute apropriate region command.
1949 (let ((char (car com)) (com (cdr com))) 1848 (let ((char (car com)) (com (cdr com)))
1950 (setq prefix-arg (cons value com)) 1849 (setq prefix-arg (cons value com))
1962 ((equal com '(?< . ?<)) (vip-line (cons value ?<))) 1861 ((equal com '(?< . ?<)) (vip-line (cons value ?<)))
1963 ((equal com '(?> . ?>)) (vip-line (cons value ?>))) 1862 ((equal com '(?> . ?>)) (vip-line (cons value ?>)))
1964 ((equal com '(?! . ?!)) (vip-line (cons value ?!))) 1863 ((equal com '(?! . ?!)) (vip-line (cons value ?!)))
1965 ((equal com '(?= . ?=)) (vip-line (cons value ?=))) 1864 ((equal com '(?= . ?=)) (vip-line (cons value ?=)))
1966 (t (error ""))))) 1865 (t (error "")))))
1967 1866
1968 (if mv-or-digit-cmd 1867 (if mv-or-digit-cmd
1969 (progn 1868 (progn
1970 (setq last-command-char char) 1869 (setq last-command-char char)
1870 (setq last-command-event
1871 (vip-copy-event
1872 (if vip-xemacs-p (character-to-event char) char)))
1971 (funcall mv-or-digit-cmd cmd-info))) 1873 (funcall mv-or-digit-cmd cmd-info)))
1972 )) 1874 ))
1973 1875
1974 (defun vip-describe-arg (arg) 1876 (defun vip-describe-arg (arg)
1975 (let (val com) 1877 (let (val com)
1991 last-command-char (if (consp arg) (cdr arg) nil))) 1893 last-command-char (if (consp arg) (cdr arg) nil)))
1992 1894
1993 (defun vip-command-argument (arg) 1895 (defun vip-command-argument (arg)
1994 "Accept a motion command as an argument." 1896 "Accept a motion command as an argument."
1995 (interactive "P") 1897 (interactive "P")
1996 (condition-case nil 1898 (let ((vip-inside-command-argument-action t))
1997 (vip-prefix-arg-com 1899 (condition-case nil
1998 last-command-char 1900 (vip-prefix-arg-com
1999 (cond ((null arg) nil) 1901 last-command-char
2000 ((consp arg) (car arg)) 1902 (cond ((null arg) nil)
2001 ((integerp arg) arg) 1903 ((consp arg) (car arg))
2002 (t (error vip-InvalidCommandArgument))) 1904 ((integerp arg) arg)
2003 (cond ((null arg) nil) 1905 (t (error vip-InvalidCommandArgument)))
2004 ((consp arg) (cdr arg)) 1906 (cond ((null arg) nil)
2005 ((integerp arg) nil) 1907 ((consp arg) (cdr arg))
2006 (t (error vip-InvalidCommandArgument)))) 1908 ((integerp arg) nil)
2007 (quit (setq vip-use-register nil) 1909 (t (error vip-InvalidCommandArgument))))
2008 (signal 'quit nil))) 1910 (quit (setq vip-use-register nil)
2009 (vip-deactivate-mark)) 1911 (signal 'quit nil)))
1912 (vip-deactivate-mark)))
2010 1913
2011 1914
2012 ;; repeat last destructive command 1915 ;; repeat last destructive command
2013 1916
2014 ;; Append region to text in register REG. 1917 ;; Append region to text in register REG.
2041 1944
2042 ;; define functions to be executed 1945 ;; define functions to be executed
2043 1946
2044 ;; invoked by the `C' command 1947 ;; invoked by the `C' command
2045 (defun vip-exec-change (m-com com) 1948 (defun vip-exec-change (m-com com)
1949 (or (and (markerp vip-com-point) (marker-position vip-com-point))
1950 (set-marker vip-com-point (point) (current-buffer)))
2046 ;; handle C cmd at the eol and at eob. 1951 ;; handle C cmd at the eol and at eob.
2047 (if (or (and (eolp) (= vip-com-point (point))) 1952 (if (or (and (eolp) (= vip-com-point (point)))
2048 (= vip-com-point (point-max))) 1953 (= vip-com-point (point-max)))
2049 (progn 1954 (progn
2050 (insert " ")(backward-char 1))) 1955 (insert " ")(backward-char 1)))
2074 (delete-region (mark t) (point))) 1979 (delete-region (mark t) (point)))
2075 (open-line 1) 1980 (open-line 1)
2076 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion))) 1981 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion)))
2077 1982
2078 (defun vip-exec-delete (m-com com) 1983 (defun vip-exec-delete (m-com com)
1984 (or (and (markerp vip-com-point) (marker-position vip-com-point))
1985 (set-marker vip-com-point (point) (current-buffer)))
2079 (if vip-use-register 1986 (if vip-use-register
2080 (progn 1987 (progn
2081 (cond ((vip-valid-register vip-use-register '(letter digit)) 1988 (cond ((vip-valid-register vip-use-register '(letter digit))
2082 ;;(vip-valid-register vip-use-register '(letter)) 1989 ;;(vip-valid-register vip-use-register '(letter))
2083 (copy-to-register 1990 (copy-to-register
2116 (kill-region (mark t) (point)) 2023 (kill-region (mark t) (point))
2117 (if (eq m-com 'vip-line) (setq this-command 'D-command))) 2024 (if (eq m-com 'vip-line) (setq this-command 'D-command)))
2118 (back-to-indentation)) 2025 (back-to-indentation))
2119 2026
2120 (defun vip-exec-yank (m-com com) 2027 (defun vip-exec-yank (m-com com)
2028 (or (and (markerp vip-com-point) (marker-position vip-com-point))
2029 (set-marker vip-com-point (point) (current-buffer)))
2121 (if vip-use-register 2030 (if vip-use-register
2122 (progn 2031 (progn
2123 (cond ((vip-valid-register vip-use-register '(letter digit)) 2032 (cond ((vip-valid-register vip-use-register '(letter digit))
2124 ;; (vip-valid-register vip-use-register '(letter)) 2033 ;; (vip-valid-register vip-use-register '(letter))
2125 (copy-to-register 2034 (copy-to-register
2324 (vip-special-ring-rotate1 vip-command-ring 1) 2233 (vip-special-ring-rotate1 vip-command-ring 1)
2325 (setq num (1+ num))) 2234 (setq num (1+ num)))
2326 )) 2235 ))
2327 2236
2328 2237
2329 ;; This command is invoked interactively by the key sequence #<char> 2238 ;; The hash-command. It is invoked interactively by the key sequence #<char>.
2239 ;; The chars that can follow `#' are determined by vip-hash-command-p
2330 (defun vip-special-prefix-com (char) 2240 (defun vip-special-prefix-com (char)
2331 (cond ((= char ?c) 2241 (cond ((= char ?c)
2332 (downcase-region (min vip-com-point (point)) 2242 (downcase-region (min vip-com-point (point))
2333 (max vip-com-point (point)))) 2243 (max vip-com-point (point))))
2334 ((= char ?C) 2244 ((= char ?C)
2587 ;; as part of the previous line. 2497 ;; as part of the previous line.
2588 (if (= (vip-line-pos 'start) end) 2498 (if (= (vip-line-pos 'start) end)
2589 (setq incr 1)) 2499 (setq incr 1))
2590 (<= (+ incr (count-lines beg end)) 1)))) 2500 (<= (+ incr (count-lines beg end)) 1))))
2591 )) 2501 ))
2592 2502
2593 2503
2594 ;; Check if the string ends with a newline. 2504 ;; Check if the string ends with a newline.
2595 (defun vip-end-with-a-newline-p (string) 2505 (defun vip-end-with-a-newline-p (string)
2596 (or (string= string "") 2506 (or (string= string "")
2597 (= (vip-seq-last-elt string) ?\n))) 2507 (= (vip-seq-last-elt string) ?\n)))
2598 2508
3867 (defun vip-line-to-bottom (arg) 3777 (defun vip-line-to-bottom (arg)
3868 "Put current line on the last line." 3778 "Put current line on the last line."
3869 (interactive "p") 3779 (interactive "p")
3870 (recenter (- (window-height) (1+ arg)))) 3780 (recenter (- (window-height) (1+ arg))))
3871 3781
3872 ;; If vip-adjust-window-after-search is t, scroll up or down 1/4 of window 3782 ;; If point is within vip-search-scroll-threshold of window top or bottom,
3873 ;; height, depending on whether we are at the bottom or at the top of the 3783 ;; scroll up or down 1/7 of window height, depending on whether we are at the
3874 ;; window. This function is called by vip-search (which is called from 3784 ;; bottom or at the top of the window. This function is called by vip-search
3875 ;; vip-search-forward/backward/next) 3785 ;; (which is called from vip-search-forward/backward/next). If the value of
3786 ;; vip-search-scroll-threshold is negative - don't scroll.
3876 (defun vip-adjust-window () 3787 (defun vip-adjust-window ()
3877 (let ((win-height (if vip-emacs-p 3788 (let ((win-height (if vip-emacs-p
3878 (1- (window-height)) ; adjust for modeline 3789 (1- (window-height)) ; adjust for modeline
3879 (window-displayed-height))) 3790 (window-displayed-height)))
3880 (pt (point)) 3791 (pt (point))
3881 at-top-p at-bottom-p 3792 at-top-p at-bottom-p
3882 min-scroll direction) 3793 min-scroll direction)
3883 (save-excursion 3794 (save-excursion
3884 (move-to-window-line 0) ; top 3795 (move-to-window-line 0) ; top
3885 (setq at-top-p (<= (count-lines pt (point)) 2)) 3796 (setq at-top-p
3797 (<= (count-lines pt (point))
3798 vip-search-scroll-threshold))
3886 (move-to-window-line -1) ; bottom 3799 (move-to-window-line -1) ; bottom
3887 (setq at-bottom-p (<= (count-lines pt (point)) 2)) 3800 (setq at-bottom-p
3801 (<= (count-lines pt (point)) vip-search-scroll-threshold))
3888 ) 3802 )
3889 (cond (at-top-p (setq min-scroll 1 3803 (cond (at-top-p (setq min-scroll (1- vip-search-scroll-threshold)
3890 direction 1)) 3804 direction 1))
3891 (at-bottom-p (setq min-scroll 2 3805 (at-bottom-p (setq min-scroll (1+ vip-search-scroll-threshold)
3892 direction -1))) 3806 direction -1)))
3893 (if (and vip-adjust-window-after-search min-scroll) 3807 (if min-scroll
3894 (recenter 3808 (recenter
3895 (* (max min-scroll (/ win-height 7)) direction))) 3809 (* (max min-scroll (/ win-height 7)) direction)))
3896 )) 3810 ))
3897 3811
3898 3812
4179 With a prefix argument, this function unsets the macros. 4093 With a prefix argument, this function unsets the macros.
4180 If the optional prefix argument is non-nil and specifies a valid major mode, 4094 If the optional prefix argument is non-nil and specifies a valid major mode,
4181 this sets the macros only in the macros in that major mode. Otherwise, 4095 this sets the macros only in the macros in that major mode. Otherwise,
4182 the macros are set in the current major mode. 4096 the macros are set in the current major mode.
4183 \(When unsetting the macros, the second argument has no effect.\)" 4097 \(When unsetting the macros, the second argument has no effect.\)"
4184 (interactive "P") 4098 (interactive "P")
4185 (or noninteractive 4099 (or noninteractive
4186 (if (not unset) 4100 (if (not unset)
4187 (progn 4101 (progn
4188 ;; toggle case sensitivity in search 4102 ;; toggle case sensitivity in search
4189 (vip-record-kbd-macro 4103 (vip-record-kbd-macro
4315 ;; pull up or down if at top/bottom of window 4229 ;; pull up or down if at top/bottom of window
4316 (vip-adjust-window) 4230 (vip-adjust-window)
4317 ;; highlight the result of search 4231 ;; highlight the result of search
4318 ;; don't wait and don't highlight in macros 4232 ;; don't wait and don't highlight in macros
4319 (or executing-kbd-macro 4233 (or executing-kbd-macro
4234 vip-inside-command-argument-action
4320 (vip-flash-search-pattern)) 4235 (vip-flash-search-pattern))
4321 ))) 4236 )))
4322 4237
4323 (defun vip-search-next (arg) 4238 (defun vip-search-next (arg)
4324 "Repeat previous search." 4239 "Repeat previous search."
4837 (message "Mark set at the end of buffer")) 4752 (message "Mark set at the end of buffer"))
4838 4753
4839 (defun vip-mark-point () 4754 (defun vip-mark-point ()
4840 "Set mark at point of buffer." 4755 "Set mark at point of buffer."
4841 (interactive) 4756 (interactive)
4842 (let ((char (vip-read-char-exclusive))) 4757 (let ((char (read-char)))
4843 (cond ((and (<= ?a char) (<= char ?z)) 4758 (cond ((and (<= ?a char) (<= char ?z))
4844 (point-to-register (1+ (- char ?a)))) 4759 (point-to-register (1+ (- char ?a))))
4845 ((= char ?<) (vip-mark-beginning-of-buffer)) 4760 ((= char ?<) (vip-mark-beginning-of-buffer))
4846 ((= char ?>) (vip-mark-end-of-buffer)) 4761 ((= char ?>) (vip-mark-end-of-buffer))
4847 ((= char ?.) (vip-set-mark-if-necessary)) 4762 ((= char ?.) (vip-set-mark-if-necessary))
4848 ((= char ?,) (vip-cycle-through-mark-ring)) 4763 ((= char ?,) (vip-cycle-through-mark-ring))
4849 ((= char ?D) (mark-defun)) 4764 ((= char ?D) (mark-defun))
4850 (t (error "")) 4765 (t (error ""))
4851 ))) 4766 )))
4852 4767
4853 ;; Algorithm: If first invocation of this command save mark on ring, goto 4768 ;; Algorithm: If first invocation of this command save mark on ring, goto
4854 ;; mark, M0, and pop the most recent elt from the mark ring into mark, 4769 ;; mark, M0, and pop the most recent elt from the mark ring into mark,
4855 ;; making it into the new mark, M1. 4770 ;; making it into the new mark, M1.
4856 ;; Push this mark back and set mark to the original point position, p1. 4771 ;; Push this mark back and set mark to the original point position, p1.
5152 vip-search-wrap-around-t t 5067 vip-search-wrap-around-t t
5153 vip-want-emacs-keys-in-vi nil 5068 vip-want-emacs-keys-in-vi nil
5154 vip-want-emacs-keys-in-insert nil)) 5069 vip-want-emacs-keys-in-insert nil))
5155 5070
5156 ((and (> vip-expert-level 1) (< vip-expert-level 5)) 5071 ((and (> vip-expert-level 1) (< vip-expert-level 5))
5157 ;; an intermediate to guru 5072 ;; intermediate to guru
5158 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice) 5073 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice)
5159 vip-want-emacs-keys-in-vi t 5074 vip-want-emacs-keys-in-vi t
5160 vip-want-emacs-keys-in-insert (> vip-expert-level 2)) 5075 vip-want-emacs-keys-in-insert (> vip-expert-level 2))
5161 5076
5162 (if (eq vip-expert-level 4) ; respect user's ex-style motions 5077 (if (eq vip-expert-level 4) ; respect user's ex-style motions
5540 elt))))) 5455 elt)))))
5541 lis)) 5456 lis))
5542 5457
5543 5458
5544 5459
5545 ;;; Bring in the rest of the files
5546 (require 'viper-mous)
5547 (require 'viper-macs)
5548 (require 'viper-ex)
5549
5550
5551
5552 ;; The following is provided for compatibility with older VIP's 5460 ;; The following is provided for compatibility with older VIP's
5553 5461
5554 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) 5462 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi)
5555 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) 5463 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert)
5556 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs) 5464 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs)
5618 (defvar lisp-interaction-mode-hook) 5526 (defvar lisp-interaction-mode-hook)
5619 (add-hook 'lisp-interaction-mode-hook 'viper-mode) 5527 (add-hook 'lisp-interaction-mode-hook 'viper-mode)
5620 5528
5621 (defvar fortran-mode-hook) 5529 (defvar fortran-mode-hook)
5622 (add-hook 'fortran-mode-hook 'vip-mode) 5530 (add-hook 'fortran-mode-hook 'vip-mode)
5623 5531
5624 (defvar basic-mode-hook) 5532 (defvar basic-mode-hook)
5625 (add-hook 'basic-mode-hook 'vip-mode) 5533 (add-hook 'basic-mode-hook 'vip-mode)
5626 (defvar bat-mode-hook) 5534 (defvar bat-mode-hook)
5627 (add-hook 'bat-mode-hook 'vip-mode) 5535 (add-hook 'bat-mode-hook 'vip-mode)
5628 5536
5629 (defvar text-mode-hook) 5537 (defvar text-mode-hook)
5630 (add-hook 'text-mode-hook 'viper-mode) 5538 (add-hook 'text-mode-hook 'viper-mode)
5631 5539
5632 (add-hook 'completion-list-mode-hook 'viper-mode) 5540 (add-hook 'completion-list-mode-hook 'viper-mode)
5633 (add-hook 'compilation-mode-hook 'viper-mode) 5541 (add-hook 'compilation-mode-hook 'viper-mode)
5646 (vip-eval-after-load 5554 (vip-eval-after-load
5647 "vc" 5555 "vc"
5648 '(defadvice vc-diff (after vip-vc-ad activate) 5556 '(defadvice vc-diff (after vip-vc-ad activate)
5649 "Force Vi state in VC diff buffer." 5557 "Force Vi state in VC diff buffer."
5650 (vip-change-state-to-vi)))) 5558 (vip-change-state-to-vi))))
5651 5559
5652 (vip-eval-after-load 5560 (vip-eval-after-load
5653 "emerge" 5561 "emerge"
5654 '(defadvice emerge-quit (after vip-emerge-advice activate) 5562 '(defadvice emerge-quit (after vip-emerge-advice activate)
5655 "Run `vip-change-state-to-vi' after quitting emerge." 5563 "Run `vip-change-state-to-vi' after quitting emerge."
5656 (vip-change-state-to-vi))) 5564 (vip-change-state-to-vi)))
5699 'internal-ange-ftp-mode 'insert-state vip-comint-mode-modifier-map) 5607 'internal-ange-ftp-mode 'insert-state vip-comint-mode-modifier-map)
5700 (vip-modify-major-mode 5608 (vip-modify-major-mode
5701 'internal-ange-ftp-mode 'vi-state vip-comint-mode-modifier-map) 5609 'internal-ange-ftp-mode 'vi-state vip-comint-mode-modifier-map)
5702 ;; set hook 5610 ;; set hook
5703 (add-hook 'comint-mode-hook 'vip-comint-mode-hook) 5611 (add-hook 'comint-mode-hook 'vip-comint-mode-hook)
5704 5612
5705 ;; Shell scripts 5613 ;; Shell scripts
5706 (defvar sh-mode-hook) 5614 (defvar sh-mode-hook)
5707 (add-hook 'sh-mode-hook 'viper-mode) 5615 (add-hook 'sh-mode-hook 'viper-mode)
5708 (defvar ksh-mode-hook) 5616 (defvar ksh-mode-hook)
5709 (add-hook 'ksh-mode-hook 'viper-mode) 5617 (add-hook 'ksh-mode-hook 'viper-mode)
5795 (vector vip-repeat-from-history-key '\2) 'vi-state 5703 (vector vip-repeat-from-history-key '\2) 'vi-state
5796 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) 5704 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
5797 5705
5798 ;; set the toggle case sensitivity and regexp search macros 5706 ;; set the toggle case sensitivity and regexp search macros
5799 (vip-set-vi-search-style-macros nil) 5707 (vip-set-vi-search-style-macros nil)
5800 5708
5801 5709
5802 ;; ~/.vip is loaded if it exists 5710 ;; ~/.vip is loaded if it exists
5803 (if (and (file-exists-p vip-custom-file-name) 5711 (if (and (file-exists-p vip-custom-file-name)
5804 (not noninteractive)) 5712 (not noninteractive))
5805 (load vip-custom-file-name)) 5713 (load vip-custom-file-name))
5878 )) 5786 ))
5879 5787
5880 5788
5881 (run-hooks 'vip-load-hook) ; the last chance to change something 5789 (run-hooks 'vip-load-hook) ; the last chance to change something
5882 5790
5883 (provide 'viper)
5884 (provide 'vip19) 5791 (provide 'vip19)
5885 (provide 'vip) 5792 (provide 'vip)
5886 5793
5887 ;;; viper.el ends here 5794 ;;; viper.el ends here