1 |
;;; viper-cmd.el --- Vi command support for Viper |
;;; viper-cmd.el --- Vi command support for Viper |
2 |
|
|
3 |
;; Copyright (C) 1997 Free Software Foundation, Inc. |
;; Copyright (C) 1997, 98, 99, 2000, 01, 02 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: Michael Kifer <kifer@cs.sunysb.edu> |
;; Author: Michael Kifer <kifer@cs.stonybrook.edu> |
6 |
|
|
7 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
8 |
|
|
41 |
(defvar quail-current-str) |
(defvar quail-current-str) |
42 |
(defvar zmacs-region-stays) |
(defvar zmacs-region-stays) |
43 |
(defvar mark-even-if-inactive) |
(defvar mark-even-if-inactive) |
44 |
|
(defvar init-message) |
45 |
|
(defvar initial) |
46 |
|
|
47 |
;; loading happens only in non-interactive compilation |
;; loading happens only in non-interactive compilation |
48 |
;; in order to spare non-viperized emacs from being viperized |
;; in order to spare non-viperized emacs from being viperized |
147 |
;; Where viper saves mark. This mark is resurrected by m^ |
;; Where viper saves mark. This mark is resurrected by m^ |
148 |
(defvar viper-saved-mark nil) |
(defvar viper-saved-mark nil) |
149 |
|
|
150 |
|
;; Contains user settings for vars affected by viper-set-expert-level function. |
151 |
|
;; Not a user option. |
152 |
|
(defvar viper-saved-user-settings nil) |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
;;; CODE |
;;; CODE |
304 |
;; desirable that viper-pre-command-sentinel is the last hook and |
;; desirable that viper-pre-command-sentinel is the last hook and |
305 |
;; viper-post-command-sentinel is the first hook. |
;; viper-post-command-sentinel is the first hook. |
306 |
|
|
307 |
(if viper-xemacs-p |
(viper-cond-compile-for-xemacs-or-emacs |
308 |
(progn |
;; xemacs |
309 |
(make-local-hook 'viper-after-change-functions) |
(progn |
310 |
(make-local-hook 'viper-before-change-functions) |
(make-local-hook 'viper-after-change-functions) |
311 |
(make-local-hook 'viper-post-command-hooks) |
(make-local-hook 'viper-before-change-functions) |
312 |
(make-local-hook 'viper-pre-command-hooks))) |
(make-local-hook 'viper-post-command-hooks) |
313 |
|
(make-local-hook 'viper-pre-command-hooks)) |
314 |
|
nil ; emacs |
315 |
|
) |
316 |
|
|
317 |
(remove-hook 'post-command-hook 'viper-post-command-sentinel) |
(remove-hook 'post-command-hook 'viper-post-command-sentinel) |
318 |
(add-hook 'post-command-hook 'viper-post-command-sentinel) |
(add-hook 'post-command-hook 'viper-post-command-sentinel) |
753 |
|
|
754 |
;; this-command, last-command-char, last-command-event |
;; this-command, last-command-char, last-command-event |
755 |
(setq this-command com) |
(setq this-command com) |
756 |
(if viper-xemacs-p ; XEmacs represents key sequences as vectors |
(viper-cond-compile-for-xemacs-or-emacs |
757 |
(setq last-command-event |
;; XEmacs represents key sequences as vectors |
758 |
(viper-copy-event (viper-seq-last-elt key)) |
(setq last-command-event |
759 |
last-command-char (event-to-character last-command-event)) |
(viper-copy-event (viper-seq-last-elt key)) |
760 |
;; Emacs represents them as sequences (str or vec) |
last-command-char (event-to-character last-command-event)) |
761 |
(setq last-command-event |
;; Emacs represents them as sequences (str or vec) |
762 |
(viper-copy-event (viper-seq-last-elt key)) |
(setq last-command-event |
763 |
last-command-char last-command-event)) |
(viper-copy-event (viper-seq-last-elt key)) |
764 |
|
last-command-char last-command-event) |
765 |
|
) |
766 |
|
|
767 |
(if (commandp com) |
(if (commandp com) |
768 |
(progn |
(progn |
861 |
(viper-copy-event (if viper-xemacs-p |
(viper-copy-event (if viper-xemacs-p |
862 |
(character-to-event ch) ch))) |
(character-to-event ch) ch))) |
863 |
) ; let |
) ; let |
864 |
(error) |
(error nil) |
865 |
) ; condition-case |
) ; condition-case |
866 |
|
|
867 |
(viper-set-input-method nil) |
(viper-set-input-method nil) |
1777 |
(message " `.' runs %s%s" |
(message " `.' runs %s%s" |
1778 |
(concat "`" (viper-array-to-string keys) "'") |
(concat "`" (viper-array-to-string keys) "'") |
1779 |
(viper-abbreviate-string |
(viper-abbreviate-string |
1780 |
(if viper-xemacs-p |
(viper-cond-compile-for-xemacs-or-emacs |
1781 |
(replace-in-string |
(replace-in-string ; xemacs |
1782 |
(cond ((characterp text) (char-to-string text)) |
(cond ((characterp text) (char-to-string text)) |
1783 |
((stringp text) text) |
((stringp text) text) |
1784 |
(t "")) |
(t "")) |
1785 |
"\n" "^J") |
"\n" "^J") |
1786 |
text) |
text ; emacs |
1787 |
|
) |
1788 |
max-text-len |
max-text-len |
1789 |
" inserting `" "'" " .......")) |
" inserting `" "'" " .......")) |
1790 |
)) |
)) |
2071 |
(setq cmd |
(setq cmd |
2072 |
(key-binding (setq key (read-key-sequence nil)))) |
(key-binding (setq key (read-key-sequence nil)))) |
2073 |
(cond ((eq cmd 'self-insert-command) |
(cond ((eq cmd 'self-insert-command) |
2074 |
(if viper-xemacs-p |
(viper-cond-compile-for-xemacs-or-emacs |
2075 |
(insert (events-to-keys key)) |
(insert (events-to-keys key)) ; xemacs |
2076 |
(insert key))) |
(insert key) ; emacs |
2077 |
|
)) |
2078 |
((memq cmd '(exit-minibuffer viper-exit-minibuffer)) |
((memq cmd '(exit-minibuffer viper-exit-minibuffer)) |
2079 |
nil) |
nil) |
2080 |
(t (command-execute cmd))) |
(t (command-execute cmd))) |
2655 |
(let ((pt (point))) |
(let ((pt (point))) |
2656 |
(condition-case nil |
(condition-case nil |
2657 |
(forward-char arg) |
(forward-char arg) |
2658 |
(error)) |
(error nil)) |
2659 |
(if (< (point) pt) ; arg was negative |
(if (< (point) pt) ; arg was negative |
2660 |
(- (viper-chars-in-region pt (point))) |
(- (viper-chars-in-region pt (point))) |
2661 |
(viper-chars-in-region pt (point))))) |
(viper-chars-in-region pt (point))))) |
2669 |
(let ((pt (point))) |
(let ((pt (point))) |
2670 |
(condition-case nil |
(condition-case nil |
2671 |
(backward-char arg) |
(backward-char arg) |
2672 |
(error)) |
(error nil)) |
2673 |
(if (> (point) pt) ; arg was negative |
(if (> (point) pt) ; arg was negative |
2674 |
(viper-chars-in-region pt (point)) |
(viper-chars-in-region pt (point)) |
2675 |
(- (viper-chars-in-region pt (point)))))) |
(- (viper-chars-in-region pt (point)))))) |
3336 |
;; (which is called from viper-search-forward/backward/next). If the value of |
;; (which is called from viper-search-forward/backward/next). If the value of |
3337 |
;; viper-search-scroll-threshold is negative - don't scroll. |
;; viper-search-scroll-threshold is negative - don't scroll. |
3338 |
(defun viper-adjust-window () |
(defun viper-adjust-window () |
3339 |
(let ((win-height (if viper-emacs-p |
(let ((win-height (viper-cond-compile-for-xemacs-or-emacs |
3340 |
(1- (window-height)) ; adjust for modeline |
(window-displayed-height) ; xemacs |
3341 |
(window-displayed-height))) |
;; emacs |
3342 |
|
(1- (window-height)) ; adjust for modeline |
3343 |
|
)) |
3344 |
(pt (point)) |
(pt (point)) |
3345 |
at-top-p at-bottom-p |
at-top-p at-bottom-p |
3346 |
min-scroll direction) |
min-scroll direction) |
4590 |
(t (error viper-InvalidTextmarker reg))))) |
(t (error viper-InvalidTextmarker reg))))) |
4591 |
|
|
4592 |
|
|
|
|
|
|
;; commands in insertion mode |
|
4593 |
|
|
4594 |
(defun viper-delete-backward-word (arg) |
(defun viper-delete-backward-word (arg) |
4595 |
"Delete previous word." |
"Delete previous word." |
4600 |
(delete-region (point) (mark t)) |
(delete-region (point) (mark t)) |
4601 |
(pop-mark))) |
(pop-mark))) |
4602 |
|
|
4603 |
|
|
4604 |
|
|
4605 |
|
;; Get viper standard value of SYMBOL. If symbol is customized, get its |
4606 |
|
;; standard value. Otherwise, get the value saved in the alist STORAGE. If |
4607 |
|
;; STORAGE is nil, use viper-saved-user-settings. |
4608 |
|
(defun viper-standard-value (symbol &optional storage) |
4609 |
|
(or (eval (car (get symbol 'customized-value))) |
4610 |
|
(eval (car (get symbol 'saved-value))) |
4611 |
|
(nth 1 (assoc symbol (or storage viper-saved-user-settings))))) |
4612 |
|
|
4613 |
|
|
4614 |
|
|
4615 |
(defun viper-set-expert-level (&optional dont-change-unless) |
(defun viper-set-expert-level (&optional dont-change-unless) |
4616 |
"Sets the expert level for a Viper user. |
"Sets the expert level for a Viper user. |
4937 |
(require 'reporter) |
(require 'reporter) |
4938 |
(set-window-configuration window-config) |
(set-window-configuration window-config) |
4939 |
|
|
4940 |
(reporter-submit-bug-report "kifer@cs.sunysb.edu" |
(reporter-submit-bug-report "kifer@cs.stonybrook.edu" |
4941 |
(viper-version) |
(viper-version) |
4942 |
varlist |
varlist |
4943 |
nil 'delete-other-windows |
nil 'delete-other-windows |
4945 |
)) |
)) |
4946 |
|
|
4947 |
|
|
|
|
|
|
;; Smoothes out the difference between Emacs' unread-command-events |
|
|
;; and XEmacs unread-command-event. Arg is a character, an event, a list of |
|
|
;; events or a sequence of keys. |
|
|
;; |
|
|
;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event |
|
|
;; symbol in unread-command-events list may cause Emacs to turn this symbol |
|
|
;; into an event. Below, we delete nil from event lists, since nil is the most |
|
|
;; common symbol that might appear in this wrong context. |
|
|
(defun viper-set-unread-command-events (arg) |
|
|
(if viper-emacs-p |
|
|
(setq |
|
|
unread-command-events |
|
|
(let ((new-events |
|
|
(cond ((eventp arg) (list arg)) |
|
|
((listp arg) arg) |
|
|
((sequencep arg) |
|
|
(listify-key-sequence arg)) |
|
|
(t (error |
|
|
"viper-set-unread-command-events: Invalid argument, %S" |
|
|
arg))))) |
|
|
(if (not (eventp nil)) |
|
|
(setq new-events (delq nil new-events))) |
|
|
(append new-events unread-command-events))) |
|
|
;; XEmacs |
|
|
(setq |
|
|
unread-command-events |
|
|
(append |
|
|
(cond ((viper-characterp arg) (list (character-to-event arg))) |
|
|
((eventp arg) (list arg)) |
|
|
((stringp arg) (mapcar 'character-to-event arg)) |
|
|
((vectorp arg) (append arg nil)) ; turn into list |
|
|
((listp arg) (viper-eventify-list-xemacs arg)) |
|
|
(t (error |
|
|
"viper-set-unread-command-events: Invalid argument, %S" arg))) |
|
|
unread-command-events)))) |
|
|
|
|
|
;; list is assumed to be a list of events of characters |
|
|
(defun viper-eventify-list-xemacs (lis) |
|
|
(mapcar |
|
|
(lambda (elt) |
|
|
(cond ((viper-characterp elt) (character-to-event elt)) |
|
|
((eventp elt) elt) |
|
|
(t (error |
|
|
"viper-eventify-list-xemacs: can't convert to event, %S" |
|
|
elt)))) |
|
|
lis)) |
|
|
|
|
4948 |
|
|
4949 |
|
|
4950 |
;;; viper-cmd.el ends here |
;;; viper-cmd.el ends here |