comparison lisp/emulation/viper-cmd.el @ 39215:8dccf2552307

2001-09-09 Michael Kifer <kifer@cs.sunysb.edu> * ediff-init.el (ediff-highest-priority): bug fix. * viper-cmd.el (viper-special-read-and-insert-char): new function that reads a character and uses the current input method or iso-accents when appropriate. * viper.el and all others: corrections to the comment blocks at the top.
author Michael Kifer <kifer@cs.stonybrook.edu>
date Sun, 09 Sep 2001 22:33:38 +0000
parents 10482dd382e7
children 25dc021070bc
comparison
equal deleted inserted replaced
39214:dd2b8f794156 39215:8dccf2552307
1 ;;; viper-cmd.el --- Vi command support for Viper 1 ;;; viper-cmd.el --- Vi command support for Viper
2
2 ;; Copyright (C) 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
3 6
4 ;; This file is part of GNU Emacs. 7 ;; This file is part of GNU Emacs.
5 8
6 ;; GNU Emacs is free software; you can redistribute it and/or modify 9 ;; GNU Emacs is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by 10 ;; it under the terms of the GNU General Public License as published by
755 ) 758 )
756 (quit (ding)) 759 (quit (ding))
757 (error (beep 1)))) 760 (error (beep 1))))
758 ;; set state in the new buffer 761 ;; set state in the new buffer
759 (viper-set-mode-vars-for viper-current-state)) 762 (viper-set-mode-vars-for viper-current-state))
763
764 ;; This is used in order to allow reading characters according to the input
765 ;; method. The character is read in emacs and inserted into the buffer.
766 ;; If an input method is in effect, this might
767 ;; cause several characters to be combined into one.
768 ;; Also takes care of the iso-accents mode
769 (defun viper-special-read-and-insert-char ()
770 (viper-set-mode-vars-for 'emacs-state)
771 (viper-normalize-minor-mode-map-alist)
772 (if viper-special-input-method
773 (viper-set-input-method t))
774 (if viper-automatic-iso-accents
775 (viper-set-iso-accents-mode t))
776 (condition-case nil
777 (let (viper-vi-kbd-minor-mode
778 viper-insert-kbd-minor-mode
779 viper-emacs-kbd-minor-mode
780 ch)
781 (cond ((and viper-special-input-method
782 viper-emacs-p
783 (fboundp 'quail-input-method))
784 ;; (let ...) is used to restore unread-command-events to the
785 ;; original state. We don't want anything left in there after
786 ;; key translation. (Such left-overs are possible if the user
787 ;; types a regular key.)
788 (let (unread-command-events)
789 ;; The next 2 cmds are intended to prevent the input method
790 ;; from swallowing ^M, ^Q and other special characters
791 (setq ch (read-char))
792 (viper-set-unread-command-events ch)
793 (quail-input-method nil)
794
795 (if (and ch (string= quail-current-str ""))
796 (insert ch)
797 (insert quail-current-str))
798 (setq ch (or ch
799 (aref quail-current-str
800 (1- (length quail-current-str)))))
801 ))
802 ((and viper-special-input-method
803 viper-xemacs-p
804 (fboundp 'quail-start-translation))
805 ;; same as above but for XEmacs, which doesn't have
806 ;; quail-input-method
807 (let (unread-command-events)
808 (setq ch (read-char))
809 (viper-set-unread-command-events ch)
810 (quail-start-translation nil)
811
812 (if (and ch (string= quail-current-str ""))
813 (insert ch)
814 (insert quail-current-str))
815 (setq ch (or ch
816 (aref quail-current-str
817 (1- (length quail-current-str)))))
818 ))
819 ((and (boundp 'iso-accents-mode) iso-accents-mode)
820 (setq ch (aref (read-key-sequence nil) 0))
821 (insert ch))
822 (t
823 (setq ch (read-char))
824 (insert ch))
825 )
826 (setq last-command-event
827 (viper-copy-event (if viper-xemacs-p
828 (character-to-event ch) ch)))
829 ) ; let
830 (error)
831 ) ; condition-case
832
833 (viper-set-input-method nil)
834 (viper-set-iso-accents-mode nil)
835 (viper-set-mode-vars-for viper-current-state)
836 )
837
760 838
761 (defun viper-exec-form-in-vi (form) 839 (defun viper-exec-form-in-vi (form)
762 "Execute FORM in Vi state, regardless of the Ccurrent Vi state." 840 "Execute FORM in Vi state, regardless of the Ccurrent Vi state."
763 (let ((buff (current-buffer)) 841 (let ((buff (current-buffer))
764 result) 842 result)
2062 (defun viper-insert (arg) 2140 (defun viper-insert (arg)
2063 "Insert before point." 2141 "Insert before point."
2064 (interactive "P") 2142 (interactive "P")
2065 (viper-set-complex-command-for-undo) 2143 (viper-set-complex-command-for-undo)
2066 (let ((val (viper-p-val arg)) 2144 (let ((val (viper-p-val arg))
2067 (com (viper-getcom arg))) 2145 ;;(com (viper-getcom arg))
2146 )
2068 (viper-set-destructive-command (list 'viper-insert val ?r nil nil nil)) 2147 (viper-set-destructive-command (list 'viper-insert val ?r nil nil nil))
2069 (if (eq viper-intermediate-command 'viper-repeat) 2148 (if (eq viper-intermediate-command 'viper-repeat)
2070 (viper-loop val (viper-yank-last-insertion)) 2149 (viper-loop val (viper-yank-last-insertion))
2071 (viper-change-state-to-insert)))) 2150 (viper-change-state-to-insert))))
2072 2151
2073 (defun viper-append (arg) 2152 (defun viper-append (arg)
2074 "Append after point." 2153 "Append after point."
2075 (interactive "P") 2154 (interactive "P")
2076 (viper-set-complex-command-for-undo) 2155 (viper-set-complex-command-for-undo)
2077 (let ((val (viper-p-val arg)) 2156 (let ((val (viper-p-val arg))
2078 (com (viper-getcom arg))) 2157 ;;(com (viper-getcom arg))
2158 )
2079 (viper-set-destructive-command (list 'viper-append val ?r nil nil nil)) 2159 (viper-set-destructive-command (list 'viper-append val ?r nil nil nil))
2080 (if (not (eolp)) (forward-char)) 2160 (if (not (eolp)) (forward-char))
2081 (if (eq viper-intermediate-command 'viper-repeat) 2161 (if (eq viper-intermediate-command 'viper-repeat)
2082 (viper-loop val (viper-yank-last-insertion)) 2162 (viper-loop val (viper-yank-last-insertion))
2083 (viper-change-state-to-insert)))) 2163 (viper-change-state-to-insert))))
2085 (defun viper-Append (arg) 2165 (defun viper-Append (arg)
2086 "Append at end of line." 2166 "Append at end of line."
2087 (interactive "P") 2167 (interactive "P")
2088 (viper-set-complex-command-for-undo) 2168 (viper-set-complex-command-for-undo)
2089 (let ((val (viper-p-val arg)) 2169 (let ((val (viper-p-val arg))
2090 (com (viper-getcom arg))) 2170 ;;(com (viper-getcom arg))
2171 )
2091 (viper-set-destructive-command (list 'viper-Append val ?r nil nil nil)) 2172 (viper-set-destructive-command (list 'viper-Append val ?r nil nil nil))
2092 (end-of-line) 2173 (end-of-line)
2093 (if (eq viper-intermediate-command 'viper-repeat) 2174 (if (eq viper-intermediate-command 'viper-repeat)
2094 (viper-loop val (viper-yank-last-insertion)) 2175 (viper-loop val (viper-yank-last-insertion))
2095 (viper-change-state-to-insert)))) 2176 (viper-change-state-to-insert))))
2097 (defun viper-Insert (arg) 2178 (defun viper-Insert (arg)
2098 "Insert before first non-white." 2179 "Insert before first non-white."
2099 (interactive "P") 2180 (interactive "P")
2100 (viper-set-complex-command-for-undo) 2181 (viper-set-complex-command-for-undo)
2101 (let ((val (viper-p-val arg)) 2182 (let ((val (viper-p-val arg))
2102 (com (viper-getcom arg))) 2183 ;;(com (viper-getcom arg))
2184 )
2103 (viper-set-destructive-command (list 'viper-Insert val ?r nil nil nil)) 2185 (viper-set-destructive-command (list 'viper-Insert val ?r nil nil nil))
2104 (back-to-indentation) 2186 (back-to-indentation)
2105 (if (eq viper-intermediate-command 'viper-repeat) 2187 (if (eq viper-intermediate-command 'viper-repeat)
2106 (viper-loop val (viper-yank-last-insertion)) 2188 (viper-loop val (viper-yank-last-insertion))
2107 (viper-change-state-to-insert)))) 2189 (viper-change-state-to-insert))))
2109 (defun viper-open-line (arg) 2191 (defun viper-open-line (arg)
2110 "Open line below." 2192 "Open line below."
2111 (interactive "P") 2193 (interactive "P")
2112 (viper-set-complex-command-for-undo) 2194 (viper-set-complex-command-for-undo)
2113 (let ((val (viper-p-val arg)) 2195 (let ((val (viper-p-val arg))
2114 (com (viper-getcom arg))) 2196 ;;(com (viper-getcom arg))
2197 )
2115 (viper-set-destructive-command (list 'viper-open-line val ?r nil nil nil)) 2198 (viper-set-destructive-command (list 'viper-open-line val ?r nil nil nil))
2116 (let ((col (current-indentation))) 2199 (let ((col (current-indentation)))
2117 (if (eq viper-intermediate-command 'viper-repeat) 2200 (if (eq viper-intermediate-command 'viper-repeat)
2118 (viper-loop val 2201 (viper-loop val
2119 (end-of-line) 2202 (end-of-line)
2128 (defun viper-Open-line (arg) 2211 (defun viper-Open-line (arg)
2129 "Open line above." 2212 "Open line above."
2130 (interactive "P") 2213 (interactive "P")
2131 (viper-set-complex-command-for-undo) 2214 (viper-set-complex-command-for-undo)
2132 (let ((val (viper-p-val arg)) 2215 (let ((val (viper-p-val arg))
2133 (com (viper-getcom arg))) 2216 ;;(com (viper-getcom arg))
2217 )
2134 (viper-set-destructive-command (list 'viper-Open-line val ?r nil nil nil)) 2218 (viper-set-destructive-command (list 'viper-Open-line val ?r nil nil nil))
2135 (let ((col (current-indentation))) 2219 (let ((col (current-indentation)))
2136 (if (eq viper-intermediate-command 'viper-repeat) 2220 (if (eq viper-intermediate-command 'viper-repeat)
2137 (viper-loop val 2221 (viper-loop val
2138 (beginning-of-line) 2222 (beginning-of-line)
2147 (defun viper-open-line-at-point (arg) 2231 (defun viper-open-line-at-point (arg)
2148 "Open line at point." 2232 "Open line at point."
2149 (interactive "P") 2233 (interactive "P")
2150 (viper-set-complex-command-for-undo) 2234 (viper-set-complex-command-for-undo)
2151 (let ((val (viper-p-val arg)) 2235 (let ((val (viper-p-val arg))
2152 (com (viper-getcom arg))) 2236 ;;(com (viper-getcom arg))
2237 )
2153 (viper-set-destructive-command 2238 (viper-set-destructive-command
2154 (list 'viper-open-line-at-point val ?r nil nil nil)) 2239 (list 'viper-open-line-at-point val ?r nil nil nil))
2155 (if (eq viper-intermediate-command 'viper-repeat) 2240 (if (eq viper-intermediate-command 'viper-repeat)
2156 (viper-loop val 2241 (viper-loop val
2157 (open-line 1) 2242 (open-line 1)
2162 ;; bound to s 2247 ;; bound to s
2163 (defun viper-substitute (arg) 2248 (defun viper-substitute (arg)
2164 "Substitute characters." 2249 "Substitute characters."
2165 (interactive "P") 2250 (interactive "P")
2166 (let ((val (viper-p-val arg)) 2251 (let ((val (viper-p-val arg))
2167 (com (viper-getcom arg))) 2252 ;;(com (viper-getcom arg))
2253 )
2168 (push-mark nil t) 2254 (push-mark nil t)
2169 (forward-char val) 2255 (forward-char val)
2170 (if (eq viper-intermediate-command 'viper-repeat) 2256 (if (eq viper-intermediate-command 'viper-repeat)
2171 (viper-change-subr (mark t) (point)) 2257 (viper-change-subr (mark t) (point))
2172 (viper-change (mark t) (point))) 2258 (viper-change (mark t) (point)))
2387 ;; Similar to Emacs's own overwrite-mode. 2473 ;; Similar to Emacs's own overwrite-mode.
2388 (defun viper-overwrite (arg) 2474 (defun viper-overwrite (arg)
2389 "Begin overwrite mode." 2475 "Begin overwrite mode."
2390 (interactive "P") 2476 (interactive "P")
2391 (let ((val (viper-p-val arg)) 2477 (let ((val (viper-p-val arg))
2392 (com (viper-getcom arg)) (len)) 2478 ;;(com (viper-getcom arg))
2479 (len))
2393 (viper-set-destructive-command (list 'viper-overwrite val ?r nil nil nil)) 2480 (viper-set-destructive-command (list 'viper-overwrite val ?r nil nil nil))
2394 (if (eq viper-intermediate-command 'viper-repeat) 2481 (if (eq viper-intermediate-command 'viper-repeat)
2395 (progn 2482 (progn
2396 ;; Viper saves inserted text in viper-last-insertion 2483 ;; Viper saves inserted text in viper-last-insertion
2397 (setq len (length viper-last-insertion)) 2484 (setq len (length viper-last-insertion))
2459 (viper-set-destructive-command 2546 (viper-set-destructive-command
2460 (list 'viper-replace-char val ?r nil viper-d-char nil)) 2547 (list 'viper-replace-char val ?r nil viper-d-char nil))
2461 )) 2548 ))
2462 2549
2463 (defun viper-replace-char-subr (com arg) 2550 (defun viper-replace-char-subr (com arg)
2464 (let (char) 2551 (let (char inhibit-quit)
2465 (setq char (if (eq viper-intermediate-command 'viper-repeat) 2552 (viper-set-complex-command-for-undo)
2466 viper-d-char 2553 (or (eq viper-intermediate-command 'viper-repeat)
2467 (read-char))) 2554 (viper-special-read-and-insert-char))
2468 (let (inhibit-quit) ; preserve consistency of undo-list and iso-accents 2555
2469 (if (and viper-automatic-iso-accents
2470 (viper-memq-char char '(?' ?\" ?^ ?~)))
2471 ;; get European characters
2472 (progn
2473 (viper-set-iso-accents-mode t)
2474 (viper-set-unread-command-events char)
2475 (setq char (aref (read-key-sequence nil) 0))
2476 (viper-set-iso-accents-mode nil)))
2477 (viper-set-complex-command-for-undo)
2478 (if (eq char ?\C-m) (setq char ?\n)) 2556 (if (eq char ?\C-m) (setq char ?\n))
2479 (if (and viper-special-input-method (fboundp 'quail-start-translation)) 2557
2480 ;; get Intl. characters 2558 (delete-char 1 t)
2481 (progn 2559
2482 (viper-set-input-method t) 2560 (setq char (if com viper-d-char (viper-char-at-pos 'backward)))
2483 (setq last-command-event 2561 (if com (insert char))
2484 (viper-copy-event 2562
2485 (if viper-xemacs-p (character-to-event char) char))) 2563 (setq viper-d-char char)
2486 (delete-char 1 t) 2564
2487 (condition-case nil 2565 (viper-loop (1- (if (> arg 0) arg (- arg)))
2488 (if com 2566 (delete-char 1 t)
2489 (insert char) 2567 (insert char))
2490 (if viper-emacs-p 2568
2491 (quail-start-translation 1)
2492 (quail-start-translation)))
2493 (error))
2494 ;; quail translation failed
2495 (if (and (not (stringp quail-current-str))
2496 (not (viper-characterp quail-current-str)))
2497 (progn
2498 (viper-adjust-undo)
2499 (undo-start)
2500 (undo-more 1)
2501 (viper-set-input-method nil)
2502 (error "Composing character failed, changes undone")))
2503 ;; quail translation seems ok
2504 (or com
2505 ;;(setq char quail-current-str))
2506 (setq char (viper-char-at-pos 'backward)))
2507 (setq viper-d-char char)
2508 (viper-loop (1- (if (> arg 0) arg (- arg)))
2509 (delete-char 1 t)
2510 (insert char))
2511 (viper-set-input-method nil))
2512 (delete-char arg t)
2513 (setq viper-d-char char)
2514 (viper-loop (if (> arg 0) arg (- arg))
2515 (insert char)))
2516 (viper-adjust-undo) 2569 (viper-adjust-undo)
2517 (backward-char arg)))) 2570 (backward-char arg)
2571 ))
2518 2572
2519 2573
2520 ;; basic cursor movement. j, k, l, h commands. 2574 ;; basic cursor movement. j, k, l, h commands.
2521 2575
2522 (defun viper-forward-char (arg) 2576 (defun viper-forward-char (arg)