diff options
| author | Richard M. Stallman | 1993-06-06 07:16:19 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-06-06 07:16:19 +0000 |
| commit | 418d45133793b45f2b44e2a8d517788085896da8 (patch) | |
| tree | de275946578e5d46debe25a19164e9797058a4f5 | |
| parent | 0a94d04eab6fc37feb8ab74590b3fe6b853bf7fc (diff) | |
| download | emacs-418d45133793b45f2b44e2a8d517788085896da8.tar.gz emacs-418d45133793b45f2b44e2a8d517788085896da8.zip | |
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
(vip-escape-to-emacs): Use read-key-sequence and key-binding.
Arg EVENTS replaces arg CHAR.
(vip-ESC, vip-ctl-c, vip-ctl-x, vip-ctl-h): These callers changed.
| -rw-r--r-- | lisp/emulation/vip.el | 97 |
1 files changed, 18 insertions, 79 deletions
diff --git a/lisp/emulation/vip.el b/lisp/emulation/vip.el index e9792745861..13f91aa069f 100644 --- a/lisp/emulation/vip.el +++ b/lisp/emulation/vip.el | |||
| @@ -169,8 +169,7 @@ No message." | |||
| 169 | ;; changing mode | 169 | ;; changing mode |
| 170 | 170 | ||
| 171 | (defun vip-change-mode (new-mode) | 171 | (defun vip-change-mode (new-mode) |
| 172 | "Change mode to NEW-MODE. NEW-MODE is either emacs-mode, vi-mode, | 172 | "Change mode to NEW-MODE---either emacs-mode, vi-mode, or insert-mode." |
| 173 | or insert-mode." | ||
| 174 | (or (eq new-mode vip-current-mode) | 173 | (or (eq new-mode vip-current-mode) |
| 175 | (progn | 174 | (progn |
| 176 | (cond ((eq new-mode 'vi-mode) | 175 | (cond ((eq new-mode 'vi-mode) |
| @@ -278,74 +277,19 @@ Type `n' to quit this window for now.\n") | |||
| 278 | 277 | ||
| 279 | ;; escape to emacs mode temporarily | 278 | ;; escape to emacs mode temporarily |
| 280 | 279 | ||
| 281 | (defun vip-get-editor-command (l-map g-map &optional str) | 280 | (defun vip-escape-to-emacs (arg &optional events) |
| 282 | "Read characters from keyboard until an editor command is formed, using | 281 | "Escape to Emacs mode for one Emacs command. |
| 283 | local keymap L-MAP and global keymap G-MAP. If the command is a | 282 | ARG is used as the prefix value for the executed command. If |
| 284 | self-insert-command, the character just read is returned instead. Optional | 283 | EVENTS is a list of events, which become the beginning of the command." |
| 285 | string STR is used as initial input string." | 284 | (interactive "P") |
| 286 | (let (char l-bind g-bind) | 285 | (let (com key (old-map (current-local-map))) |
| 287 | (setq char | 286 | (if events (setq unread-command-events events)) |
| 288 | (if (or (null str) (string= str "")) | ||
| 289 | (read-char) | ||
| 290 | (string-to-char str))) | ||
| 291 | (setq last-command-char char) | ||
| 292 | (setq l-bind (vip-binding-of char l-map)) | ||
| 293 | (if (null l-bind) | ||
| 294 | ;; since local binding is empty, we concentrate on global one. | ||
| 295 | (progn | ||
| 296 | (setq g-bind (vip-binding-of char g-map)) | ||
| 297 | (if (null g-bind) | ||
| 298 | nil ;; return nil, since both bindings are void. | ||
| 299 | (if (keymapp g-bind) | ||
| 300 | (vip-get-editor-command nil g-bind (vip-string-tail str)) | ||
| 301 | (if (eq g-bind 'self-insert-command) char g-bind)))) | ||
| 302 | ;; local binding is nonvoid | ||
| 303 | (if (keymapp l-bind) | ||
| 304 | ;; since l-bind is a keymap, we consider g-bind as well. | ||
| 305 | (progn | ||
| 306 | (setq g-bind (vip-binding-of char g-map)) | ||
| 307 | (if (null g-bind) | ||
| 308 | (vip-get-editor-command l-bind nil (vip-string-tail str)) | ||
| 309 | (if (keymapp g-bind) | ||
| 310 | ;; both bindings are keymap | ||
| 311 | (vip-get-editor-command l-bind g-bind (vip-string-tail str)) | ||
| 312 | ;; l-bind is a keymap, so we neglect g-bind | ||
| 313 | (vip-get-editor-command l-bind nil (vip-string-tail str))))) | ||
| 314 | ;; l-bind is a command | ||
| 315 | (if (eq l-bind 'self-insert-command) char l-bind))))) | ||
| 316 | |||
| 317 | (defun vip-binding-of (char map) | ||
| 318 | "Return key-binding of CHAR under keymap MAP. It is nil if the binding | ||
| 319 | is void, or a command, or a keymap" | ||
| 320 | (let ((val (if (listp map) | ||
| 321 | (cdr (assq char map)) | ||
| 322 | (aref map char)))) | ||
| 323 | (cond ((null val) nil) | ||
| 324 | ((keymapp val) | ||
| 325 | (if (symbolp val) (symbol-function val) val)) | ||
| 326 | (t | ||
| 327 | ;; otherwise, it is a function which is either a real function or | ||
| 328 | ;; a keymap fset to val. | ||
| 329 | (let ((fun (symbol-function val))) | ||
| 330 | (if (or (null fun) (keymapp fun)) fun val)))))) | ||
| 331 | |||
| 332 | (defun vip-escape-to-emacs (arg &optional char) | ||
| 333 | "Escape to emacs mode and execute one emacs command and then return to | ||
| 334 | vi mode. ARG is used as the prefix value for the executed command. If | ||
| 335 | CHAR is given it becomes the first character of the command." | ||
| 336 | (interactive "P") | ||
| 337 | (let (com (buff (current-buffer)) (first t)) | ||
| 338 | (if char (setq unread-command-events (list char))) | ||
| 339 | (setq prefix-arg arg) | 287 | (setq prefix-arg arg) |
| 340 | (while (or first unread-command-events) | 288 | (use-local-map vip-emacs-local-map) |
| 341 | ;; this while loop is executed until unread command char will be | 289 | (unwind-protect |
| 342 | ;; exhausted. | 290 | (setq com (key-binding (setq key (read-key-sequence nil)))) |
| 343 | (setq first nil) | 291 | (use-local-map old-map)) |
| 344 | (setq com (vip-get-editor-command vip-emacs-local-map global-map)) | 292 | (command-execute com prefix-arg) |
| 345 | (if (numberp com) | ||
| 346 | (vip-loop (vip-p-val prefix-arg) | ||
| 347 | (insert (char-to-string com))) | ||
| 348 | (command-execute com prefix-arg))) | ||
| 349 | (setq prefix-arg nil) ;; reset prefix arg | 293 | (setq prefix-arg nil) ;; reset prefix arg |
| 350 | )) | 294 | )) |
| 351 | 295 | ||
| @@ -360,22 +304,22 @@ CHAR is given it becomes the first character of the command." | |||
| 360 | (defun vip-ESC (arg) | 304 | (defun vip-ESC (arg) |
| 361 | "Emulate ESC key in Emacs mode." | 305 | "Emulate ESC key in Emacs mode." |
| 362 | (interactive "P") | 306 | (interactive "P") |
| 363 | (vip-escape-to-emacs arg ?\e)) | 307 | (vip-escape-to-emacs arg '(?\e))) |
| 364 | 308 | ||
| 365 | (defun vip-ctl-c (arg) | 309 | (defun vip-ctl-c (arg) |
| 366 | "Emulate C-c key in Emacs mode." | 310 | "Emulate C-c key in Emacs mode." |
| 367 | (interactive "P") | 311 | (interactive "P") |
| 368 | (vip-escape-to-emacs arg ?\C-c)) | 312 | (vip-escape-to-emacs arg '(?\C-c))) |
| 369 | 313 | ||
| 370 | (defun vip-ctl-x (arg) | 314 | (defun vip-ctl-x (arg) |
| 371 | "Emulate C-x key in Emacs mode." | 315 | "Emulate C-x key in Emacs mode." |
| 372 | (interactive "P") | 316 | (interactive "P") |
| 373 | (vip-escape-to-emacs arg ?\C-x)) | 317 | (vip-escape-to-emacs arg '(?\C-x))) |
| 374 | 318 | ||
| 375 | (defun vip-ctl-h (arg) | 319 | (defun vip-ctl-h (arg) |
| 376 | "Emulate C-h key in Emacs mode." | 320 | "Emulate C-h key in Emacs mode." |
| 377 | (interactive "P") | 321 | (interactive "P") |
| 378 | (vip-escape-to-emacs arg ?\C-h)) | 322 | (vip-escape-to-emacs arg '(?\C-h))) |
| 379 | 323 | ||
| 380 | 324 | ||
| 381 | ;; prefix argmument for vi mode | 325 | ;; prefix argmument for vi mode |
| @@ -1881,12 +1825,7 @@ the query replace mode will toggle between string replace and regexp replace." | |||
| 1881 | (let ((char (read-char))) | 1825 | (let ((char (read-char))) |
| 1882 | (if (and (<= ?A char) (<= char ?Z)) | 1826 | (if (and (<= ?A char) (<= char ?Z)) |
| 1883 | (setq char (- char (- ?A ?\C-a)))) | 1827 | (setq char (- char (- ?A ?\C-a)))) |
| 1884 | (setq prefix-arg arg) | 1828 | (vip-escape-to-emacs arg (list (aref key 0) char)))) |
| 1885 | (command-execute | ||
| 1886 | (vip-get-editor-command | ||
| 1887 | vip-emacs-local-map global-map | ||
| 1888 | (format "%s%s" key (char-to-string char)))))) | ||
| 1889 | |||
| 1890 | 1829 | ||
| 1891 | ;; commands in insertion mode | 1830 | ;; commands in insertion mode |
| 1892 | 1831 | ||