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

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