home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / mvi.shar.3 / text0000.txt < prev   
Encoding:
Text File  |  1990-07-22  |  52.5 KB  |  2,189 lines

  1.  
  2.  
  3. # This is a shell archive.  Remove anything before this line, then
  4. # unpack it by saving it in a file and typing "sh file".  (Files
  5. # unpacked will be owned by you and have default permissions.)
  6. #
  7. # This archive contains:
  8. # mvi.el.2
  9.  
  10. echo x - mvi.el.2
  11. cat > "mvi.el.2" << '//E*O*F mvi.el.2//'
  12. (defun mvi-0 (arg number &optional motion-arg text)
  13.   "mvi move to first non-whitespace character on line."
  14.   (interactive "P\nV")
  15.     (let ((raw-number (mvi-nth 0 arg))
  16.                 (register (mvi-nth 1 arg))
  17.                 (append (mvi-nth 2 arg))
  18.                 (g-flag (mvi-nth 3 arg))
  19.                 (command (mvi-nth 4 arg))
  20.                 (hist-tmp))
  21.         (if (not raw-number) (setq number 0))
  22.         (move-marker mvi-g-point (point))
  23.         (if command 
  24.             (progn
  25.                 (move-marker mvi-com-point (point))
  26.                 (mvi-forward-line number)
  27.                 (mvi-execute-com 'mvi-0))
  28.             (mvi-forward-line number))))
  29.  
  30. (defun mvi-bol (arg number &optional motion-arg text)
  31.   "mvi to beginning of line."
  32.   (interactive "P\nV")
  33.     (let ((raw-number (mvi-nth 0 arg))
  34.                 (register (mvi-nth 1 arg))
  35.                 (append (mvi-nth 2 arg))
  36.                 (g-flag (mvi-nth 3 arg))
  37.                 (command (mvi-nth 4 arg))
  38.                 (hist-tmp))
  39.         (if (not raw-number) (setq number 0))
  40.         (move-marker mvi-g-point (point))
  41.         (if command 
  42.             (progn
  43.                 (move-marker mvi-com-point (point))
  44.                 (forward-line number)
  45.                 (mvi-execute-com 'mvi-bol))
  46.             (forward-line number))))
  47.  
  48. (defun mvi-paren (arg number &optional motion-arg text)
  49.   "mvi find matching parenthetical character."
  50.   (interactive "P\nV")
  51.     (let ((register (mvi-nth 1 arg))
  52.                 (append (mvi-nth 2 arg))
  53.                 (g-flag (mvi-nth 3 arg))
  54.                 (command (mvi-nth 4 arg))
  55.                 (hist-tmp))
  56.         (move-marker mvi-g-point (point))
  57.         (if command 
  58.             (progn
  59.                 (if (looking-at "[[({]") 
  60.                     (progn
  61.                         (move-marker mvi-com-point (point))
  62.                         (forward-list number))
  63.                     (if (looking-at "[])}]") 
  64.                         (progn
  65.                             (forward-char)
  66.                             (move-marker mvi-com-point (point))
  67.                             (backward-list number))
  68.                         (error "Not on parenthetical character")))
  69.                 (mvi-execute-com 'mvi-paren))
  70.             (if (looking-at "[[({]") 
  71.                 (progn
  72.                     (forward-list number)
  73.                     (backward-char))
  74.                 (if (looking-at "[])}]") 
  75.                     (progn
  76.                         (forward-char)
  77.                         (backward-list number))
  78.                     (error "Not on parenthetical character"))))))
  79.  
  80. (defun mvi-f-list (arg number &optional motion-arg text)
  81.   "mvi forward list."
  82.   (interactive "P\nV")
  83.     (let ((register (mvi-nth 1 arg))
  84.                 (append (mvi-nth 2 arg))
  85.                 (g-flag (mvi-nth 3 arg))
  86.                 (command (mvi-nth 4 arg))
  87.                 (hist-tmp))
  88.         (move-marker mvi-g-point (point))
  89.         (if command 
  90.             (progn
  91.                 (move-marker mvi-com-point (point))
  92.                 (forward-list number)
  93.                 (mvi-execute-com 'mvi-f-list))
  94.             (forward-list number))))
  95.  
  96. (defun mvi-b-list (arg number &optional motion-arg text)
  97.   "mvi backward list."
  98.   (interactive "P\nV")
  99.     (let ((register (mvi-nth 1 arg))
  100.                 (append (mvi-nth 2 arg))
  101.                 (g-flag (mvi-nth 3 arg))
  102.                 (command (mvi-nth 4 arg))
  103.                 (hist-tmp))
  104.         (move-marker mvi-g-point (point))
  105.         (if command 
  106.             (progn
  107.                 (move-marker mvi-com-point (point))
  108.                 (backward-list number)
  109.                 (mvi-execute-com 'mvi-b-list))
  110.             (backward-list number))))
  111.  
  112. (defun mvi-f-sexp (arg number &optional motion-arg text)
  113.   "mvi forward sub-expression."
  114.   (interactive "P\nV")
  115.     (let ((register (mvi-nth 1 arg))
  116.                 (append (mvi-nth 2 arg))
  117.                 (g-flag (mvi-nth 3 arg))
  118.                 (command (mvi-nth 4 arg))
  119.                 (hist-tmp))
  120.         (move-marker mvi-g-point (point))
  121.         (if command 
  122.             (progn
  123.                 (move-marker mvi-com-point (point))
  124.                 (forward-sexp number)
  125.                 (mvi-execute-com 'mvi-f-sexp))
  126.             (forward-sexp number))))
  127.  
  128. (defun mvi-b-sexp (arg number &optional motion-arg text)
  129.   "mvi backward sub-expression."
  130.   (interactive "P\nV")
  131.     (let ((register (mvi-nth 1 arg))
  132.                 (append (mvi-nth 2 arg))
  133.                 (g-flag (mvi-nth 3 arg))
  134.                 (command (mvi-nth 4 arg))
  135.                 (hist-tmp))
  136.         (move-marker mvi-g-point (point))
  137.         (if command 
  138.             (progn
  139.                 (move-marker mvi-com-point (point))
  140.                 (backward-sexp number)
  141.                 (mvi-execute-com 'mvi-b-sexp))
  142.             (backward-sexp number))))
  143.  
  144. (defun forward-text-sexp (arg &optional no-error)
  145.   "Move forward over text sub-expressions.
  146. Arguments are COUNT and optionally NO-ERROR on incomplete expressions.
  147. When interactive, COUNT is the processed prefix argument.
  148.  
  149. This function relies on 2 variables to parse the text.  The first is
  150. \"text-sexp-delim\" which is a regular expression that matches all the 
  151. delimeters. The second is \"text-sexp-data\" which is an a-list, the
  152. car of which is a string representing the opening delimeter, the cdr
  153. contains a list of data related to it.  The elements of the list in
  154. order are:
  155.  
  156. 0. A string that is used as a regular expression of the corresponding
  157.    closing delimiter.
  158. 1. If t nesting of sub-expressions inside this one is allowed.
  159. 2. A string that is used as a regular expression of a delimiter that is an
  160.    error if found before the closing delimiter.
  161. 3. If t after a closing delimeter if found, go to the end of the delimiter.
  162. 4. If t after a full text sub-expression, go to the end of the delimiter.
  163. 5. On moving backward over a text sub-expression, if starting on a delimiter,
  164.    if t, it is a valid starting point."
  165.   (interactive "p")
  166.   (let ((case-fold-search nil)
  167.                 (end nil)
  168.                 (not-done t)
  169.                 (exit-status t)
  170.                 (flag)
  171.                 (key)
  172.                 (data)
  173.                 (hold-end))
  174.         (while (and (> arg 0) not-done)
  175.             (if (re-search-forward text-sexp-delim nil 1 1)
  176.                     (progn
  177.                         (setq key (buffer-substring (match-beginning 0) (point)))
  178.                         (setq data (cdr (assoc key text-sexp-data)))
  179.                         (setq end (list data))
  180.                         (or data (setq not-done nil exit-status nil)))
  181.                 (setq not-done nil))
  182.             (setq flag t)
  183.             (while (and flag not-done)
  184.                 (if (re-search-forward (if (nth 1 data) text-sexp-delim (nth 0 data)) nil 1 1)
  185.                         (progn
  186.                             (setq hold-end (point))
  187.                             (goto-char (match-beginning 0))
  188.                             (cond
  189.                              ((looking-at (nth 0 data))
  190.                                 (if (nth 3 data) (goto-char (match-end 0)))
  191.                                 (setq end (nthcdr 1 end))
  192.                                 (setq data (nth 0 end))
  193.                                 (or end 
  194.                                         (progn 
  195.                                             (if (nth 4 data) (goto-char (match-end 0)))
  196.                                             (setq flag nil))))
  197.                              ((and (nth 2 data) (looking-at (nth 2 data)))
  198.                                 (goto-char (match-end 0))
  199.                                 (setq not-done nil exit-status nil))
  200.                              (t
  201.                                 (setq key (buffer-substring (point) hold-end))
  202.                                 (setq data (cdr (assoc key text-sexp-data)))
  203.                                 (setq end (cons data end))
  204.                                 (goto-char hold-end)
  205.                                 (or data (setq not-done nil exit-status nil)))))
  206.                     (setq not-done nil)))
  207.             (setq arg (1- arg)))
  208.     (if exit-status
  209.                 t
  210.       (if no-error
  211.                     nil
  212.                 (error "Incomplete text sub-expression")))))
  213.  
  214. (defun backward-text-sexp (arg &optional no-error start-at)
  215.   "Move backward over text sub-expressions.
  216. Arguments are COUNT and optionally NO-ERROR on incomplete expressions
  217. and START-AT to start the search at a different point.
  218. When interactive, COUNT is the processed prefix argument."
  219.   (interactive "p")
  220.   (let ((exit-status t)
  221.                 (not-done t)
  222.                 (hold-beg)
  223.                 (hold-end)
  224.                 (top))
  225.         (if (and (looking-at text-sexp-delim)
  226.                          (nth 5 (cdr (assoc (buffer-substring (point) (match-end 0))
  227.                                                                 text-sexp-data))))
  228.                 (setq hold-beg (match-beginning 0) hold-end (match-end 0))
  229.             (if (re-search-backward text-sexp-delim nil 1 1)
  230.                     (setq hold-beg (match-beginning 0) hold-end (match-end 0))
  231.                 (setq exit-status nil not-done nil)))
  232.         (if start-at (goto-char start-at))
  233.         (while not-done
  234.             (if (re-search-backward text-sexp-delim nil 1 1)
  235.                     (progn
  236.                         (setq top (point))
  237.                         (and (forward-text-sexp arg t)
  238.                                  (or (= (point) hold-beg) (= (point) hold-end))
  239.                                  (setq not-done nil))
  240.                         (goto-char top))
  241.                 (setq exit-status nil not-done nil)))
  242.     (if exit-status
  243.                 t
  244.       (if no-error
  245.                     nil
  246.                 (error "Incomplete text sub-expression")))))
  247.  
  248. (defun mvi-f-text-sexp (arg number &optional motion-arg text)
  249.   "mvi forward text sub-expression."
  250.   (interactive "P\nV")
  251.     (let ((register (mvi-nth 1 arg))
  252.                 (append (mvi-nth 2 arg))
  253.                 (g-flag (mvi-nth 3 arg))
  254.                 (command (mvi-nth 4 arg))
  255.                 (hist-tmp))
  256.         (move-marker mvi-g-point (point))
  257.         (if command 
  258.             (progn
  259.                 (move-marker mvi-com-point (point))
  260.                 (forward-text-sexp number)
  261.                 (mvi-execute-com 'mvi-f-text-sexp))
  262.             (forward-text-sexp number))))
  263.  
  264. (defun mvi-b-text-sexp (arg number &optional motion-arg text)
  265.   "mvi backward text sub-expression."
  266.   (interactive "P\nV")
  267.     (let ((register (mvi-nth 1 arg))
  268.                 (append (mvi-nth 2 arg))
  269.                 (g-flag (mvi-nth 3 arg))
  270.                 (command (mvi-nth 4 arg))
  271.                 (orig-char (point))
  272.                 (start-at (point))
  273.                 (flag t)
  274.                 (c)
  275.                 (hist-tmp))
  276.         (move-marker mvi-g-point (point))
  277.         (if command (move-marker mvi-com-point (point)))
  278.         (if (>= number 0)
  279.                 (backward-text-sexp number)
  280.             (while flag
  281.                 (if (backward-text-sexp (- number) t start-at) 
  282.                         (if (progn (message "Go back further?") 
  283.                                              (setq c (read-char)) (or (= c ?y) (= c ?Y)))
  284.                                 (progn
  285.                                     (setq start-at (point))
  286.                                     (goto-char orig-char))
  287.                             (setq flag nil))
  288.                     (error "Incomplete text sub-expression"))))
  289.         (if command (mvi-execute-com 'mvi-b-text-sexp))))
  290.  
  291. (defun mvi-forward-sentence (arg)
  292.   "Move forward to next sentence-end.  Differs from gnus by moving to
  293. the beginning of the next sentence if possible."
  294.   (while (< arg 0)
  295.     (let ((par-beg (save-excursion (start-of-paragraph-text) (point))))
  296.       (if (re-search-backward (concat sentence-end "[^ \t\n]") par-beg t)
  297.       (goto-char (1- (match-end 0)))
  298.     (goto-char par-beg)))
  299.     (setq arg (1+ arg)))
  300.   (while (> arg 0)
  301.     (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
  302.       (if (re-search-forward sentence-end par-end t)
  303.                 (progn
  304.                     (skip-chars-backward " \t\n")
  305.                     (and (= arg 1) (looking-at "[ \t]+\\w\\|[ \t]*\n[ \t]*\\w") 
  306.                         (goto-char (1- (match-end 0)))))
  307.                 (goto-char par-end)))
  308.     (setq arg (1- arg))))
  309.  
  310. (defun mvi-f-sent (arg number &optional motion-arg text)
  311.   "mvi forward sentence."
  312.   (interactive "P\nV")
  313.     (let ((register (mvi-nth 1 arg))
  314.                 (append (mvi-nth 2 arg))
  315.                 (g-flag (mvi-nth 3 arg))
  316.                 (command (mvi-nth 4 arg))
  317.                 (hist-tmp))
  318.         (move-marker mvi-g-point (point))
  319.         (if command 
  320.             (progn
  321.                 (move-marker mvi-com-point (point))
  322.                 (mvi-forward-sentence number)
  323.                 (mvi-execute-com 'mvi-f-sent))
  324.             (mvi-forward-sentence number))))
  325.  
  326. (defun mvi-b-sent (arg number &optional motion-arg text)
  327.   "mvi backward sentence."
  328.   (interactive "P\nV")
  329.     (let ((register (mvi-nth 1 arg))
  330.                 (append (mvi-nth 2 arg))
  331.                 (g-flag (mvi-nth 3 arg))
  332.                 (command (mvi-nth 4 arg))
  333.                 (hist-tmp))
  334.         (move-marker mvi-g-point (point))
  335.         (if command 
  336.             (progn
  337.                 (move-marker mvi-com-point (point))
  338.                 (mvi-forward-sentence (- number))
  339.                 (mvi-execute-com 'mvi-b-sent))
  340.             (mvi-forward-sentence (- number)))))
  341.  
  342. (defun mvi-f-par (arg number &optional motion-arg text)
  343.   "mvi forward paragraph."
  344.   (interactive "P\nV")
  345.     (let ((register (mvi-nth 1 arg))
  346.                 (append (mvi-nth 2 arg))
  347.                 (g-flag (mvi-nth 3 arg))
  348.                 (command (mvi-nth 4 arg))
  349.                 (hist-tmp))
  350.         (move-marker mvi-g-point (point))
  351.         (if command 
  352.             (progn
  353.                 (move-marker mvi-com-point (point))
  354.                 (forward-paragraph number)
  355.                 (mvi-execute-com 'mvi-f-par))
  356.             (forward-paragraph number))))
  357.  
  358. (defun mvi-b-par (arg number &optional motion-arg text)
  359.   "mvi backward paragraph."
  360.   (interactive "P\nV")
  361.     (let ((register (mvi-nth 1 arg))
  362.                 (append (mvi-nth 2 arg))
  363.                 (g-flag (mvi-nth 3 arg))
  364.                 (command (mvi-nth 4 arg))
  365.                 (hist-tmp))
  366.         (move-marker mvi-g-point (point))
  367.         (if command 
  368.             (progn
  369.                 (move-marker mvi-com-point (point))
  370.                 (backward-paragraph number)
  371.                 (mvi-execute-com 'mvi-b-par))
  372.             (backward-paragraph number))))
  373.  
  374. (defun mvi-forward-page (count)
  375.   "Move forward to page boundary.  Differs from gnus in that it stops at
  376. the beginning of the next page."
  377.     (and (> count 0) (looking-at page-delimiter) (goto-char (match-end 0)))
  378.   (while (and (> count 0) (not (eobp)))
  379.     (if (re-search-forward page-delimiter nil t)
  380.             (if (= count 1) (goto-char (match-beginning 0)))
  381.       (goto-char (point-max)))
  382.     (setq count (1- count)))
  383.   (while (and (< count 0) (not (bobp)))
  384.     (or (re-search-backward page-delimiter nil t)
  385.       (goto-char (point-min)))
  386.     (setq count (1+ count))))
  387.  
  388. (defun mvi-f-page (arg number &optional motion-arg text)
  389.   "mvi forward page."
  390.   (interactive "P\nV")
  391.     (let ((register (mvi-nth 1 arg))
  392.                 (append (mvi-nth 2 arg))
  393.                 (g-flag (mvi-nth 3 arg))
  394.                 (command (mvi-nth 4 arg))
  395.                 (hist-tmp))
  396.         (move-marker mvi-g-point (point))
  397.         (if command 
  398.             (progn
  399.                 (move-marker mvi-com-point (point))
  400.                 (mvi-forward-page number)
  401.                 (mvi-execute-com 'mvi-f-page))
  402.             (mvi-forward-page number))))
  403.  
  404. (defun mvi-b-page (arg number &optional motion-arg text)
  405.   "mvi backward page."
  406.   (interactive "P\nV")
  407.     (let ((register (mvi-nth 1 arg))
  408.                 (append (mvi-nth 2 arg))
  409.                 (g-flag (mvi-nth 3 arg))
  410.                 (command (mvi-nth 4 arg))
  411.                 (hist-tmp))
  412.         (move-marker mvi-g-point (point))
  413.         (if command 
  414.             (progn
  415.                 (move-marker mvi-com-point (point))
  416.                 (mvi-forward-page (- number))
  417.                 (mvi-execute-com 'mvi-b-page))
  418.             (mvi-forward-page (- number)))))
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480. ;; moving around
  481.  
  482. (defun mvi-to-col (arg number &optional motion-arg text)
  483.   "mvi move to column."
  484.   (interactive "P\nV")
  485.     (let ((raw-number (mvi-nth 0 arg))
  486.                 (register (mvi-nth 1 arg))
  487.                 (append (mvi-nth 2 arg))
  488.                 (g-flag (mvi-nth 3 arg))
  489.                 (command (mvi-nth 4 arg))
  490.                 (hist-tmp))
  491.         (if (not raw-number) (setq number 0))
  492.         (move-marker mvi-g-point (point))
  493.         (if command 
  494.             (progn
  495.                 (move-marker mvi-com-point (point))
  496.                 (move-to-column number)
  497.                 (mvi-execute-com 'mvi-to-col))
  498.             (move-to-column number))))
  499.  
  500. (defun mvi-what-col (arg)
  501.   "mvi display current column."
  502.   (interactive "P")
  503.     (let ((command (mvi-nth 4 arg)))
  504.         (if command (error "Bad command"))
  505.         (message (format "Current column = %s" (current-column)))))
  506.  
  507. (defun mvi-G (arg number &optional motion-arg text)
  508.   "mvi goto line number."
  509.   (interactive "P\nV")
  510.     (let ((raw-number (mvi-nth 0 arg))
  511.                 (register (mvi-nth 1 arg))
  512.                 (append (mvi-nth 2 arg))
  513.                 (g-flag (mvi-nth 3 arg))
  514.                 (command (mvi-nth 4 arg))
  515.                 (hist-tmp))
  516.         (if (not raw-number) (setq number 8000000))
  517.         (move-marker mvi-g-point (point))
  518.         (if (< number 0)
  519.             (setq number (- number))
  520.             (push-mark nil t))
  521.         (if command 
  522.             (progn
  523.                 (mvi-enlarge-region (point) (progn (goto-line number) (point)))
  524.                 (setq number raw-number)
  525.                 (mvi-execute-com 'mvi-G))
  526.             (goto-line number))))
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588. ;; window scrolling etc.
  589.  
  590. (defun mvi-H (arg number &optional motion-arg text)
  591.   "mvi move to top of screen."
  592.   (interactive "P\nV")
  593.     (let ((register (mvi-nth 1 arg))
  594.                 (append (mvi-nth 2 arg))
  595.                 (g-flag (mvi-nth 3 arg))
  596.                 (command (mvi-nth 4 arg))
  597.                 (hist-tmp))
  598.         (move-marker mvi-g-point (point))
  599.         (if command 
  600.             (progn
  601.                 (mvi-enlarge-region (point) (progn (move-to-window-line (1- number))
  602.                     (point)))
  603.                 (mvi-execute-com 'mvi-H))
  604.             (move-to-window-line (1- number)))))
  605.  
  606. (defun mvi-L (arg number &optional motion-arg text)
  607.   "mvi move to bottom of screen."
  608.   (interactive "P\nV")
  609.     (let ((register (mvi-nth 1 arg))
  610.                 (append (mvi-nth 2 arg))
  611.                 (g-flag (mvi-nth 3 arg))
  612.                 (command (mvi-nth 4 arg))
  613.                 (hist-tmp))
  614.         (move-marker mvi-g-point (point))
  615.         (if command 
  616.             (progn
  617.                 (mvi-enlarge-region (point) (progn (move-to-window-line (- number))
  618.                     (point)))
  619.                 (mvi-execute-com 'mvi-L))
  620.             (move-to-window-line (- number)))))
  621.  
  622. (defun mvi-M (arg number &optional motion-arg text)
  623.   "mvi move to the middle of screen."
  624.   (interactive "P\nV")
  625.     (let ((register (mvi-nth 1 arg))
  626.                 (append (mvi-nth 2 arg))
  627.                 (g-flag (mvi-nth 3 arg))
  628.                 (command (mvi-nth 4 arg))
  629.                 (hist-tmp))
  630.         (move-marker mvi-g-point (point))
  631.         (if command 
  632.             (progn
  633.                 (mvi-enlarge-region (point) (progn 
  634.                     (move-to-window-line (+ (/ (1- (window-height)) 2) (1- number)))
  635.                     (point)))
  636.                 (mvi-execute-com 'mvi-M))
  637.             (move-to-window-line (+ (/ (1- (window-height)) 2) (1- number))))))
  638.  
  639. (defun mvi-line-to (arg number)
  640.   "Move point to top, middle, or bottom of screen."
  641.   (interactive "P\nV")
  642.     (let ((command (mvi-nth 4 arg)))
  643.         (if command (error "Bad command"))
  644.         (move-marker mvi-g-point (point))
  645.         (cond
  646.          ((= last-command-char ?t)
  647.                 (recenter (1- number))) 
  648.          ((= last-command-char ?m) 
  649.                 (recenter (+ (1- number) (/ (1- (window-height)) 2))))
  650.          ((= last-command-char ?b)
  651.                 (recenter (- (window-height) (1+ number)))))))
  652.  
  653. (defun mvi-search-recenter (arg number)
  654.   "Move point to top, middle, or bottom of screen after a search."
  655.   (interactive "P\nV")
  656.     (let ((command (mvi-nth 4 arg)))
  657.         (if command (error "Bad command"))
  658.         (cond
  659.          ((= last-command-char ?T)
  660.             (setq mvi-search-func (list 'lambda '() (list 'recenter (1- number)))))
  661.          ((= last-command-char ?M) 
  662.             (setq mvi-search-func (list 'lambda '() (list
  663.                 'recenter (list '+ (1- number) 
  664.                                                 (list '/ (list '1- (list 'window-height)) 2))))))
  665.          ((= last-command-char ?B)
  666.             (setq mvi-search-func (list 'lambda '() (list
  667.                 'recenter (list '- (list 'window-height) (1+ number))))))
  668.          ((> number 1)
  669.             (setq mvi-search-func (list 'lambda '() (list 'mvi-search-context number))))
  670.          (t
  671.             (setq mvi-search-func '(lambda ()))))))
  672.  
  673. (defun mvi-search-context (number)
  674.     "After a search, try to force at least NUMBER lines of context on screen."
  675.     (let ((height (window-height))
  676.                 (line (count-lines (window-start) (point))))
  677.         (cond
  678.          ((>= number height))
  679.          ((< line number) (recenter (1- number)))
  680.          ((< (- height line) number) (recenter (- height (1+ number)))))))
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741. ;; scrolling
  742.  
  743. (defun mvi-scroll-back (arg number)
  744.   "mvi scroll back page."
  745.   (interactive "P\nV")
  746.     (let ((command (mvi-nth 4 arg)))
  747.         (if command (error "Bad command"))
  748.         (move-marker mvi-g-point (point))
  749.         (if arg
  750.             (scroll-down (* (1- (window-height)) number))
  751.             (scroll-down))))
  752.  
  753. (defun mvi-scroll-forward (arg number)
  754.   "mvi scroll forward page."
  755.   (interactive "P\nV")
  756.     (let ((command (mvi-nth 4 arg)))
  757.         (if command (error "Bad command"))
  758.         (move-marker mvi-g-point (point))
  759.         (if arg
  760.             (scroll-up (* (1- (window-height)) number))
  761.             (scroll-up))))
  762.  
  763. (defun mvi-scroll-up (arg number)
  764.   "mvi scroll up a half of page."
  765.   (interactive "P\nV")
  766.     (let ((command (mvi-nth 4 arg)))
  767.         (if command (error "Bad command"))
  768.         (move-marker mvi-g-point (point))
  769.         (scroll-down (/ (* (1- (window-height)) number) 2))))
  770.  
  771. (defun mvi-scroll-down (arg number)
  772.   "mvi scroll down a half of page."
  773.   (interactive "P\nV")
  774.     (let ((command (mvi-nth 4 arg)))
  775.         (if command (error "Bad command"))
  776.         (move-marker mvi-g-point (point))
  777.         (scroll-up (/ (* (1- (window-height)) number) 2))))
  778.  
  779. (defun mvi-scroll-up-one (arg number)
  780.   "mvi scroll up a line."
  781.   (interactive "P\nV")
  782.     (let ((command (mvi-nth 4 arg)))
  783.         (if command (error "Bad command"))
  784.         (move-marker mvi-g-point (point))
  785.         (scroll-down number)))
  786.  
  787. (defun mvi-scroll-down-one (arg number)
  788.   "mvi scroll down a line."
  789.   (interactive "P\nV")
  790.     (let ((command (mvi-nth 4 arg)))
  791.         (if command (error "Bad command"))
  792.         (move-marker mvi-g-point (point))
  793.         (scroll-up number)))
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855. ;; searching
  856.  
  857. (defun mvi-f-search-beg (arg number &optional motion-arg text no-update)
  858.   "Search forward to beginning."
  859.   (interactive "P\nV")
  860.     (let ((register (mvi-nth 1 arg))
  861.                 (append (mvi-nth 2 arg))
  862.                 (g-flag (mvi-nth 3 arg))
  863.                 (command (mvi-nth 4 arg))
  864.                 (count (if (> number 0) number (- number)))
  865.                 (fold case-fold-search)
  866.                 (case-fold-search nil)
  867.                 (orig-char (point))
  868.                 (regexp)
  869.                 (start)
  870.                 (hist-tmp))
  871.         (or motion-arg
  872.             (progn
  873.                 (if mvi-magic 
  874.                     (setq motion-arg (read-string "Enter re-string: "))
  875.                     (setq motion-arg (read-string "Enter string: ")))
  876.                 (or (string= motion-arg "")
  877.                     (setq command-history 
  878.                         (cons (list 'mvi-f-search-beg nil number motion-arg nil) 
  879.                             command-history)))))
  880.         (if (string= motion-arg "")
  881.             (setq motion-arg mvi-search-string)
  882.             (setq mvi-search-string motion-arg))
  883.         (or no-update (setq mvi-last-search (list 'mvi-f-search-beg 
  884.             (if (> number 0) t nil))))
  885.         (move-marker mvi-g-point (point))
  886.         (if (> number 0) (push-mark nil t))
  887.         (if (and fold (not (string-match "[A-Z]" motion-arg)))
  888.             (setq case-fold-search t)
  889.             (setq case-fold-search nil))
  890.         (if mvi-magic 
  891.           (setq regexp motion-arg)
  892.           (setq regexp (regexp-quote motion-arg)))
  893.         (if command (move-marker mvi-com-point (point)))
  894.         (condition-case ERR
  895.             (progn
  896.                 (if (and folded-display search-skip-fold)
  897.                     (progn
  898.                         (if (looking-at regexp) (goto-char (match-end 0)))
  899.                         (setq start (point))
  900.                         (while (and (/= count 0) (re-search-forward regexp nil mvi-wrap 1))
  901.                             (or (folded-p (match-beginning 0)) (setq count (1- count))))
  902.                         (if (= count 0)
  903.                             (goto-char (match-beginning 0))
  904.                             (progn
  905.                                 (goto-char (point-min))
  906.                                 (while (and (re-search-forward regexp start nil 1)
  907.                                     (folded-p (match-beginning 0)))) 
  908.                                 (goto-char (match-beginning 0))
  909.                                 (setq command nil)
  910.                                 (message "Search wrapped around buffer"))))
  911.                     (if (looking-at regexp) (goto-char (match-end 0)))
  912.                     (setq start (point))
  913.                     (if (re-search-forward regexp nil mvi-wrap count)
  914.                         (goto-char (match-beginning 0))
  915.                         (progn
  916.                             (goto-char (point-min))
  917.                             (re-search-forward regexp start nil 1)
  918.                             (goto-char (match-beginning 0))
  919.                             (setq command nil)
  920.                             (message "Search wrapped around buffer"))))
  921.                 (and command (mvi-execute-com 'mvi-f-search-beg))
  922.                 (funcall mvi-search-func))
  923.         (error 
  924.             (goto-char orig-char)
  925.             (error "Search failed: %s" (prin1-to-string motion-arg)))
  926.         (quit 
  927.             (goto-char orig-char)))))
  928.  
  929. (defun mvi-b-search-beg (arg number &optional motion-arg text no-update)
  930.   "Search backward to beginning."
  931.   (interactive "P\nV")
  932.     (let ((register (mvi-nth 1 arg))
  933.                 (append (mvi-nth 2 arg))
  934.                 (g-flag (mvi-nth 3 arg))
  935.                 (command (mvi-nth 4 arg))
  936.                 (count (if (> number 0) number (- number)))
  937.                 (fold case-fold-search)
  938.                 (case-fold-search nil)
  939.                 (orig-char (point))
  940.                 (regexp)
  941.                 (start)
  942.                 (hist-tmp))
  943.         (or motion-arg
  944.             (progn
  945.                 (if mvi-magic 
  946.                     (setq motion-arg (read-string "Enter re-string: "))
  947.                     (setq motion-arg (read-string "Enter string: ")))
  948.                 (or (string= motion-arg "")
  949.                     (setq command-history 
  950.                         (cons (list 'mvi-b-search-beg nil number motion-arg nil) 
  951.                             command-history)))))
  952.         (if (string= motion-arg "")
  953.             (setq motion-arg mvi-search-string)
  954.             (setq mvi-search-string motion-arg))
  955.         (or no-update (setq mvi-last-search (list 'mvi-b-search-beg 
  956.             (if (> number 0) t nil))))
  957.         (move-marker mvi-g-point (point))
  958.         (if (> number 0) (push-mark nil t))
  959.         (if (and fold (not (string-match "[A-Z]" motion-arg)))
  960.             (setq case-fold-search t)
  961.             (setq case-fold-search nil))
  962.         (if mvi-magic 
  963.           (setq regexp motion-arg)
  964.           (setq regexp (regexp-quote motion-arg)))
  965.         (if command (move-marker mvi-com-point (point)))
  966.         (condition-case ERR
  967.             (progn
  968.                 (if (and folded-display search-skip-fold)
  969.                     (progn
  970.                         (setq start (point))
  971.                         (while (and (/= count 0) 
  972.                             (re-search-backward regexp nil mvi-wrap 1))
  973.                                 (or (folded-p) (setq count (1- count))))
  974.                         (or (= count 0)
  975.                             (progn
  976.                                 (goto-char (point-max))
  977.                                 (while (and (re-search-backward regexp start nil 1)
  978.                                     (folded-p))) 
  979.                                 (setq command nil)
  980.                                 (message "Search wrapped around buffer"))))
  981.                     (setq start (point))
  982.                     (or (re-search-backward regexp nil mvi-wrap count)
  983.                         (progn
  984.                             (goto-char (point-max))
  985.                             (re-search-backward regexp start nil 1)
  986.                             (setq command nil)
  987.                             (message "Search wrapped around buffer"))))
  988.                 (and command (mvi-execute-com 'mvi-b-search-beg))
  989.                 (funcall mvi-search-func))
  990.         (error 
  991.             (goto-char orig-char)
  992.             (error "Search failed: %s" (prin1-to-string motion-arg)))
  993.         (quit 
  994.             (goto-char orig-char)))))
  995.  
  996. (defun mvi-f-search-end (arg number &optional motion-arg text no-update)
  997.   "Search forward to end."
  998.   (interactive "P\nV")
  999.     (let ((register (mvi-nth 1 arg))
  1000.                 (append (mvi-nth 2 arg))
  1001.                 (g-flag (mvi-nth 3 arg))
  1002.                 (command (mvi-nth 4 arg))
  1003.                 (count (if (> number 0) number (- number)))
  1004.                 (fold case-fold-search)
  1005.                 (case-fold-search nil)
  1006.                 (orig-char (point))
  1007.                 (regexp)
  1008.                 (start)
  1009.                 (hist-tmp))
  1010.         (or motion-arg
  1011.             (progn
  1012.                 (if mvi-magic 
  1013.                     (setq motion-arg (read-string "Enter re-string: "))
  1014.                     (setq motion-arg (read-string "Enter string: ")))
  1015.                 (or (string= motion-arg "")
  1016.                     (setq command-history 
  1017.                         (cons (list 'mvi-f-search-end nil number motion-arg nil) 
  1018.                             command-history)))))
  1019.         (if (string= motion-arg "")
  1020.             (setq motion-arg mvi-search-string)
  1021.             (setq mvi-search-string motion-arg))
  1022.         (or no-update (setq mvi-last-search (list 'mvi-f-search-end 
  1023.             (if (> number 0) t nil))))
  1024.         (move-marker mvi-g-point (point))
  1025.         (if (> number 0) (push-mark nil t))
  1026.         (if (and fold (not (string-match "[A-Z]" motion-arg)))
  1027.             (setq case-fold-search t)
  1028.             (setq case-fold-search nil))
  1029.         (if mvi-magic 
  1030.           (setq regexp motion-arg)
  1031.           (setq regexp (regexp-quote motion-arg)))
  1032.         (if command (move-marker mvi-com-point (point)))
  1033.         (condition-case ERR
  1034.             (progn
  1035.                 (if (and folded-display search-skip-fold)
  1036.                     (progn
  1037.                         (setq start (point))
  1038.                         (while (and (/= count 0) (re-search-forward regexp nil mvi-wrap 1))
  1039.                             (or (folded-p (match-beginning 0)) (setq count (1- count))))
  1040.                         (or (= count 0)
  1041.                             (progn
  1042.                                 (goto-char (point-min))
  1043.                                 (while (and (re-search-forward regexp start nil 1)
  1044.                                     (folded-p (match-beginning 0)))) 
  1045.                                 (setq command nil)
  1046.                                 (message "Search wrapped around buffer"))))
  1047.                     (setq start (point))
  1048.                     (or (re-search-forward regexp nil mvi-wrap count)
  1049.                         (progn
  1050.                             (goto-char (point-min))
  1051.                             (re-search-forward regexp start nil 1)
  1052.                             (setq command nil)
  1053.                             (message "Search wrapped around buffer"))))
  1054.                 (and command (mvi-execute-com 'mvi-f-search-end))
  1055.                 (funcall mvi-search-func))
  1056.         (error 
  1057.             (goto-char orig-char)
  1058.             (error "Search failed: %s" (prin1-to-string motion-arg)))
  1059.         (quit 
  1060.             (goto-char orig-char)))))
  1061.  
  1062. (defun mvi-b-search-end (arg number &optional motion-arg text no-update)
  1063.   "Search backward to end."
  1064.   (interactive "P\nV")
  1065.     (let ((register (mvi-nth 1 arg))
  1066.                 (append (mvi-nth 2 arg))
  1067.                 (g-flag (mvi-nth 3 arg))
  1068.                 (command (mvi-nth 4 arg))
  1069.                 (count (if (> number 0) number (- number)))
  1070.                 (fold case-fold-search)
  1071.                 (case-fold-search nil)
  1072.                 (orig-char (point))
  1073.                 (regexp)
  1074.                 (start)
  1075.                 (hist-tmp))
  1076.         (or motion-arg
  1077.             (progn
  1078.                 (if mvi-magic 
  1079.                     (setq motion-arg (read-string "Enter re-string: "))
  1080.                     (setq motion-arg (read-string "Enter string: ")))
  1081.                 (or (string= motion-arg "")
  1082.                     (setq command-history 
  1083.                         (cons (list 'mvi-b-search-end nil number motion-arg nil) 
  1084.                             command-history)))))
  1085.         (if (string= motion-arg "")
  1086.             (setq motion-arg mvi-search-string)
  1087.             (setq mvi-search-string motion-arg))
  1088.         (or no-update (setq mvi-last-search (list 'mvi-b-search-end 
  1089.             (if (> number 0) t nil))))
  1090.         (move-marker mvi-g-point (point))
  1091.         (if (> number 0) (push-mark nil t))
  1092.         (if (and fold (not (string-match "[A-Z]" motion-arg)))
  1093.             (setq case-fold-search t)
  1094.             (setq case-fold-search nil))
  1095.         (if mvi-magic 
  1096.           (setq regexp motion-arg)
  1097.           (setq regexp (regexp-quote motion-arg)))
  1098.         (if command (move-marker mvi-com-point (point)))
  1099.         (condition-case ERR
  1100.             (progn
  1101.                 (if (and folded-display search-skip-fold)
  1102.                     (progn
  1103.                         (if (and (re-search-backward regexp nil t 1)
  1104.                                     (= orig-char (match-end 0)))
  1105.                                 (goto-char (match-beginning 0))
  1106.                                 (goto-char orig-char))
  1107.                         (setq start (point))
  1108.                         (while (and (/= count 0) 
  1109.                             (re-search-backward regexp nil mvi-wrap 1))
  1110.                                 (or (folded-p) (setq count (1- count))))
  1111.                         (if (= count 0)
  1112.                             (goto-char (match-end 0))
  1113.                             (progn
  1114.                                 (goto-char (point-max))
  1115.                                 (while (and (re-search-backward regexp start nil 1)
  1116.                                     (folded-p))) 
  1117.                                 (goto-char (match-end 0))
  1118.                                 (setq command nil)
  1119.                                 (message "Search wrapped around buffer"))))
  1120.                     (if (and (re-search-backward regexp nil t 1)
  1121.                                 (= orig-char (match-end 0)))
  1122.                             (goto-char (match-beginning 0))
  1123.                             (goto-char orig-char))
  1124.                     (setq start (point))
  1125.                     (if (re-search-backward regexp nil mvi-wrap count)
  1126.                         (goto-char (match-end 0))
  1127.                         (progn
  1128.                             (goto-char (point-max))
  1129.                             (re-search-backward regexp start nil 1)
  1130.                             (goto-char (match-end 0))
  1131.                             (setq command nil)
  1132.                             (message "Search wrapped around buffer"))))
  1133.                 (and command (mvi-execute-com 'mvi-b-search-end))
  1134.                 (funcall mvi-search-func))
  1135.         (error 
  1136.             (goto-char orig-char)
  1137.             (error "Search failed: %s" (prin1-to-string motion-arg)))
  1138.         (quit 
  1139.             (goto-char orig-char)))))
  1140.  
  1141. (defun mvi-n (arg number)
  1142.   "Repeat previous search."
  1143.   (interactive "P\nV")
  1144.     (let ((raw-number (mvi-nth 0 arg))
  1145.                 (command (mvi-nth 4 arg))
  1146.                 (function (nth 0 mvi-last-search))
  1147.                 (do-push (nth 1 mvi-last-search)))
  1148.         (if command (error "Bad command"))
  1149.         (or raw-number (setq number (if do-push 1 -1)))
  1150.         (funcall function nil number "" nil (not raw-number))))
  1151.  
  1152. (defun mvi-N (arg number)
  1153.   "Repeat previous search in opposite direction."
  1154.   (interactive "P\nV")
  1155.     (let ((raw-number (mvi-nth 0 arg))
  1156.                 (command (mvi-nth 4 arg))
  1157.                 (function (nth 0 mvi-last-search))
  1158.                 (do-push (nth 1 mvi-last-search)))
  1159.         (if command (error "Bad command"))
  1160.         (or raw-number (setq number (if do-push 1 -1)))
  1161.         (cond
  1162.          ((eq function 'mvi-f-search-beg) (setq function 'mvi-b-search-beg))
  1163.          ((eq function 'mvi-b-search-beg) (setq function 'mvi-f-search-beg))
  1164.          ((eq function 'mvi-f-search-end) (setq function 'mvi-b-search-end))
  1165.          ((eq function 'mvi-b-search-end) (setq function 'mvi-f-search-end)))
  1166.         (funcall function nil number "" nil (not raw-number))))
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228. ;; yank and pop
  1229.  
  1230. (defun mvi-p (arg number &optional motion-arg text not-in-history)
  1231.   "Put back after point/below line."
  1232.   (interactive "*P\nV")
  1233.     (let ((register (mvi-nth 1 arg))
  1234.                 (append (mvi-nth 2 arg))
  1235.                 (g-flag (mvi-nth 3 arg))
  1236.                 (command (mvi-nth 4 arg))
  1237.                 (count number)
  1238.                 (killed-text)
  1239.                 (hist-tmp))
  1240.         (setq mvi-put-number number)
  1241.         (setq mvi-put-command 'mvi-p)
  1242.         (if command (error "Bad command"))
  1243.         (move-marker mvi-put-point (point))
  1244.         (move-marker mvi-g-point (point))
  1245.         (if register
  1246.             (setq killed-text (get-register register))
  1247.             (setq killed-text (car kill-ring-yank-pointer)))
  1248.         (if (null (stringp killed-text)) (error "No text to put"))
  1249.         (if (= (aref killed-text (1- (length killed-text))) ?\n)
  1250.             (progn
  1251.                 (next-line 1)
  1252.                 (beginning-of-line)
  1253.                 (move-marker mvi-put-start (point))
  1254.                 (while (> count 0)
  1255.                     (insert killed-text)
  1256.                     (setq count (1- count)))
  1257.                 (move-marker mvi-put-end (point))
  1258.                 (goto-char mvi-put-start)
  1259.                 (mvi-forward-line 0))
  1260.             (progn
  1261.                 (if (not (eolp)) (forward-char 1))
  1262.                 (move-marker mvi-put-start (point))
  1263.                 (while (> count 0)
  1264.                     (insert killed-text)
  1265.                     (setq count (1- count)))
  1266.                 (move-marker mvi-put-end (point))
  1267.                 (backward-char)))
  1268.         (or (pos-visible-in-window-p mvi-put-end)
  1269.             (message (format "%s More lines" 
  1270.                 (count-lines mvi-put-start mvi-put-end))))
  1271.         (if g-flag (goto-char mvi-g-point))
  1272.         (or not-in-history executing-macro
  1273.             (equal (aref mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max)) 
  1274.                 (setq hist-tmp (vector number register append g-flag command 
  1275.                     'mvi-p motion-arg text)))
  1276.             (progn
  1277.                 (setq mvi-com-ring-point (1+ mvi-com-ring-point))
  1278.                 (aset mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max) 
  1279.                     hist-tmp)))))
  1280.  
  1281. (defun mvi-P (arg number &optional motion-arg text not-in-history)
  1282.   "Put back before point/above line."
  1283.   (interactive "*P\nV")
  1284.     (let ((register (mvi-nth 1 arg))
  1285.                 (append (mvi-nth 2 arg))
  1286.                 (g-flag (mvi-nth 3 arg))
  1287.                 (command (mvi-nth 4 arg))
  1288.                 (count number)
  1289.                 (killed-text)
  1290.                 (hist-tmp))
  1291.         (setq mvi-put-number number)
  1292.         (setq mvi-put-command 'mvi-P)
  1293.         (if command (error "Bad command"))
  1294.         (move-marker mvi-g-point (point))
  1295.         (move-marker mvi-put-point (point))
  1296.         (if register
  1297.             (setq killed-text (get-register register))
  1298.             (setq killed-text (car kill-ring-yank-pointer)))
  1299.         (if (null (stringp killed-text)) (error "No text to put"))
  1300.         (if (= (aref killed-text (1- (length killed-text))) ?\n)
  1301.             (progn
  1302.                 (beginning-of-line)
  1303.                 (move-marker mvi-put-start (point))
  1304.                 (while (> count 0)
  1305.                     (insert killed-text)
  1306.                     (setq count (1- count)))
  1307.                 (move-marker mvi-put-end (point))
  1308.                 (goto-char mvi-put-start)
  1309.                 (mvi-forward-line 0))
  1310.             (progn
  1311.                 (move-marker mvi-put-start (point))
  1312.                 (while (> count 0)
  1313.                     (insert killed-text)
  1314.                     (setq count (1- count)))
  1315.                 (move-marker mvi-put-end (point))))
  1316.         (or (pos-visible-in-window-p mvi-put-end)
  1317.             (message (format "%s More lines" 
  1318.                 (count-lines mvi-put-start mvi-put-end))))
  1319.         (if g-flag (goto-char mvi-g-point))
  1320.         (or not-in-history executing-macro
  1321.             (equal (aref mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max)) 
  1322.                 (setq hist-tmp (vector number register append g-flag command 
  1323.                     'mvi-P motion-arg text)))
  1324.             (progn
  1325.                 (setq mvi-com-ring-point (1+ mvi-com-ring-point))
  1326.                 (aset mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max) 
  1327.                     hist-tmp)))))
  1328.  
  1329. (defun mvi-Cp (arg number &optional motion-arg text not-in-history)
  1330.   "Put back right at point."
  1331.   (interactive "*P\nV")
  1332.     (let ((register (mvi-nth 1 arg))
  1333.                 (append (mvi-nth 2 arg))
  1334.                 (g-flag (mvi-nth 3 arg))
  1335.                 (command (mvi-nth 4 arg))
  1336.                 (count number)
  1337.                 (killed-text)
  1338.                 (hist-tmp))
  1339.         (setq mvi-put-number number)
  1340.         (setq mvi-put-command 'mvi-Cp)
  1341.         (if command (error "Bad command"))
  1342.         (move-marker mvi-g-point (point))
  1343.         (move-marker mvi-put-point (point))
  1344.         (if register
  1345.             (setq killed-text (get-register register))
  1346.             (setq killed-text (car kill-ring-yank-pointer)))
  1347.         (if (null (stringp killed-text)) (error "No text to put"))
  1348.         (move-marker mvi-put-start (point))
  1349.         (while (> count 0)
  1350.             (insert killed-text)
  1351.             (setq count (1- count)))
  1352.         (move-marker mvi-put-end (point))
  1353.         (or (pos-visible-in-window-p mvi-put-end)
  1354.             (message (format "%s More lines" 
  1355.                 (count-lines mvi-put-start mvi-put-end))))
  1356.         (if g-flag (goto-char mvi-g-point))
  1357.         (or not-in-history executing-macro
  1358.             (equal (aref mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max)) 
  1359.                 (setq hist-tmp (vector number register append g-flag command 
  1360.                     'mvi-Cp motion-arg text)))
  1361.             (progn
  1362.                 (setq mvi-com-ring-point (1+ mvi-com-ring-point))
  1363.                 (aset mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max) 
  1364.                     hist-tmp)))))
  1365.  
  1366. (defun mvi-qp (arg number &optional motion-arg text)
  1367.   "Replace just put stretch of killed-text with a different stretch - p."
  1368.   (interactive "*P\nV")
  1369.     (mvi-yank-pop arg number 'mvi-p 
  1370.         (if (eq mvi-put-command 'mvi-p) t nil) 'mvi-qp))
  1371.  
  1372. (defun mvi-qP (arg number &optional motion-arg text)
  1373.   "Replace just put stretch of killed-text with a different stretch - P."
  1374.   (interactive "*P\nV")
  1375.     (mvi-yank-pop arg number 'mvi-P 
  1376.         (if (eq mvi-put-command 'mvi-P) t nil) 'mvi-qP))
  1377.  
  1378. (defun mvi-qCp (arg number &optional motion-arg text)
  1379.   "Replace just put stretch of killed-text with a different stretch - Cp."
  1380.   (interactive "*P\nV")
  1381.     (mvi-yank-pop arg number 'mvi-Cp 
  1382.         (if (eq mvi-put-command 'mvi-Cp) t nil) 'mvi-qCp))
  1383.  
  1384. (defun mvi-yank-pop (arg number motion same-motion history-func)
  1385.   "Replace just put stretch of killed-text with a different stretch.
  1386. At such a time, the region contains a stretch of reinserted
  1387. previously-killed text.  mvi-yank-pop  deletes that text and inserts in its
  1388. place a different stretch of killed text.
  1389.  
  1390. With no argument, the previous kill is inserted.
  1391. With argument n, n puts are done.
  1392. With register, that register is put.
  1393.  
  1394. The sequence of kills wraps around, so that after the oldest one
  1395. comes the newest one."
  1396.     (let ((register (mvi-nth 1 arg))
  1397.                 (append (mvi-nth 2 arg))
  1398.                 (g-flag (mvi-nth 3 arg))
  1399.                 (command (mvi-nth 4 arg))
  1400.                 (put-arg)
  1401.                 (offset 1)
  1402.                 (hist-number)
  1403.                 (hist-tmp))
  1404.         (if command (error "Bad command"))
  1405.         (if (null mvi-put-number) (error "No put done"))
  1406.         (if (null (mvi-nth 0 arg)) (setq number mvi-put-number))
  1407.         (setq hist-number number)
  1408.         (if (< number 0) 
  1409.             (setq 
  1410.                 number (- number)
  1411.                 offset -1))
  1412.         (move-marker mvi-g-point (point))
  1413.         (move-marker mvi-com-point (point))
  1414.         (delete-region mvi-put-start mvi-put-end)
  1415.         (goto-char mvi-put-point)
  1416.         (setq put-arg (list number register nil nil nil))
  1417.         (if (and (null register) (= mvi-put-number number) same-motion)
  1418.             (rotate-yank-pointer offset))
  1419.         (funcall motion put-arg number nil nil t)
  1420.         (if g-flag (goto-char mvi-g-point))
  1421.         (or executing-macro
  1422.             (equal (aref mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max)) 
  1423.                 (setq hist-tmp (vector hist-number register append g-flag command 
  1424.                     history-func motion-arg text)))
  1425.             (progn
  1426.                 (setq mvi-com-ring-point (1+ mvi-com-ring-point))
  1427.                 (aset mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max) 
  1428.                     hist-tmp)))))
  1429.  
  1430. (defun mvi-goto-put-end (arg number &optional motion-arg text)
  1431.   "mvi move to the end of a previous put.  With number move to the
  1432. beginning of a previous put."
  1433.   (interactive "P\nV")
  1434.     (let ((raw-number (mvi-nth 0 arg))
  1435.                 (register (mvi-nth 1 arg))
  1436.                 (append (mvi-nth 2 arg))
  1437.                 (g-flag (mvi-nth 3 arg))
  1438.                 (command (mvi-nth 4 arg))
  1439.                 (hist-tmp))
  1440.         (move-marker mvi-g-point (point))
  1441.         (if command 
  1442.             (progn
  1443.                 (setq number raw-number)
  1444.                 (move-marker mvi-com-point (point))
  1445.                 (goto-char (if raw-number mvi-put-start mvi-put-end))
  1446.                 (mvi-execute-com 'mvi-goto-put-end))
  1447.             (goto-char (if raw-number mvi-put-start mvi-put-end)))))
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509. ;; join lines.
  1510.  
  1511. (defun mvi-J (arg number &optional motion-arg text)
  1512.   "Join this line to next, if ARG is nil.  Otherwise, join ARG lines"
  1513.   (interactive "*P\nV")
  1514.   (let ((count number)
  1515.                 (g-flag (mvi-nth 3 arg))
  1516.                 (command (mvi-nth 4 arg))
  1517.                 (hist-tmp))
  1518.         (if command (error "Bad command"))
  1519.         (move-marker mvi-g-point (point))
  1520.         (move-marker mvi-com-point (point))
  1521.         (while (> count 0)
  1522.             (end-of-line)
  1523.             (mvi-forward-end -1 nil)
  1524.             (if (looking-at sentence-end)
  1525.                 (progn
  1526.                     (end-of-line)
  1527.                     (delete-char 1)
  1528.                     (fixup-whitespace)
  1529.                     (insert " "))
  1530.                 (progn
  1531.                     (end-of-line)
  1532.                     (delete-char 1)
  1533.                     (fixup-whitespace)))
  1534.             (setq count (1- count)))
  1535.         (if g-flag (goto-char mvi-g-point))
  1536.         (or executing-macro
  1537.             (equal (aref mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max)) 
  1538.                 (setq hist-tmp (vector number nil nil g-flag command 
  1539.                     'mvi-J motion-arg text)))
  1540.             (progn
  1541.                 (setq mvi-com-ring-point (1+ mvi-com-ring-point))
  1542.                 (aset mvi-com-ring (% mvi-com-ring-point mvi-com-ring-max) 
  1543.                     hist-tmp)))))
  1544.  
  1545. (defun mvi-m (arg)
  1546.     "Mark position in register."
  1547.   (interactive "P")
  1548.     (if (mvi-nth 4 arg) (error "Bad command"))
  1549.     (let ((char))
  1550.         (or (eq (minibuffer-window) (selected-window))
  1551.             (message "Set mark:"))
  1552.         (setq char (read-char))
  1553.         (if (and (>= char ?a) (<= char ?z))
  1554.             (point-to-register (- char 32))
  1555.             (point-to-register char))))
  1556.  
  1557. (defun mvi-to-line (arg number &optional motion-arg text)
  1558.   "mvi move to line pointed to by register."
  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 (mvi-nth 4 arg))
  1564.                 (buf (current-buffer))
  1565.                 (hist-tmp))
  1566.         (or motion-arg (progn
  1567.             (or (eq (minibuffer-window) (selected-window))
  1568.                 (message "Go to line of mark:"))
  1569.             (setq motion-arg (read-char))))
  1570.         (cond 
  1571.          ((= motion-arg ?\e) (message "Command cancelled"))
  1572.          (command 
  1573.                 (if (> number 0) (push-mark nil t))
  1574.                 (move-marker mvi-g-point (point))
  1575.                 (mvi-enlarge-region (point)
  1576.                     (progn
  1577.                         (if (and (>= motion-arg ?a) (<= motion-arg ?z))
  1578.                             (register-to-point (- motion-arg 32))
  1579.                             (register-to-point motion-arg))
  1580.                         (point)))
  1581.                 (if (not (eq buf (current-buffer))) (error "Differen't buffer"))
  1582.                 (mvi-execute-com 'mvi-to-line))
  1583.             (t
  1584.                 (if (> number 0) (push-mark nil t))
  1585.                 (move-marker mvi-g-point (point))
  1586.                 (if (and (>= motion-arg ?a) (<= motion-arg ?z))
  1587.                     (register-to-point (- motion-arg 32))
  1588.                     (register-to-point motion-arg))
  1589.                 (mvi-forward-line 0)))))
  1590.  
  1591. (defun mvi-to-point (arg number &optional motion-arg text)
  1592.   "mvi move to point pointed to by register."
  1593.   (interactive "P\nV")
  1594.     (let ((register (mvi-nth 1 arg))
  1595.                 (append (mvi-nth 2 arg))
  1596.                 (g-flag (mvi-nth 3 arg))
  1597.                 (command (mvi-nth 4 arg))
  1598.                 (buf (current-buffer))
  1599.                 (hist-tmp))
  1600.         (or motion-arg (progn
  1601.             (or (eq (minibuffer-window) (selected-window))
  1602.                 (message "Go to mark:"))
  1603.             (setq motion-arg (read-char))))
  1604.         (cond 
  1605.          ((= motion-arg ?\e) (message "Command cancelled"))
  1606.             (command 
  1607.                 (move-marker mvi-g-point (point))
  1608.                 (if (> number 0) (push-mark nil t))
  1609.                 (move-marker mvi-com-point (point))
  1610.                 (if (and (>= motion-arg ?a) (<= motion-arg ?z))
  1611.                     (register-to-point (- motion-arg 32))
  1612.                     (register-to-point motion-arg))
  1613.                 (if (not (eq buf (current-buffer))) (error "Differen't buffer"))
  1614.                 (mvi-execute-com 'mvi-to-point))
  1615.             (t
  1616.                 (move-marker mvi-g-point (point))
  1617.                 (if (> number 0) (push-mark nil t))
  1618.                 (if (and (>= motion-arg ?a) (<= motion-arg ?z))
  1619.                     (register-to-point (- motion-arg 32))
  1620.                     (register-to-point motion-arg))))))
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682. ;; debug aid
  1683.  
  1684. (defun mvi-toggle-debug ()
  1685.   "mvi toggle debug"
  1686.   (interactive)
  1687.   (if debug-on-error 
  1688.     (progn
  1689.       (setq debug-on-error nil)
  1690.       (message "Debug off"))
  1691.     (progn
  1692.       (setq debug-on-error t)
  1693.       (message "Debug on"))))
  1694.  
  1695. (defun mvi-dump-emacs (arg)
  1696.   "mvi dump emacs in a given filename.  Can be re-executed to restore the
  1697. complete state of emacs."
  1698.   (interactive "FDump emacs to: ")
  1699.     (dump-emacs arg "/usr/local/src/gnumacs/src/temacs"))
  1700.  
  1701. (defun mvi-version ()
  1702.   "Print version number of emacs."
  1703.   (interactive)
  1704.     (message "MVI Version 1.0, March 26, 1990, send bug reports to: osu-cis!nimbus3!djs"))
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766. ;; next window
  1767.  
  1768. (defun mvi-other-window (arg number)
  1769.   "mvi to other window."
  1770.   (interactive "P\nV")
  1771.     (let ((command (mvi-nth 4 arg)))
  1772.         (if command (error "Bad command"))
  1773.         (other-window number)
  1774.         (if (eq (current-local-map) nil)
  1775.                 (mvi-emacs-to-vi))))
  1776.  
  1777. (defun mvi-call-last-kbd-macro (number)
  1778.   "mvi call last keyboard macro."
  1779.   (interactive "V")
  1780.     (call-last-kbd-macro number))
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.  
  1798.  
  1799.  
  1800.  
  1801.  
  1802.  
  1803.  
  1804.  
  1805.  
  1806.  
  1807.  
  1808.  
  1809.  
  1810.  
  1811.  
  1812.  
  1813.  
  1814.  
  1815.  
  1816.  
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842. ;; fold commands
  1843.  
  1844. (defun fold-mode (arg)
  1845.   "Turn on fold mode.  With argument, turn off fold mode."
  1846.   (interactive "P")
  1847.     (let ((raw-number (mvi-nth 0 arg))
  1848.                 (command (mvi-nth 4 arg)))
  1849.         (if command (error "Bad command"))
  1850.         (if raw-number
  1851.                 (setq selective-display nil
  1852.                             folded-display nil)
  1853.                 (save-excursion
  1854.                     (save-restriction
  1855.                         (widen)
  1856.                         (goto-char (point-min))
  1857.                         (skip-chars-forward "^\C-m-\C-z")
  1858.                         (if (or (= (point) (point-max)) (y-or-n-p 
  1859.                                 "Enter fold mode with buffer containing fold charachters? "))
  1860.                                 (setq selective-display t
  1861.                                             folded-display t)))))))
  1862.  
  1863. (defun unfold-buffer (arg number)
  1864.   "unfold complete buffer by NUMBER, defaults to 1, folds."
  1865.   (interactive "P\nV")
  1866.     (let ((raw-number (mvi-nth 0 arg))
  1867.                 (command (mvi-nth 4 arg)))
  1868.         (if command (error "Bad command"))
  1869.         (or folded-display (error "Fold mode not enabled"))
  1870.         (save-excursion
  1871.             (save-restriction
  1872.                 (widen)
  1873.                 (unfold-region (point-min) (point-max) (if raw-number number 15) t)))))
  1874.  
  1875. (defun fold-line (arg number)
  1876.   "fold NUMBER of lines."
  1877.   (interactive "P\nV")
  1878.     (let ((command (mvi-nth 4 arg))
  1879.                 (orig-char (point)))
  1880.         (if command (error "Bad command"))
  1881.         (or folded-display (error "Fold mode not enabled"))
  1882.         (subst-char-in-region (point) (progn (forward-line number) (point))
  1883.             ?\n ?\C-m t)
  1884.         (goto-char orig-char)
  1885.         (scroll-up 0)))
  1886.  
  1887. (defun unfold-line (arg number)
  1888.   "unfold line by NUMBER, defaults to 1, folds."
  1889.   (interactive "P\nV")
  1890.     (let ((command (mvi-nth 4 arg))
  1891.                 (orig-char (point)))
  1892.         (if command (error "Bad command"))
  1893.         (or folded-display (error "Fold mode not enabled"))
  1894.         (beginning-of-line)
  1895.         (unfold-region (point) (progn (forward-line 1) (point)) number t)
  1896.         (goto-char orig-char)
  1897.         (scroll-up 0)))
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.  
  1922.  
  1923.  
  1924.  
  1925.  
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.  
  1932.  
  1933.  
  1934.  
  1935.  
  1936.  
  1937.  
  1938.  
  1939.  
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959. ;; key bindings
  1960.  
  1961. (set 'mvi-static-map (make-keymap))
  1962.  
  1963. (define-key mvi-static-map "\C-@" 'mvi-set-mark)
  1964. (define-key mvi-static-map "\C-a" global-map)
  1965. (define-key mvi-static-map "\C-b" 'mvi-scroll-back)
  1966. (define-key mvi-static-map "\C-d" 'mvi-scroll-down)
  1967. (define-key mvi-static-map "\C-e" 'mvi-scroll-down-one)
  1968. (define-key mvi-static-map "\C-f" 'mvi-scroll-forward)
  1969. (define-key mvi-static-map "\C-g" 'keyboard-quit)
  1970. (define-key mvi-static-map "\C-h" 'help-command)
  1971. (define-key mvi-static-map "\C-j" 'mvi-j)
  1972. (define-key mvi-static-map "\C-k" 'mvi-command-arg)
  1973. (define-key mvi-static-map "\C-l" 'redraw-display)
  1974. (define-key mvi-static-map "\C-m" 'mvi-forward-line)
  1975. (define-key mvi-static-map "\C-n" 'mvi-other-window)
  1976. (define-key mvi-static-map "\C-o" 'mvi-Co)
  1977. (define-key mvi-static-map "\C-p" 'mvi-Cp)
  1978. (define-key mvi-static-map "\C-t" 'universal-argument)
  1979. (define-key mvi-static-map "\C-u" 'mvi-scroll-up)
  1980. (define-key mvi-static-map "\C-y" 'mvi-scroll-up-one)
  1981. (define-key mvi-static-map "\C-z" 'mvi-vi-to-emacs)
  1982. (define-key mvi-static-map "\e" 'mvi-ESC)
  1983.  
  1984. (define-key mvi-static-map " " 'mvi-l)
  1985. (define-key mvi-static-map "!" 'mvi-command-arg)
  1986. (define-key mvi-static-map "\"" 'mvi-register-arg)
  1987. (define-key mvi-static-map "#" 'mvi-to-col)
  1988. (define-key mvi-static-map "$" 'mvi-eol)
  1989. (define-key mvi-static-map "%" 'mvi-paren)
  1990. (define-key mvi-static-map "&" 'mvi-goto-put-end)
  1991. (define-key mvi-static-map "'" 'mvi-to-line)
  1992. (define-key mvi-static-map "(" 'mvi-b-sent)
  1993. (define-key mvi-static-map ")" 'mvi-f-sent)
  1994. (define-key mvi-static-map "*" 'mvi-call-last-kbd-macro)
  1995. (define-key mvi-static-map "+" 'mvi-f-list)
  1996. (define-key mvi-static-map "," 'mvi-r-f-t)
  1997. (define-key mvi-static-map "-" 'mvi-digit-arg)
  1998. (define-key mvi-static-map "." 'mvi-repeat)
  1999. (define-key mvi-static-map "/" 'mvi-f-search-beg)
  2000.  
  2001. (define-key mvi-static-map "0" 'mvi-0)
  2002. (define-key mvi-static-map "1" 'mvi-digit-arg)
  2003. (define-key mvi-static-map "2" 'mvi-digit-arg)
  2004. (define-key mvi-static-map "3" 'mvi-digit-arg)
  2005. (define-key mvi-static-map "4" 'mvi-digit-arg)
  2006. (define-key mvi-static-map "5" 'mvi-digit-arg)
  2007. (define-key mvi-static-map "6" 'mvi-digit-arg)
  2008. (define-key mvi-static-map "7" 'mvi-digit-arg)
  2009. (define-key mvi-static-map "8" 'mvi-digit-arg)
  2010. (define-key mvi-static-map "9" 'mvi-digit-arg)
  2011.  
  2012. (define-key mvi-static-map ":" 'execute-extended-command)
  2013. (define-key mvi-static-map ";" 'mvi-s-f-t)
  2014. (define-key mvi-static-map "<" 'mvi-command-arg)
  2015. (define-key mvi-static-map "=" 'exchange-point-and-mark)
  2016. (define-key mvi-static-map ">" 'mvi-command-arg)
  2017. (define-key mvi-static-map "?" 'mvi-b-search-beg)
  2018.  
  2019. (define-key mvi-static-map "A" 'mvi-A)
  2020. (define-key mvi-static-map "B" 'mvi-B)
  2021. (define-key mvi-static-map "C" 'mvi-C)
  2022. (define-key mvi-static-map "D" 'mvi-D)
  2023. (define-key mvi-static-map "E" 'mvi-E)
  2024. (define-key mvi-static-map "F" 'mvi-F)
  2025. (define-key mvi-static-map "G" 'mvi-G)
  2026. (define-key mvi-static-map "H" 'mvi-H)
  2027. (define-key mvi-static-map "I" 'mvi-I)
  2028. (define-key mvi-static-map "J" 'mvi-J)
  2029. (define-key mvi-static-map "K" 'mvi-command-arg)
  2030. (define-key mvi-static-map "L" 'mvi-L)
  2031. (define-key mvi-static-map "M" 'mvi-M)
  2032. (define-key mvi-static-map "N" 'mvi-N)
  2033. (define-key mvi-static-map "O" 'mvi-O)
  2034. (define-key mvi-static-map "P" 'mvi-P)
  2035. (define-key mvi-static-map "Q" 'query-replace)
  2036. (define-key mvi-static-map "R" 'mvi-overwrite)
  2037. (define-key mvi-static-map "S" 'suspend-emacs)
  2038. (define-key mvi-static-map "T" 'mvi-T)
  2039. (define-key mvi-static-map "U" 'mvi-jump-mark)
  2040. (define-key mvi-static-map "V" 'mvi-V)
  2041. (define-key mvi-static-map "W" 'mvi-W)
  2042. (define-key mvi-static-map "X" 'mvi-X)
  2043. (define-key mvi-static-map "Y" 'mvi-Y)
  2044. (define-key mvi-static-map "Z" 'unfold-line)
  2045.  
  2046. (define-key mvi-static-map "[" 'mvi-b-par)
  2047. (define-key mvi-static-map "\\" 'mvi-exc-point-and-g)
  2048. (define-key mvi-static-map "]" 'mvi-f-par)
  2049. (define-key mvi-static-map "^" 'mvi-bol)
  2050. (define-key mvi-static-map "_" 'mvi-b-list)
  2051. (define-key mvi-static-map "`" 'mvi-to-point)
  2052.  
  2053. (define-key mvi-static-map "a" 'mvi-a)
  2054. (define-key mvi-static-map "b" 'mvi-b)
  2055. (define-key mvi-static-map "c" 'mvi-command-arg)
  2056. (define-key mvi-static-map "d" 'mvi-command-arg)
  2057. (define-key mvi-static-map "e" 'mvi-e)
  2058. (define-key mvi-static-map "f" 'mvi-f)
  2059. (define-key mvi-static-map "g" 'mvi-g-flag-arg)
  2060. (define-key mvi-static-map "h" 'mvi-h)
  2061. (define-key mvi-static-map "i" 'mvi-i)
  2062. (define-key mvi-static-map "j" 'mvi-j)
  2063. (define-key mvi-static-map "k" 'mvi-k)
  2064. (define-key mvi-static-map "l" 'mvi-l)
  2065. (define-key mvi-static-map "m" 'mvi-m)
  2066. (define-key mvi-static-map "n" 'mvi-n)
  2067. (define-key mvi-static-map "o" 'mvi-o)
  2068. (define-key mvi-static-map "p" 'mvi-p)
  2069. (define-key mvi-static-map "q" 'mvi-q-prefix)
  2070. (define-key mvi-static-map "r" 'mvi-r)
  2071. (define-key mvi-static-map "s" 'mvi-s)
  2072. (define-key mvi-static-map "t" 'mvi-t)
  2073. (define-key mvi-static-map "u" 'mvi-undo)
  2074. (define-key mvi-static-map "v" 'mvi-v)
  2075. (define-key mvi-static-map "w" 'mvi-w)
  2076. (define-key mvi-static-map "x" 'mvi-x)
  2077. (define-key mvi-static-map "y" 'mvi-command-arg)
  2078. (define-key mvi-static-map "z" 'fold-line)
  2079.  
  2080. (define-key mvi-static-map "{" 'mvi-b-page)
  2081. (define-key mvi-static-map "|" 'mvi-command-arg)
  2082. (define-key mvi-static-map "}" 'mvi-f-page)
  2083. (define-key mvi-static-map "~" 'mvi-change-case)
  2084. (define-key mvi-static-map "\177" 'mvi-h)
  2085.  
  2086. (defvar mvi-q-map (make-keymap)
  2087.   "Keymap for subcommands of q")
  2088. (fset 'mvi-q-prefix mvi-q-map)
  2089.  
  2090. (define-key mvi-q-map "\C-i" 'mvi-command-arg)
  2091. (define-key mvi-q-map "\C-p" 'mvi-qCp)
  2092. (define-key mvi-q-map "\C-r" 'isearch-backward-regexp)
  2093. (define-key mvi-q-map "\C-s" 'isearch-forward-regexp)
  2094. (define-key mvi-q-map "\C-t" 'mvi-toggle-debug)
  2095. (define-key mvi-q-map "\C-v" 'mvi-version)
  2096. (define-key mvi-q-map "\C-z" 'mvi-dump-emacs)
  2097. (define-key mvi-q-map "\e" 'mvi-ESC)
  2098. (define-key mvi-q-map " " 'mvi-search-recenter)
  2099. (define-key mvi-q-map "!" 'shell-command)
  2100. (define-key mvi-q-map "#" 'mvi-what-col)
  2101. (define-key mvi-q-map "(" 'mvi-b-sexp)
  2102. (define-key mvi-q-map ")" 'mvi-f-sexp)
  2103. (define-key mvi-q-map "+" 'mvi-command-arg)
  2104. (define-key mvi-q-map "-" 'backward-up-list)
  2105. (define-key mvi-q-map "." 'mvi-edit-history)
  2106. (define-key mvi-q-map "/" 'mvi-f-search-end)
  2107. (define-key mvi-q-map ";" 'repeat-complex-command)
  2108. (define-key mvi-q-map ":" 'repeat-matching-complex-command)
  2109. (define-key mvi-q-map "?" 'mvi-b-search-end)
  2110. (define-key mvi-q-map "@" 'mvi-map-macro)
  2111. (define-key mvi-q-map "[" 'mvi-b-text-sexp)
  2112. (define-key mvi-q-map "]" 'mvi-f-text-sexp)
  2113. (define-key mvi-q-map "_" 'mvi-command-arg)
  2114. (define-key mvi-q-map "5" 'mvi-command-arg)
  2115. (define-key mvi-q-map "B" 'mvi-search-recenter)
  2116. (define-key mvi-q-map "C" 'mvi-command-arg)
  2117. (define-key mvi-q-map "F" 'mvi-command-arg)
  2118. (define-key mvi-q-map "G" 'mvi-command-arg)
  2119. (define-key mvi-q-map "I" 'mvi-insert-all-macro)
  2120. (define-key mvi-q-map "M" 'mvi-search-recenter)
  2121. (define-key mvi-q-map "P" 'mvi-qP)
  2122. (define-key mvi-q-map "Q" 'query-replace-regexp)
  2123. (define-key mvi-q-map "R" 'mvi-command-arg)
  2124. (define-key mvi-q-map "T" 'mvi-search-recenter)
  2125. (define-key mvi-q-map "U" 'mvi-command-arg)
  2126. (define-key mvi-q-map "a" 'mvi-command-arg)
  2127. (define-key mvi-q-map "b" 'mvi-line-to)
  2128. (define-key mvi-q-map "f" 'mvi-command-arg)
  2129. (define-key mvi-q-map "g" 'what-line)
  2130. (define-key mvi-q-map "i" 'mvi-insert-macro)
  2131. (define-key mvi-q-map "l" 'mvi-command-arg)
  2132. (define-key mvi-q-map "m" 'mvi-line-to)
  2133. (define-key mvi-q-map "n" 'mvi-command-arg)
  2134. (define-key mvi-q-map "p" 'mvi-qp)
  2135. (define-key mvi-q-map "r" 'mvi-command-arg)
  2136. (define-key mvi-q-map "t" 'mvi-line-to)
  2137. (define-key mvi-q-map "u" 'mvi-command-arg)
  2138. (define-key mvi-q-map "v" 'set-variable)
  2139. (define-key mvi-q-map "w" 'mvi-command-arg)
  2140. (define-key mvi-q-map "x" 'mvi-edit-saved-history)
  2141.  
  2142. (define-key minibuffer-local-map "\e" 'mvi-minibuffer-to-vi)
  2143. (define-key minibuffer-local-ns-map "\e" 'mvi-minibuffer-to-vi)
  2144. (define-key minibuffer-local-completion-map "\e" 'mvi-minibuffer-to-vi)
  2145. (define-key minibuffer-local-must-match-map "\e" 'mvi-minibuffer-to-vi)
  2146.  
  2147. (setq mvi-history-edit-map (copy-keymap mvi-static-map))
  2148. (setq mvi-history-q-map (copy-keymap mvi-q-map))
  2149. (fset 'mvi-history-q-prefix mvi-history-q-map)
  2150.  
  2151. (define-key mvi-history-edit-map "\C-m" 'exit-minibuffer)
  2152. (define-key mvi-history-edit-map "\C-j" 'exit-minibuffer)
  2153. (define-key mvi-history-edit-map "\C-g" 'abort-recursive-edit)
  2154. (define-key mvi-history-edit-map "q" 'mvi-history-q-prefix)
  2155.  
  2156. (define-key mvi-history-q-map "j" 'mvi-edit-next)
  2157. (define-key mvi-history-q-map "k" 'mvi-edit-prev)
  2158. (define-key mvi-history-q-map "\\" 'mvi-edit-match)
  2159. (define-key mvi-history-q-map "N" 'mvi-edit-match-again)
  2160. (define-key mvi-history-q-map "V" 'mvi-save-history)
  2161.  
  2162. (setq mvi-history-insert-map (make-sparse-keymap))
  2163. (define-key mvi-history-insert-map "\C-g" 'abort-recursive-edit)
  2164. (define-key mvi-history-insert-map "\e" 'mvi-minibuffer-to-vi)
  2165. (define-key mvi-history-insert-map "\C-m" 'exit-minibuffer)
  2166. (define-key mvi-history-insert-map "\C-n" 'mvi-edit-next)
  2167. (define-key mvi-history-insert-map "\C-p" 'mvi-edit-prev)
  2168.  
  2169. (define-key repeat-complex-command-map "\e" 'mvi-minibuffer-to-vi)
  2170. (define-key repeat-complex-command-map "\C-n" 'next-complex-command)
  2171. (define-key repeat-complex-command-map "\C-p" 'previous-complex-command)
  2172.  
  2173. (setq enable-recursive-minibuffers t)
  2174.  
  2175. (setq mvi-map-map (make-sparse-keymap))
  2176. (fset 'mvi-map-prefix mvi-map-map)
  2177. (fset 'mvi-map-prefix-prefix 'mvi-map-prefix)
  2178.  
  2179. ;; End of MVI
  2180. ;; Local Variables:
  2181. ;; tab-width:2
  2182. ;; eval:(define-key mvi-map-map "g" "/^(defun mvi-q")
  2183. ;; End:
  2184. //E*O*F mvi.el.2//
  2185.  
  2186. exit 0
  2187. -- 
  2188. Doug Scofea   Email: nimbus3!djs@cis.ohio-state.edu    Phone:+1 614 459-1889
  2189.