Mercurial > emacs
comparison lisp/emulation/viper.el @ 18047:1b06411ccc04
new version
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Sat, 31 May 1997 00:02:53 +0000 |
parents | beb94a5271e2 |
children | e92598964ee6 |
comparison
equal
deleted
inserted
replaced
18046:5c0bcd2a1716 | 18047:1b06411ccc04 |
---|---|
4 ;; Viper Is also a Package for Emacs Rebels. | 4 ;; Viper Is also a Package for Emacs Rebels. |
5 ;; | 5 ;; |
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, 1997 Free Software Foundation, Inc. |
10 | 10 |
11 (defconst viper-version "2.91 of August 5, 1996" | 11 (defconst viper-version "2.93 of May 20, 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 (expand-file-name ".") 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 |
313 | 328 |
329 | |
330 (require 'viper-util) | |
331 (require 'viper-keym) | |
332 (require 'viper-mous) | |
333 (require 'viper-macs) | |
334 (require 'viper-ex) | |
335 | |
336 | |
314 | 337 |
315 ;;; Variables | |
316 | |
317 ;; Is t until viper-mode executes for the very first time. | |
318 ;; Prevents recursive descend into startup messages. | |
319 (defvar vip-first-time t) | |
320 | |
321 (defvar vip-expert-level 0 | |
322 "User's expert level. | |
323 The minor mode vip-vi-diehard-minor-mode is in effect when | |
324 vip-expert-level is 1 or 2 or when vip-want-emacs-keys-in-vi is t. | |
325 The minor mode vip-insert-diehard-minor-mode is in effect when | |
326 vip-expert-level is 1 or 2 or if vip-want-emacs-keys-in-insert is t. | |
327 Use `M-x vip-set-expert-level' to change this.") | |
328 | |
329 ;; Max expert level supported by Viper. This is NOT a user option. | |
330 ;; It is here to make it hard for the user from resetting it. | |
331 (defconst vip-max-expert-level 5) | |
332 | |
333 ;; Contains user settings for vars affected by vip-set-expert-level function. | |
334 ;; Not a user option. | |
335 (defvar vip-saved-user-settings nil) | |
336 | |
337 | |
338 ;;; Viper minor modes | |
339 | |
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. | |
347 (make-variable-buffer-local 'minor-mode-map-alist) | |
348 | |
349 ;; Mode for vital things like \e, C-z. | |
350 (vip-deflocalvar vip-vi-intercept-minor-mode nil) | |
351 | |
352 (vip-deflocalvar vip-vi-basic-minor-mode nil | |
353 "Viper's minor mode for Vi bindings.") | |
354 | |
355 (vip-deflocalvar vip-vi-local-user-minor-mode nil | |
356 "Auxiliary minor mode for user-defined local bindings in Vi state.") | |
357 | |
358 (vip-deflocalvar vip-vi-global-user-minor-mode nil | |
359 "Auxiliary minor mode for user-defined global bindings in Vi state.") | |
360 | |
361 (vip-deflocalvar vip-vi-state-modifier-minor-mode nil | |
362 "Minor mode used to make major-mode-specific modification to Vi state.") | |
363 | |
364 (vip-deflocalvar vip-vi-diehard-minor-mode nil | |
365 "This minor mode is in effect when the user wants Viper to be Vi.") | |
366 | |
367 (vip-deflocalvar vip-vi-kbd-minor-mode nil | |
368 "Minor mode for Ex command macros in Vi state. | |
369 The corresponding keymap stores key bindings of Vi macros defined with | |
370 the Ex command :map.") | |
371 | |
372 ;; Mode for vital things like \e, C-z. | |
373 (vip-deflocalvar vip-insert-intercept-minor-mode nil) | |
374 | |
375 (vip-deflocalvar vip-insert-basic-minor-mode nil | |
376 "Viper's minor mode for bindings in Insert mode.") | |
377 | |
378 (vip-deflocalvar vip-insert-local-user-minor-mode nil | |
379 "Auxiliary minor mode for buffer-local user-defined bindings in Insert state. | |
380 This is a way to overshadow normal Insert mode bindings locally to certain | |
381 designated buffers.") | |
382 | |
383 (vip-deflocalvar vip-insert-global-user-minor-mode nil | |
384 "Auxiliary minor mode for global user-defined bindings in Insert state.") | |
385 | |
386 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil | |
387 "Minor mode used to make major-mode-specific modification to Insert state.") | |
388 | |
389 (vip-deflocalvar vip-insert-diehard-minor-mode nil | |
390 "Minor mode that simulates Vi very closely. | |
391 Not recommened, except for the novice user.") | |
392 | |
393 (vip-deflocalvar vip-insert-kbd-minor-mode nil | |
394 "Minor mode for Ex command macros Insert state. | |
395 The corresponding keymap stores key bindings of Vi macros defined with | |
396 the Ex command :map!.") | |
397 | |
398 (vip-deflocalvar vip-replace-minor-mode nil | |
399 "Minor mode in effect in replace state (cw, C, and the like commands).") | |
400 | |
401 ;; Mode for vital things like \C-z and \C-x) | |
402 ;; This is t, by default. So, any new buffer will have C-z defined as | |
403 ;; switch to Vi, unless we switched states in this buffer | |
404 (vip-deflocalvar vip-emacs-intercept-minor-mode t) | |
405 | |
406 (vip-deflocalvar vip-emacs-local-user-minor-mode t | |
407 "Minor mode for local user bindings effective in Emacs state. | |
408 Users can use it to override Emacs bindings when Viper is in its Emacs | |
409 state.") | |
410 | |
411 (vip-deflocalvar vip-emacs-global-user-minor-mode t | |
412 "Minor mode for global user bindings in effect in Emacs state. | |
413 Users can use it to override Emacs bindings when Viper is in its Emacs | |
414 state.") | |
415 | |
416 (vip-deflocalvar vip-emacs-kbd-minor-mode t | |
417 "Minor mode for Vi style macros in Emacs state. | |
418 The corresponding keymap stores key bindings of Vi macros defined with | |
419 `vip-record-kbd-macro' command. There is no Ex-level command to do this | |
420 interactively.") | |
421 | |
422 (vip-deflocalvar vip-emacs-state-modifier-minor-mode t | |
423 "Minor mode used to make major-mode-specific modification to Emacs state. | |
424 For instance, a Vi purist may want to bind `dd' in Dired mode to a function | |
425 that deletes a file.") | |
426 | |
427 | |
428 | |
429 ;;; ISO characters | |
430 | |
431 (vip-deflocalvar vip-automatic-iso-accents nil | |
432 "*If non-nil, ISO accents will be turned on in insert/replace emacs states and turned off in vi-state. | |
433 For some users, this behavior may be too primitive. In this case, use | |
434 insert/emacs/vi state hooks.") | |
435 | |
436 | |
437 ;;; Emacs keys in other states. | |
438 | |
439 (defvar vip-want-emacs-keys-in-insert t | |
440 "*Set to nil if you want complete Vi compatibility in insert mode. | |
441 Complete compatibility with Vi is not recommended for power use of Viper.") | |
442 | |
443 (defvar vip-want-emacs-keys-in-vi t | |
444 "*Set to nil if you want complete Vi compatibility in Vi mode. | |
445 Full Vi compatibility is not recommended for power use of Viper.") | |
446 | |
447 | |
448 | |
449 ;; VI-style Undo | |
450 | |
451 ;; Used to 'undo' complex commands, such as replace and insert commands. | |
452 (vip-deflocalvar vip-undo-needs-adjustment nil) | |
453 (put 'vip-undo-needs-adjustment 'permanent-local t) | |
454 | |
455 ;; A mark that Viper puts on buffer-undo-list. Marks the beginning of a | |
456 ;; complex command that must be undone atomically. If inserted, it is | |
457 ;; erased by vip-change-state-to-vi and vip-repeat. | |
458 (defconst vip-buffer-undo-list-mark 'viper) | |
459 | |
460 (defvar vip-keep-point-on-undo nil | |
461 "*Non-nil means not to move point while undoing commands. | |
462 This style is different from Emacs and Vi. Try it to see if | |
463 it better fits your working style.") | |
464 | |
465 ;; Replace mode and changing text | |
466 | |
467 ;; Viper's own after/before change functions, which get vip-add-hook'ed to | |
468 ;; Emacs's | |
469 (vip-deflocalvar vip-after-change-functions nil "") | |
470 (vip-deflocalvar vip-before-change-functions nil "") | |
471 (vip-deflocalvar vip-post-command-hooks nil "") | |
472 (vip-deflocalvar vip-pre-command-hooks nil "") | |
473 | |
474 ;; Can be used to pass global states around for short period of time | |
475 (vip-deflocalvar vip-intermediate-command nil "") | |
476 | |
477 ;; Indicates that the current destructive command has started in replace mode. | |
478 (vip-deflocalvar vip-began-as-replace nil "") | |
479 | |
480 (defvar vip-replace-overlay-cursor-color "Red" | |
481 "*Cursor color to use in Replace state") | |
482 (defvar vip-insert-state-cursor-color nil | |
483 "Cursor color for Viper insert state.") | |
484 (put 'vip-insert-state-cursor-color 'permanent-local t) | |
485 ;; place to save cursor colow when switching to insert mode | |
486 (vip-deflocalvar vip-saved-cursor-color nil "") | |
487 | |
488 (vip-deflocalvar vip-replace-overlay nil "") | |
489 (put 'vip-replace-overlay 'permanent-local t) | |
490 | |
491 (defvar vip-replace-overlay-pixmap "gray3" | |
492 "Pixmap to use for search face on non-color displays.") | |
493 (defvar vip-search-face-pixmap "gray3" | |
494 "Pixmap to use for search face on non-color displays.") | |
495 | |
496 | |
497 (defun vip-set-replace-overlay-face () | |
498 (if (vip-has-face-support-p) | |
499 (defvar vip-replace-overlay-face | |
500 (progn | |
501 (make-face 'vip-replace-overlay-face) | |
502 (vip-hide-face 'vip-replace-overlay-face) | |
503 (or (face-differs-from-default-p 'vip-replace-overlay-face) | |
504 (progn | |
505 (if (vip-can-use-colors "darkseagreen2" "Black") | |
506 (progn | |
507 (set-face-background | |
508 'vip-replace-overlay-face "darkseagreen2") | |
509 (set-face-foreground 'vip-replace-overlay-face "Black"))) | |
510 (set-face-underline-p 'vip-replace-overlay-face t) | |
511 (vip-set-face-pixmap | |
512 'vip-replace-overlay-face vip-replace-overlay-pixmap))) | |
513 'vip-replace-overlay-face) | |
514 "*Face for highlighting replace regions on a window display.") | |
515 )) | |
516 | |
517 (defvar vip-replace-region-end-delimiter "$" | |
518 "A string marking the end of replacement regions. | |
519 It is used only with TTYs or if `vip-use-replace-region-delimiters' | |
520 is non-nil.") | |
521 (defvar vip-replace-region-start-delimiter "" | |
522 "A string marking the beginning of replacement regions. | |
523 It is used only with TTYs or if `vip-use-replace-region-delimiters' | |
524 is non-nil.") | |
525 (defvar vip-use-replace-region-delimiters (not (vip-has-face-support-p)) | |
526 "*If non-nil, Viper will always use `vip-replace-region-end-delimiter' and | |
527 `vip-replace-region-start-delimiter' to delimit replacement regions, even on | |
528 color displays. By default, the delimiters are used only on TTYs.") | |
529 | |
530 ;; XEmacs requires glyphs | |
531 (if vip-xemacs-p | |
532 (progn | |
533 (or (glyphp vip-replace-region-end-delimiter) | |
534 (setq vip-replace-region-end-delimiter | |
535 (make-glyph vip-replace-region-end-delimiter))) | |
536 (or (glyphp vip-replace-region-start-delimiter) | |
537 (setq vip-replace-region-start-delimiter | |
538 (make-glyph vip-replace-region-start-delimiter))) | |
539 )) | |
540 | |
541 | |
542 ;; These are local marker that must be initialized to nil and moved with | |
543 ;; `vip-move-marker-locally' | |
544 ;; | |
545 ;; Remember the last position inside the replace region. | |
546 (vip-deflocalvar vip-last-posn-in-replace-region nil) | |
547 ;; Remember the last position while inserting | |
548 (vip-deflocalvar vip-last-posn-while-in-insert-state nil) | |
549 (put 'vip-last-posn-in-replace-region 'permanent-local t) | |
550 (put 'vip-last-posn-while-in-insert-state 'permanent-local t) | |
551 | |
552 (vip-deflocalvar vip-sitting-in-replace nil "") | |
553 (put 'vip-sitting-in-replace 'permanent-local t) | |
554 | |
555 ;; Remember the number of characters that have to be deleted in replace | |
556 ;; mode to compensate for the inserted characters. | |
557 (vip-deflocalvar vip-replace-chars-to-delete 0 "") | |
558 (vip-deflocalvar vip-replace-chars-deleted 0 "") | |
559 | |
560 ;; Insertion ring and command ring | |
561 (defvar vip-insertion-ring-size 14 | |
562 "The size of the insertion ring.") | |
563 ;; The insertion ring. | |
564 (defvar vip-insertion-ring nil) | |
565 ;; This is temp insertion ring. Used to do rotation for display purposes. | |
566 ;; When rotation just started, it is initialized to vip-insertion-ring. | |
567 (defvar vip-temp-insertion-ring nil) | |
568 (defvar vip-last-inserted-string-from-insertion-ring "") | |
569 | |
570 (defvar vip-command-ring-size 14 | |
571 "The size of the command ring.") | |
572 ;; The command ring. | |
573 (defvar vip-command-ring nil) | |
574 ;; This is temp command ring. Used to do rotation for display purposes. | |
575 ;; When rotation just started, it is initialized to vip-command-ring. | |
576 (defvar vip-temp-command-ring nil) | |
577 | |
578 ;; Modes and related variables | |
579 | |
580 ;; Current mode. One of: `emacs-state', `vi-state', `insert-state' | |
581 (vip-deflocalvar vip-current-state 'emacs-state) | |
582 | |
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 | |
597 ;; Autoindent in insert | |
598 | |
599 ;; Variable that keeps track of whether C-t has been pressed. | |
600 (vip-deflocalvar vip-cted nil "") | |
601 | |
602 ;; Preserve the indent value, used by C-d in insert mode. | |
603 (vip-deflocalvar vip-current-indent 0) | |
604 | |
605 ;; Whether to preserve the indent, used by C-d in insert mode. | |
606 (vip-deflocalvar vip-preserve-indent nil) | |
607 | |
608 (vip-deflocalvar vip-auto-indent nil | |
609 "*Autoindent if t.") | |
610 (vip-deflocalvar vip-electric-mode t | |
611 "*If t, enable electric behavior. | |
612 Currently only enables auto-indentation `according to mode'.") | |
613 | |
614 (defconst vip-shift-width 8 | |
615 "*The shiftwidth variable.") | |
616 | |
617 ;; Variables for repeating destructive commands | |
618 | |
619 (defconst vip-keep-point-on-repeat t | |
620 "*If t, don't move point when repeating previous command. | |
621 This is useful for doing repeated changes with the '.' key. | |
622 The user can change this to nil, if she likes when the cursor moves | |
623 to a new place after repeating previous Vi command.") | |
624 | |
625 ;; Remember insert point as a marker. This is a local marker that must be | |
626 ;; initialized to nil and moved with `vip-move-marker-locally'. | |
627 (vip-deflocalvar vip-insert-point nil) | |
628 (put 'vip-insert-point 'permanent-local t) | |
629 | |
630 ;; This remembers the point before dabbrev-expand was called. | |
631 ;; If vip-insert-point turns out to be bigger than that, it is reset | |
632 ;; back to vip-pre-command-point. | |
633 ;; The reason this is needed is because dabbrev-expand (and possibly | |
634 ;; others) may jump to before the insertion point, delete something and | |
635 ;; then reinsert a bigger piece. For instance: bla^blo | |
636 ;; If dabbrev-expand is called after `blo' and ^ undicates vip-insert-point, | |
637 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo' | |
638 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand | |
639 ;; will insert the expansion, and we get: blablo^ | |
640 ;; Whatever we insert next goes before the ^, i.e., before the | |
641 ;; vip-insert-point marker. So, Viper will think that nothing was | |
642 ;; inserted. Remembering the orig position of the marker circumvents the | |
643 ;; problem. | |
644 ;; We don't know of any command, except dabbrev-expand, that has the same | |
645 ;; problem. However, the same trick can be used if such a command is | |
646 ;; discovered later. | |
647 ;; | |
648 (vip-deflocalvar vip-pre-command-point nil) | |
649 (put 'vip-pre-command-point 'permanent-local t) ; this is probably an overkill | |
650 | |
651 ;; This is used for saving inserted text. | |
652 (defvar vip-last-insertion nil) | |
653 | |
654 ;; Remembers the last replaced region. | |
655 (defvar vip-last-replace-region "") | |
656 | |
657 ;; Remember com point as a marker. | |
658 ;; This is a local marker. Should be moved with `vip-move-marker-locally' | |
659 (vip-deflocalvar vip-com-point nil) | |
660 | |
661 ;; If non-nil, the value is a list (M-COM VAL COM REG inserted-text cmd-keys) | |
662 ;; It is used to re-execute last destructive command. | |
663 ;; M-COM is a Lisp symbol representing the function to be executed. | |
664 ;; VAL is the prefix argument that was used with that command. | |
665 ;; COM is an internal descriptor, such as ?r, ?c, ?C, which contains | |
666 ;; additional information on how the function in M-COM is to be handled. | |
667 ;; REG is the register used by command | |
668 ;; INSERTED-TEXT is text inserted by that command (in case of o, c, C, i, r | |
669 ;; commands). | |
670 ;; COMMAND-KEYS are the keys that were typed to invoke the command. | |
671 (defvar vip-d-com nil) | |
672 | |
673 ;; The character remembered by the Vi `r' command. | |
674 (defvar vip-d-char nil) | |
675 | |
676 ;; Name of register to store deleted or yanked strings | |
677 (defvar vip-use-register nil) | |
678 | |
679 | |
680 | |
681 ;; Variables for Moves and Searches | |
682 | |
683 ;; For use by `;' command. | |
684 (defvar vip-f-char nil) | |
685 | |
686 ;; For use by `.' command. | |
687 (defvar vip-F-char nil) | |
688 | |
689 ;; For use by `;' command. | |
690 (defvar vip-f-forward nil) | |
691 | |
692 ;; For use by `;' command. | |
693 (defvar vip-f-offset nil) | |
694 | |
695 ;; Last search string | |
696 (defvar vip-s-string "") | |
697 | |
698 (defvar vip-quote-string "> " | |
699 "String inserted at the beginning of quoted region.") | |
700 | |
701 ;; If t, search is forward. | |
702 (defvar vip-s-forward nil) | |
703 | |
704 (defconst vip-case-fold-search nil | |
705 "*If not nil, search ignores cases.") | |
706 | |
707 (defconst vip-re-search t | |
708 "*If not nil, search is reg-exp search, otherwise vanilla search.") | |
709 | |
710 (defvar vip-adjust-window-after-search t | |
711 "*If not nil, pull the window up or down, depending on the direction of the | |
712 search, if search ends up near the bottom or near the top of the window.") | |
713 | |
714 (defconst vip-re-query-replace t | |
715 "*If t then do regexp replace, if nil then do string replace.") | |
716 | |
717 (defconst vip-re-replace t | |
718 "*If t, do regexp replace. nil means do string replace.") | |
719 | |
720 (vip-deflocalvar vip-ex-style-motion t | |
721 "*Ex-style: the commands l,h do not cross lines, etc.") | |
722 | |
723 (vip-deflocalvar vip-ex-style-editing-in-insert t | |
724 "*The keys ^H, ^? don't jump lines in insert, ESC moves cursor back, etc. | |
725 Note: this doesn't preclude ^H and ^? from deleting characters by moving | |
726 past the insertion point. This is a feature, not a bug. ") | |
727 | |
728 (vip-deflocalvar vip-delete-backwards-in-replace nil | |
729 "*If t, DEL key will delete characters while moving the cursor backwards. | |
730 If nil, the cursor will move backwards without deleting anything.") | |
731 | |
732 (defconst vip-buffer-search-char nil | |
733 "*Key bound for buffer-searching.") | |
734 | |
735 (defconst vip-search-wrap-around-t t | |
736 "*If t, search wraps around.") | |
737 | |
738 (vip-deflocalvar vip-related-files-and-buffers-ring nil | |
739 "*Ring of file and buffer names that are considered to be related to the | |
740 current buffer. | |
741 These buffers can be cycled through via :R and :P commands.") | |
742 (put 'vip-related-files-and-buffers-ring 'permanent-local t) | |
743 | |
744 ;; Used to find out if we are done with searching the current buffer. | |
745 (vip-deflocalvar vip-local-search-start-marker nil) | |
746 ;; As above, but global | |
747 (defvar vip-search-start-marker (make-marker)) | |
748 | |
749 ;; the search overlay | |
750 (vip-deflocalvar vip-search-overlay nil) | |
751 | |
752 | |
753 (defvar vip-heading-start | |
754 (concat "^\\s-*(\\s-*defun\\s-\\|" ; lisp | |
755 "^{\\s-*$\\|^[_a-zA-Z][^()]*[()].*{\\s-*$\\|" ; C/C++ | |
756 "^\\s-*class.*{\\|^\\s-*struct.*{\\|^\\s-*enum.*{\\|" | |
757 "^\\\\[sb][a-z]*{.*}\\s-*$\\|" ; latex | |
758 "^@node\\|@table\\|^@m?enu\\|^@itemize\\|^@if\\|" ; texinfo | |
759 "^.+:-") ; prolog | |
760 "*Regexps for Headings. Used by \[\[ and \]\].") | |
761 | |
762 (defvar vip-heading-end | |
763 (concat "^}\\|" ; C/C++ | |
764 "^\\\\end{\\|" ; latex | |
765 "^@end \\|" ; texinfo | |
766 ")\n\n[ \t\n]*\\|" ; lisp | |
767 "\\.\\s-*$") ; prolog | |
768 "*Regexps to end Headings/Sections. Used by \[\].") | |
769 | |
770 | |
771 ;; These two vars control the interaction of jumps performed by ' and `. | |
772 ;; In this new version, '' doesn't erase the marks set by ``, so one can | |
773 ;; use both kinds of jumps interchangeably and without loosing positions | |
774 ;; inside the lines. | |
775 | |
776 ;; Remembers position of the last jump done using ``'. | |
777 (vip-deflocalvar vip-last-jump nil) | |
778 ;; Remembers position of the last jump done using `''. | |
779 (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 | |
797 ;; History variables | |
798 | |
799 ;; History of search strings. | |
800 (defvar vip-search-history (list "")) | |
801 ;; History of query-replace strings used as a source. | |
802 (defvar vip-replace1-history nil) | |
803 ;; History of query-replace strings used as replacement. | |
804 (defvar vip-replace2-history nil) | |
805 ;; History of region quoting strings. | |
806 (defvar vip-quote-region-history (list vip-quote-string)) | |
807 ;; History of Ex-style commands. | |
808 (defvar vip-ex-history nil) | |
809 ;; History of shell commands. | |
810 (defvar vip-shell-history nil) | |
811 | |
812 | |
813 ;; Last shell command. There are two of these, one for Ex (in viper-ex) | |
814 ;; and one for Vi. | |
815 | |
816 ;; Last shell command executed with ! command. | |
817 (defvar vip-last-shell-com nil) | |
818 | |
819 | |
820 | |
821 ;;; Miscellaneous | |
822 | |
823 ;; don't bark when mark is inactive | |
824 (setq mark-even-if-inactive t) | |
825 | |
826 (defvar vip-inhibit-startup-message nil | |
827 "Whether Viper startup message should be inhibited.") | |
828 | |
829 (defvar vip-always t | |
830 "t means, arrange that vi-state will be a default.") | |
831 | |
832 (defvar vip-custom-file-name (vip-convert-standard-file-name "~/.vip") | |
833 "Viper customisation file. | |
834 This variable must be set _before_ loading Viper.") | |
835 | |
836 | |
837 (defvar vip-spell-function 'ispell-region | |
838 "Spell function used by #s<move> command to spell.") | |
839 | |
840 (defvar vip-tags-file-name "TAGS" | |
841 "The tags file used by Viper.") | |
842 | |
843 ;; Minibuffer | |
844 | |
845 (defvar vip-vi-style-in-minibuffer t | |
846 "If t, use vi-style editing in minibuffer. | |
847 Should be set in `~/.vip' file.") | |
848 | |
849 ;; overlay used in the minibuffer to indicate which state it is in | |
850 (vip-deflocalvar vip-minibuffer-overlay nil) | |
851 | |
852 ;; 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 | |
854 ;; *after* exiting the minibuffer | |
855 (defvar vip-minibuffer-exit-hook nil) | |
856 | |
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 | |
863 (setq next-line-add-newlines nil | |
864 require-final-newline t) | |
865 | |
866 (make-variable-buffer-local 'require-final-newline) | |
867 | |
868 | |
869 ;; Mode line | |
870 (defconst vip-vi-state-id "<V> " | |
871 "Mode line tag identifying the Vi mode of Viper.") | |
872 (defconst vip-emacs-state-id "<E> " | |
873 "Mode line tag identifying the Emacs mode of Viper.") | |
874 (defconst vip-insert-state-id "<I> " | |
875 "Mode line tag identifying the Insert mode of Viper.") | |
876 (defconst vip-replace-state-id "<R> " | |
877 "Mode line tag identifying the Replace mode of Viper.") | |
878 | |
879 ;; Viper changes the default mode-line-buffer-identification | |
880 (setq-default mode-line-buffer-identification '(" %b")) | |
881 | |
882 ;; Variable displaying the current Viper state in the mode line. | |
883 (vip-deflocalvar vip-mode-string vip-emacs-state-id) | |
884 (or (memq 'vip-mode-string global-mode-string) | |
885 (setq global-mode-string | |
886 (append '("" vip-mode-string) (cdr global-mode-string)))) | |
887 | |
888 | |
889 (defvar vip-vi-state-hook nil | |
890 "*Hooks run just before the switch to Vi mode is completed.") | |
891 (defvar vip-insert-state-hook nil | |
892 "*Hooks run just before the switch to Insert mode is completed.") | |
893 (defvar vip-replace-state-hook nil | |
894 "*Hooks run just before the switch to Replace mode is completed.") | |
895 (defvar vip-emacs-state-hook nil | |
896 "*Hooks run just before the switch to Emacs mode is completed.") | |
897 | |
898 (defvar vip-load-hook nil | |
899 "Hooks run just after loading Viper.") | |
900 | |
901 | |
902 ;; Generic predicates | 338 ;; Generic predicates |
903 | 339 |
904 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane | 340 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane |
905 | 341 |
906 ;; generate test functions | 342 ;; generate test functions |
918 | 354 |
919 ;; Variables for defining VI commands | 355 ;; Variables for defining VI commands |
920 | 356 |
921 ;; Modifying commands that can be prefixes to movement commands | 357 ;; Modifying commands that can be prefixes to movement commands |
922 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\")) | 358 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\")) |
359 ;; define vip-prefix-command-p | |
923 (vip-test-com-defun vip-prefix-command) | 360 (vip-test-com-defun vip-prefix-command) |
924 | 361 |
925 ;; Commands that are pairs eg. dd. r and R here are a hack | 362 ;; Commands that are pairs eg. dd. r and R here are a hack |
926 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R)) | 363 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R)) |
364 ;; define vip-charpair-command-p | |
927 (vip-test-com-defun vip-charpair-command) | 365 (vip-test-com-defun vip-charpair-command) |
928 | 366 |
929 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l | 367 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l |
930 ?H ?M ?n ?t ?T ?w ?W ?$ ?% | 368 ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?% |
931 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?` | 369 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?` |
932 ?; ?, ?0 ?? ?/ | 370 ?; ?, ?0 ?? ?/ |
933 ) | 371 ) |
934 "Movement commands") | 372 "Movement commands") |
373 ;; define vip-movement-command-p | |
935 (vip-test-com-defun vip-movement-command) | 374 (vip-test-com-defun vip-movement-command) |
936 | 375 |
376 (defconst vip-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9) | |
377 "Digit commands") | |
378 ;; define vip-digit-command-p | |
379 (vip-test-com-defun vip-digit-command) | |
380 | |
937 ;; Commands that can be repeated by . (dotted) | 381 ;; Commands that can be repeated by . (dotted) |
938 (defconst vip-dotable-commands '(?c ?d ?C ?D ?> ?<)) | 382 (defconst vip-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<)) |
383 ;; define vip-dotable-command-p | |
939 (vip-test-com-defun vip-dotable-command) | 384 (vip-test-com-defun vip-dotable-command) |
940 | 385 |
941 ;; Commands that can follow a # | 386 ;; Commands that can follow a # |
942 (defconst vip-hash-cmds '(?c ?C ?g ?q ?S)) | 387 (defconst vip-hash-commands '(?c ?C ?g ?q ?s)) |
943 (vip-test-com-defun vip-hash-cmd) | 388 ;; define vip-hash-command-p |
389 (vip-test-com-defun vip-hash-command) | |
944 | 390 |
945 ;; Commands that may have registers as prefix | 391 ;; Commands that may have registers as prefix |
946 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X)) | 392 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X)) |
393 ;; define vip-regsuffix-command-p | |
947 (vip-test-com-defun vip-regsuffix-command) | 394 (vip-test-com-defun vip-regsuffix-command) |
948 | 395 |
949 (defconst vip-vi-commands (append vip-movement-commands | 396 (defconst vip-vi-commands (append vip-movement-commands |
397 vip-digit-commands | |
950 vip-dotable-commands | 398 vip-dotable-commands |
951 vip-charpair-commands | 399 vip-charpair-commands |
952 vip-hash-cmds | 400 vip-hash-commands |
953 vip-prefix-commands | 401 vip-prefix-commands |
954 vip-regsuffix-commands) | 402 vip-regsuffix-commands) |
955 "The list of all commands in Vi-state.") | 403 "The list of all commands in Vi-state.") |
404 ;; define vip-vi-command-p | |
956 (vip-test-com-defun vip-vi-command) | 405 (vip-test-com-defun vip-vi-command) |
957 | |
958 | |
959 ;;; Arrange the keymaps | |
960 (require 'viper-keym) | |
961 | 406 |
962 | 407 |
963 ;;; CODE | 408 ;;; CODE |
964 | 409 |
965 ;; sentinels | 410 ;; sentinels |
1160 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent) | 605 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent) |
1161 (if vip-want-emacs-keys-in-insert | 606 (if vip-want-emacs-keys-in-insert |
1162 ;; expert | 607 ;; expert |
1163 (define-key vip-insert-basic-map "\C-j" nil) | 608 (define-key vip-insert-basic-map "\C-j" nil) |
1164 ;; novice | 609 ;; novice |
1165 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent)))) | 610 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent))) |
611 (define-key vip-insert-basic-map "\C-m" nil) | |
612 (define-key vip-insert-basic-map "\C-j" nil)) | |
1166 | 613 |
1167 (setq vip-insert-diehard-minor-mode | 614 (setq vip-insert-diehard-minor-mode |
1168 (not vip-want-emacs-keys-in-insert)) | 615 (not vip-want-emacs-keys-in-insert)) |
1169 | 616 |
1170 (if vip-want-ctl-h-help | 617 (if vip-want-ctl-h-help |
1573 (vip-set-mode-vars-for vip-current-state) | 1020 (vip-set-mode-vars-for vip-current-state) |
1574 | 1021 |
1575 ;; this-command, last-command-char, last-command-event | 1022 ;; this-command, last-command-char, last-command-event |
1576 (setq this-command com) | 1023 (setq this-command com) |
1577 (if vip-xemacs-p ; XEmacs represents key sequences as vectors | 1024 (if vip-xemacs-p ; XEmacs represents key sequences as vectors |
1578 (setq last-command-event (vip-seq-last-elt key) | 1025 (setq last-command-event (vip-copy-event (vip-seq-last-elt key)) |
1579 last-command-char (event-to-character last-command-event)) | 1026 last-command-char (event-to-character last-command-event)) |
1580 ;; Emacs represents them as sequences (str or vec) | 1027 ;; Emacs represents them as sequences (str or vec) |
1581 (setq last-command-event (vip-seq-last-elt key) | 1028 (setq last-command-event (vip-copy-event (vip-seq-last-elt key)) |
1582 last-command-char last-command-event)) | 1029 last-command-char last-command-event)) |
1583 | 1030 |
1584 (if (commandp com) | 1031 (if (commandp com) |
1585 (progn | 1032 (progn |
1586 (setq prefix-arg (or prefix-arg arg)) | 1033 (setq prefix-arg (or prefix-arg arg)) |
1594 (defun vip-exec-form-in-vi (form) | 1041 (defun vip-exec-form-in-vi (form) |
1595 "Execute FORM in Vi state, regardless of the Ccurrent Vi state." | 1042 "Execute FORM in Vi state, regardless of the Ccurrent Vi state." |
1596 (let ((buff (current-buffer)) | 1043 (let ((buff (current-buffer)) |
1597 result) | 1044 result) |
1598 (vip-set-mode-vars-for 'vi-state) | 1045 (vip-set-mode-vars-for 'vi-state) |
1599 (setq result (eval form)) | 1046 |
1047 (condition-case nil | |
1048 (setq result (eval form)) | |
1049 (error | |
1050 (signal 'quit nil))) | |
1051 | |
1600 (if (not (equal buff (current-buffer))) ; cmd switched buffer | 1052 (if (not (equal buff (current-buffer))) ; cmd switched buffer |
1601 (save-excursion | 1053 (save-excursion |
1602 (set-buffer buff) | 1054 (set-buffer buff) |
1603 (vip-set-mode-vars-for vip-current-state))) | 1055 (vip-set-mode-vars-for vip-current-state))) |
1604 (vip-set-mode-vars-for vip-current-state) | 1056 (vip-set-mode-vars-for vip-current-state) |
1743 (character-to-event (event-key first-key))) | 1195 (character-to-event (event-key first-key))) |
1744 (subseq keyseq 1))) | 1196 (subseq keyseq 1))) |
1745 (setq last-input-event event | 1197 (setq last-input-event event |
1746 keyseq (vector (character-to-event ?\e)))) | 1198 keyseq (vector (character-to-event ?\e)))) |
1747 ((eventp first-key) | 1199 ((eventp first-key) |
1748 (setq last-command-event first-key)) | 1200 (setq last-command-event (vip-copy-event first-key))) |
1749 )) | 1201 )) |
1750 ) ; end progn | 1202 ) ; end progn |
1751 | 1203 |
1752 ;; this is escape event with nothing after it | 1204 ;; this is escape event with nothing after it |
1753 ;; put in unread-command-event and then re-read | 1205 ;; put in unread-command-event and then re-read |
1812 ((eq vip-current-state 'replace-state) | 1264 ((eq vip-current-state 'replace-state) |
1813 'vip-replace-state-exit-cmd) | 1265 'vip-replace-state-exit-cmd) |
1814 (t 'vip-change-state-to-vi) | 1266 (t 'vip-change-state-to-vi) |
1815 ))) | 1267 ))) |
1816 (call-interactively cmd))) | 1268 (call-interactively cmd))) |
1269 | |
1817 | 1270 |
1818 | 1271 |
1819 | 1272 |
1820 ;; prefix argument for Vi mode | 1273 ;; prefix argument for Vi mode |
1821 | 1274 |
1855 ;; Invoked by EVENT. COM is the command part obtained so far. | 1308 ;; Invoked by EVENT. COM is the command part obtained so far. |
1856 (defun vip-prefix-arg-value (event com) | 1309 (defun vip-prefix-arg-value (event com) |
1857 (let (value func) | 1310 (let (value func) |
1858 ;; read while number | 1311 ;; read while number |
1859 (while (and (vip-characterp event) (>= event ?0) (<= event ?9)) | 1312 (while (and (vip-characterp event) (>= event ?0) (<= event ?9)) |
1860 (setq value (+ (* (if (vip-characterp value) value 0) 10) (- event ?0))) | 1313 (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0))) |
1861 (setq event (vip-read-event-convert-to-char))) | 1314 (setq event (vip-read-event-convert-to-char))) |
1862 | 1315 |
1863 (setq prefix-arg value) | 1316 (setq prefix-arg value) |
1864 (if com (setq prefix-arg (cons prefix-arg com))) | 1317 (if com (setq prefix-arg (cons prefix-arg com))) |
1865 (while (eq event ?U) | 1318 (while (eq event ?U) |
1878 ;; last. If com is not nil, the vip-digit-argument command was called | 1331 ;; last. If com is not nil, the vip-digit-argument command was called |
1879 ;; from within vip-prefix-arg command, such as `d', `w', etc., i.e., | 1332 ;; from within vip-prefix-arg command, such as `d', `w', etc., i.e., |
1880 ;; the user typed, say, d2. In this case, `com' would be `d', `w', | 1333 ;; the user typed, say, d2. In this case, `com' would be `d', `w', |
1881 ;; etc. | 1334 ;; etc. |
1882 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is | 1335 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is |
1883 ;; indicated by the fact that the current state is not vi-state, | 1336 ;; indicated by the fact that the current state is not vi-state), |
1884 ;; then `event' represents the vi command to be executed (e.g., `d', | 1337 ;; then `event' represents the vi command to be executed (e.g., `d', |
1885 ;; `w', etc. Again, last-command-char must make emacs believe that | 1338 ;; `w', etc). Again, last-command-char must make emacs believe that |
1886 ;; this is the command we typed. | 1339 ;; this is the command we typed. |
1887 (setq last-command-char (or com event)) | 1340 (setq last-command-char (or com event)) |
1888 (setq func (vip-exec-form-in-vi | 1341 (setq func (vip-exec-form-in-vi |
1889 (` (key-binding (char-to-string (, event)))))) | 1342 (` (key-binding (char-to-string (, event)))))) |
1890 (funcall func prefix-arg) | 1343 (funcall func prefix-arg) |
1929 (setq vip-use-register reg) | 1382 (setq vip-use-register reg) |
1930 (error "")) | 1383 (error "")) |
1931 (setq char (read-char)))) | 1384 (setq char (read-char)))) |
1932 (t | 1385 (t |
1933 (setq com char) | 1386 (setq com char) |
1934 (setq char (vip-read-char-exclusive)))))) | 1387 (setq char (read-char)))))) |
1935 | 1388 |
1936 (if (atom com) | 1389 (if (atom com) |
1937 ;; `com' is a single char, so we construct the command argument | 1390 ;; `com' is a single char, so we construct the command argument |
1938 ;; and if `char' is `?', we describe the arg; otherwise | 1391 ;; and if `char' is `?', we describe the arg; otherwise |
1939 ;; we prepare the command that will be executed at the end. | 1392 ;; we prepare the command that will be executed at the end. |
1940 (progn | 1393 (progn |
1941 (setq cmd-info (cons value com)) | 1394 (setq cmd-info (cons value com)) |
1942 (while (= char ?U) | 1395 (while (= char ?U) |
1943 (vip-describe-arg cmd-info) | 1396 (vip-describe-arg cmd-info) |
1944 (setq char (read-char))) | 1397 (setq char (read-char))) |
1945 ;; `char' is a movement command or a digit arg command---so we execute | 1398 ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so we |
1946 ;; it at the very end | 1399 ;; execute it at the very end |
1400 (or (vip-movement-command-p char) | |
1401 (vip-digit-command-p char) | |
1402 (vip-regsuffix-command-p char) | |
1403 (error "")) | |
1947 (setq mv-or-digit-cmd | 1404 (setq mv-or-digit-cmd |
1948 (vip-exec-form-in-vi | 1405 (vip-exec-form-in-vi |
1949 (` (key-binding (char-to-string (, char))))))) | 1406 (` (key-binding (char-to-string (, char))))))) |
1950 | 1407 |
1951 ;; as com is non-nil, this means that we have a command to execute | 1408 ;; as com is non-nil, this means that we have a command to execute |
1971 (t (error ""))))) | 1428 (t (error ""))))) |
1972 | 1429 |
1973 (if mv-or-digit-cmd | 1430 (if mv-or-digit-cmd |
1974 (progn | 1431 (progn |
1975 (setq last-command-char char) | 1432 (setq last-command-char char) |
1976 (funcall mv-or-digit-cmd cmd-info))) | 1433 (setq last-command-event |
1434 (vip-copy-event | |
1435 (if vip-xemacs-p (character-to-event char) char))) | |
1436 (condition-case nil | |
1437 (funcall mv-or-digit-cmd cmd-info) | |
1438 (error | |
1439 (error ""))))) | |
1977 )) | 1440 )) |
1978 | 1441 |
1979 (defun vip-describe-arg (arg) | 1442 (defun vip-describe-arg (arg) |
1980 (let (val com) | 1443 (let (val com) |
1981 (setq val (vip-P-val arg) | 1444 (setq val (vip-P-val arg) |
1996 last-command-char (if (consp arg) (cdr arg) nil))) | 1459 last-command-char (if (consp arg) (cdr arg) nil))) |
1997 | 1460 |
1998 (defun vip-command-argument (arg) | 1461 (defun vip-command-argument (arg) |
1999 "Accept a motion command as an argument." | 1462 "Accept a motion command as an argument." |
2000 (interactive "P") | 1463 (interactive "P") |
2001 (condition-case nil | 1464 (let ((vip-inside-command-argument-action t)) |
2002 (vip-prefix-arg-com | 1465 (condition-case nil |
2003 last-command-char | 1466 (vip-prefix-arg-com |
2004 (cond ((null arg) nil) | 1467 last-command-char |
2005 ((consp arg) (car arg)) | 1468 (cond ((null arg) nil) |
2006 ((integerp arg) arg) | 1469 ((consp arg) (car arg)) |
2007 (t (error vip-InvalidCommandArgument))) | 1470 ((integerp arg) arg) |
2008 (cond ((null arg) nil) | 1471 (t (error vip-InvalidCommandArgument))) |
2009 ((consp arg) (cdr arg)) | 1472 (cond ((null arg) nil) |
2010 ((integerp arg) nil) | 1473 ((consp arg) (cdr arg)) |
2011 (t (error vip-InvalidCommandArgument)))) | 1474 ((integerp arg) nil) |
2012 (quit (setq vip-use-register nil) | 1475 (t (error vip-InvalidCommandArgument)))) |
2013 (signal 'quit nil))) | 1476 (quit (setq vip-use-register nil) |
2014 (vip-deactivate-mark)) | 1477 (signal 'quit nil))) |
1478 (vip-deactivate-mark))) | |
2015 | 1479 |
2016 | 1480 |
2017 ;; repeat last destructive command | 1481 ;; repeat last destructive command |
2018 | 1482 |
2019 ;; Append region to text in register REG. | 1483 ;; Append region to text in register REG. |
2046 | 1510 |
2047 ;; define functions to be executed | 1511 ;; define functions to be executed |
2048 | 1512 |
2049 ;; invoked by the `C' command | 1513 ;; invoked by the `C' command |
2050 (defun vip-exec-change (m-com com) | 1514 (defun vip-exec-change (m-com com) |
1515 (or (and (markerp vip-com-point) (marker-position vip-com-point)) | |
1516 (set-marker vip-com-point (point) (current-buffer))) | |
2051 ;; handle C cmd at the eol and at eob. | 1517 ;; handle C cmd at the eol and at eob. |
2052 (if (or (and (eolp) (= vip-com-point (point))) | 1518 (if (or (and (eolp) (= vip-com-point (point))) |
2053 (= vip-com-point (point-max))) | 1519 (= vip-com-point (point-max))) |
2054 (progn | 1520 (progn |
2055 (insert " ")(backward-char 1))) | 1521 (insert " ")(backward-char 1))) |
2079 (delete-region (mark t) (point))) | 1545 (delete-region (mark t) (point))) |
2080 (open-line 1) | 1546 (open-line 1) |
2081 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion))) | 1547 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion))) |
2082 | 1548 |
2083 (defun vip-exec-delete (m-com com) | 1549 (defun vip-exec-delete (m-com com) |
1550 (or (and (markerp vip-com-point) (marker-position vip-com-point)) | |
1551 (set-marker vip-com-point (point) (current-buffer))) | |
2084 (if vip-use-register | 1552 (if vip-use-register |
2085 (progn | 1553 (progn |
2086 (cond ((vip-valid-register vip-use-register '(letter digit)) | 1554 (cond ((vip-valid-register vip-use-register '(letter digit)) |
2087 ;;(vip-valid-register vip-use-register '(letter)) | 1555 ;;(vip-valid-register vip-use-register '(letter)) |
2088 (copy-to-register | 1556 (copy-to-register |
2121 (kill-region (mark t) (point)) | 1589 (kill-region (mark t) (point)) |
2122 (if (eq m-com 'vip-line) (setq this-command 'D-command))) | 1590 (if (eq m-com 'vip-line) (setq this-command 'D-command))) |
2123 (back-to-indentation)) | 1591 (back-to-indentation)) |
2124 | 1592 |
2125 (defun vip-exec-yank (m-com com) | 1593 (defun vip-exec-yank (m-com com) |
1594 (or (and (markerp vip-com-point) (marker-position vip-com-point)) | |
1595 (set-marker vip-com-point (point) (current-buffer))) | |
2126 (if vip-use-register | 1596 (if vip-use-register |
2127 (progn | 1597 (progn |
2128 (cond ((vip-valid-register vip-use-register '(letter digit)) | 1598 (cond ((vip-valid-register vip-use-register '(letter digit)) |
2129 ;; (vip-valid-register vip-use-register '(letter)) | 1599 ;; (vip-valid-register vip-use-register '(letter)) |
2130 (copy-to-register | 1600 (copy-to-register |
2329 (vip-special-ring-rotate1 vip-command-ring 1) | 1799 (vip-special-ring-rotate1 vip-command-ring 1) |
2330 (setq num (1+ num))) | 1800 (setq num (1+ num))) |
2331 )) | 1801 )) |
2332 | 1802 |
2333 | 1803 |
2334 ;; This command is invoked interactively by the key sequence #<char> | 1804 ;; The hash-command. It is invoked interactively by the key sequence #<char>. |
1805 ;; The chars that can follow `#' are determined by vip-hash-command-p | |
2335 (defun vip-special-prefix-com (char) | 1806 (defun vip-special-prefix-com (char) |
2336 (cond ((= char ?c) | 1807 (cond ((= char ?c) |
2337 (downcase-region (min vip-com-point (point)) | 1808 (downcase-region (min vip-com-point (point)) |
2338 (max vip-com-point (point)))) | 1809 (max vip-com-point (point)))) |
2339 ((= char ?C) | 1810 ((= char ?C) |
2630 (let (command) | 2101 (let (command) |
2631 (setq command (local-key-binding (char-to-string last-command-char))) | 2102 (setq command (local-key-binding (char-to-string last-command-char))) |
2632 (if command | 2103 (if command |
2633 (command-execute command) | 2104 (command-execute command) |
2634 (exit-minibuffer)))) | 2105 (exit-minibuffer)))) |
2635 | |
2636 | |
2637 (defun vip-set-search-face () | |
2638 (if (vip-has-face-support-p) | |
2639 (defvar vip-search-face | |
2640 (progn | |
2641 (make-face 'vip-search-face) | |
2642 (vip-hide-face 'vip-search-face) | |
2643 (or (face-differs-from-default-p 'vip-search-face) | |
2644 ;; face wasn't set in .vip or .Xdefaults | |
2645 (if (vip-can-use-colors "Black" "khaki") | |
2646 (progn | |
2647 (set-face-background 'vip-search-face "khaki") | |
2648 (set-face-foreground 'vip-search-face "Black")) | |
2649 (set-face-underline-p 'vip-search-face t) | |
2650 (vip-set-face-pixmap 'vip-search-face vip-search-face-pixmap))) | |
2651 'vip-search-face) | |
2652 "*Face used to flash out the search pattern.") | |
2653 )) | |
2654 | |
2655 | |
2656 (defun vip-set-minibuffer-faces () | |
2657 (if (not (vip-has-face-support-p)) | |
2658 () | |
2659 (defvar vip-minibuffer-emacs-face | |
2660 (progn | |
2661 (make-face 'vip-minibuffer-emacs-face) | |
2662 (vip-hide-face 'vip-minibuffer-emacs-face) | |
2663 (or (face-differs-from-default-p 'vip-minibuffer-emacs-face) | |
2664 ;; face wasn't set in .vip or .Xdefaults | |
2665 (if vip-vi-style-in-minibuffer | |
2666 ;; emacs state is an exception in the minibuffer | |
2667 (if (vip-can-use-colors "darkseagreen2" "Black") | |
2668 (progn | |
2669 (set-face-background | |
2670 'vip-minibuffer-emacs-face "darkseagreen2") | |
2671 (set-face-foreground | |
2672 'vip-minibuffer-emacs-face "Black")) | |
2673 (copy-face 'modeline 'vip-minibuffer-emacs-face)) | |
2674 ;; emacs state is the main state in the minibuffer | |
2675 (if (vip-can-use-colors "Black" "pink") | |
2676 (progn | |
2677 (set-face-background 'vip-minibuffer-emacs-face "pink") | |
2678 (set-face-foreground | |
2679 'vip-minibuffer-emacs-face "Black")) | |
2680 (copy-face 'italic 'vip-minibuffer-emacs-face)) | |
2681 )) | |
2682 'vip-minibuffer-emacs-face) | |
2683 "Face used in the Minibuffer when it is in Emacs state.") | |
2684 | |
2685 (defvar vip-minibuffer-insert-face | |
2686 (progn | |
2687 (make-face 'vip-minibuffer-insert-face) | |
2688 (vip-hide-face 'vip-minibuffer-insert-face) | |
2689 (or (face-differs-from-default-p 'vip-minibuffer-insert-face) | |
2690 (if vip-vi-style-in-minibuffer | |
2691 (if (vip-can-use-colors "Black" "pink") | |
2692 (progn | |
2693 (set-face-background 'vip-minibuffer-insert-face "pink") | |
2694 (set-face-foreground | |
2695 'vip-minibuffer-insert-face "Black")) | |
2696 (copy-face 'italic 'vip-minibuffer-insert-face)) | |
2697 ;; If Insert state is an exception | |
2698 (if (vip-can-use-colors "darkseagreen2" "Black") | |
2699 (progn | |
2700 (set-face-background | |
2701 'vip-minibuffer-insert-face "darkseagreen2") | |
2702 (set-face-foreground | |
2703 'vip-minibuffer-insert-face "Black")) | |
2704 (copy-face 'modeline 'vip-minibuffer-insert-face)) | |
2705 (vip-italicize-face 'vip-minibuffer-insert-face))) | |
2706 'vip-minibuffer-insert-face) | |
2707 "Face used in the Minibuffer when it is in Insert state.") | |
2708 | |
2709 (defvar vip-minibuffer-vi-face | |
2710 (progn | |
2711 (make-face 'vip-minibuffer-vi-face) | |
2712 (vip-hide-face 'vip-minibuffer-vi-face) | |
2713 (or (face-differs-from-default-p 'vip-minibuffer-vi-face) | |
2714 (if vip-vi-style-in-minibuffer | |
2715 (if (vip-can-use-colors "Black" "grey") | |
2716 (progn | |
2717 (set-face-background 'vip-minibuffer-vi-face "grey") | |
2718 (set-face-foreground 'vip-minibuffer-vi-face "Black")) | |
2719 (copy-face 'bold 'vip-minibuffer-vi-face)) | |
2720 (copy-face 'bold 'vip-minibuffer-vi-face) | |
2721 (invert-face 'vip-minibuffer-vi-face))) | |
2722 'vip-minibuffer-vi-face) | |
2723 "Face used in the Minibuffer when it is in Vi state.") | |
2724 | |
2725 ;; the current face used in the minibuffer | |
2726 (vip-deflocalvar vip-minibuffer-current-face vip-minibuffer-emacs-face "") | |
2727 )) | |
2728 | |
2729 | 2106 |
2730 | 2107 |
2731 ;;; Reading string with history | 2108 ;;; Reading string with history |
2732 | 2109 |
2733 (defun vip-read-string-with-history (prompt &optional initial | 2110 (defun vip-read-string-with-history (prompt &optional initial |
2966 (vip-replace-start)) | 2343 (vip-replace-start)) |
2967 (vip-add-hook | 2344 (vip-add-hook |
2968 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t) | 2345 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t) |
2969 (vip-add-hook | 2346 (vip-add-hook |
2970 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) | 2347 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
2348 ;; guard against a smartie who switched from R-replace to normal replace | |
2349 (vip-remove-hook | |
2350 'vip-post-command-hooks 'vip-R-state-post-command-sentinel) | |
2351 (if overwrite-mode (overwrite-mode nil)) | |
2971 ) | 2352 ) |
2972 | 2353 |
2973 | 2354 |
2974 ;; checks how many chars were deleted by the last change | 2355 ;; checks how many chars were deleted by the last change |
2975 (defun vip-replace-mode-spy-before (beg end) | 2356 (defun vip-replace-mode-spy-before (beg end) |
3041 (or (marker-position vip-last-posn-in-replace-region) | 2422 (or (marker-position vip-last-posn-in-replace-region) |
3042 (vip-replace-start)) | 2423 (vip-replace-start)) |
3043 )) | 2424 )) |
3044 | 2425 |
3045 (setq vip-replace-chars-to-delete | 2426 (setq vip-replace-chars-to-delete |
3046 (max 0 (min vip-replace-chars-to-delete | 2427 (max 0 |
3047 (- (vip-replace-end) | 2428 (min vip-replace-chars-to-delete |
3048 vip-last-posn-in-replace-region)))) | 2429 (- (vip-replace-end) vip-last-posn-in-replace-region) |
2430 (- (vip-line-pos 'end) vip-last-posn-in-replace-region) | |
2431 ))) | |
3049 ))) | 2432 ))) |
3050 | 2433 |
3051 | 2434 |
3052 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if | 2435 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if |
3053 ;; posn is within the overlay. | 2436 ;; posn is within the overlay. |
3095 (overwrite-mode 1) | 2478 (overwrite-mode 1) |
3096 (vip-add-hook | 2479 (vip-add-hook |
3097 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t) | 2480 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t) |
3098 (vip-add-hook | 2481 (vip-add-hook |
3099 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) | 2482 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
2483 ;; guard against a smartie who switched from R-replace to normal replace | |
2484 (vip-remove-hook | |
2485 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel) | |
3100 ) | 2486 ) |
3101 | 2487 |
3102 | 2488 |
3103 | 2489 |
3104 (defun vip-replace-state-exit-cmd () | 2490 (defun vip-replace-state-exit-cmd () |
3118 (command-execute com) | 2504 (command-execute com) |
3119 (error | 2505 (error |
3120 (vip-message-conditions conds))) | 2506 (vip-message-conditions conds))) |
3121 ) | 2507 ) |
3122 (vip-hide-replace-overlay)) | 2508 (vip-hide-replace-overlay)) |
2509 | |
2510 (defun vip-replace-state-carriage-return () | |
2511 "Implements carriage return in Viper replace state." | |
2512 (interactive) | |
2513 ;; If Emacs start supporting overlay maps, as it currently supports | |
2514 ;; text-property maps, we could do away with vip-replace-minor-mode and | |
2515 ;; just have keymap attached to replace overlay. Then the "if part" of this | |
2516 ;; statement can be deleted. | |
2517 (if (or (< (point) (vip-replace-start)) | |
2518 (> (point) (vip-replace-end))) | |
2519 (let (vip-replace-minor-mode com) | |
2520 (vip-set-unread-command-events last-input-char) | |
2521 (setq com (key-binding (read-key-sequence nil))) | |
2522 (condition-case conds | |
2523 (command-execute com) | |
2524 (error | |
2525 (vip-message-conditions conds)))) | |
2526 (if (not vip-allow-multiline-replace-regions) | |
2527 (vip-replace-state-exit-cmd) | |
2528 (if (vip-same-line (point) (vip-replace-end)) | |
2529 (vip-replace-state-exit-cmd) | |
2530 (vip-kill-line nil) | |
2531 (vip-next-line-at-bol nil))))) | |
3123 | 2532 |
3124 | 2533 |
3125 ;; This is the function bound to 'R'---unlimited replace. | 2534 ;; This is the function bound to 'R'---unlimited replace. |
3126 ;; Similar to Emacs's own overwrite-mode. | 2535 ;; Similar to Emacs's own overwrite-mode. |
3127 (defun vip-overwrite (arg) | 2536 (defun vip-overwrite (arg) |
3514 (defun vip-goto-col (arg) | 2923 (defun vip-goto-col (arg) |
3515 "Go to ARG's column." | 2924 "Go to ARG's column." |
3516 (interactive "P") | 2925 (interactive "P") |
3517 (vip-leave-region-active) | 2926 (vip-leave-region-active) |
3518 (let ((val (vip-p-val arg)) | 2927 (let ((val (vip-p-val arg)) |
3519 (com (vip-getcom arg))) | 2928 (com (vip-getcom arg)) |
2929 line-len) | |
2930 (setq line-len (- (vip-line-pos 'end) (vip-line-pos 'start))) | |
2931 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
2932 (beginning-of-line) | |
2933 (forward-char (1- (min line-len val))) | |
2934 (while (> (current-column) (1- val)) | |
2935 (backward-char 1)) | |
2936 (if com (vip-execute-com 'vip-goto-col val com)) | |
3520 (save-excursion | 2937 (save-excursion |
3521 (end-of-line) | 2938 (end-of-line) |
3522 (if (> val (1+ (current-column))) (error ""))) | 2939 (if (> val (current-column)) (error ""))) |
3523 (if com (vip-move-marker-locally 'vip-com-point (point))) | 2940 )) |
3524 (beginning-of-line) | |
3525 (forward-char (1- val)) | |
3526 (if com (vip-execute-com 'vip-goto-col val com)))) | |
3527 | 2941 |
3528 | 2942 |
3529 (defun vip-next-line (arg) | 2943 (defun vip-next-line (arg) |
3530 "Go to next line." | 2944 "Go to next line." |
3531 (interactive "P") | 2945 (interactive "P") |
3872 (defun vip-line-to-bottom (arg) | 3286 (defun vip-line-to-bottom (arg) |
3873 "Put current line on the last line." | 3287 "Put current line on the last line." |
3874 (interactive "p") | 3288 (interactive "p") |
3875 (recenter (- (window-height) (1+ arg)))) | 3289 (recenter (- (window-height) (1+ arg)))) |
3876 | 3290 |
3877 ;; If vip-adjust-window-after-search is t, scroll up or down 1/4 of window | 3291 ;; If point is within vip-search-scroll-threshold of window top or bottom, |
3878 ;; height, depending on whether we are at the bottom or at the top of the | 3292 ;; scroll up or down 1/7 of window height, depending on whether we are at the |
3879 ;; window. This function is called by vip-search (which is called from | 3293 ;; bottom or at the top of the window. This function is called by vip-search |
3880 ;; vip-search-forward/backward/next) | 3294 ;; (which is called from vip-search-forward/backward/next). If the value of |
3295 ;; vip-search-scroll-threshold is negative - don't scroll. | |
3881 (defun vip-adjust-window () | 3296 (defun vip-adjust-window () |
3882 (let ((win-height (if vip-emacs-p | 3297 (let ((win-height (if vip-emacs-p |
3883 (1- (window-height)) ; adjust for modeline | 3298 (1- (window-height)) ; adjust for modeline |
3884 (window-displayed-height))) | 3299 (window-displayed-height))) |
3885 (pt (point)) | 3300 (pt (point)) |
3886 at-top-p at-bottom-p | 3301 at-top-p at-bottom-p |
3887 min-scroll direction) | 3302 min-scroll direction) |
3888 (save-excursion | 3303 (save-excursion |
3889 (move-to-window-line 0) ; top | 3304 (move-to-window-line 0) ; top |
3890 (setq at-top-p (<= (count-lines pt (point)) 2)) | 3305 (setq at-top-p |
3306 (<= (count-lines pt (point)) | |
3307 vip-search-scroll-threshold)) | |
3891 (move-to-window-line -1) ; bottom | 3308 (move-to-window-line -1) ; bottom |
3892 (setq at-bottom-p (<= (count-lines pt (point)) 2)) | 3309 (setq at-bottom-p |
3310 (<= (count-lines pt (point)) vip-search-scroll-threshold)) | |
3893 ) | 3311 ) |
3894 (cond (at-top-p (setq min-scroll 1 | 3312 (cond (at-top-p (setq min-scroll (1- vip-search-scroll-threshold) |
3895 direction 1)) | 3313 direction 1)) |
3896 (at-bottom-p (setq min-scroll 2 | 3314 (at-bottom-p (setq min-scroll (1+ vip-search-scroll-threshold) |
3897 direction -1))) | 3315 direction -1))) |
3898 (if (and vip-adjust-window-after-search min-scroll) | 3316 (if min-scroll |
3899 (recenter | 3317 (recenter |
3900 (* (max min-scroll (/ win-height 7)) direction))) | 3318 (* (max min-scroll (/ win-height 7)) direction))) |
3901 )) | 3319 )) |
3902 | 3320 |
3903 | 3321 |
3909 (defun vip-paren-match (arg) | 3327 (defun vip-paren-match (arg) |
3910 "Go to the matching parenthesis." | 3328 "Go to the matching parenthesis." |
3911 (interactive "P") | 3329 (interactive "P") |
3912 (vip-leave-region-active) | 3330 (vip-leave-region-active) |
3913 (let ((com (vip-getcom arg)) | 3331 (let ((com (vip-getcom arg)) |
3914 parse-sexp-ignore-comments anchor-point) | 3332 (parse-sexp-ignore-comments vip-parse-sexp-ignore-comments) |
3333 anchor-point) | |
3915 (if (integerp arg) | 3334 (if (integerp arg) |
3916 (if (or (> arg 99) (< arg 1)) | 3335 (if (or (> arg 99) (< arg 1)) |
3917 (error "Prefix must be between 1 and 99") | 3336 (error "Prefix must be between 1 and 99") |
3918 (goto-char | 3337 (goto-char |
3919 (if (> (point-max) 80000) | 3338 (if (> (point-max) 80000) |
3951 (forward-char) | 3370 (forward-char) |
3952 (if com (vip-move-marker-locally 'vip-com-point (point))) | 3371 (if com (vip-move-marker-locally 'vip-com-point (point))) |
3953 (backward-sexp 1) | 3372 (backward-sexp 1) |
3954 (if com (vip-execute-com 'vip-paren-match nil com))) | 3373 (if com (vip-execute-com 'vip-paren-match nil com))) |
3955 (t (error "")))))) | 3374 (t (error "")))))) |
3375 | |
3376 (defun vip-toggle-parse-sexp-ignore-comments () | |
3377 (interactive) | |
3378 (setq vip-parse-sexp-ignore-comments (not vip-parse-sexp-ignore-comments)) | |
3379 (prin1 (format "`%%' will %signore parentheses inside the comments" | |
3380 (if vip-parse-sexp-ignore-comments "" "NOT "))) | |
3381 ) | |
3956 | 3382 |
3957 | 3383 |
3958 ;; sentence ,paragraph and heading | 3384 ;; sentence ,paragraph and heading |
3959 | 3385 |
3960 (defun vip-forward-sentence (arg) | 3386 (defun vip-forward-sentence (arg) |
4320 ;; pull up or down if at top/bottom of window | 3746 ;; pull up or down if at top/bottom of window |
4321 (vip-adjust-window) | 3747 (vip-adjust-window) |
4322 ;; highlight the result of search | 3748 ;; highlight the result of search |
4323 ;; don't wait and don't highlight in macros | 3749 ;; don't wait and don't highlight in macros |
4324 (or executing-kbd-macro | 3750 (or executing-kbd-macro |
3751 vip-inside-command-argument-action | |
4325 (vip-flash-search-pattern)) | 3752 (vip-flash-search-pattern)) |
4326 ))) | 3753 ))) |
4327 | 3754 |
4328 (defun vip-search-next (arg) | 3755 (defun vip-search-next (arg) |
4329 "Repeat previous search." | 3756 "Repeat previous search." |
4422 buffer-name))) | 3849 buffer-name))) |
4423 (kill-buffer buffer) | 3850 (kill-buffer buffer) |
4424 (error "Buffer not killed")))) | 3851 (error "Buffer not killed")))) |
4425 | 3852 |
4426 | 3853 |
4427 (defvar vip-smart-suffix-list '("" "tex" "c" "cc" "el" "p") | 3854 (defvar vip-smart-suffix-list |
3855 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p") | |
4428 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'. | 3856 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'. |
4429 This is useful when you the current directory contains files with the same | 3857 This is useful when you the current directory contains files with the same |
4430 prefix and many different suffixes. Usually, only one of the suffixes | 3858 prefix and many different suffixes. Usually, only one of the suffixes |
4431 represents an editable file. However, file completion will stop at the `.' | 3859 represents an editable file. However, file completion will stop at the `.' |
4432 The smart suffix feature lets you hit RET in such a case, and Viper will | 3860 The smart suffix feature lets you hit RET in such a case, and Viper will |
4480 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer." | 3908 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer." |
4481 (run-hooks 'vip-minibuffer-exit-hook)) | 3909 (run-hooks 'vip-minibuffer-exit-hook)) |
4482 | 3910 |
4483 (defadvice find-file (before vip-add-suffix-advice activate) | 3911 (defadvice find-file (before vip-add-suffix-advice activate) |
4484 "Use `read-file-name' for reading arguments." | 3912 "Use `read-file-name' for reading arguments." |
4485 (interactive (list (read-file-name "Find file: " | 3913 (interactive (cons (read-file-name "Find file: " nil default-directory) |
4486 nil default-directory)))) | 3914 ;; if Mule and prefix argument, ask for coding system |
3915 (if (or (boundp 'MULE) ; mule integrated Emacs 19 | |
3916 (featurep 'mule)) ; mule integrated XEmacs 20 | |
3917 (list | |
3918 (and current-prefix-arg | |
3919 (read-coding-system "Coding-system: ")))) | |
3920 ))) | |
4487 | 3921 |
4488 (defadvice find-file-other-window (before vip-add-suffix-advice activate) | 3922 (defadvice find-file-other-window (before vip-add-suffix-advice activate) |
4489 "Use `read-file-name' for reading arguments." | 3923 "Use `read-file-name' for reading arguments." |
4490 (interactive (list (read-file-name "Find file in other window: " | 3924 (interactive (cons (read-file-name "Find file in other window: " |
4491 nil default-directory)))) | 3925 nil default-directory) |
3926 ;; if Mule and prefix argument, ask for coding system | |
3927 (if (or (boundp 'MULE) ; mule integrated Emacs 19 | |
3928 (featurep 'mule)) ; mule integrated XEmacs 20 | |
3929 (list | |
3930 (and current-prefix-arg | |
3931 (read-coding-system "Coding-system: ")))) | |
3932 ))) | |
4492 | 3933 |
4493 (defadvice find-file-other-frame (before vip-add-suffix-advice activate) | 3934 (defadvice find-file-other-frame (before vip-add-suffix-advice activate) |
4494 "Use `read-file-name' for reading arguments." | 3935 "Use `read-file-name' for reading arguments." |
4495 (interactive (list (read-file-name "Find file in other frame: " | 3936 (interactive (cons (read-file-name "Find file in other frame: " |
4496 nil default-directory)))) | 3937 nil default-directory) |
3938 ;; if Mule and prefix argument, ask for coding system | |
3939 (if (or (boundp 'MULE) ; mule integrated Emacs 19 | |
3940 (featurep 'mule)) ; mule integrated XEmacs 20 | |
3941 (list | |
3942 (and current-prefix-arg | |
3943 (read-coding-system "Coding-system: ")))) | |
3944 ))) | |
4497 | 3945 |
4498 (defadvice read-file-name (around vip-suffix-advice activate) | 3946 (defadvice read-file-name (around vip-suffix-advice activate) |
4499 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook." | 3947 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook." |
4500 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix)) | 3948 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix)) |
4501 ad-do-it)) | 3949 ad-do-it)) |
4721 (vip-replace-end))) | 4169 (vip-replace-end))) |
4722 | 4170 |
4723 ;; protect against error while inserting "@" and other disasters | 4171 ;; protect against error while inserting "@" and other disasters |
4724 ;; (e.g., read-only buff) | 4172 ;; (e.g., read-only buff) |
4725 (condition-case conds | 4173 (condition-case conds |
4726 (if (vip-same-line (vip-replace-start) | 4174 (if (or vip-allow-multiline-replace-regions |
4727 (vip-replace-end)) | 4175 (vip-same-line (vip-replace-start) |
4176 (vip-replace-end))) | |
4728 (progn | 4177 (progn |
4729 ;; tabs cause problems in replace, so untabify | 4178 ;; tabs cause problems in replace, so untabify |
4730 (goto-char (vip-replace-end)) | 4179 (goto-char (vip-replace-end)) |
4731 (insert-before-markers "@") ; put placeholder after the TAB | 4180 (insert-before-markers "@") ; put placeholder after the TAB |
4732 (untabify (vip-replace-start) (point)) | 4181 (untabify (vip-replace-start) (point)) |
4842 (message "Mark set at the end of buffer")) | 4291 (message "Mark set at the end of buffer")) |
4843 | 4292 |
4844 (defun vip-mark-point () | 4293 (defun vip-mark-point () |
4845 "Set mark at point of buffer." | 4294 "Set mark at point of buffer." |
4846 (interactive) | 4295 (interactive) |
4847 (let ((char (vip-read-char-exclusive))) | 4296 (let ((char (read-char))) |
4848 (cond ((and (<= ?a char) (<= char ?z)) | 4297 (cond ((and (<= ?a char) (<= char ?z)) |
4849 (point-to-register (1+ (- char ?a)))) | 4298 (point-to-register (1+ (- char ?a)))) |
4850 ((= char ?<) (vip-mark-beginning-of-buffer)) | 4299 ((= char ?<) (vip-mark-beginning-of-buffer)) |
4851 ((= char ?>) (vip-mark-end-of-buffer)) | 4300 ((= char ?>) (vip-mark-end-of-buffer)) |
4852 ((= char ?.) (vip-set-mark-if-necessary)) | 4301 ((= char ?.) (vip-set-mark-if-necessary)) |
4853 ((= char ?,) (vip-cycle-through-mark-ring)) | 4302 ((= char ?,) (vip-cycle-through-mark-ring)) |
4854 ((= char ?D) (mark-defun)) | 4303 ((= char ?D) (mark-defun)) |
4855 (t (error "")) | 4304 (t (error "")) |
4856 ))) | 4305 ))) |
4857 | 4306 |
4858 ;; Algorithm: If first invocation of this command save mark on ring, goto | 4307 ;; Algorithm: If first invocation of this command save mark on ring, goto |
4859 ;; mark, M0, and pop the most recent elt from the mark ring into mark, | 4308 ;; mark, M0, and pop the most recent elt from the mark ring into mark, |
4860 ;; making it into the new mark, M1. | 4309 ;; making it into the new mark, M1. |
4861 ;; Push this mark back and set mark to the original point position, p1. | 4310 ;; Push this mark back and set mark to the original point position, p1. |
5010 | 4459 |
5011 (defun vip-autoindent () | 4460 (defun vip-autoindent () |
5012 "Auto Indentation, Vi-style." | 4461 "Auto Indentation, Vi-style." |
5013 (interactive) | 4462 (interactive) |
5014 (let ((col (current-indentation))) | 4463 (let ((col (current-indentation))) |
4464 (if abbrev-mode (expand-abbrev)) | |
5015 (if vip-preserve-indent | 4465 (if vip-preserve-indent |
5016 (setq vip-preserve-indent nil) | 4466 (setq vip-preserve-indent nil) |
5017 (setq vip-current-indent col)) | 4467 (setq vip-current-indent col)) |
5018 ;; don't leave whitespace lines around | 4468 ;; don't leave whitespace lines around |
5019 (if (memq last-command | 4469 (if (memq last-command |
5545 elt))))) | 4995 elt))))) |
5546 lis)) | 4996 lis)) |
5547 | 4997 |
5548 | 4998 |
5549 | 4999 |
5550 ;;; Bring in the rest of the files | |
5551 (require 'viper-mous) | |
5552 (require 'viper-macs) | |
5553 (require 'viper-ex) | |
5554 | |
5555 | |
5556 | |
5557 ;; The following is provided for compatibility with older VIP's | 5000 ;; The following is provided for compatibility with older VIP's |
5558 | 5001 |
5559 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) | 5002 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) |
5560 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) | 5003 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) |
5561 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs) | 5004 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs) |
5589 (defvar makefile-mode-hook) | 5032 (defvar makefile-mode-hook) |
5590 (add-hook 'makefile-mode-hook 'viper-mode) | 5033 (add-hook 'makefile-mode-hook 'viper-mode) |
5591 | 5034 |
5592 (defvar help-mode-hook) | 5035 (defvar help-mode-hook) |
5593 (add-hook 'help-mode-hook 'viper-mode) | 5036 (add-hook 'help-mode-hook 'viper-mode) |
5037 (vip-modify-major-mode 'help-mode 'vi-state vip-help-modifier-map) | |
5594 | 5038 |
5595 (defvar awk-mode-hook) | 5039 (defvar awk-mode-hook) |
5596 (add-hook 'awk-mode-hook 'viper-mode) | 5040 (add-hook 'awk-mode-hook 'viper-mode) |
5597 | 5041 |
5598 (defvar html-mode-hook) | 5042 (defvar html-mode-hook) |
5800 (vector vip-repeat-from-history-key '\2) 'vi-state | 5244 (vector vip-repeat-from-history-key '\2) 'vi-state |
5801 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) | 5245 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) |
5802 | 5246 |
5803 ;; set the toggle case sensitivity and regexp search macros | 5247 ;; set the toggle case sensitivity and regexp search macros |
5804 (vip-set-vi-search-style-macros nil) | 5248 (vip-set-vi-search-style-macros nil) |
5249 | |
5250 ;; Make %%% toggle parsing comments for matching parentheses | |
5251 (vip-record-kbd-macro | |
5252 "%%%" 'vi-state | |
5253 [(meta x) v i p - t o g g l e - p a r s e - s e x p - i g n o r e - c o m m e n t s return] | |
5254 't) | |
5805 | 5255 |
5806 | 5256 |
5807 ;; ~/.vip is loaded if it exists | 5257 ;; ~/.vip is loaded if it exists |
5808 (if (and (file-exists-p vip-custom-file-name) | 5258 (if (and (file-exists-p vip-custom-file-name) |
5809 (not noninteractive)) | 5259 (not noninteractive)) |
5828 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert) | 5278 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert) |
5829 (cons 'vip-re-search vip-re-search))) | 5279 (cons 'vip-re-search vip-re-search))) |
5830 | 5280 |
5831 | 5281 |
5832 (vip-set-minibuffer-style) | 5282 (vip-set-minibuffer-style) |
5833 (vip-set-minibuffer-faces) | |
5834 (vip-set-search-face) | |
5835 (vip-set-replace-overlay-face) | |
5836 (if vip-buffer-search-char | 5283 (if vip-buffer-search-char |
5837 (vip-buffer-search-enable)) | 5284 (vip-buffer-search-enable)) |
5838 (vip-update-alphanumeric-class) | 5285 (vip-update-alphanumeric-class) |
5839 | 5286 |
5840 ;;; Familiarize Viper with some minor modes that have their own keymaps | 5287 ;;; Familiarize Viper with some minor modes that have their own keymaps |
5883 )) | 5330 )) |
5884 | 5331 |
5885 | 5332 |
5886 (run-hooks 'vip-load-hook) ; the last chance to change something | 5333 (run-hooks 'vip-load-hook) ; the last chance to change something |
5887 | 5334 |
5888 (provide 'viper) | |
5889 (provide 'vip19) | 5335 (provide 'vip19) |
5890 (provide 'vip) | 5336 (provide 'vip) |
5891 | 5337 |
5892 ;;; viper.el ends here | 5338 ;;; viper.el ends here |