home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1078 < prev    next >
Internet Message Format  |  1990-12-28  |  52KB

  1. From: djs@nimbus3.uucp (Doug)
  2. Newsgroups: comp.editors,gnu.emacs,comp.emacs,alt.sources
  3. Subject: Yet another vi emulator for GNU emacs (part 2 of 3)
  4. Message-ID: <1990Mar27.233258.6339@nimbus3.uucp>
  5. Date: 27 Mar 90 23:32:58 GMT
  6.  
  7.  
  8. # This is a shell archive.  Remove anything before this line, then
  9. # unpack it by saving it in a file and typing "sh file".  (Files
  10. # unpacked will be owned by you and have default permissions.)
  11. #
  12. # This archive contains:
  13. # mvi.el.1
  14.  
  15. echo x - mvi.el.1
  16. cat > "mvi.el.1" << '//E*O*F mvi.el.1//'
  17. ;; MVI: A VI Package for GNU Emacs (Version 1.0 March 26, 1990)
  18. ;; Copyright (C) 1990 Doug Scofea
  19. ;; Author: Doug Scofea -- nimbus3!djs@osu-cis.ohio-state.edu
  20. ;; or                     osu-cis!nimbus3!djs
  21.  
  22. ;; Send suggestions and bug reports to the above address.
  23. ;; When you report a bug, be sure to include the version number of MVI and
  24. ;; Emacs you are using.
  25.  
  26. ;; MVI is distributed in the hope that it will be useful,
  27. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  28. ;; accepts responsibility to anyone for the consequences of using it
  29. ;; or for whether it serves any particular purpose or works at all,
  30. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  31. ;; License for full details.
  32.  
  33. ;; Everyone is granted permission to copy, modify and redistribute
  34. ;; MVI, but only under the conditions described in the
  35. ;; GNU Emacs General Public License.   A copy of this license is
  36. ;; supposed to have been given to you along with GNU Emacs so you
  37. ;; can know your rights and responsibilities.  It should be in a
  38. ;; file named COPYING.  Among other things, the copyright notice
  39. ;; and this notice must be preserved on all copies.
  40.  
  41.  
  42. ;; external variables
  43.  
  44. (defvar mvi-commands (make-vector 128 nil)
  45.     "Hold function definitions for commands")
  46.  
  47. (defvar mvi-insert-args nil
  48.   "Hold a complete list of arguments for insert mode.")
  49. (make-variable-buffer-local 'mvi-insert-args)
  50.  
  51. (defvar mvi-last-inserted-text ""
  52.   "Hold a the last inserted text.")
  53.  
  54. (defconst mvi-com-ring-max 32
  55.     "Number of commands kept on mvi-com-ring")
  56.  
  57. (defvar mvi-com-ring-point 32768
  58.     "Point to the last executed mvi command, start arbitrarily high since
  59. the indexing is really done modulo")
  60.  
  61. (defvar mvi-com-ring (make-vector mvi-com-ring-max nil)
  62.     "Hold previous mvi commands in an array.  The elements are: number;
  63. register; register append, not meaningful if register is nil; g-flag; command; 
  64. motion; motion argument; and text")
  65.  
  66. (defconst mvi-doc-string "*User saved command"
  67.     "Doc string entered for all saved commands.")
  68.  
  69. (defvar mvi-search-string ""
  70.     "*Saved search string.")
  71.  
  72. (defvar mvi-ai t
  73.     "*When t, Auto-indent is performed")
  74. (make-variable-buffer-local 'mvi-ai)
  75.  
  76. (defvar mvi-magic t
  77.     "*When t, searches are regular expressions")
  78. (make-variable-buffer-local 'mvi-magic)
  79.  
  80. (defvar mvi-wrap t
  81.     "*When t, searches wrap around when the end of the buffer is reached.
  82. If a wrap occurs, a command is cancelled but the motion occurs")
  83. (make-variable-buffer-local 'mvi-wrap)
  84.  
  85. (defvar search-skip-fold nil
  86.     "*When t, folded text is skipped on searches.")
  87. (make-variable-buffer-local 'search-skip-fold)
  88.  
  89. (make-variable-buffer-local 'mvi-search-func)
  90. (setq-default mvi-search-func '(lambda ()))
  91.  
  92. (defvar mvi-shell-string ""
  93.     "*Initial string to be used by shell commands")
  94.  
  95. (defvar mvi-emacs-local-map nil
  96.   "Local map used in emacs mode. \(buffer specific\)")
  97. (make-variable-buffer-local 'mvi-emacs-local-map)
  98.  
  99. (defvar mvi-insert-local-map nil
  100.   "Local map used in insert command mode. \(buffer specific\)")
  101. (make-variable-buffer-local 'mvi-insert-local-map)
  102.  
  103. (defvar mvi-mode-map nil
  104.   "Vi mode map used in command mode. \(buffer specific\)")
  105. (make-variable-buffer-local 'mvi-mode-map)
  106.  
  107. (make-variable-buffer-local 'mvi-com-point)
  108. (setq-default mvi-com-point nil)
  109.  
  110. (make-variable-buffer-local 'mvi-g-point)
  111. (setq-default mvi-g-point nil)
  112.  
  113. (defvar mvi-put-number 1
  114.   "Remember number of puts done. \(buffer specific\)")
  115. (make-variable-buffer-local 'mvi-put-number)
  116.  
  117. (make-variable-buffer-local 'mvi-put-point)
  118. (setq-default mvi-put-point nil)
  119.  
  120. (make-variable-buffer-local 'mvi-put-start)
  121. (setq-default mvi-put-start nil)
  122.  
  123. (make-variable-buffer-local 'mvi-put-end)
  124. (setq-default mvi-put-end nil)
  125.  
  126. (defvar mvi-mlbi nil
  127.   "value of mode-line-buffer-identification in emacs-mode.")
  128. (make-variable-buffer-local 'mvi-mlbi)
  129. (setq-default mvi-mlbi '("Emacs: %17b"))
  130.  
  131. (aset mvi-commands ?c (function (lambda ()
  132.     (mvi-copy-region-as-kill mvi-com-point (point))
  133.     (delete-region mvi-com-point (point))
  134.     (mvi-do-insert motion))))
  135.  
  136. (aset mvi-commands ?d (function (lambda ()
  137.     (mvi-copy-region-as-kill mvi-com-point (point))
  138.     (delete-region mvi-com-point (point)))))
  139.  
  140. (aset mvi-commands ?K (function (lambda ()
  141.     (and (eq this-command 'mvi-repeat) 
  142.         (or (eq last-command 'mvi-repeat) (eq last-command 'kill-region))
  143.             (setq last-command 'kill-region))
  144.     (copy-region-as-kill mvi-com-point (point))
  145.     (delete-region mvi-com-point (point)))))
  146.  
  147. (aset mvi-commands ?\C-k (function (lambda ()
  148.     (and (eq this-command 'mvi-repeat) 
  149.         (or (eq last-command 'mvi-repeat) (eq last-command 'kill-region))
  150.             (setq last-command 'kill-region))
  151.     (copy-region-as-kill mvi-com-point (point)))))
  152.  
  153. (aset mvi-commands ?y (function (lambda ()
  154.     (mvi-copy-region-as-kill mvi-com-point (point))
  155.     (if (or (pos-visible-in-window-p) g-flag)
  156.         (let ((tmp (marker-position mvi-g-point)))
  157.             (move-marker mvi-g-point (point))
  158.             (goto-char tmp))))))
  159.  
  160. (aset mvi-commands ?> (function (lambda ()
  161.     (mvi-copy-region-as-kill mvi-com-point (point))
  162.     (if (< mvi-com-point (point))
  163.         (indent-rigidly mvi-com-point (point) tab-width)
  164.         (indent-rigidly (point) mvi-com-point tab-width))
  165.     (if (or (pos-visible-in-window-p) g-flag)
  166.         (let ((tmp (marker-position mvi-g-point)))
  167.             (move-marker mvi-g-point (point))
  168.             (goto-char tmp))))))
  169.  
  170. (aset mvi-commands ?< (function (lambda ()
  171.     (mvi-copy-region-as-kill mvi-com-point (point))
  172.     (if (< mvi-com-point (point))
  173.         (indent-rigidly mvi-com-point (point) (- tab-width))
  174.         (indent-rigidly (point) mvi-com-point (- tab-width)))
  175.     (if (or (pos-visible-in-window-p) g-flag)
  176.         (let ((tmp (marker-position mvi-g-point)))
  177.             (move-marker mvi-g-point (point))
  178.             (goto-char tmp))))))
  179.  
  180. (aset mvi-commands ?\C-i (function (lambda ()
  181.     (mvi-copy-region-as-kill mvi-com-point (point))
  182.     (if (< mvi-com-point (point))
  183.         (indent-region mvi-com-point (point) nil)
  184.         (indent-region (point) mvi-com-point nil))
  185.     (if g-flag (goto-char mvi-g-point)))))
  186.  
  187. (aset mvi-commands ?! (function (lambda ()
  188.     (mvi-copy-region-as-kill mvi-com-point (point))
  189.     (if (not text)
  190.         (setq text (read-string "Enter shell command: " mvi-shell-string)))
  191.     (setq mvi-shell-string text)
  192.     (shell-command-on-region mvi-com-point (point) text t)
  193.     (if g-flag (goto-char mvi-g-point)))))
  194.  
  195. (aset mvi-commands ?| (function (lambda ()
  196.     (if (not text)
  197.         (setq text (read-string "Enter shell command: " mvi-shell-string)))
  198.     (setq mvi-shell-string text)
  199.     (shell-command-on-region mvi-com-point (point) text nil)
  200.     (if g-flag (goto-char mvi-g-point)))))
  201.  
  202. (aset mvi-commands ?U  (function (lambda ()
  203.     (mvi-copy-region-as-kill mvi-com-point (point))
  204.     (upcase-region mvi-com-point (point))
  205.     (if g-flag (goto-char mvi-g-point)))))
  206.  
  207. (aset mvi-commands ?l  (function (lambda ()
  208.     (mvi-copy-region-as-kill mvi-com-point (point))
  209.     (downcase-region mvi-com-point (point))
  210.     (if g-flag (goto-char mvi-g-point)))))
  211.  
  212. (aset mvi-commands ?C  (function (lambda ()
  213.     (mvi-copy-region-as-kill mvi-com-point (point))
  214.     (capitalize-region mvi-com-point (point))
  215.     (if g-flag (goto-char mvi-g-point)))))
  216.  
  217. (aset mvi-commands ?5  (function (lambda ()
  218.     (mvi-copy-region-as-kill mvi-com-point (point))
  219.     (center-region mvi-com-point (point))
  220.     (if g-flag (goto-char mvi-g-point)))))
  221.  
  222. (aset mvi-commands ?_  (function (lambda ()
  223.     (mvi-copy-region-as-kill mvi-com-point (point))
  224.     (underline-region mvi-com-point (point))
  225.     (if g-flag (goto-char mvi-g-point)))))
  226.  
  227. (aset mvi-commands ?+  (function (lambda ()
  228.     (mvi-copy-region-as-kill mvi-com-point (point))
  229.     (ununderline-region mvi-com-point (point))
  230.     (if g-flag (goto-char mvi-g-point)))))
  231.  
  232. (aset mvi-commands ?F  (function (lambda ()
  233.     (mvi-copy-region-as-kill mvi-com-point (point))
  234.     (fill-region mvi-com-point (point))
  235.     (if g-flag (goto-char mvi-g-point)))))
  236.  
  237. (aset mvi-commands ?a  (function (lambda ()
  238.     (if (not text)
  239.         (setq text (call-interactively 'mvi-get-filename)))
  240.     (append-to-file mvi-com-point (point) text)
  241.     (if g-flag (goto-char mvi-g-point)))))
  242.  
  243. (aset mvi-commands ?w  (function (lambda ()
  244.     (if (not text)
  245.         (setq text (call-interactively 'mvi-get-filename)))
  246.     (write-region mvi-com-point (point) text)
  247.     (if g-flag (goto-char mvi-g-point)))))
  248.  
  249. (aset mvi-commands ?n  (function (lambda ()
  250.     (narrow-to-region mvi-com-point (point))
  251.     (if g-flag (goto-char mvi-g-point)))))
  252.  
  253. (aset mvi-commands ?f  (function (lambda ()
  254.     (or folded-display (error "Fold mode not enabled"))
  255.     (if (< mvi-com-point (point))
  256.             (progn
  257.                 (if (bolp) (backward-char 1))
  258.                 (setq hist-tmp (point))
  259.                 (if (search-backward "\n" mvi-com-point t 1) (fold-region 
  260.                     (progn (goto-char mvi-com-point) (beginning-of-line) (point))
  261.                     (progn (goto-char hist-tmp) (end-of-line) (point)) t)))
  262.         (setq hist-tmp (point))
  263.         (goto-char mvi-com-point)
  264.         (if (bolp) (backward-char 1))
  265.         (move-marker mvi-com-point (point))
  266.         (if (search-backward "\n" hist-tmp t 1) (fold-region 
  267.             (progn (goto-char hist-tmp) (beginning-of-line) (point))
  268.             (progn (goto-char mvi-com-point) (end-of-line) (point)) t)))
  269.     (scroll-up 0)
  270.     (if g-flag (goto-char mvi-g-point)))))
  271.  
  272. (aset mvi-commands ?u  (function (lambda ()
  273.     (or folded-display (error "Fold mode not enabled"))
  274.     (if (< mvi-com-point (point))
  275.             (progn
  276.                 (if (bolp) (backward-char 1))
  277.                 (setq hist-tmp (point))
  278.                 (if (re-search-backward "[\C-m-\C-z]" mvi-com-point t 1) (unfold-region 
  279.                     (progn (goto-char mvi-com-point) (beginning-of-line) (point))
  280.                     (progn (goto-char hist-tmp) (end-of-line) (point)) 1 t)))
  281.         (setq hist-tmp (point))
  282.         (goto-char mvi-com-point)
  283.         (if (bolp) (backward-char 1))
  284.         (move-marker mvi-com-point (point))
  285.         (if (re-search-backward "[\C-m-\C-z]" hist-tmp t 1) (unfold-region 
  286.             (progn (goto-char hist-tmp) (beginning-of-line) (point))
  287.             (progn (goto-char mvi-com-point) (end-of-line) (point)) 1 t)))
  288.     (scroll-up 0)
  289.     (if g-flag (goto-char mvi-g-point)))))
  290.  
  291. (aset mvi-commands ?G  (function (lambda ()
  292.   (let ((tmp))
  293.         (if (> (point) mvi-com-point) 
  294.                 (progn 
  295.                     (setq tmp (marker-position mvi-com-point))
  296.                     (move-marker mvi-com-point (point))
  297.                     (goto-char tmp)))
  298.         (setq tmp (copy-marker mvi-com-point))
  299.         (beginning-of-line)
  300.         (while (< (point) tmp)
  301.             (progn
  302.                 (beginning-of-line)
  303.                 (call-last-kbd-macro)
  304.                 (forward-line 1))))
  305.     (if g-flag (goto-char mvi-g-point)))))
  306.  
  307. (aset mvi-commands ?R (function (lambda ()
  308.     (mvi-enlarge-region mvi-com-point (point))
  309.     (push-mark nil t)
  310.     (goto-char mvi-com-point)
  311.     (if (not g-flag) (exchange-point-and-mark)))))
  312.  
  313. (aset mvi-commands ?r (function (lambda ()
  314.     (push-mark nil t)
  315.     (goto-char mvi-com-point)
  316.     (if (not g-flag) (exchange-point-and-mark)))))
  317.  
  318. (defun mvi-copy-region-as-kill (beg end)
  319.   "Save the region as if killed, but don't kill it."
  320.     (setq kill-ring (cons (buffer-substring beg end) kill-ring))
  321.     (if (> (length kill-ring) kill-ring-max)
  322.         (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
  323.   (setq kill-ring-yank-pointer kill-ring))
  324.  
  325.  
  326. ;; basic set up
  327.  
  328. (global-set-key "\C-z" 'mvi-emacs-to-vi)
  329. (global-set-key "\C-_" 'ESC-prefix)
  330.  
  331.  
  332. ;; changing mode
  333.  
  334. (defun mvi-emacs-to-vi ()
  335.   "Change mode from emacs to vi."
  336.   (interactive)
  337.     (or mvi-com-point (setq mvi-com-point (make-marker)))
  338.     (or mvi-g-point (setq mvi-g-point (make-marker)))
  339.     (or mvi-put-point (setq mvi-put-point (make-marker)))
  340.     (or mvi-put-start (setq mvi-put-start (make-marker)))
  341.     (or mvi-put-end (setq mvi-put-end (make-marker)))
  342.     (or (and mvi-mode-map (eq (current-local-map) mvi-mode-map))
  343.             (progn
  344.                 (setq mvi-emacs-local-map (current-local-map))
  345.                 (setq mvi-mlbi mode-line-buffer-identification)
  346.                 (setq mvi-insert-local-map 
  347.                             (if mvi-emacs-local-map (copy-keymap mvi-emacs-local-map)
  348.                                 (make-sparse-keymap)))
  349.                 (define-key mvi-insert-local-map "\C-_" (local-key-binding "\e"))
  350.                 (define-key mvi-insert-local-map "\t" 'self-insert-command)
  351.                 (define-key mvi-insert-local-map "\e" 'mvi-insert-to-vi)
  352.                 (define-key mvi-insert-local-map "\C-z" 'mvi-insert-last)
  353.                 (define-key mvi-insert-local-map "\C-h" 'mvi-delete-previous-word)
  354.                 (setq mvi-mode-map (copy-keymap mvi-static-map))
  355.                 (define-key mvi-mode-map "\C-_" (local-key-binding "\e"))
  356.                 (define-key mvi-mode-map "\C-x" (local-key-binding "\C-x"))
  357.                 (define-key mvi-mode-map "\C-c" (local-key-binding "\C-c"))
  358.                 (define-key mvi-mode-map "@" 'mvi-map-prefix-prefix)
  359.                 (setq mode-line-buffer-identification '("Vi:    %17b"))
  360.                 (set-buffer-modified-p (buffer-modified-p))
  361.                 (use-local-map mvi-mode-map))))
  362.  
  363. (defun mvi-minibuffer-to-vi ()
  364.     "Change to vi mode while in minibuffer."
  365.     (interactive)
  366.     (or mvi-com-point (setq mvi-com-point (make-marker)))
  367.     (or mvi-g-point (setq mvi-g-point (make-marker)))
  368.     (or mvi-put-point (setq mvi-put-point (make-marker)))
  369.     (or mvi-put-start (setq mvi-put-start (make-marker)))
  370.     (or mvi-put-end (setq mvi-put-end (make-marker)))
  371.     (define-key mvi-history-edit-map "@" 'mvi-map-prefix-prefix)
  372.     (setq mvi-emacs-local-map (current-local-map))
  373.     (setq mvi-insert-local-map 
  374.                 (if mvi-emacs-local-map (copy-keymap mvi-emacs-local-map)
  375.                     (make-sparse-keymap)))
  376.     (define-key mvi-insert-local-map "\e" 'mvi-insert-to-vi)
  377.     (define-key mvi-insert-local-map "\C-z" 'mvi-insert-last)
  378.     (define-key mvi-insert-local-map "\C-h" 'mvi-delete-previous-word)
  379.     (setq mvi-mode-map mvi-history-edit-map)
  380.     (use-local-map mvi-mode-map))
  381.  
  382. (defun mvi-vi-to-emacs ()
  383.   "Change mode from vi to emacs."
  384.   (interactive)
  385.     (setq mode-line-buffer-identification mvi-mlbi)
  386.     (set-buffer-modified-p (buffer-modified-p))
  387.     (use-local-map mvi-emacs-local-map))
  388.  
  389. (defun mvi-do-insert (motion)
  390.   "Perform the insertion of text."
  391.         (if text
  392.             (let ((count (if command 1 number))
  393.                         (start))
  394.                 (while (> count 0)
  395.                     (if overwrite-mode
  396.                         (progn 
  397.                             (setq start (point))
  398.                             (end-of-line)
  399.                             (if (> (length text) (- (point) start))
  400.                                 (delete-region start (point))
  401.                                 (progn
  402.                                     (goto-char start)
  403.                                     (delete-char (length text))))))
  404.                     (insert text)
  405.                     (and (/= count 1) 
  406.                         (or (eq motion 'mvi-o) (eq motion 'mvi-O) (eq motion 'mvi-Co)) 
  407.                             (insert ?\n))
  408.                     (setq count (1- count)))
  409.                 (overwrite-mode 0)
  410.                 (if (not (string= text "")) 
  411.                     (progn
  412.                         (setq mvi-last-inserted-text text)
  413.                         (and register append (not command)
  414.                             (mvi-append-to-register-text register text))
  415.                         (and register (not append) (not command)
  416.                             (set-register register text))))
  417.                 (if g-flag (goto-char mvi-g-point))
  418.                 (or executing-macro
  419.                     (equal (aref mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max)) 
  420.                         (setq hist-tmp (vector number register append g-flag command 
  421.                             motion motion-arg text)))
  422.                     (progn
  423.                         (setq mvi-com-ring-point (1+ mvi-com-ring-point))
  424.                         (aset mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max) 
  425.                             hist-tmp))))
  426.             (progn
  427.                 (setq mvi-insert-args (list number register append g-flag command 
  428.                                                                         motion motion-arg))
  429.                 (setq mode-line-buffer-identification '("Insert:%17b"))
  430.                 (set-buffer-modified-p (buffer-modified-p))
  431.                 (use-local-map mvi-insert-local-map))))
  432.  
  433. (defun mvi-insert-to-vi ()
  434.   "Change mode from insert to vi mode."
  435.     (interactive)
  436.     (let* ((number (nth 0 mvi-insert-args))
  437.                 (register (nth 1 mvi-insert-args))
  438.                 (append (nth 2 mvi-insert-args))
  439.                 (g-flag (nth 3 mvi-insert-args))
  440.                 (command (nth 4 mvi-insert-args))
  441.                 (motion (nth 5 mvi-insert-args))
  442.                 (motion-arg (nth 6 mvi-insert-args))
  443.                 (count (if command 1 number))
  444.                 (text (buffer-substring mvi-com-point (point)))
  445.                 (start))
  446.         (use-local-map mvi-mode-map)
  447.         (setq mode-line-buffer-identification '("Vi:    %17b"))
  448.         (set-buffer-modified-p (buffer-modified-p))
  449.         (while (> count 1)
  450.             (if overwrite-mode
  451.                 (progn 
  452.                     (setq start (point))
  453.                     (end-of-line)
  454.                     (if (> (length text) (- (point) start))
  455.                         (delete-region start (point))
  456.                         (progn
  457.                             (goto-char start)
  458.                             (delete-char (length text))))))
  459.             (if (or (eq motion 'mvi-o) (eq motion 'mvi-O) (eq motion 'mvi-Co)) 
  460.                 (insert ?\n))
  461.             (insert text)
  462.             (setq count (1- count)))
  463.         (overwrite-mode 0)
  464.         (if (not (string= text ""))
  465.             (progn
  466.                 (setq mvi-last-inserted-text text)
  467.                 (and register append (not command)
  468.                     (mvi-append-to-register-text register text))
  469.                 (and register (not append) (not command)
  470.                     (set-register register text))))
  471.         (if g-flag (goto-char mvi-g-point))
  472.         (or executing-macro
  473.             (equal (aref mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max)) 
  474.                 (setq hist-tmp (vector number register append g-flag command motion 
  475.                     motion-arg text)))
  476.             (progn
  477.                 (setq mvi-com-ring-point (1+ mvi-com-ring-point))
  478.                 (aset mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max) 
  479.                     hist-tmp)))))
  480.  
  481. (defun mvi-insert-last ()
  482.     "Insert last-inserted-text."
  483.     (interactive)
  484.     (insert mvi-last-inserted-text))
  485.  
  486. (defun mvi-delete-previous-word ()
  487.     "Delete previous word in insert mode."
  488.     (interactive)
  489.     (delete-region (point) (progn (mvi-forward-word -1 ?d) (point))))
  490.  
  491. (defun mvi-map-macro (arg char)
  492.   "Bind last keyboard macro to a @ subkey."
  493.   (interactive "P\ncEnter character to bind macro to:")
  494.     (let ((command (mvi-nth 4 arg)))
  495.         (if command (error "Bad command"))
  496.         (define-key mvi-map-map (char-to-string char) last-kbd-macro)))
  497.  
  498. (defun mvi-insert-macro (arg char)
  499.   "Insert a macro into the buffer."
  500.   (interactive "P\ncEnter character of macro to insert:")
  501.     (let ((command (mvi-nth 4 arg)))
  502.         (if command (error "Bad command"))
  503.         (insert (format "(define-key mvi-map-map %s %s)" 
  504.             (prin1-to-string (char-to-string char))
  505.                 (prin1-to-string (cdr (assq char mvi-map-map)))))))
  506.  
  507. (defun mvi-insert-all-macro (arg)
  508.   "Insert all macros into the buffer."
  509.   (interactive "P")
  510.     (let ((command (mvi-nth 4 arg))
  511.                 (count 0)
  512.                 (key-a-list (cdr mvi-map-map))
  513.                 (tmp))
  514.         (if command (error "Bad command"))
  515.         (while (setq tmp (nth count key-a-list))
  516.             (insert (format "(define-key mvi-map-map %s %s)\n" 
  517.                 (prin1-to-string (char-to-string (car tmp)))
  518.                     (prin1-to-string (cdr tmp))))
  519.             (setq count (1+ count)))))
  520.  
  521. (defun mvi-ESC ()
  522.   "Escape in vi mode cancels command."
  523.   (interactive)
  524.     (message "Command cancelled"))
  525.  
  526. (defun mvi-register-arg (arg)
  527. "Begin register argument for the next command."
  528.     (interactive "P")
  529.     (cond 
  530.      ((null arg) (setq arg (make-list 5 nil)))
  531.      ((integerp arg) (setq arg (list arg nil nil nil nil))))
  532.     (let ((c (read-char)))
  533.         (cond 
  534.             ((and (>= c ?a) (<= c ?z))
  535.                 (setcar (nthcdr 1 arg) c))
  536.             ((and (>= c ?A) (<= c ?Z))
  537.                 (setcar (nthcdr 1 arg) (+ c 32))
  538.                 (setcar (nthcdr 2 arg) t)) 
  539.             (t (error "Bad register")))
  540.         (setq prefix-arg arg)))
  541.  
  542. (defun mvi-digit-arg (arg)
  543.   "Begin numeric argument for the next command."
  544.     (interactive "P")
  545.     (let ((n 0)
  546.                 (negative nil)
  547.                 (c last-command-char))
  548.         (if (= c ?-)
  549.             (setq negative t
  550.                 c (read-char)))
  551.         (while (and (>= c ?0) (<= c ?9))
  552.             (progn
  553.                 (setq n (+ (* n 10) (- c ?0)))
  554.                 (setq c (read-char))))
  555.         (setq unread-command-char c)
  556.         (if negative
  557.             (if (= n 0) 
  558.                 (setq n -1)
  559.                 (setq n (- n))))
  560.         (if (or (null arg) (integerp arg)) (setq arg n) (setcar arg n))
  561.         (setq prefix-arg arg)))
  562.  
  563. (defun mvi-command-arg (arg number)
  564.   "Begin command argument for the next command."
  565.     (interactive "P\nV")
  566.     (cond 
  567.      ((null arg) (setq arg (make-list 5 nil)))
  568.      ((integerp arg) (setq arg (list arg nil nil nil nil))))
  569.     (if (nth 4 arg)
  570.         (if (= (nth 4 arg) last-command-char)
  571.             (mvi-cc arg number)
  572.             (error "Bad command"))
  573.         (progn
  574.             (setcar (nthcdr 4 arg) last-command-char)
  575.             (setq prefix-arg arg))))
  576.  
  577. (defun mvi-cc (arg number &optional motion-arg text)
  578.   "Perform double command character commands like dd, yy, etc."
  579.     (let ((register (mvi-nth 1 arg))
  580.                 (append (mvi-nth 2 arg))
  581.                 (g-flag (mvi-nth 3 arg))
  582.                 (command (mvi-nth 4 arg))
  583.                 (hist-tmp))
  584.         (move-marker mvi-g-point (point))
  585.         (beginning-of-line)
  586.         (mvi-enlarge-region (point) (progn (forward-line (1- number)) (point)))
  587.         (mvi-execute-com 'mvi-cc)))
  588.  
  589. (defun mvi-g-flag-arg (arg)
  590.   "Set g flag for the next command."
  591.     (interactive "P")
  592.     (cond 
  593.      ((null arg) (setq arg (make-list 5 nil)))
  594.      ((integerp arg) (setq arg (list arg nil nil nil nil))))
  595.     (setcar (nthcdr 3 arg) t)
  596.     (setq prefix-arg arg))
  597.  
  598. (defun mvi-append-to-register (char start end)
  599.   "Append region to text in register REG.
  600. Called from program, takes three args:
  601. REG, START, END.
  602. START and END are buffer positions indicating what to append."
  603.   (if (not (stringp (get-register char)))
  604.         (progn
  605.       (message (format "Warning: register %c did not contain text" char))
  606.             (set-register char (buffer-substring start end)))
  607.         (set-register char (concat (get-register char)
  608.                  (buffer-substring start end)))))
  609.  
  610. (defun mvi-append-to-register-text (char text)
  611.   "Append TEXT to register CHAR."
  612.   (if (not (stringp (get-register char)))
  613.         (progn
  614.       (message (format "Warning: register %c did not contain text" char))
  615.             (set-register char text))
  616.         (set-register char (concat (get-register char) text))))
  617.  
  618. (defun mvi-execute-com (motion)
  619.   "Execute a mvi command."
  620.     (or (pos-visible-in-window-p)
  621.         (message (format "%s Lines" (count-lines mvi-com-point (point)))))
  622.     (and register append 
  623.         (mvi-append-to-register register mvi-com-point (point)))
  624.     (and register (not append) 
  625.         (copy-to-register register mvi-com-point (point)))
  626.     (funcall (aref mvi-commands command))
  627.     (or executing-macro (= command ?c)
  628.         (equal (aref mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max)) 
  629.             (setq hist-tmp (vector number register append g-flag command motion 
  630.                 motion-arg text)))
  631.         (progn
  632.             (setq mvi-com-ring-point (1+ mvi-com-ring-point))
  633.             (aset mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max) 
  634.                 hist-tmp))))
  635.  
  636. (defun mvi-repeat (arg number)
  637.   "Repeat mvi command."
  638.   (interactive "P\nV")
  639.     (let ((raw-number (mvi-nth 0 arg))
  640.                 (register (mvi-nth 1 arg))
  641.                 (append (mvi-nth 2 arg))
  642.                 (g-flag (mvi-nth 3 arg))
  643.                 (command (mvi-nth 4 arg))
  644.                 (tmp))
  645.         (if (and (eq last-command 'mvi-undo) mvi-repeat-then-undo) 
  646.             (setq mvi-history-point (1- mvi-history-point))
  647.             (setq mvi-history-point  mvi-com-ring-point))
  648.         (setq tmp (aref mvi-com-ring (% mvi-history-point mvi-com-ring-max)))
  649.         (or raw-number (setq number (aref tmp 0)))
  650.         (or register (setq register (aref tmp 1) append (aref tmp 2)))
  651.         (or g-flag (setq g-flag (aref tmp 3)))
  652.         (or command (setq command (aref tmp 4)))
  653.         (setq mvi-repeat-point (point))
  654.         (funcall (aref tmp 5) (list number register append g-flag command) number
  655.             (aref tmp 6) (aref tmp 7))
  656.         (setq this-command 'mvi-repeat)))
  657.  
  658. (defun mvi-edit-and-eval-command (prompt command)
  659.   "Prompting with PROMPT, let user edit COMMAND and eval result.
  660. COMMAND is a Lisp expression.  Let user edit that expression in
  661. the minibuffer, then read and evaluate the result. Use vi insert map."
  662.   (eval (read-from-minibuffer prompt 
  663.              (prin1-to-string command) mvi-history-insert-map t)))
  664.  
  665. (defun mvi-edit-history (count)
  666.   "Edit and evaluate a previous mvi command."
  667.     (interactive "V")
  668.     (setq mvi-history-point (- mvi-com-ring-point count -1))
  669.     (mvi-edit-and-eval-command "" (mvi-format-history mvi-history-point)))
  670.  
  671. (defun mvi-edit-prev (count)
  672.   "Edit the next previous mvi command."
  673.     (interactive "V")
  674.     (setq mvi-history-point (- mvi-history-point count))
  675.     (erase-buffer)
  676.     (insert (format "%s" (mvi-format-history mvi-history-point)))
  677.     (beginning-of-buffer))
  678.  
  679. (defun mvi-edit-next (count)
  680.   "Edit the next following mvi command."
  681.     (interactive "V")
  682.     (setq mvi-history-point (+ mvi-history-point count))
  683.     (erase-buffer)
  684.     (insert (format "%s" (mvi-format-history mvi-history-point)))
  685.     (beginning-of-buffer))
  686.  
  687. (defun mvi-save-history (name)
  688.   "Save a mvi command as a symbol."
  689.     (interactive "sEnter save name: ")
  690.     (let ((c))
  691.         (if (intern-soft name)
  692.             (progn
  693.                 (message "Symbol exists, enter y to continue")
  694.                 (setq c (read-char)))
  695.             (setq c ?y))
  696.         (if (or (= c ?y)  (= c ?Y))
  697.             (progn
  698.                 (make-symbol name)
  699.                 (put (intern name) 'variable-documentation mvi-doc-string)
  700.                 (set (intern name) 
  701.                     (aref mvi-com-ring (% mvi-history-point mvi-com-ring-max)))))))
  702.  
  703. (defun mvi-edit-saved-history (variable)
  704.   "Edit a mvi command previously saved in a symbol."
  705.     (interactive "vSaved name: ")
  706.     (let ((tmp (aref mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max)))
  707.                 (saved (eval variable)))
  708.         (if (not (equal tmp saved))
  709.                 (progn
  710.                     (setq mvi-com-ring-point (1+ mvi-com-ring-point))
  711.                     (aset mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max) saved)
  712.                     (setq mvi-history-point mvi-com-ring-point)
  713.                     (erase-buffer)
  714.                     (insert (format "%s" (mvi-format-history mvi-history-point)))
  715.                     (beginning-of-buffer)))))
  716.  
  717. (defun mvi-edit-match (re-string)
  718.   "Search previous mvi commands for a pattern."
  719.     (interactive "sEnter re-string: ")
  720.     (let ((count mvi-com-ring-max))
  721.         (if (not (string= re-string ""))
  722.             (setq mvi-history-match-string re-string))
  723.         (while (> count 0)
  724.             (setq mvi-history-point (- mvi-history-point 1))
  725.             (if (string-match mvi-history-match-string 
  726.                         (format "%s" (mvi-format-history mvi-history-point)))
  727.                 (setq count -99))
  728.                 (setq count (1- count)))
  729.         (if (= count -100)
  730.             (progn
  731.                 (erase-buffer)
  732.                 (insert (format "%s" (mvi-format-history mvi-history-point)))
  733.                 (beginning-of-buffer))
  734.             (message "No match"))))
  735.  
  736. (defun mvi-edit-match-again ()
  737.   "Repeat search of previous mvi commands."
  738.     (interactive)
  739.     (mvi-edit-match ""))
  740.  
  741. (defun mvi-format-history (count)
  742.   "Take a previous mvi command and make a lisp expression that can be 
  743. evaluated."
  744.     (let ((number)
  745.                 (register)
  746.                 (append)
  747.                 (g-flag)
  748.                 (command)
  749.                 (motion)
  750.                 (motion-arg)
  751.                 (text)
  752.                 (tmp)
  753.                 (register-s)
  754.                 (g-flag-s)
  755.                 (command-s ""))
  756.         (setq tmp (aref mvi-com-ring (% count mvi-com-ring-max)))
  757.         (setq
  758.             number (aref tmp 0)
  759.             register (aref tmp 1)
  760.             append (aref tmp 2)
  761.             g-flag (aref tmp 3)
  762.             command (aref tmp 4)
  763.             motion (aref tmp 5)
  764.             motion-arg (aref tmp 6)
  765.             text (aref tmp 7))
  766.         (if register
  767.             (if append
  768.                 (setq register-s (format "R-%c" (- register 32)))
  769.                 (setq register-s (format "R-%c" register)))
  770.             (setq register-s "R-")) 
  771.         (if g-flag
  772.             (setq g-flag-s "g-g")
  773.             (setq g-flag-s "g-"))
  774.         (if (or (eq motion 'mvi-r) (eq motion 'mvi-s) (eq motion 'mvi-x) 
  775.             (eq motion 'mvi-X) (eq motion 'mvi-change-case)
  776.             (eq motion 'mvi-C) (eq motion 'mvi-D) (eq motion 'mvi-Y))
  777.                 (setq command nil))
  778.         (if command 
  779.             (if (or (= command ?c) (= command ?y) (= command ?d) (= command ?K) 
  780.                             (= command ?!) (= command ?|) (= command ?>) (= command ?<)
  781.                             (= command ?\C-k))
  782.                 (setq command-s (char-to-string command))
  783.                 (setq command-s (concat "q" (char-to-string command)))))
  784.         (if (eq motion 'mvi-cc)
  785.             (setq command-s (concat "C-" command-s command-s))
  786.             (setq command-s (concat "C-" command-s 
  787.                 (where-is-internal motion mvi-static-map t))))
  788.         (if (and (integerp motion-arg) (< motion-arg 256))
  789.             (setq motion-arg (list 'string-to-char (char-to-string motion-arg))))
  790.         (list 'mvi-rx register-s number g-flag-s command-s motion-arg text)))
  791.  
  792. (defun mvi-rx (register-s number g-flag-s command-s motion-arg text)
  793.     "Parse an edited mvi command and re-execute."
  794.     (let ((register)
  795.                 (append)
  796.                 (g-flag)
  797.                 (command)
  798.                 (motion)
  799.                 (case-fold-search nil))
  800.         (if (string-match "^R-[a-z]$" register-s)
  801.             (setq register (aref register-s 2)))
  802.         (if (string-match "^R-[A-Z]$" register-s)
  803.             (setq register (+ (aref register-s 2) 32)
  804.                 append t))
  805.         (if (string-match "^g-g$" g-flag-s) (setq g-flag t))
  806.         (cond
  807.             ((string-match 
  808.                 "^C-q[lUCGwnaFRrfu5_+\C-i]q[lUCGwnaFRrfu5_+\C-i]$" command-s)
  809.                 (if (= (aref command-s 3) (aref command-s 5))
  810.                     (setq command (aref command-s 3)
  811.                         motion 'mvi-cc)
  812.                     (error "Bad command")))
  813.             ((string-match "^C-q[lUCGwnaFRrfu5_+\C-i]" command-s)
  814.                 (setq command (aref command-s 3)
  815.                         motion (key-binding (substring command-s 4 nil)))
  816.                 (if (not (commandp motion)) (error "Bad command")))
  817.             ((string-match "^C-[cdyK!|<>\C-k][cdyK!|<>\C-k]$" command-s)
  818.                 (if (= (aref command-s 2) (aref command-s 3))
  819.                     (setq command (aref command-s 2)
  820.                         motion 'mvi-cc)
  821.                     (error "Bad command")))
  822.             ((string-match "^C-[cdyK!|<>\C-k]" command-s)
  823.                 (setq command (aref command-s 2)
  824.                         motion (key-binding (substring command-s 3 nil)))
  825.                 (if (not (commandp motion)) (error "Bad command")))
  826.             ((string-match "^C-" command-s)
  827.                 (setq motion (key-binding (substring command-s 2 nil)))
  828.                 (if (not (commandp motion)) (error "Bad command")))
  829.             (t (error "Bad command")))
  830.         (funcall motion (list number register append g-flag command) number
  831.         motion-arg text)))
  832.  
  833.  
  834. ;; undoing
  835.  
  836. (defun mvi-undo (arg)
  837.   "Undo a previous change."
  838.   (interactive "V")
  839.   (let ((modified (buffer-modified-p)))
  840.         (if (eq last-command 'mvi-repeat) 
  841.             (setq mvi-repeat-then-undo t)
  842.             (setq mvi-repeat-then-undo nil))
  843.     (message "Undo!")
  844.     (or (eq last-command 'mvi-undo) (progn (undo-start) (undo-more 1)))
  845.     (undo-more (or arg 1))
  846.     (and modified (not (buffer-modified-p))
  847.             (delete-auto-save-file-if-necessary))
  848.         (if (eq last-command 'mvi-repeat) (goto-char mvi-repeat-point))
  849.     (setq this-command 'mvi-undo)))
  850.  
  851.  
  852. ;; utilities
  853.  
  854. (defun mvi-enlarge-region (beg end)
  855.   "Enlarge region between BEG and END.  Used for commands that want the region
  856. to consist of full lines."
  857.     (if (<= beg end)
  858.         (progn
  859.             (goto-char beg)
  860.             (beginning-of-line)
  861.             (move-marker mvi-com-point (point))
  862.             (goto-char end)
  863.             (forward-line))
  864.         (progn
  865.             (goto-char beg)
  866.             (forward-line)
  867.             (move-marker mvi-com-point (point))
  868.             (goto-char end)
  869.             (beginning-of-line))))
  870.  
  871. (defun mvi-set-mark (arg number &optional motion-arg text)
  872.   "mvi set mark, or execute a command from point to the mark.
  873. With numeric argument, expand the region into full lines."
  874.   (interactive "P\nV")
  875.     (let ((raw-number (mvi-nth 0 arg))
  876.                 (register (mvi-nth 1 arg))
  877.                 (append (mvi-nth 2 arg))
  878.                 (g-flag (mvi-nth 3 arg))
  879.                 (command (mvi-nth 4 arg))
  880.                 (hist-tmp))
  881.         (if command 
  882.             (progn
  883.                 (or (mark) (error "No mark set in this buffer"))
  884.                 (move-marker mvi-g-point (point))
  885.                 (setq number raw-number)
  886.                 (if raw-number
  887.                     (mvi-enlarge-region (point) (mark))
  888.                     (move-marker mvi-com-point (point))
  889.                     (goto-char (mark)))
  890.                 (mvi-execute-com 'mvi-set-mark))
  891.             (set-mark-command raw-number))))
  892.  
  893. (defun mvi-jump-mark (arg number)
  894.   "mvi jump to mark, repeating rotates the mark ring bringing the point
  895.  to the position of previous marks."
  896.   (interactive "P\nV")
  897.     (let ((command (mvi-nth 4 arg)))
  898.         (if command (error "Bad command"))
  899.         (move-marker mvi-g-point (point))
  900.         (if (< number 0) 
  901.                 (progn
  902.                     (setq mark-ring (nreverse mark-ring))
  903.                     (set-mark-command 1)
  904.                     (set-mark-command 1)))
  905.         (if (eq this-command last-command)
  906.                 (set-mark-command 1)
  907.             (push-mark nil t)
  908.             (set-mark-command 1)
  909.             (set-mark-command 1))))
  910.  
  911. (defun mvi-exc-point-and-g (arg number &optional motion-arg text)
  912.   "mvi move to previous commands starting point."
  913.   (interactive "P\nV")
  914.     (let ((raw-number (mvi-nth 0 arg))
  915.                 (register (mvi-nth 1 arg))
  916.                 (append (mvi-nth 2 arg))
  917.                 (g-flag (mvi-nth 3 arg))
  918.                 (command (mvi-nth 4 arg))
  919.                 (tmp (marker-position mvi-g-point))
  920.                 (hist-tmp))
  921.         (move-marker mvi-g-point (point))
  922.         (if command 
  923.             (progn
  924.                 (setq number raw-number)
  925.                 (if raw-number
  926.                     (mvi-enlarge-region (point) tmp)
  927.                     (move-marker mvi-com-point (point))
  928.                     (goto-char tmp))
  929.                 (mvi-execute-com 'mvi-exc-point-and-g))
  930.             (goto-char tmp))))
  931.  
  932. (defun mvi-get-filename (arg)
  933.   "Used to get a filename with completion."
  934.   (interactive "FWrite file: ")
  935.     arg)
  936.  
  937.  
  938. ;; insertion commands
  939.  
  940. (defun mvi-i (arg number &optional motion-arg text)
  941.   "mvi insert before point."
  942.   (interactive "*P\nV")
  943.     (let ((register (mvi-nth 1 arg))
  944.                 (append (mvi-nth 2 arg))
  945.                 (g-flag (mvi-nth 3 arg))
  946.                 (command (mvi-nth 4 arg))
  947.                 (hist-tmp))
  948.         (if command (error "Bad command"))
  949.         (move-marker mvi-g-point (point))
  950.         (move-marker mvi-com-point (point))
  951.         (mvi-do-insert 'mvi-i)))
  952.  
  953. (defun mvi-overwrite (arg number &optional motion-arg text)
  954.   "mvi overwrite."
  955.   (interactive "*P\nV")
  956.     (let ((register (mvi-nth 1 arg))
  957.                 (append (mvi-nth 2 arg))
  958.                 (g-flag (mvi-nth 3 arg))
  959.                 (command (mvi-nth 4 arg))
  960.                 (hist-tmp))
  961.         (if command (error "Bad command"))
  962.         (move-marker mvi-g-point (point))
  963.         (overwrite-mode 1)
  964.         (move-marker mvi-com-point (point))
  965.         (mvi-do-insert 'mvi-overwrite)))
  966.  
  967. (defun mvi-a (arg number &optional motion-arg text)
  968.   "mvi append after point."
  969.   (interactive "*P\nV")
  970.     (let ((register (mvi-nth 1 arg))
  971.                 (append (mvi-nth 2 arg))
  972.                 (g-flag (mvi-nth 3 arg))
  973.                 (command (mvi-nth 4 arg))
  974.                 (hist-tmp))
  975.         (if command (error "Bad command"))
  976.         (move-marker mvi-g-point (point))
  977.         (if (not (eolp)) (forward-char))
  978.         (move-marker mvi-com-point (point))
  979.         (mvi-do-insert 'mvi-a)))
  980.  
  981. (defun mvi-I (arg number &optional motion-arg text)
  982.   "mvi insert at the beginning of the line."
  983.   (interactive "*P\nV")
  984.     (let ((register (mvi-nth 1 arg))
  985.                 (append (mvi-nth 2 arg))
  986.                 (g-flag (mvi-nth 3 arg))
  987.                 (command (mvi-nth 4 arg))
  988.                 (hist-tmp))
  989.         (if command (error "Bad command"))
  990.         (move-marker mvi-g-point (point))
  991.         (beginning-of-line)
  992.         (move-marker mvi-com-point (point))
  993.         (mvi-do-insert 'mvi-I)))
  994.  
  995. (defun mvi-A (arg number &optional motion-arg text)
  996.   "mvi append at the end of the line."
  997.   (interactive "*P\nV")
  998.     (let ((register (mvi-nth 1 arg))
  999.                 (append (mvi-nth 2 arg))
  1000.                 (g-flag (mvi-nth 3 arg))
  1001.                 (command (mvi-nth 4 arg))
  1002.                 (hist-tmp))
  1003.         (if command (error "Bad command"))
  1004.         (move-marker mvi-g-point (point))
  1005.         (end-of-line)
  1006.         (move-marker mvi-com-point (point))
  1007.         (mvi-do-insert 'mvi-A)))
  1008.  
  1009. (defun mvi-o (arg number &optional motion-arg text)
  1010.   "mvi open a line below the current line."
  1011.   (interactive "*P\nV")
  1012.     (let ((register (mvi-nth 1 arg))
  1013.                 (append (mvi-nth 2 arg))
  1014.                 (g-flag (mvi-nth 3 arg))
  1015.                 (command (mvi-nth 4 arg))
  1016.                 (hist-tmp))
  1017.         (if command (error "Bad command"))
  1018.         (move-marker mvi-g-point (point))
  1019.         (end-of-line)
  1020.         (insert ?\n)
  1021.         (move-marker mvi-com-point (point))
  1022.         (and mvi-ai (interactive-p) (indent-for-tab-command))
  1023.         (mvi-do-insert 'mvi-o)))
  1024.  
  1025. (defun mvi-O (arg number &optional motion-arg text)
  1026.   "mvi open a line above the current line."
  1027.   (interactive "*P\nV")
  1028.     (let ((register (mvi-nth 1 arg))
  1029.                 (append (mvi-nth 2 arg))
  1030.                 (g-flag (mvi-nth 3 arg))
  1031.                 (command (mvi-nth 4 arg))
  1032.                 (hist-tmp))
  1033.         (if command (error "Bad command"))
  1034.         (move-marker mvi-g-point (point))
  1035.         (beginning-of-line)
  1036.         (insert-before-markers ?\n)
  1037.         (forward-line -1)
  1038.         (move-marker mvi-com-point (point))
  1039.         (and mvi-ai (interactive-p) (indent-for-tab-command))
  1040.         (mvi-do-insert 'mvi-O)))
  1041.  
  1042. (defun mvi-Co (arg number &optional motion-arg text)
  1043.   "mvi open a line at the current point."
  1044.   (interactive "*P\nV")
  1045.     (let ((register (mvi-nth 1 arg))
  1046.                 (append (mvi-nth 2 arg))
  1047.                 (g-flag (mvi-nth 3 arg))
  1048.                 (command (mvi-nth 4 arg))
  1049.                 (hist-tmp))
  1050.         (if command (error "Bad command"))
  1051.         (move-marker mvi-g-point (point))
  1052.         (insert ?\n)
  1053.         (if mvi-ai (indent-for-tab-command))
  1054.         (beginning-of-line)
  1055.         (insert ?\n)
  1056.         (forward-line -1)
  1057.         (move-marker mvi-com-point (point))
  1058.         (and mvi-ai (interactive-p) (indent-for-tab-command))
  1059.         (mvi-do-insert 'mvi-Co)))
  1060.  
  1061.  
  1062. ;; basic cursor movement.  j, k, l, m commands.
  1063.  
  1064. (defun mvi-l (arg number &optional motion-arg text)
  1065.   "Move point right ARG characters (left if ARG negative). On reaching end
  1066. of buffer, stop and signal error."
  1067.   (interactive "P\nV")
  1068.     (let ((register (mvi-nth 1 arg))
  1069.                 (append (mvi-nth 2 arg))
  1070.                 (g-flag (mvi-nth 3 arg))
  1071.                 (command (mvi-nth 4 arg))
  1072.                 (hist-tmp))
  1073.         (move-marker mvi-g-point (point))
  1074.         (if command 
  1075.             (progn
  1076.                 (move-marker mvi-com-point (point))
  1077.                 (forward-char number)
  1078.                 (mvi-execute-com 'mvi-l))
  1079.             (forward-char number))))
  1080.  
  1081. (defun mvi-s (arg number &optional motion-arg text)
  1082.   "Substitute text for a number of characters."
  1083.   (interactive "P\nV")
  1084.     (let ((register (mvi-nth 1 arg))
  1085.                 (append (mvi-nth 2 arg))
  1086.                 (g-flag (mvi-nth 3 arg))
  1087.                 (command (mvi-nth 4 arg))
  1088.                 (hist-tmp))
  1089.         (if (and (interactive-p) command) (error "Bad command"))
  1090.         (move-marker mvi-g-point (point))
  1091.         (setq command ?c)
  1092.         (move-marker mvi-com-point (point))
  1093.         (forward-char number)
  1094.         (mvi-execute-com 'mvi-s)))
  1095.  
  1096. (defun mvi-x (arg number &optional motion-arg text)
  1097.   "Delete a number of characters forward from point."
  1098.   (interactive "P\nV")
  1099.     (let ((register (mvi-nth 1 arg))
  1100.                 (append (mvi-nth 2 arg))
  1101.                 (g-flag (mvi-nth 3 arg))
  1102.                 (command (mvi-nth 4 arg))
  1103.                 (hist-tmp))
  1104.         (if (and (interactive-p) command) (error "Bad command"))
  1105.         (move-marker mvi-g-point (point))
  1106.         (setq command ?K)
  1107.         (move-marker mvi-com-point (point))
  1108.         (forward-char number)
  1109.         (mvi-execute-com 'mvi-x)))
  1110.  
  1111. (defun mvi-X (arg number &optional motion-arg text)
  1112.   "Delete a number of characters backward from point."
  1113.   (interactive "P\nV")
  1114.     (let ((register (mvi-nth 1 arg))
  1115.                 (append (mvi-nth 2 arg))
  1116.                 (g-flag (mvi-nth 3 arg))
  1117.                 (command (mvi-nth 4 arg))
  1118.                 (hist-tmp))
  1119.         (if (and (interactive-p) command) (error "Bad command"))
  1120.         (move-marker mvi-g-point (point))
  1121.         (setq command ?K)
  1122.         (move-marker mvi-com-point (point))
  1123.         (backward-char number)
  1124.         (mvi-execute-com 'mvi-X)))
  1125.  
  1126. (defun mvi-r (arg number &optional motion-arg text)
  1127.   "Change a number of characters forward from point."
  1128.   (interactive "P\nV")
  1129.     (let ((register (mvi-nth 1 arg))
  1130.                 (append (mvi-nth 2 arg))
  1131.                 (g-flag (mvi-nth 3 arg))
  1132.                 (command (mvi-nth 4 arg))
  1133.                 (tmp (point))
  1134.                 (hist-tmp))
  1135.         (and command (interactive-p) (error "Bad command"))
  1136.         (or motion-arg (progn
  1137.             (or (eq (minibuffer-window) (selected-window))
  1138.                 (message "Replace 1 character:"))
  1139.             (setq motion-arg (read-char))))
  1140.         (and (= motion-arg ?\C-m) (interactive-p) (setq motion-arg ?\n))
  1141.         (if (and (= motion-arg ?\e) (interactive-p))
  1142.             (message "Command cancelled")
  1143.             (progn
  1144.                 (if (and (= motion-arg ?\C-q) (interactive-p))
  1145.                     (setq motion-arg (read-quoted-char "Enter quoted char")))
  1146.                 (setq command ?c
  1147.                     text (make-string number motion-arg))
  1148.                 (move-marker mvi-com-point (point))
  1149.                 (forward-char number)
  1150.                 (mvi-execute-com 'mvi-r)
  1151.                 (move-marker mvi-g-point (point))
  1152.                 (goto-char tmp)))))
  1153.  
  1154. (defun mvi-change-case (arg number &optional motion-arg text)
  1155.   "Toggle the case of a number of characters forward from point."
  1156.   (interactive "P\nV")
  1157.     (let ((register (mvi-nth 1 arg))
  1158.                 (append (mvi-nth 2 arg))
  1159.                 (g-flag (mvi-nth 3 arg))
  1160.                 (command (mvi-nth 4 arg))
  1161.                 (string)
  1162.                 (count 0)
  1163.                 (c)
  1164.                 (hist-tmp))
  1165.         (if (and (interactive-p) command) (error "Bad command"))
  1166.         (move-marker mvi-g-point (point))
  1167.         (move-marker mvi-com-point (point))
  1168.         (forward-char number)
  1169.         (setq 
  1170.           command ?K
  1171.             string (buffer-substring mvi-com-point (point)))
  1172.         (while (< count number)
  1173.             (setq c (aref string count))
  1174.             (if (and (>= c ?a) (<= c ?z)) 
  1175.                 (setq c (- c 32))
  1176.                 (if (and (>= c ?A) (<= c ?Z)) (setq c (+ c 32))))
  1177.             (aset string count c)
  1178.             (setq count (1+ count)))
  1179.         (mvi-execute-com 'mvi-change-case)
  1180.         (insert string)
  1181.         (if g-flag (goto-char mvi-g-point))))
  1182.  
  1183. (defun mvi-h (arg number &optional motion-arg text)
  1184.   "Move point left ARG characters (right if ARG negative). On reaching end
  1185. of buffer, stop and signal error."
  1186.   (interactive "P\nV")
  1187.     (let ((register (mvi-nth 1 arg))
  1188.                 (append (mvi-nth 2 arg))
  1189.                 (g-flag (mvi-nth 3 arg))
  1190.                 (command (mvi-nth 4 arg))
  1191.                 (hist-tmp))
  1192.         (move-marker mvi-g-point (point))
  1193.         (if command 
  1194.             (progn
  1195.                 (move-marker mvi-com-point (point))
  1196.                 (backward-char number)
  1197.                 (mvi-execute-com 'mvi-h))
  1198.             (backward-char number))))
  1199.  
  1200. (defun mvi-line-move (arg)
  1201.   (if (not (or (eq last-command 'mvi-j)
  1202.            (eq last-command 'mvi-k)))
  1203.       (setq temporary-goal-column
  1204.         (if (and track-eol (eolp))
  1205.         9999
  1206.           (current-column))))
  1207.   (if (not (integerp selective-display))
  1208.       (forward-line arg)
  1209.     ;; Move by arg lines, but ignore invisible ones.
  1210.     (while (> arg 0)
  1211.       (vertical-motion 1)
  1212.       (forward-char -1)
  1213.       (forward-line 1)
  1214.       (setq arg (1- arg)))
  1215.     (while (< arg 0)
  1216.       (vertical-motion -1)
  1217.       (beginning-of-line)
  1218.       (setq arg (1+ arg))))
  1219.   (move-to-column (or goal-column temporary-goal-column))
  1220.   nil)
  1221.  
  1222. (defun mvi-j (arg number &optional motion-arg text)
  1223.   "Move point down."
  1224.   (interactive "P\nV")
  1225.     (let ((register (mvi-nth 1 arg))
  1226.                 (append (mvi-nth 2 arg))
  1227.                 (g-flag (mvi-nth 3 arg))
  1228.                 (command (mvi-nth 4 arg))
  1229.                 (hist-tmp))
  1230.         (move-marker mvi-g-point (point))
  1231.         (if command 
  1232.             (progn
  1233.                 (mvi-enlarge-region (point) (progn (forward-line number) (point)))
  1234.                 (mvi-execute-com 'mvi-j))
  1235.             (mvi-line-move number))))
  1236.  
  1237. (defun mvi-k (arg number &optional motion-arg text)
  1238.   "Move point up."
  1239.   (interactive "P\nV")
  1240.     (let ((register (mvi-nth 1 arg))
  1241.                 (append (mvi-nth 2 arg))
  1242.                 (g-flag (mvi-nth 3 arg))
  1243.                 (command (mvi-nth 4 arg))
  1244.                 (hist-tmp))
  1245.         (move-marker mvi-g-point (point))
  1246.         (if command 
  1247.             (progn
  1248.                 (mvi-enlarge-region (point) (progn (forward-line (- number)) (point)))
  1249.                 (mvi-execute-com 'mvi-k))
  1250.             (mvi-line-move (- number)))))
  1251.  
  1252.  
  1253. ;; word command
  1254.  
  1255. (defun mvi-w (arg number &optional motion-arg text)
  1256.   "mvi forward word."
  1257.   (interactive "P\nV")
  1258.     (let ((register (mvi-nth 1 arg))
  1259.                 (append (mvi-nth 2 arg))
  1260.                 (g-flag (mvi-nth 3 arg))
  1261.                 (command (mvi-nth 4 arg))
  1262.                 (hist-tmp))
  1263.         (move-marker mvi-g-point (point))
  1264.         (if command 
  1265.             (progn
  1266.                 (move-marker mvi-com-point (point))
  1267.                 (mvi-forward-word number command)
  1268.                 (mvi-execute-com 'mvi-w))
  1269.             (mvi-forward-word number nil))))
  1270.  
  1271. (defun mvi-b (arg number &optional motion-arg text)
  1272.   "mvi backward word."
  1273.   (interactive "P\nV")
  1274.     (let ((register (mvi-nth 1 arg))
  1275.                 (append (mvi-nth 2 arg))
  1276.                 (g-flag (mvi-nth 3 arg))
  1277.                 (command (mvi-nth 4 arg))
  1278.                 (hist-tmp))
  1279.         (move-marker mvi-g-point (point))
  1280.         (if command 
  1281.             (progn
  1282.                 (move-marker mvi-com-point (point))
  1283.                 (mvi-forward-word (- number) command)
  1284.                 (mvi-execute-com 'mvi-b))
  1285.             (mvi-forward-word (- number) nil))))
  1286.  
  1287.  
  1288. (defun mvi-W (arg number &optional motion-arg text)
  1289.   "mvi forward whitespace delimited word."
  1290.   (interactive "P\nV")
  1291.     (let ((register (mvi-nth 1 arg))
  1292.                 (append (mvi-nth 2 arg))
  1293.                 (g-flag (mvi-nth 3 arg))
  1294.                 (command (mvi-nth 4 arg))
  1295.                 (hist-tmp))
  1296.         (move-marker mvi-g-point (point))
  1297.         (if command 
  1298.             (progn
  1299.                 (move-marker mvi-com-point (point))
  1300.                 (mvi-forward-Word number command)
  1301.                 (mvi-execute-com 'mvi-W))
  1302.             (mvi-forward-Word number nil))))
  1303.  
  1304. (defun mvi-B (arg number &optional motion-arg text)
  1305.   "mvi backward whitespace delimited word."
  1306.   (interactive "P\nV")
  1307.     (let ((register (mvi-nth 1 arg))
  1308.                 (append (mvi-nth 2 arg))
  1309.                 (g-flag (mvi-nth 3 arg))
  1310.                 (command (mvi-nth 4 arg))
  1311.                 (hist-tmp))
  1312.         (move-marker mvi-g-point (point))
  1313.         (if command 
  1314.             (progn
  1315.                 (move-marker mvi-com-point (point))
  1316.                 (mvi-forward-Word (- number) command)
  1317.                 (mvi-execute-com 'mvi-B))
  1318.             (mvi-forward-Word (- number) nil))))
  1319.  
  1320. (defun mvi-e (arg number &optional motion-arg text)
  1321.   "mvi to end of word."
  1322.   (interactive "P\nV")
  1323.     (let ((register (mvi-nth 1 arg))
  1324.                 (append (mvi-nth 2 arg))
  1325.                 (g-flag (mvi-nth 3 arg))
  1326.                 (command (mvi-nth 4 arg))
  1327.                 (hist-tmp))
  1328.         (move-marker mvi-g-point (point))
  1329.         (if command 
  1330.             (progn
  1331.                 (move-marker mvi-com-point (point))
  1332.                 (mvi-forward-end number t)
  1333.                 (mvi-execute-com 'mvi-e))
  1334.             (mvi-forward-end number nil))))
  1335.  
  1336. (defun mvi-v (arg number &optional motion-arg text)
  1337.   "mvi to end of previous word."
  1338.   (interactive "P\nV")
  1339.     (let ((register (mvi-nth 1 arg))
  1340.                 (append (mvi-nth 2 arg))
  1341.                 (g-flag (mvi-nth 3 arg))
  1342.                 (command (mvi-nth 4 arg))
  1343.                 (hist-tmp))
  1344.         (move-marker mvi-g-point (point))
  1345.         (if command 
  1346.             (progn
  1347.                 (move-marker mvi-com-point (point))
  1348.                 (mvi-forward-end (- number) t)
  1349.                 (mvi-execute-com 'mvi-v))
  1350.             (mvi-forward-end (- number) nil))))
  1351.  
  1352. (defun mvi-E (arg number &optional motion-arg text)
  1353.   "mvi to end of whitespace delimited word."
  1354.   (interactive "P\nV")
  1355.     (let ((register (mvi-nth 1 arg))
  1356.                 (append (mvi-nth 2 arg))
  1357.                 (g-flag (mvi-nth 3 arg))
  1358.                 (command (mvi-nth 4 arg))
  1359.                 (hist-tmp))
  1360.         (move-marker mvi-g-point (point))
  1361.         (if command 
  1362.             (progn
  1363.                 (move-marker mvi-com-point (point))
  1364.                 (mvi-forward-End number t)
  1365.                 (mvi-execute-com 'mvi-E))
  1366.             (mvi-forward-End number nil))))
  1367.  
  1368. (defun mvi-V (arg number &optional motion-arg text)
  1369.   "mvi to end of previous whitespace delimited word."
  1370.   (interactive "P\nV")
  1371.     (let ((register (mvi-nth 1 arg))
  1372.                 (append (mvi-nth 2 arg))
  1373.                 (g-flag (mvi-nth 3 arg))
  1374.                 (command (mvi-nth 4 arg))
  1375.                 (hist-tmp))
  1376.         (move-marker mvi-g-point (point))
  1377.         (if command 
  1378.             (progn
  1379.                 (move-marker mvi-com-point (point))
  1380.                 (mvi-forward-End (- number) t)
  1381.                 (mvi-execute-com 'mvi-V))
  1382.             (mvi-forward-End (- number) nil))))
  1383.  
  1384. (defun mvi-f (arg number &optional motion-arg text)
  1385.   "mvi find character."
  1386.   (interactive "P\nV")
  1387.     (let ((register (mvi-nth 1 arg))
  1388.                 (append (mvi-nth 2 arg))
  1389.                 (g-flag (mvi-nth 3 arg))
  1390.                 (command (mvi-nth 4 arg))
  1391.                 (hist-tmp))
  1392.         (or motion-arg (progn
  1393.             (or (eq (minibuffer-window) (selected-window))
  1394.                 (message "Find char:"))
  1395.             (setq motion-arg (read-char))))
  1396.         (cond
  1397.             ((and (= motion-arg ?\e) (interactive-p))
  1398.                 (message "Command cancelled"))
  1399.             (command 
  1400.                 (if (and (= motion-arg ?\C-q) (interactive-p))
  1401.                     (setq motion-arg (read-quoted-char "Enter quoted char")))
  1402.                 (setq mvi-last-f (list 'mvi-find t motion-arg))
  1403.                 (move-marker mvi-g-point (point))
  1404.                 (move-marker mvi-com-point (point))
  1405.                 (mvi-find number motion-arg t)
  1406.                 (mvi-execute-com 'mvi-f))
  1407.             (t
  1408.                 (if (and (= motion-arg ?\C-q) (interactive-p))
  1409.                     (setq motion-arg (read-quoted-char "Enter quoted char")))
  1410.                 (setq mvi-last-f (list 'mvi-find t motion-arg))
  1411.                 (move-marker mvi-g-point (point))
  1412.                 (mvi-find number motion-arg nil)))))
  1413.  
  1414. (defun mvi-F (arg number &optional motion-arg text)
  1415.   "mvi find backward character."
  1416.   (interactive "P\nV")
  1417.     (let ((register (mvi-nth 1 arg))
  1418.                 (append (mvi-nth 2 arg))
  1419.                 (g-flag (mvi-nth 3 arg))
  1420.                 (command (mvi-nth 4 arg))
  1421.                 (hist-tmp))
  1422.         (or motion-arg (progn
  1423.             (or (eq (minibuffer-window) (selected-window))
  1424.                 (message "Find char backwards:"))
  1425.             (setq motion-arg (read-char))))
  1426.         (cond
  1427.             ((and (= motion-arg ?\e) (interactive-p))
  1428.                 (message "Command cancelled"))
  1429.             (command 
  1430.                 (if (and (= motion-arg ?\C-q) (interactive-p))
  1431.                     (setq motion-arg (read-quoted-char "Enter quoted char")))
  1432.                 (setq mvi-last-f (list 'mvi-find nil motion-arg))
  1433.                 (move-marker mvi-g-point (point))
  1434.                 (move-marker mvi-com-point (point))
  1435.                 (mvi-find (- number) motion-arg t)
  1436.                 (mvi-execute-com 'mvi-F))
  1437.             (t
  1438.                 (if (and (= motion-arg ?\C-q) (interactive-p))
  1439.                     (setq motion-arg (read-quoted-char "Enter quoted char")))
  1440.                 (setq mvi-last-f (list 'mvi-find nil motion-arg))
  1441.                 (move-marker mvi-g-point (point))
  1442.                 (mvi-find (- number) motion-arg nil)))))
  1443.  
  1444. (defun mvi-t (arg number &optional motion-arg text)
  1445.   "mvi to character."
  1446.   (interactive "P\nV")
  1447.     (let ((register (mvi-nth 1 arg))
  1448.                 (append (mvi-nth 2 arg))
  1449.                 (g-flag (mvi-nth 3 arg))
  1450.                 (command (mvi-nth 4 arg)))
  1451.         (or motion-arg (progn
  1452.             (or (eq (minibuffer-window) (selected-window))
  1453.                 (message "To char:"))
  1454.             (setq motion-arg (read-char))))
  1455.         (cond
  1456.             ((and (= motion-arg ?\e) (interactive-p))
  1457.                 (message "Command cancelled"))
  1458.             (command 
  1459.                 (if (and (= motion-arg ?\C-q) (interactive-p))
  1460.                     (setq motion-arg (read-quoted-char "Enter quoted char")))
  1461.                 (setq mvi-last-f (list 'mvi-to t motion-arg))
  1462.                 (move-marker mvi-g-point (point))
  1463.                 (move-marker mvi-com-point (point))
  1464.                 (mvi-to number motion-arg t)
  1465.                 (mvi-execute-com 'mvi-t))
  1466.             (t
  1467.                 (if (and (= motion-arg ?\C-q) (interactive-p))
  1468.                     (setq motion-arg (read-quoted-char "Enter quoted char")))
  1469.                 (setq mvi-last-f (list 'mvi-to t motion-arg))
  1470.                 (move-marker mvi-g-point (point))
  1471.                 (mvi-to number motion-arg nil)))))
  1472.  
  1473. (defun mvi-T (arg number &optional motion-arg text)
  1474.   "mvi to backward character."
  1475.   (interactive "P\nV")
  1476.     (let ((register (mvi-nth 1 arg))
  1477.                 (append (mvi-nth 2 arg))
  1478.                 (g-flag (mvi-nth 3 arg))
  1479.                 (command (mvi-nth 4 arg))
  1480.                 (hist-tmp))
  1481.         (or motion-arg (progn
  1482.             (or (eq (minibuffer-window) (selected-window))
  1483.                 (message "To char backwards:"))
  1484.             (setq motion-arg (read-char))))
  1485.         (cond
  1486.             ((and (= motion-arg ?\e) (interactive-p))
  1487.                 (message "Command cancelled"))
  1488.             (command 
  1489.                 (if (and (= motion-arg ?\C-q) (interactive-p))
  1490.                     (setq motion-arg (read-quoted-char "Enter quoted char")))
  1491.                 (setq mvi-last-f (list 'mvi-to nil motion-arg))
  1492.                 (move-marker mvi-g-point (point))
  1493.                 (move-marker mvi-com-point (point))
  1494.                 (mvi-to (- number) motion-arg t)
  1495.                 (mvi-execute-com 'mvi-T))
  1496.             (t
  1497.                 (if (and (= motion-arg ?\C-q) (interactive-p))
  1498.                     (setq motion-arg (read-quoted-char "Enter quoted char")))
  1499.                 (setq mvi-last-f (list 'mvi-to nil motion-arg))
  1500.                 (move-marker mvi-g-point (point))
  1501.                 (mvi-to (- number) motion-arg nil)))))
  1502.  
  1503. (defun mvi-s-f-t (arg number &optional motion-arg text)
  1504.   "Repeat previous find or to command."
  1505.   (interactive "P\nV")
  1506.     (let ((register (mvi-nth 1 arg))
  1507.                 (append (mvi-nth 2 arg))
  1508.                 (g-flag (mvi-nth 3 arg))
  1509.                 (command (mvi-nth 4 arg))
  1510.                 (was-motion (nth 0 mvi-last-f))
  1511.                 (num (if (nth 1 mvi-last-f) number (- number)))
  1512.                 (motion-arg (nth 2 mvi-last-f))
  1513.                 (hist-tmp))
  1514.         (move-marker mvi-g-point (point))
  1515.         (if command 
  1516.             (progn
  1517.                 (move-marker mvi-com-point (point))
  1518.                 (funcall was-motion num motion-arg t)
  1519.                 (mvi-execute-com 'mvi-s-f-t))
  1520.             (funcall was-motion num motion-arg nil))))
  1521.  
  1522. (defun mvi-r-f-t (arg number &optional motion-arg text)
  1523.   "Repeat previous find or to command in the opposite direction."
  1524.   (interactive "P\nV")
  1525.     (let ((register (mvi-nth 1 arg))
  1526.                 (append (mvi-nth 2 arg))
  1527.                 (g-flag (mvi-nth 3 arg))
  1528.                 (command (mvi-nth 4 arg))
  1529.                 (was-motion (nth 0 mvi-last-f))
  1530.                 (num (if (nth 1 mvi-last-f) (- number) number))
  1531.                 (motion-arg (nth 2 mvi-last-f))
  1532.                 (hist-tmp))
  1533.         (move-marker mvi-g-point (point))
  1534.         (if command 
  1535.             (progn
  1536.                 (move-marker mvi-com-point (point))
  1537.                 (funcall was-motion num motion-arg t)
  1538.                 (mvi-execute-com 'mvi-r-f-t))
  1539.             (funcall was-motion num motion-arg nil))))
  1540.  
  1541. (defun mvi-eol (arg number &optional motion-arg text)
  1542.   "mvi to end of line."
  1543.   (interactive "P\nV")
  1544.     (let ((register (mvi-nth 1 arg))
  1545.                 (append (mvi-nth 2 arg))
  1546.                 (g-flag (mvi-nth 3 arg))
  1547.                 (command (mvi-nth 4 arg))
  1548.                 (hist-tmp))
  1549.         (move-marker mvi-g-point (point))
  1550.         (if command 
  1551.             (progn
  1552.                 (move-marker mvi-com-point (point))
  1553.                 (end-of-line number)
  1554.                 (mvi-execute-com 'mvi-eol))
  1555.             (end-of-line number))))
  1556.  
  1557. (defun mvi-C (arg number &optional motion-arg text)
  1558.   "mvi change to end of line."
  1559.   (interactive "P\nV")
  1560.     (let ((register (mvi-nth 1 arg))
  1561.                 (append (mvi-nth 2 arg))
  1562.                 (g-flag (mvi-nth 3 arg))
  1563.                 (command ?c)
  1564.                 (hist-tmp))
  1565.         (move-marker mvi-g-point (point))
  1566.         (move-marker mvi-com-point (point))
  1567.         (end-of-line number)
  1568.         (mvi-execute-com 'mvi-C)))
  1569.  
  1570. (defun mvi-D (arg number &optional motion-arg text)
  1571.   "mvi delete to end of line."
  1572.   (interactive "P\nV")
  1573.     (let ((register (mvi-nth 1 arg))
  1574.                 (append (mvi-nth 2 arg))
  1575.                 (g-flag (mvi-nth 3 arg))
  1576.                 (command ?d)
  1577.                 (hist-tmp))
  1578.         (move-marker mvi-g-point (point))
  1579.         (move-marker mvi-com-point (point))
  1580.         (end-of-line number)
  1581.         (mvi-execute-com 'mvi-D)))
  1582.  
  1583. (defun mvi-Y (arg number &optional motion-arg text)
  1584.   "mvi yank to end of line."
  1585.   (interactive "P\nV")
  1586.     (let ((register (mvi-nth 1 arg))
  1587.                 (append (mvi-nth 2 arg))
  1588.                 (g-flag (mvi-nth 3 arg))
  1589.                 (command ?y)
  1590.                 (hist-tmp))
  1591.         (move-marker mvi-g-point (point))
  1592.         (move-marker mvi-com-point (point))
  1593.         (end-of-line number)
  1594.         (mvi-execute-com 'mvi-Y)))
  1595.  
  1596. //E*O*F mvi.el.1//
  1597.  
  1598. exit 0
  1599. -- 
  1600. Doug Scofea   Email: nimbus3!djs@cis.ohio-state.edu    Phone:+1 614 459-1889
  1601.