Mercurial > hg > xemacs-beta
comparison lisp/viper/viper.el @ 16:0293115a14e9 r19-15b91
Import from CVS: tag r19-15b91
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:49:20 +0200 |
parents | 9ee227acff29 |
children | 4103f0995bd7 |
comparison
equal
deleted
inserted
replaced
15:ad457d5f7d04 | 16:0293115a14e9 |
---|---|
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.92 of January 3, 1997" | 11 (defconst viper-version "2.92 of January 10, 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 |
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) | 312 (defvar mark-even-if-inactive) |
313 | 313 |
314 (eval-when-compile | 314 (eval-when-compile |
315 (let ((load-path (cons "." load-path))) | 315 (let ((load-path (cons (expand-file-name ".") load-path))) |
316 (or (featurep 'viper-util) | 316 (or (featurep 'viper-util) |
317 (load "viper-util.el" nil nil 'nosuffix)) | 317 (load "viper-util.el" nil nil 'nosuffix)) |
318 (or (featurep 'viper-keym) | 318 (or (featurep 'viper-keym) |
319 (load "viper-keym.el" nil nil 'nosuffix)) | 319 (load "viper-keym.el" nil nil 'nosuffix)) |
320 (or (featurep 'viper-mous) | 320 (or (featurep 'viper-mous) |
324 (or (featurep 'viper-ex) | 324 (or (featurep 'viper-ex) |
325 (load "viper-ex.el" nil nil 'nosuffix)) | 325 (load "viper-ex.el" nil nil 'nosuffix)) |
326 )) | 326 )) |
327 ;; end pacifier | 327 ;; end pacifier |
328 | 328 |
329 | |
329 (require 'viper-util) | 330 (require 'viper-util) |
330 (require 'viper-keym) | 331 (require 'viper-keym) |
331 (require 'viper-mous) | 332 (require 'viper-mous) |
332 (require 'viper-macs) | 333 (require 'viper-macs) |
333 (require 'viper-ex) | 334 (require 'viper-ex) |
334 | 335 |
335 | 336 |
336 | 337 |
337 ;;; Variables | |
338 | |
339 ;; Is t until viper-mode executes for the very first time. | |
340 ;; Prevents recursive descend into startup messages. | |
341 (defvar vip-first-time t) | |
342 | |
343 (defvar vip-expert-level 0 | |
344 "User's expert level. | |
345 The minor mode vip-vi-diehard-minor-mode is in effect when | |
346 vip-expert-level is 1 or 2 or when vip-want-emacs-keys-in-vi is t. | |
347 The minor mode vip-insert-diehard-minor-mode is in effect when | |
348 vip-expert-level is 1 or 2 or if vip-want-emacs-keys-in-insert is t. | |
349 Use `M-x vip-set-expert-level' to change this.") | |
350 | |
351 ;; Max expert level supported by Viper. This is NOT a user option. | |
352 ;; It is here to make it hard for the user from resetting it. | |
353 (defconst vip-max-expert-level 5) | |
354 | |
355 ;; Contains user settings for vars affected by vip-set-expert-level function. | |
356 ;; Not a user option. | |
357 (defvar vip-saved-user-settings nil) | |
358 | |
359 | |
360 ;;; ISO characters | |
361 | |
362 (vip-deflocalvar vip-automatic-iso-accents nil | |
363 "*If non-nil, ISO accents will be turned on in insert/replace emacs states and turned off in vi-state. | |
364 For some users, this behavior may be too primitive. In this case, use | |
365 insert/emacs/vi state hooks.") | |
366 | |
367 | |
368 ;; VI-style Undo | |
369 | |
370 ;; Used to 'undo' complex commands, such as replace and insert commands. | |
371 (vip-deflocalvar vip-undo-needs-adjustment nil) | |
372 (put 'vip-undo-needs-adjustment 'permanent-local t) | |
373 | |
374 ;; A mark that Viper puts on buffer-undo-list. Marks the beginning of a | |
375 ;; complex command that must be undone atomically. If inserted, it is | |
376 ;; erased by vip-change-state-to-vi and vip-repeat. | |
377 (defconst vip-buffer-undo-list-mark 'viper) | |
378 | |
379 (defvar vip-keep-point-on-undo nil | |
380 "*Non-nil means not to move point while undoing commands. | |
381 This style is different from Emacs and Vi. Try it to see if | |
382 it better fits your working style.") | |
383 | |
384 ;; Replace mode and changing text | |
385 | |
386 ;; Viper's own after/before change functions, which get vip-add-hook'ed to | |
387 ;; Emacs's | |
388 (vip-deflocalvar vip-after-change-functions nil "") | |
389 (vip-deflocalvar vip-before-change-functions nil "") | |
390 (vip-deflocalvar vip-post-command-hooks nil "") | |
391 (vip-deflocalvar vip-pre-command-hooks nil "") | |
392 | |
393 ;; Can be used to pass global states around for short period of time | |
394 (vip-deflocalvar vip-intermediate-command nil "") | |
395 | |
396 ;; Indicates that the current destructive command has started in replace mode. | |
397 (vip-deflocalvar vip-began-as-replace nil "") | |
398 | |
399 (defvar vip-replace-overlay-cursor-color "Red" | |
400 "*Cursor color to use in Replace state") | |
401 (defvar vip-insert-state-cursor-color nil | |
402 "Cursor color for Viper insert state.") | |
403 (put 'vip-insert-state-cursor-color 'permanent-local t) | |
404 ;; place to save cursor colow when switching to insert mode | |
405 (vip-deflocalvar vip-saved-cursor-color nil "") | |
406 | |
407 (vip-deflocalvar vip-replace-overlay nil "") | |
408 (put 'vip-replace-overlay 'permanent-local t) | |
409 | |
410 (defvar vip-replace-overlay-pixmap "gray3" | |
411 "Pixmap to use for search face on non-color displays.") | |
412 (defvar vip-search-face-pixmap "gray3" | |
413 "Pixmap to use for search face on non-color displays.") | |
414 | |
415 | |
416 (defun vip-set-replace-overlay-face () | |
417 (if (vip-has-face-support-p) | |
418 (defvar vip-replace-overlay-face | |
419 (progn | |
420 (make-face 'vip-replace-overlay-face) | |
421 (vip-hide-face 'vip-replace-overlay-face) | |
422 (or (face-differs-from-default-p 'vip-replace-overlay-face) | |
423 (progn | |
424 (if (vip-can-use-colors "darkseagreen2" "Black") | |
425 (progn | |
426 (set-face-background | |
427 'vip-replace-overlay-face "darkseagreen2") | |
428 (set-face-foreground 'vip-replace-overlay-face "Black"))) | |
429 (set-face-underline-p 'vip-replace-overlay-face t) | |
430 (vip-set-face-pixmap | |
431 'vip-replace-overlay-face vip-replace-overlay-pixmap))) | |
432 'vip-replace-overlay-face) | |
433 "*Face for highlighting replace regions on a window display.") | |
434 )) | |
435 | |
436 (defvar vip-replace-region-end-delimiter "$" | |
437 "A string marking the end of replacement regions. | |
438 It is used only with TTYs or if `vip-use-replace-region-delimiters' | |
439 is non-nil.") | |
440 (defvar vip-replace-region-start-delimiter "" | |
441 "A string marking the beginning of replacement regions. | |
442 It is used only with TTYs or if `vip-use-replace-region-delimiters' | |
443 is non-nil.") | |
444 (defvar vip-use-replace-region-delimiters (not (vip-has-face-support-p)) | |
445 "*If non-nil, Viper will always use `vip-replace-region-end-delimiter' and | |
446 `vip-replace-region-start-delimiter' to delimit replacement regions, even on | |
447 color displays. By default, the delimiters are used only on TTYs.") | |
448 | |
449 ;; XEmacs requires glyphs | |
450 (if vip-xemacs-p | |
451 (progn | |
452 (or (glyphp vip-replace-region-end-delimiter) | |
453 (setq vip-replace-region-end-delimiter | |
454 (make-glyph vip-replace-region-end-delimiter))) | |
455 (or (glyphp vip-replace-region-start-delimiter) | |
456 (setq vip-replace-region-start-delimiter | |
457 (make-glyph vip-replace-region-start-delimiter))) | |
458 )) | |
459 | |
460 | |
461 ;; These are local marker that must be initialized to nil and moved with | |
462 ;; `vip-move-marker-locally' | |
463 ;; | |
464 ;; Remember the last position inside the replace region. | |
465 (vip-deflocalvar vip-last-posn-in-replace-region nil) | |
466 ;; Remember the last position while inserting | |
467 (vip-deflocalvar vip-last-posn-while-in-insert-state nil) | |
468 (put 'vip-last-posn-in-replace-region 'permanent-local t) | |
469 (put 'vip-last-posn-while-in-insert-state 'permanent-local t) | |
470 | |
471 (vip-deflocalvar vip-sitting-in-replace nil "") | |
472 (put 'vip-sitting-in-replace 'permanent-local t) | |
473 | |
474 ;; Remember the number of characters that have to be deleted in replace | |
475 ;; mode to compensate for the inserted characters. | |
476 (vip-deflocalvar vip-replace-chars-to-delete 0 "") | |
477 (vip-deflocalvar vip-replace-chars-deleted 0 "") | |
478 | |
479 ;; Insertion ring and command ring | |
480 (defvar vip-insertion-ring-size 14 | |
481 "The size of the insertion ring.") | |
482 ;; The insertion ring. | |
483 (defvar vip-insertion-ring nil) | |
484 ;; This is temp insertion ring. Used to do rotation for display purposes. | |
485 ;; When rotation just started, it is initialized to vip-insertion-ring. | |
486 (defvar vip-temp-insertion-ring nil) | |
487 (defvar vip-last-inserted-string-from-insertion-ring "") | |
488 | |
489 (defvar vip-command-ring-size 14 | |
490 "The size of the command ring.") | |
491 ;; The command ring. | |
492 (defvar vip-command-ring nil) | |
493 ;; This is temp command ring. Used to do rotation for display purposes. | |
494 ;; When rotation just started, it is initialized to vip-command-ring. | |
495 (defvar vip-temp-command-ring nil) | |
496 | |
497 ;; Modes and related variables | |
498 | |
499 ;; Current mode. One of: `emacs-state', `vi-state', `insert-state' | |
500 (vip-deflocalvar vip-current-state 'emacs-state) | |
501 | |
502 | |
503 ;; Autoindent in insert | |
504 | |
505 ;; Variable that keeps track of whether C-t has been pressed. | |
506 (vip-deflocalvar vip-cted nil "") | |
507 | |
508 ;; Preserve the indent value, used by C-d in insert mode. | |
509 (vip-deflocalvar vip-current-indent 0) | |
510 | |
511 ;; Whether to preserve the indent, used by C-d in insert mode. | |
512 (vip-deflocalvar vip-preserve-indent nil) | |
513 | |
514 (vip-deflocalvar vip-auto-indent nil | |
515 "*Autoindent if t.") | |
516 (vip-deflocalvar vip-electric-mode t | |
517 "*If t, enable electric behavior. | |
518 Currently only enables auto-indentation `according to mode'.") | |
519 | |
520 (defconst vip-shift-width 8 | |
521 "*The shiftwidth variable.") | |
522 | |
523 ;; Variables for repeating destructive commands | |
524 | |
525 (defconst vip-keep-point-on-repeat t | |
526 "*If t, don't move point when repeating previous command. | |
527 This is useful for doing repeated changes with the '.' key. | |
528 The user can change this to nil, if she likes when the cursor moves | |
529 to a new place after repeating previous Vi command.") | |
530 | |
531 ;; Remember insert point as a marker. This is a local marker that must be | |
532 ;; initialized to nil and moved with `vip-move-marker-locally'. | |
533 (vip-deflocalvar vip-insert-point nil) | |
534 (put 'vip-insert-point 'permanent-local t) | |
535 | |
536 ;; This remembers the point before dabbrev-expand was called. | |
537 ;; If vip-insert-point turns out to be bigger than that, it is reset | |
538 ;; back to vip-pre-command-point. | |
539 ;; The reason this is needed is because dabbrev-expand (and possibly | |
540 ;; others) may jump to before the insertion point, delete something and | |
541 ;; then reinsert a bigger piece. For instance: bla^blo | |
542 ;; If dabbrev-expand is called after `blo' and ^ undicates vip-insert-point, | |
543 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo' | |
544 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand | |
545 ;; will insert the expansion, and we get: blablo^ | |
546 ;; Whatever we insert next goes before the ^, i.e., before the | |
547 ;; vip-insert-point marker. So, Viper will think that nothing was | |
548 ;; inserted. Remembering the orig position of the marker circumvents the | |
549 ;; problem. | |
550 ;; We don't know of any command, except dabbrev-expand, that has the same | |
551 ;; problem. However, the same trick can be used if such a command is | |
552 ;; discovered later. | |
553 ;; | |
554 (vip-deflocalvar vip-pre-command-point nil) | |
555 (put 'vip-pre-command-point 'permanent-local t) ; this is probably an overkill | |
556 | |
557 ;; This is used for saving inserted text. | |
558 (defvar vip-last-insertion nil) | |
559 | |
560 ;; Remembers the last replaced region. | |
561 (defvar vip-last-replace-region "") | |
562 | |
563 ;; Remember com point as a marker. | |
564 ;; This is a local marker. Should be moved with `vip-move-marker-locally' | |
565 (vip-deflocalvar vip-com-point nil) | |
566 | |
567 ;; If non-nil, the value is a list (M-COM VAL COM REG inserted-text cmd-keys) | |
568 ;; It is used to re-execute last destructive command. | |
569 ;; M-COM is a Lisp symbol representing the function to be executed. | |
570 ;; VAL is the prefix argument that was used with that command. | |
571 ;; COM is an internal descriptor, such as ?r, ?c, ?C, which contains | |
572 ;; additional information on how the function in M-COM is to be handled. | |
573 ;; REG is the register used by command | |
574 ;; INSERTED-TEXT is text inserted by that command (in case of o, c, C, i, r | |
575 ;; commands). | |
576 ;; COMMAND-KEYS are the keys that were typed to invoke the command. | |
577 (defvar vip-d-com nil) | |
578 | |
579 ;; The character remembered by the Vi `r' command. | |
580 (defvar vip-d-char nil) | |
581 | |
582 ;; Name of register to store deleted or yanked strings | |
583 (defvar vip-use-register nil) | |
584 | |
585 | |
586 | |
587 ;; Variables for Moves and Searches | |
588 | |
589 ;; For use by `;' command. | |
590 (defvar vip-f-char nil) | |
591 | |
592 ;; For use by `.' command. | |
593 (defvar vip-F-char nil) | |
594 | |
595 ;; For use by `;' command. | |
596 (defvar vip-f-forward nil) | |
597 | |
598 ;; For use by `;' command. | |
599 (defvar vip-f-offset nil) | |
600 | |
601 ;; Last search string | |
602 (defvar vip-s-string "") | |
603 | |
604 (defvar vip-quote-string "> " | |
605 "String inserted at the beginning of quoted region.") | |
606 | |
607 ;; If t, search is forward. | |
608 (defvar vip-s-forward nil) | |
609 | |
610 (defconst vip-case-fold-search nil | |
611 "*If not nil, search ignores cases.") | |
612 | |
613 (defconst vip-re-search t | |
614 "*If not nil, search is reg-exp search, otherwise vanilla search.") | |
615 | |
616 (defvar vip-search-scroll-threshold 2 | |
617 "*If search lands within this threshnold from the window top/bottom, | |
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.") | |
621 | |
622 (defconst vip-re-query-replace t | |
623 "*If t then do regexp replace, if nil then do string replace.") | |
624 | |
625 (defconst vip-re-replace t | |
626 "*If t, do regexp replace. nil means do string replace.") | |
627 | |
628 (vip-deflocalvar vip-ex-style-motion t | |
629 "*Ex-style: the commands l,h do not cross lines, etc.") | |
630 | |
631 (vip-deflocalvar vip-ex-style-editing-in-insert t | |
632 "*The keys ^H, ^? don't jump lines in insert, ESC moves cursor back, etc. | |
633 Note: this doesn't preclude ^H and ^? from deleting characters by moving | |
634 past the insertion point. This is a feature, not a bug. ") | |
635 | |
636 (vip-deflocalvar vip-delete-backwards-in-replace nil | |
637 "*If t, DEL key will delete characters while moving the cursor backwards. | |
638 If nil, the cursor will move backwards without deleting anything.") | |
639 | |
640 (defconst vip-buffer-search-char nil | |
641 "*Key bound for buffer-searching.") | |
642 | |
643 (defconst vip-search-wrap-around-t t | |
644 "*If t, search wraps around.") | |
645 | |
646 (vip-deflocalvar vip-related-files-and-buffers-ring nil | |
647 "*Ring of file and buffer names that are considered to be related to the | |
648 current buffer. | |
649 These buffers can be cycled through via :R and :P commands.") | |
650 (put 'vip-related-files-and-buffers-ring 'permanent-local t) | |
651 | |
652 ;; Used to find out if we are done with searching the current buffer. | |
653 (vip-deflocalvar vip-local-search-start-marker nil) | |
654 ;; As above, but global | |
655 (defvar vip-search-start-marker (make-marker)) | |
656 | |
657 ;; the search overlay | |
658 (vip-deflocalvar vip-search-overlay nil) | |
659 | |
660 | |
661 (defvar vip-heading-start | |
662 (concat "^\\s-*(\\s-*defun\\s-\\|" ; lisp | |
663 "^{\\s-*$\\|^[_a-zA-Z][^()]*[()].*{\\s-*$\\|" ; C/C++ | |
664 "^\\s-*class.*{\\|^\\s-*struct.*{\\|^\\s-*enum.*{\\|" | |
665 "^\\\\[sb][a-z]*{.*}\\s-*$\\|" ; latex | |
666 "^@node\\|@table\\|^@m?enu\\|^@itemize\\|^@if\\|" ; texinfo | |
667 "^.+:-") ; prolog | |
668 "*Regexps for Headings. Used by \[\[ and \]\].") | |
669 | |
670 (defvar vip-heading-end | |
671 (concat "^}\\|" ; C/C++ | |
672 "^\\\\end{\\|" ; latex | |
673 "^@end \\|" ; texinfo | |
674 ")\n\n[ \t\n]*\\|" ; lisp | |
675 "\\.\\s-*$") ; prolog | |
676 "*Regexps to end Headings/Sections. Used by \[\].") | |
677 | |
678 | |
679 ;; These two vars control the interaction of jumps performed by ' and `. | |
680 ;; In this new version, '' doesn't erase the marks set by ``, so one can | |
681 ;; use both kinds of jumps interchangeably and without loosing positions | |
682 ;; inside the lines. | |
683 | |
684 ;; Remembers position of the last jump done using ``'. | |
685 (vip-deflocalvar vip-last-jump nil) | |
686 ;; Remembers position of the last jump done using `''. | |
687 (vip-deflocalvar vip-last-jump-ignore 0) | |
688 | |
689 ;; History variables | |
690 | |
691 ;; History of search strings. | |
692 (defvar vip-search-history (list "")) | |
693 ;; History of query-replace strings used as a source. | |
694 (defvar vip-replace1-history nil) | |
695 ;; History of query-replace strings used as replacement. | |
696 (defvar vip-replace2-history nil) | |
697 ;; History of region quoting strings. | |
698 (defvar vip-quote-region-history (list vip-quote-string)) | |
699 ;; History of Ex-style commands. | |
700 (defvar vip-ex-history nil) | |
701 ;; History of shell commands. | |
702 (defvar vip-shell-history nil) | |
703 | |
704 | |
705 ;; Last shell command. There are two of these, one for Ex (in viper-ex) | |
706 ;; and one for Vi. | |
707 | |
708 ;; Last shell command executed with ! command. | |
709 (defvar vip-last-shell-com nil) | |
710 | |
711 | |
712 | |
713 ;;; Miscellaneous | |
714 | |
715 ;; don't bark when mark is inactive | |
716 (setq mark-even-if-inactive t) | |
717 | |
718 (defvar vip-inhibit-startup-message nil | |
719 "Whether Viper startup message should be inhibited.") | |
720 | |
721 (defvar vip-always t | |
722 "t means, arrange that vi-state will be a default.") | |
723 | |
724 (defvar vip-custom-file-name (vip-convert-standard-file-name "~/.vip") | |
725 "Viper customisation file. | |
726 This variable must be set _before_ loading Viper.") | |
727 | |
728 | |
729 (defvar vip-spell-function 'ispell-region | |
730 "Spell function used by #s<move> command to spell.") | |
731 | |
732 (defvar vip-tags-file-name "TAGS" | |
733 "The tags file used by Viper.") | |
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 | |
739 ;; Minibuffer | |
740 | |
741 (defvar vip-vi-style-in-minibuffer t | |
742 "If t, use vi-style editing in minibuffer. | |
743 Should be set in `~/.vip' file.") | |
744 | |
745 ;; overlay used in the minibuffer to indicate which state it is in | |
746 (vip-deflocalvar vip-minibuffer-overlay nil) | |
747 | |
748 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer. | |
749 ;; Beginning with Emacs 19.26, the standard `minibuffer-exit-hook' is run | |
750 ;; *after* exiting the minibuffer | |
751 (defvar vip-minibuffer-exit-hook nil) | |
752 | |
753 ;; setup emacs-supported vi-style feel | |
754 (setq next-line-add-newlines nil | |
755 require-final-newline t) | |
756 | |
757 (make-variable-buffer-local 'require-final-newline) | |
758 | |
759 | |
760 ;; Mode line | |
761 (defconst vip-vi-state-id "<V> " | |
762 "Mode line tag identifying the Vi mode of Viper.") | |
763 (defconst vip-emacs-state-id "<E> " | |
764 "Mode line tag identifying the Emacs mode of Viper.") | |
765 (defconst vip-insert-state-id "<I> " | |
766 "Mode line tag identifying the Insert mode of Viper.") | |
767 (defconst vip-replace-state-id "<R> " | |
768 "Mode line tag identifying the Replace mode of Viper.") | |
769 | |
770 ;; Viper changes the default mode-line-buffer-identification | |
771 (setq-default mode-line-buffer-identification '(" %b")) | |
772 | |
773 ;; Variable displaying the current Viper state in the mode line. | |
774 (vip-deflocalvar vip-mode-string vip-emacs-state-id) | |
775 (or (memq 'vip-mode-string global-mode-string) | |
776 (setq global-mode-string | |
777 (append '("" vip-mode-string) (cdr global-mode-string)))) | |
778 | |
779 | |
780 (defvar vip-vi-state-hook nil | |
781 "*Hooks run just before the switch to Vi mode is completed.") | |
782 (defvar vip-insert-state-hook nil | |
783 "*Hooks run just before the switch to Insert mode is completed.") | |
784 (defvar vip-replace-state-hook nil | |
785 "*Hooks run just before the switch to Replace mode is completed.") | |
786 (defvar vip-emacs-state-hook nil | |
787 "*Hooks run just before the switch to Emacs mode is completed.") | |
788 | |
789 (defvar vip-load-hook nil | |
790 "Hooks run just after loading Viper.") | |
791 | |
792 | |
793 ;; Generic predicates | 338 ;; Generic predicates |
794 | 339 |
795 ;; 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 |
796 | 341 |
797 ;; generate test functions | 342 ;; generate test functions |
826 ) | 371 ) |
827 "Movement commands") | 372 "Movement commands") |
828 ;; define vip-movement-command-p | 373 ;; define vip-movement-command-p |
829 (vip-test-com-defun vip-movement-command) | 374 (vip-test-com-defun vip-movement-command) |
830 | 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 | |
831 ;; Commands that can be repeated by . (dotted) | 381 ;; Commands that can be repeated by . (dotted) |
832 (defconst vip-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<)) | 382 (defconst vip-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<)) |
833 ;; define vip-dotable-command-p | 383 ;; define vip-dotable-command-p |
834 (vip-test-com-defun vip-dotable-command) | 384 (vip-test-com-defun vip-dotable-command) |
835 | 385 |
842 (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)) |
843 ;; define vip-regsuffix-command-p | 393 ;; define vip-regsuffix-command-p |
844 (vip-test-com-defun vip-regsuffix-command) | 394 (vip-test-com-defun vip-regsuffix-command) |
845 | 395 |
846 (defconst vip-vi-commands (append vip-movement-commands | 396 (defconst vip-vi-commands (append vip-movement-commands |
397 vip-digit-commands | |
847 vip-dotable-commands | 398 vip-dotable-commands |
848 vip-charpair-commands | 399 vip-charpair-commands |
849 vip-hash-commands | 400 vip-hash-commands |
850 vip-prefix-commands | 401 vip-prefix-commands |
851 vip-regsuffix-commands) | 402 vip-regsuffix-commands) |
1488 (defun vip-exec-form-in-vi (form) | 1039 (defun vip-exec-form-in-vi (form) |
1489 "Execute FORM in Vi state, regardless of the Ccurrent Vi state." | 1040 "Execute FORM in Vi state, regardless of the Ccurrent Vi state." |
1490 (let ((buff (current-buffer)) | 1041 (let ((buff (current-buffer)) |
1491 result) | 1042 result) |
1492 (vip-set-mode-vars-for 'vi-state) | 1043 (vip-set-mode-vars-for 'vi-state) |
1493 (setq result (eval form)) | 1044 |
1045 (condition-case nil | |
1046 (setq result (eval form)) | |
1047 (error | |
1048 (signal 'quit nil))) | |
1049 | |
1494 (if (not (equal buff (current-buffer))) ; cmd switched buffer | 1050 (if (not (equal buff (current-buffer))) ; cmd switched buffer |
1495 (save-excursion | 1051 (save-excursion |
1496 (set-buffer buff) | 1052 (set-buffer buff) |
1497 (vip-set-mode-vars-for vip-current-state))) | 1053 (vip-set-mode-vars-for vip-current-state))) |
1498 (vip-set-mode-vars-for vip-current-state) | 1054 (vip-set-mode-vars-for vip-current-state) |
1706 ((eq vip-current-state 'replace-state) | 1262 ((eq vip-current-state 'replace-state) |
1707 'vip-replace-state-exit-cmd) | 1263 'vip-replace-state-exit-cmd) |
1708 (t 'vip-change-state-to-vi) | 1264 (t 'vip-change-state-to-vi) |
1709 ))) | 1265 ))) |
1710 (call-interactively cmd))) | 1266 (call-interactively cmd))) |
1267 | |
1711 | 1268 |
1712 | 1269 |
1713 | 1270 |
1714 ;; prefix argument for Vi mode | 1271 ;; prefix argument for Vi mode |
1715 | 1272 |
1836 (while (= char ?U) | 1393 (while (= char ?U) |
1837 (vip-describe-arg cmd-info) | 1394 (vip-describe-arg cmd-info) |
1838 (setq char (read-char))) | 1395 (setq char (read-char))) |
1839 ;; `char' is a movement command or a digit arg command---so we execute | 1396 ;; `char' is a movement command or a digit arg command---so we execute |
1840 ;; it at the very end | 1397 ;; it at the very end |
1398 (or (vip-movement-command-p char) | |
1399 (vip-digit-command-p char) | |
1400 (error "")) | |
1841 (setq mv-or-digit-cmd | 1401 (setq mv-or-digit-cmd |
1842 (vip-exec-form-in-vi | 1402 (vip-exec-form-in-vi |
1843 (` (key-binding (char-to-string (, char))))))) | 1403 (` (key-binding (char-to-string (, char))))))) |
1844 | 1404 |
1845 ;; as com is non-nil, this means that we have a command to execute | 1405 ;; as com is non-nil, this means that we have a command to execute |
1868 (progn | 1428 (progn |
1869 (setq last-command-char char) | 1429 (setq last-command-char char) |
1870 (setq last-command-event | 1430 (setq last-command-event |
1871 (vip-copy-event | 1431 (vip-copy-event |
1872 (if vip-xemacs-p (character-to-event char) char))) | 1432 (if vip-xemacs-p (character-to-event char) char))) |
1873 (funcall mv-or-digit-cmd cmd-info))) | 1433 (condition-case nil |
1434 (funcall mv-or-digit-cmd cmd-info) | |
1435 (error | |
1436 (error ""))))) | |
1874 )) | 1437 )) |
1875 | 1438 |
1876 (defun vip-describe-arg (arg) | 1439 (defun vip-describe-arg (arg) |
1877 (let (val com) | 1440 (let (val com) |
1878 (setq val (vip-P-val arg) | 1441 (setq val (vip-P-val arg) |
2535 (let (command) | 2098 (let (command) |
2536 (setq command (local-key-binding (char-to-string last-command-char))) | 2099 (setq command (local-key-binding (char-to-string last-command-char))) |
2537 (if command | 2100 (if command |
2538 (command-execute command) | 2101 (command-execute command) |
2539 (exit-minibuffer)))) | 2102 (exit-minibuffer)))) |
2540 | |
2541 | |
2542 (defun vip-set-search-face () | |
2543 (if (vip-has-face-support-p) | |
2544 (defvar vip-search-face | |
2545 (progn | |
2546 (make-face 'vip-search-face) | |
2547 (vip-hide-face 'vip-search-face) | |
2548 (or (face-differs-from-default-p 'vip-search-face) | |
2549 ;; face wasn't set in .vip or .Xdefaults | |
2550 (if (vip-can-use-colors "Black" "khaki") | |
2551 (progn | |
2552 (set-face-background 'vip-search-face "khaki") | |
2553 (set-face-foreground 'vip-search-face "Black")) | |
2554 (set-face-underline-p 'vip-search-face t) | |
2555 (vip-set-face-pixmap 'vip-search-face vip-search-face-pixmap))) | |
2556 'vip-search-face) | |
2557 "*Face used to flash out the search pattern.") | |
2558 )) | |
2559 | |
2560 | |
2561 (defun vip-set-minibuffer-faces () | |
2562 (if (not (vip-has-face-support-p)) | |
2563 () | |
2564 (defvar vip-minibuffer-emacs-face | |
2565 (progn | |
2566 (make-face 'vip-minibuffer-emacs-face) | |
2567 (vip-hide-face 'vip-minibuffer-emacs-face) | |
2568 (or (face-differs-from-default-p 'vip-minibuffer-emacs-face) | |
2569 ;; face wasn't set in .vip or .Xdefaults | |
2570 (if vip-vi-style-in-minibuffer | |
2571 ;; emacs state is an exception in the minibuffer | |
2572 (if (vip-can-use-colors "darkseagreen2" "Black") | |
2573 (progn | |
2574 (set-face-background | |
2575 'vip-minibuffer-emacs-face "darkseagreen2") | |
2576 (set-face-foreground | |
2577 'vip-minibuffer-emacs-face "Black")) | |
2578 (copy-face 'modeline 'vip-minibuffer-emacs-face)) | |
2579 ;; emacs state is the main state in the minibuffer | |
2580 (if (vip-can-use-colors "Black" "pink") | |
2581 (progn | |
2582 (set-face-background 'vip-minibuffer-emacs-face "pink") | |
2583 (set-face-foreground | |
2584 'vip-minibuffer-emacs-face "Black")) | |
2585 (copy-face 'italic 'vip-minibuffer-emacs-face)) | |
2586 )) | |
2587 'vip-minibuffer-emacs-face) | |
2588 "Face used in the Minibuffer when it is in Emacs state.") | |
2589 | |
2590 (defvar vip-minibuffer-insert-face | |
2591 (progn | |
2592 (make-face 'vip-minibuffer-insert-face) | |
2593 (vip-hide-face 'vip-minibuffer-insert-face) | |
2594 (or (face-differs-from-default-p 'vip-minibuffer-insert-face) | |
2595 (if vip-vi-style-in-minibuffer | |
2596 (if (vip-can-use-colors "Black" "pink") | |
2597 (progn | |
2598 (set-face-background 'vip-minibuffer-insert-face "pink") | |
2599 (set-face-foreground | |
2600 'vip-minibuffer-insert-face "Black")) | |
2601 (copy-face 'italic 'vip-minibuffer-insert-face)) | |
2602 ;; If Insert state is an exception | |
2603 (if (vip-can-use-colors "darkseagreen2" "Black") | |
2604 (progn | |
2605 (set-face-background | |
2606 'vip-minibuffer-insert-face "darkseagreen2") | |
2607 (set-face-foreground | |
2608 'vip-minibuffer-insert-face "Black")) | |
2609 (copy-face 'modeline 'vip-minibuffer-insert-face)) | |
2610 (vip-italicize-face 'vip-minibuffer-insert-face))) | |
2611 'vip-minibuffer-insert-face) | |
2612 "Face used in the Minibuffer when it is in Insert state.") | |
2613 | |
2614 (defvar vip-minibuffer-vi-face | |
2615 (progn | |
2616 (make-face 'vip-minibuffer-vi-face) | |
2617 (vip-hide-face 'vip-minibuffer-vi-face) | |
2618 (or (face-differs-from-default-p 'vip-minibuffer-vi-face) | |
2619 (if vip-vi-style-in-minibuffer | |
2620 (if (vip-can-use-colors "Black" "grey") | |
2621 (progn | |
2622 (set-face-background 'vip-minibuffer-vi-face "grey") | |
2623 (set-face-foreground 'vip-minibuffer-vi-face "Black")) | |
2624 (copy-face 'bold 'vip-minibuffer-vi-face)) | |
2625 (copy-face 'bold 'vip-minibuffer-vi-face) | |
2626 (invert-face 'vip-minibuffer-vi-face))) | |
2627 'vip-minibuffer-vi-face) | |
2628 "Face used in the Minibuffer when it is in Vi state.") | |
2629 | |
2630 ;; the current face used in the minibuffer | |
2631 (vip-deflocalvar vip-minibuffer-current-face vip-minibuffer-emacs-face "") | |
2632 )) | |
2633 | |
2634 | 2103 |
2635 | 2104 |
2636 ;;; Reading string with history | 2105 ;;; Reading string with history |
2637 | 2106 |
2638 (defun vip-read-string-with-history (prompt &optional initial | 2107 (defun vip-read-string-with-history (prompt &optional initial |
2871 (vip-replace-start)) | 2340 (vip-replace-start)) |
2872 (vip-add-hook | 2341 (vip-add-hook |
2873 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t) | 2342 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t) |
2874 (vip-add-hook | 2343 (vip-add-hook |
2875 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) | 2344 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
2345 ;; guard against a smartie who switched from R-replace to normal replace | |
2346 (vip-remove-hook | |
2347 'vip-post-command-hooks 'vip-R-state-post-command-sentinel) | |
2348 (if overwrite-mode (overwrite-mode nil)) | |
2876 ) | 2349 ) |
2877 | 2350 |
2878 | 2351 |
2879 ;; checks how many chars were deleted by the last change | 2352 ;; checks how many chars were deleted by the last change |
2880 (defun vip-replace-mode-spy-before (beg end) | 2353 (defun vip-replace-mode-spy-before (beg end) |
2946 (or (marker-position vip-last-posn-in-replace-region) | 2419 (or (marker-position vip-last-posn-in-replace-region) |
2947 (vip-replace-start)) | 2420 (vip-replace-start)) |
2948 )) | 2421 )) |
2949 | 2422 |
2950 (setq vip-replace-chars-to-delete | 2423 (setq vip-replace-chars-to-delete |
2951 (max 0 (min vip-replace-chars-to-delete | 2424 (max 0 |
2952 (- (vip-replace-end) | 2425 (min vip-replace-chars-to-delete |
2953 vip-last-posn-in-replace-region)))) | 2426 (- (vip-replace-end) vip-last-posn-in-replace-region) |
2427 (- (vip-line-pos 'end) vip-last-posn-in-replace-region) | |
2428 ))) | |
2954 ))) | 2429 ))) |
2955 | 2430 |
2956 | 2431 |
2957 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if | 2432 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if |
2958 ;; posn is within the overlay. | 2433 ;; posn is within the overlay. |
3000 (overwrite-mode 1) | 2475 (overwrite-mode 1) |
3001 (vip-add-hook | 2476 (vip-add-hook |
3002 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t) | 2477 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t) |
3003 (vip-add-hook | 2478 (vip-add-hook |
3004 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) | 2479 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
2480 ;; guard against a smartie who switched from R-replace to normal replace | |
2481 (vip-remove-hook | |
2482 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel) | |
3005 ) | 2483 ) |
3006 | 2484 |
3007 | 2485 |
3008 | 2486 |
3009 (defun vip-replace-state-exit-cmd () | 2487 (defun vip-replace-state-exit-cmd () |
3023 (command-execute com) | 2501 (command-execute com) |
3024 (error | 2502 (error |
3025 (vip-message-conditions conds))) | 2503 (vip-message-conditions conds))) |
3026 ) | 2504 ) |
3027 (vip-hide-replace-overlay)) | 2505 (vip-hide-replace-overlay)) |
2506 | |
2507 (defun vip-replace-state-carriage-return () | |
2508 "Implements carriage return in Viper replace state." | |
2509 (interactive) | |
2510 ;; If Emacs start supporting overlay maps, as it currently supports | |
2511 ;; text-property maps, we could do away with vip-replace-minor-mode and | |
2512 ;; just have keymap attached to replace overlay. Then the "if part" of this | |
2513 ;; statement can be deleted. | |
2514 (if (or (< (point) (vip-replace-start)) | |
2515 (> (point) (vip-replace-end))) | |
2516 (let (vip-replace-minor-mode com) | |
2517 (vip-set-unread-command-events last-input-char) | |
2518 (setq com (key-binding (read-key-sequence nil))) | |
2519 (condition-case conds | |
2520 (command-execute com) | |
2521 (error | |
2522 (vip-message-conditions conds)))) | |
2523 (if (not vip-allow-multiline-replace-regions) | |
2524 (vip-replace-state-exit-cmd) | |
2525 (if (vip-same-line (point) (vip-replace-end)) | |
2526 (vip-replace-state-exit-cmd) | |
2527 (vip-kill-line nil) | |
2528 (vip-next-line-at-bol nil))))) | |
3028 | 2529 |
3029 | 2530 |
3030 ;; This is the function bound to 'R'---unlimited replace. | 2531 ;; This is the function bound to 'R'---unlimited replace. |
3031 ;; Similar to Emacs's own overwrite-mode. | 2532 ;; Similar to Emacs's own overwrite-mode. |
3032 (defun vip-overwrite (arg) | 2533 (defun vip-overwrite (arg) |
4631 (vip-replace-end))) | 4132 (vip-replace-end))) |
4632 | 4133 |
4633 ;; protect against error while inserting "@" and other disasters | 4134 ;; protect against error while inserting "@" and other disasters |
4634 ;; (e.g., read-only buff) | 4135 ;; (e.g., read-only buff) |
4635 (condition-case conds | 4136 (condition-case conds |
4636 (if (vip-same-line (vip-replace-start) | 4137 (if (or vip-allow-multiline-replace-regions |
4637 (vip-replace-end)) | 4138 (vip-same-line (vip-replace-start) |
4139 (vip-replace-end))) | |
4638 (progn | 4140 (progn |
4639 ;; tabs cause problems in replace, so untabify | 4141 ;; tabs cause problems in replace, so untabify |
4640 (goto-char (vip-replace-end)) | 4142 (goto-char (vip-replace-end)) |
4641 (insert-before-markers "@") ; put placeholder after the TAB | 4143 (insert-before-markers "@") ; put placeholder after the TAB |
4642 (untabify (vip-replace-start) (point)) | 4144 (untabify (vip-replace-start) (point)) |
5731 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert) | 5233 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert) |
5732 (cons 'vip-re-search vip-re-search))) | 5234 (cons 'vip-re-search vip-re-search))) |
5733 | 5235 |
5734 | 5236 |
5735 (vip-set-minibuffer-style) | 5237 (vip-set-minibuffer-style) |
5736 (vip-set-minibuffer-faces) | |
5737 (vip-set-search-face) | |
5738 (vip-set-replace-overlay-face) | |
5739 (if vip-buffer-search-char | 5238 (if vip-buffer-search-char |
5740 (vip-buffer-search-enable)) | 5239 (vip-buffer-search-enable)) |
5741 (vip-update-alphanumeric-class) | 5240 (vip-update-alphanumeric-class) |
5742 | 5241 |
5743 ;;; Familiarize Viper with some minor modes that have their own keymaps | 5242 ;;; Familiarize Viper with some minor modes that have their own keymaps |