comparison lisp/emulation/viper-util.el @ 42602:633233bf2bbf

2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu> * viper-init.el (viper-cond-compile-for-xemacs-or-emacs): new macro that replaces viper-emacs-p and viper-xemacs-p in many cases. Used to reduce the number of warnings. * viper-cmd.el: use viper-cond-compile-for-xemacs-or-emacs. (viper-standard-value): moved here from viper.el. (viper-set-unread-command-events): moved to viper-util.el (viper-check-minibuffer-overlay): make sure viper-minibuffer-overlay is moved to cover the entire input field. * viper-util.el: use viper-cond-compile-for-xemacs-or-emacs. (viper-read-key-sequence, viper-set-unread-command-events, viper-char-symbol-sequence-p, viper-char-array-p): moved here. * viper-ex.el: use viper-cond-compile-for-xemacs-or-emacs. * viper-keym.el: use viper-cond-compile-for-xemacs-or-emacs. * viper-mous.el: use viper-cond-compile-for-xemacs-or-emacs. * viper-macs.el (viper-char-array-p, viper-char-symbol-sequence-p, viper-event-vector-p): moved to viper-util.el * viper.el (viper-standard-value): moved to viper-cmd.el. Use viper-cond-compile-for-xemacs-or-emacs. * ediff-help.el: use ediff-cond-compile-for-xemacs-or-emacs. * ediff-hook.el: use ediff-cond-compile-for-xemacs-or-emacs. * ediff-init.el (ediff-cond-compile-for-xemacs-or-emacs): new macro designed to be used in many places where ediff-emacs-p or ediff-xemacs-p was previously used. Reduces the number of warnings. Use ediff-cond-compile-for-xemacs-or-emacs in many places in lieue of ediff-xemacs-p. (ediff-make-current-diff-overlay, ediff-highlight-diff-in-one-buffer, ediff-convert-fine-diffs-to-overlays, ediff-empty-diff-region-p, ediff-whitespace-diff-region-p, ediff-get-region-contents): moved to ediff-util.el. (ediff-event-key): moved here. * ediff-merge.el: got rid of unreferenced variables. * ediff-mult.el: use ediff-cond-compile-for-xemacs-or-emacs. * ediff-util.el: use ediff-cond-compile-for-xemacs-or-emacs. (ediff-cleanup-mess): improved the way windows are set up after quitting ediff. (ediff-janitor): use ediff-dispose-of-variant-according-to-user. (ediff-dispose-of-variant-according-to-user): new function designed to be smarter and also understands indirect buffers. (ediff-highlight-diff-in-one-buffer, ediff-unhighlight-diff-in-one-buffer, ediff-unhighlight-diffs-totally-in-one-buffer, ediff-highlight-diff, ediff-highlight-diff, ediff-unhighlight-diff, ediff-unhighlight-diffs-totally, ediff-empty-diff-region-p, ediff-whitespace-diff-region-p, ediff-get-region-contents, ediff-make-current-diff-overlay): moved here. (ediff-format-bindings-of): new function by Hannu Koivisto <azure@iki.fi>. (ediff-setup): make sure the merge buffer is always widened and modifiable. (ediff-write-merge-buffer-and-maybe-kill): refuse to write the result of a merge into a file visited by another buffer. (ediff-arrange-autosave-in-merge-jobs): check if the merge file is visited by another buffer and ask to save/delete that buffer. (ediff-verify-file-merge-buffer): new function to do the above. * ediff-vers.el: load ediff-init.el at compile time. * ediff-wind.el: use ediff-cond-compile-for-xemacs-or-emacs. * ediff.el (ediff-windows, ediff-regions-wordwise, ediff-regions-linewise): use indirect buffers to improve robustness and make it possible to compare regions of the same buffer (even overlapping regions). (ediff-clone-buffer-for-region-comparison, ediff-clone-buffer-for-window-comparison): new functions. (ediff-files-internal): refuse to compare identical files. (ediff-regions-internal): get rid of the warning about comparing regions of the same buffer. * ediff-diff.el (ediff-convert-fine-diffs-to-overlays): moved here. Plus the following fixes courtesy of Dave Love: Doc fixes. (ediff-word-1): Use word class and move - to the front per regexp documentation. (ediff-wordify): Bind forward-word-function outside loop. (ediff-copy-to-buffer): Use insert-buffer-substring rather than consing buffer contents. (ediff-goto-word): Move syntax table setting outside loop.
author Michael Kifer <kifer@cs.stonybrook.edu>
date Tue, 08 Jan 2002 04:36:01 +0000
parents 8dccf2552307
children 69c91aaa067a
comparison
equal deleted inserted replaced
42601:ddd4802ff361 42602:633233bf2bbf
1 ;;; viper-util.el --- Utilities used by viper.el 1 ;;; viper-util.el --- Utilities used by viper.el
2 2
3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 95, 96, 97, 99, 2000, 01, 02 Free Software Foundation, Inc.
4 4
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> 5 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
6 6
7 ;; This file is part of GNU Emacs. 7 ;; This file is part of GNU Emacs.
8 8
9 ;; 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
10 ;; 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
37 (defvar viper-fast-keyseq-timeout) 37 (defvar viper-fast-keyseq-timeout)
38 (defvar ex-unix-type-shell) 38 (defvar ex-unix-type-shell)
39 (defvar ex-unix-type-shell-options) 39 (defvar ex-unix-type-shell-options)
40 (defvar viper-ex-tmp-buf-name) 40 (defvar viper-ex-tmp-buf-name)
41 (defvar viper-syntax-preference) 41 (defvar viper-syntax-preference)
42 (defvar viper-saved-mark)
42 43
43 (require 'cl) 44 (require 'cl)
44 (require 'ring) 45 (require 'ring)
45 46
46 (if noninteractive 47 (if noninteractive
64 65
65 66
66 ;;; XEmacs support 67 ;;; XEmacs support
67 68
68 69
69 (if viper-xemacs-p 70 (viper-cond-compile-for-xemacs-or-emacs
70 (progn 71 (progn ; xemacs
71 (fset 'viper-read-event (symbol-function 'next-command-event)) 72 (fset 'viper-overlay-p (symbol-function 'extentp))
72 (fset 'viper-make-overlay (symbol-function 'make-extent)) 73 (fset 'viper-make-overlay (symbol-function 'make-extent))
73 (fset 'viper-overlay-start (symbol-function 'extent-start-position)) 74 (fset 'viper-overlay-live-p (symbol-function 'extent-live-p))
74 (fset 'viper-overlay-end (symbol-function 'extent-end-position)) 75 (fset 'viper-move-overlay (symbol-function 'set-extent-endpoints))
75 (fset 'viper-overlay-put (symbol-function 'set-extent-property)) 76 (fset 'viper-overlay-start (symbol-function 'extent-start-position))
76 (fset 'viper-overlay-p (symbol-function 'extentp)) 77 (fset 'viper-overlay-end (symbol-function 'extent-end-position))
77 (fset 'viper-overlay-get (symbol-function 'extent-property)) 78 (fset 'viper-overlay-get (symbol-function 'extent-property))
78 (fset 'viper-move-overlay (symbol-function 'set-extent-endpoints)) 79 (fset 'viper-overlay-put (symbol-function 'set-extent-property))
79 (fset 'viper-overlay-live-p (symbol-function 'extent-live-p)) 80 (fset 'viper-read-event (symbol-function 'next-command-event))
80 (if (viper-window-display-p) 81 (fset 'viper-characterp (symbol-function 'characterp))
81 (fset 'viper-iconify (symbol-function 'iconify-frame))) 82 (fset 'viper-int-to-char (symbol-function 'int-to-char))
82 (cond ((viper-has-face-support-p) 83 (if (viper-window-display-p)
83 (fset 'viper-get-face (symbol-function 'get-face)) 84 (fset 'viper-iconify (symbol-function 'iconify-frame)))
84 (fset 'viper-color-defined-p 85 (cond ((viper-has-face-support-p)
85 (symbol-function 'valid-color-name-p)) 86 (fset 'viper-get-face (symbol-function 'get-face))
86 ))) 87 (fset 'viper-color-defined-p (symbol-function 'valid-color-name-p))
87 (fset 'viper-read-event (symbol-function 'read-event)) 88 )))
88 (fset 'viper-make-overlay (symbol-function 'make-overlay)) 89 (progn ; emacs
89 (fset 'viper-overlay-start (symbol-function 'overlay-start)) 90 (fset 'viper-overlay-p (symbol-function 'overlayp))
90 (fset 'viper-overlay-end (symbol-function 'overlay-end)) 91 (fset 'viper-make-overlay (symbol-function 'make-overlay))
91 (fset 'viper-overlay-put (symbol-function 'overlay-put)) 92 (fset 'viper-overlay-live-p (symbol-function 'overlayp))
92 (fset 'viper-overlay-p (symbol-function 'overlayp)) 93 (fset 'viper-move-overlay (symbol-function 'move-overlay))
93 (fset 'viper-overlay-get (symbol-function 'overlay-get)) 94 (fset 'viper-overlay-start (symbol-function 'overlay-start))
94 (fset 'viper-move-overlay (symbol-function 'move-overlay)) 95 (fset 'viper-overlay-end (symbol-function 'overlay-end))
95 (fset 'viper-overlay-live-p (symbol-function 'overlayp)) 96 (fset 'viper-overlay-get (symbol-function 'overlay-get))
96 (if (viper-window-display-p) 97 (fset 'viper-overlay-put (symbol-function 'overlay-put))
97 (fset 'viper-iconify (symbol-function 'iconify-or-deiconify-frame))) 98 (fset 'viper-read-event (symbol-function 'read-event))
98 (cond ((viper-has-face-support-p) 99 (fset 'viper-characterp (symbol-function 'integerp))
99 (fset 'viper-get-face (symbol-function 'internal-get-face)) 100 (fset 'viper-int-to-char (symbol-function 'identity))
100 (fset 'viper-color-defined-p (symbol-function 'x-color-defined-p)) 101 (if (viper-window-display-p)
101 ))) 102 (fset 'viper-iconify (symbol-function 'iconify-or-deiconify-frame)))
102 103 (cond ((viper-has-face-support-p)
103 104 (fset 'viper-get-face (symbol-function 'internal-get-face))
104 (fset 'viper-characterp 105 (fset 'viper-color-defined-p (symbol-function 'x-color-defined-p))
105 (symbol-function 106 )))
106 (if viper-xemacs-p 'characterp 'integerp))) 107 )
107 108
108 (fset 'viper-int-to-char 109
109 (symbol-function
110 (if viper-xemacs-p 'int-to-char 'identity)))
111 110
112 ;; CHAR is supposed to be a char or an integer (positive or negative) 111 ;; CHAR is supposed to be a char or an integer (positive or negative)
113 ;; LIST is a list of chars, nil, and negative numbers 112 ;; LIST is a list of chars, nil, and negative numbers
114 ;; Check if CHAR is a member by trying to convert in characters, if necessary. 113 ;; Check if CHAR is a member by trying to convert in characters, if necessary.
115 ;; Introduced for compatibility with XEmacs, where integers are not the same as 114 ;; Introduced for compatibility with XEmacs, where integers are not the same as
131 ((and (viper-characterp char) (viper-characterp char1)) 130 ((and (viper-characterp char) (viper-characterp char1))
132 (= char char1)) 131 (= char char1))
133 (t nil))) 132 (t nil)))
134 133
135 (defsubst viper-color-display-p () 134 (defsubst viper-color-display-p ()
136 (if viper-emacs-p 135 (viper-cond-compile-for-xemacs-or-emacs
137 (x-display-color-p) 136 (eq (device-class (selected-device)) 'color) ; xemacs
138 (eq (device-class (selected-device)) 'color))) 137 (x-display-color-p) ; emacs
138 ))
139 139
140 (defsubst viper-get-cursor-color () 140 (defsubst viper-get-cursor-color ()
141 (if viper-emacs-p 141 (viper-cond-compile-for-xemacs-or-emacs
142 (cdr (assoc 'cursor-color (frame-parameters))) 142 ;; xemacs
143 (color-instance-name (frame-property (selected-frame) 'cursor-color)))) 143 (color-instance-name (frame-property (selected-frame) 'cursor-color))
144 (cdr (assoc 'cursor-color (frame-parameters))) ; emacs
145 ))
144 146
145 147
146 ;; OS/2 148 ;; OS/2
147 (cond ((eq (viper-device-type) 'pm) 149 (cond ((eq (viper-device-type) 'pm)
148 (fset 'viper-color-defined-p 150 (fset 'viper-color-defined-p
152 ;; cursor colors 154 ;; cursor colors
153 (defun viper-change-cursor-color (new-color) 155 (defun viper-change-cursor-color (new-color)
154 (if (and (viper-window-display-p) (viper-color-display-p) 156 (if (and (viper-window-display-p) (viper-color-display-p)
155 (stringp new-color) (viper-color-defined-p new-color) 157 (stringp new-color) (viper-color-defined-p new-color)
156 (not (string= new-color (viper-get-cursor-color)))) 158 (not (string= new-color (viper-get-cursor-color))))
157 (if viper-emacs-p 159 (viper-cond-compile-for-xemacs-or-emacs
158 (modify-frame-parameters 160 (set-frame-property
159 (selected-frame) (list (cons 'cursor-color new-color))) 161 (selected-frame) 'cursor-color (make-color-instance new-color))
160 (set-frame-property 162 (modify-frame-parameters
161 (selected-frame) 'cursor-color (make-color-instance new-color))) 163 (selected-frame) (list (cons 'cursor-color new-color)))
164 )
162 )) 165 ))
163 166
164 ;; By default, saves current frame cursor color in the 167 ;; By default, saves current frame cursor color in the
165 ;; viper-saved-cursor-color-in-replace-mode property of viper-replace-overlay 168 ;; viper-saved-cursor-color-in-replace-mode property of viper-replace-overlay
166 (defun viper-save-cursor-color (before-which-mode) 169 (defun viper-save-cursor-color (before-which-mode)
822 (viper-overlay-put viper-minibuffer-overlay 'start-open nil) 825 (viper-overlay-put viper-minibuffer-overlay 'start-open nil)
823 (viper-overlay-put viper-minibuffer-overlay 'end-open nil))) 826 (viper-overlay-put viper-minibuffer-overlay 'end-open nil)))
824 ))) 827 )))
825 828
826 (defun viper-check-minibuffer-overlay () 829 (defun viper-check-minibuffer-overlay ()
827 (or (viper-overlay-p viper-minibuffer-overlay) 830 (if (viper-overlay-live-p viper-minibuffer-overlay)
828 (setq viper-minibuffer-overlay 831 (viper-move-overlay
829 (if viper-xemacs-p 832 viper-minibuffer-overlay
830 (viper-make-overlay 1 (1+ (buffer-size)) (current-buffer)) 833 (if (fboundp 'minibuffer-prompt-end) (minibuffer-prompt-end) 1)
831 ;; make overlay open-ended 834 (1+ (buffer-size)))
832 (viper-make-overlay 835 (setq viper-minibuffer-overlay
833 1 (1+ (buffer-size)) (current-buffer) nil 'rear-advance))) 836 (if viper-xemacs-p
834 )) 837 (viper-make-overlay 1 (1+ (buffer-size)) (current-buffer))
838 ;; make overlay open-ended
839 (viper-make-overlay
840 (if (fboundp 'minibuffer-prompt-end) (minibuffer-prompt-end) 1)
841 (1+ (buffer-size))
842 (current-buffer) nil 'rear-advance)))
843 ))
835 844
836 845
837 (defsubst viper-is-in-minibuffer () 846 (defsubst viper-is-in-minibuffer ()
838 (save-match-data 847 (save-match-data
839 (string-match "\*Minibuf-" (buffer-name)))) 848 (string-match "\*Minibuf-" (buffer-name))))
841 850
842 851
843 ;;; XEmacs compatibility 852 ;;; XEmacs compatibility
844 853
845 (defun viper-abbreviate-file-name (file) 854 (defun viper-abbreviate-file-name (file)
846 (if viper-emacs-p 855 (viper-cond-compile-for-xemacs-or-emacs
847 (abbreviate-file-name file) 856 ;; XEmacs requires addl argument
848 ;; XEmacs requires addl argument 857 (abbreviate-file-name file t)
849 (abbreviate-file-name file t))) 858 ;; emacs
859 (abbreviate-file-name file)
860 ))
850 861
851 ;; Sit for VAL milliseconds. XEmacs doesn't support the millisecond arg 862 ;; Sit for VAL milliseconds. XEmacs doesn't support the millisecond arg
852 ;; in sit-for, so this function smoothes out the differences. 863 ;; in sit-for, so this function smoothes out the differences.
853 (defsubst viper-sit-for-short (val &optional nodisp) 864 (defsubst viper-sit-for-short (val &optional nodisp)
854 (if viper-xemacs-p 865 (if viper-xemacs-p
869 (save-excursion 880 (save-excursion
870 (set-buffer buf) 881 (set-buffer buf)
871 (and (<= pos (point-max)) (<= (point-min) pos)))))) 882 (and (<= pos (point-max)) (<= (point-min) pos))))))
872 883
873 (defsubst viper-mark-marker () 884 (defsubst viper-mark-marker ()
874 (if viper-xemacs-p 885 (viper-cond-compile-for-xemacs-or-emacs
875 (mark-marker t) 886 (mark-marker t) ; xemacs
876 (mark-marker))) 887 (mark-marker) ; emacs
888 ))
877 889
878 ;; like (set-mark-command nil) but doesn't push twice, if (car mark-ring) 890 ;; like (set-mark-command nil) but doesn't push twice, if (car mark-ring)
879 ;; is the same as (mark t). 891 ;; is the same as (mark t).
880 (defsubst viper-set-mark-if-necessary () 892 (defsubst viper-set-mark-if-necessary ()
881 (setq mark-ring (delete (viper-mark-marker) mark-ring)) 893 (setq mark-ring (delete (viper-mark-marker) mark-ring))
884 896
885 ;; In transient mark mode (zmacs mode), it is annoying when regions become 897 ;; In transient mark mode (zmacs mode), it is annoying when regions become
886 ;; highlighted due to Viper's pushing marks. So, we deactivate marks, unless 898 ;; highlighted due to Viper's pushing marks. So, we deactivate marks, unless
887 ;; the user explicitly wants highlighting, e.g., by hitting '' or `` 899 ;; the user explicitly wants highlighting, e.g., by hitting '' or ``
888 (defun viper-deactivate-mark () 900 (defun viper-deactivate-mark ()
889 (if viper-xemacs-p 901 (viper-cond-compile-for-xemacs-or-emacs
890 (zmacs-deactivate-region) 902 (zmacs-deactivate-region)
891 (deactivate-mark))) 903 (deactivate-mark)
904 ))
892 905
893 (defsubst viper-leave-region-active () 906 (defsubst viper-leave-region-active ()
894 (if viper-xemacs-p 907 (viper-cond-compile-for-xemacs-or-emacs
895 (setq zmacs-region-stays t))) 908 (setq zmacs-region-stays t)
909 nil
910 ))
896 911
897 ;; Check if arg is a valid character for register 912 ;; Check if arg is a valid character for register
898 ;; TYPE is a list that can contain `letter', `Letter', and `digit'. 913 ;; TYPE is a list that can contain `letter', `Letter', and `digit'.
899 ;; Letter means lowercase letters, Letter means uppercase letters, and 914 ;; Letter means lowercase letters, Letter means uppercase letters, and
900 ;; digit means digits from 1 to 9. 915 ;; digit means digits from 1 to 9.
909 (and (<= ?A reg) (<= reg ?Z))) 924 (and (<= ?A reg) (<= reg ?Z)))
910 )) 925 ))
911 926
912 927
913 (defsubst viper-events-to-keys (events) 928 (defsubst viper-events-to-keys (events)
914 (cond (viper-xemacs-p (events-to-keys events)) 929 (viper-cond-compile-for-xemacs-or-emacs
915 (t events))) 930 (events-to-keys events) ; xemacs
931 events ; emacs
932 ))
916 933
917 934
918 ;; it is suggested that an event must be copied before it is assigned to 935 ;; it is suggested that an event must be copied before it is assigned to
919 ;; last-command-event in XEmacs 936 ;; last-command-event in XEmacs
920 (defun viper-copy-event (event) 937 (defun viper-copy-event (event)
921 (if viper-xemacs-p 938 (viper-cond-compile-for-xemacs-or-emacs
922 (copy-event event) 939 (copy-event event) ; xemacs
923 event)) 940 event ; emacs
941 ))
942
943 ;; Uses different timeouts for ESC-sequences and others
944 (defsubst viper-fast-keysequence-p ()
945 (not (viper-sit-for-short
946 (if (viper-ESC-event-p last-input-event)
947 viper-ESC-keyseq-timeout
948 viper-fast-keyseq-timeout)
949 t)))
924 950
925 ;; like read-event, but in XEmacs also try to convert to char, if possible 951 ;; like read-event, but in XEmacs also try to convert to char, if possible
926 (defun viper-read-event-convert-to-char () 952 (defun viper-read-event-convert-to-char ()
927 (let (event) 953 (let (event)
928 (if viper-emacs-p 954 (viper-cond-compile-for-xemacs-or-emacs
929 (read-event) 955 (progn
930 (setq event (next-command-event)) 956 (setq event (next-command-event))
931 (or (event-to-character event) 957 (or (event-to-character event)
932 event)) 958 event))
959 (read-event)
960 )
933 )) 961 ))
962
963 ;; Viperized read-key-sequence
964 (defun viper-read-key-sequence (prompt &optional continue-echo)
965 (let (inhibit-quit event keyseq)
966 (setq keyseq (read-key-sequence prompt continue-echo))
967 (setq event (if viper-xemacs-p
968 (elt keyseq 0) ; XEmacs returns vector of events
969 (elt (listify-key-sequence keyseq) 0)))
970 (if (viper-ESC-event-p event)
971 (let (unread-command-events)
972 (viper-set-unread-command-events keyseq)
973 (if (viper-fast-keysequence-p)
974 (let ((viper-vi-global-user-minor-mode nil)
975 (viper-vi-local-user-minor-mode nil)
976 (viper-replace-minor-mode nil) ; actually unnecessary
977 (viper-insert-global-user-minor-mode nil)
978 (viper-insert-local-user-minor-mode nil))
979 (setq keyseq (read-key-sequence prompt continue-echo)))
980 (setq keyseq (read-key-sequence prompt continue-echo)))))
981 keyseq))
982
934 983
935 ;; This function lets function-key-map convert key sequences into logical 984 ;; This function lets function-key-map convert key sequences into logical
936 ;; keys. This does a better job than viper-read-event when it comes to kbd 985 ;; keys. This does a better job than viper-read-event when it comes to kbd
937 ;; macros, since it enables certain macros to be shared between X and TTY modes 986 ;; macros, since it enables certain macros to be shared between X and TTY modes
938 ;; by correctly mapping key sequences for Left/Right/... (one an ascii 987 ;; by correctly mapping key sequences for Left/Right/... (one an ascii
952 ;; instead of nil, if '(nil) was previously inadvertently assigned to 1001 ;; instead of nil, if '(nil) was previously inadvertently assigned to
953 ;; unread-command-events 1002 ;; unread-command-events
954 (defun viper-event-key (event) 1003 (defun viper-event-key (event)
955 (or (and event (eventp event)) 1004 (or (and event (eventp event))
956 (error "viper-event-key: Wrong type argument, eventp, %S" event)) 1005 (error "viper-event-key: Wrong type argument, eventp, %S" event))
957 (when (cond (viper-xemacs-p (or (key-press-event-p event) 1006 (when (viper-cond-compile-for-xemacs-or-emacs
958 (mouse-event-p event))) 1007 (or (key-press-event-p event) (mouse-event-p event)) ; xemacs
959 (t t)) 1008 t ; emacs
1009 )
960 (let ((mod (event-modifiers event)) 1010 (let ((mod (event-modifiers event))
961 basis) 1011 basis)
962 (setq basis 1012 (setq basis
963 (cond 1013 (viper-cond-compile-for-xemacs-or-emacs
964 (viper-xemacs-p 1014 ;; XEmacs
965 (cond ((key-press-event-p event) 1015 (cond ((key-press-event-p event)
966 (event-key event)) 1016 (event-key event))
967 ((button-event-p event) 1017 ((button-event-p event)
968 (concat "mouse-" (prin1-to-string (event-button event)))) 1018 (concat "mouse-" (prin1-to-string (event-button event))))
969 (t 1019 (t
970 (error "viper-event-key: Unknown event, %S" event)))) 1020 (error "viper-event-key: Unknown event, %S" event)))
971 (t 1021 ;; Emacs doesn't handle capital letters correctly, since
972 ;; Emacs doesn't handle capital letters correctly, since 1022 ;; \S-a isn't considered the same as A (it behaves as
973 ;; \S-a isn't considered the same as A (it behaves as 1023 ;; plain `a' instead). So we take care of this here
974 ;; plain `a' instead). So we take care of this here 1024 (cond ((and (viper-characterp event) (<= ?A event) (<= event ?Z))
975 (cond ((and (viper-characterp event) (<= ?A event) (<= event ?Z)) 1025 (setq mod nil
976 (setq mod nil 1026 event event))
977 event event)) 1027 ;; Emacs has the oddity whereby characters 128+char
978 ;; Emacs has the oddity whereby characters 128+char 1028 ;; represent M-char *if* this appears inside a string.
979 ;; represent M-char *if* this appears inside a string. 1029 ;; So, we convert them manually to (meta char).
980 ;; So, we convert them manually to (meta char). 1030 ((and (viper-characterp event)
981 ((and (viper-characterp event) 1031 (< ?\C-? event) (<= event 255))
982 (< ?\C-? event) (<= event 255)) 1032 (setq mod '(meta)
983 (setq mod '(meta) 1033 event (- event ?\C-? 1)))
984 event (- event ?\C-? 1))) 1034 ((and (null mod) (eq event 'return))
985 ((and (null mod) (eq event 'return)) 1035 (setq event ?\C-m))
986 (setq event ?\C-m)) 1036 ((and (null mod) (eq event 'space))
987 ((and (null mod) (eq event 'space)) 1037 (setq event ?\ ))
988 (setq event ?\ )) 1038 ((and (null mod) (eq event 'delete))
989 ((and (null mod) (eq event 'delete)) 1039 (setq event ?\C-?))
990 (setq event ?\C-?)) 1040 ((and (null mod) (eq event 'backspace))
991 ((and (null mod) (eq event 'backspace)) 1041 (setq event ?\C-h))
992 (setq event ?\C-h)) 1042 (t (event-basic-type event)))
993 (t (event-basic-type event))) 1043 ) ; viper-cond-compile-for-xemacs-or-emacs
994 ))) 1044 )
995 (if (viper-characterp basis) 1045 (if (viper-characterp basis)
996 (setq basis 1046 (setq basis
997 (if (viper= basis ?\C-?) 1047 (if (viper= basis ?\C-?)
998 (list 'control '\?) ; taking care of an emacs bug 1048 (list 'control '\?) ; taking care of an emacs bug
999 (intern (char-to-string basis))))) 1049 (intern (char-to-string basis)))))
1044 "-" 1094 "-"
1045 base-key-name)))))) 1095 base-key-name))))))
1046 )) 1096 ))
1047 1097
1048 1098
1099 ;; LIS is assumed to be a list of events of characters
1100 (defun viper-eventify-list-xemacs (lis)
1101 (mapcar
1102 (lambda (elt)
1103 (cond ((viper-characterp elt) (character-to-event elt))
1104 ((eventp elt) elt)
1105 (t (error
1106 "viper-eventify-list-xemacs: can't convert to event, %S"
1107 elt))))
1108 lis))
1109
1110
1111 ;; Smoothes out the difference between Emacs' unread-command-events
1112 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of
1113 ;; events or a sequence of keys.
1114 ;;
1115 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event
1116 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
1117 ;; into an event. Below, we delete nil from event lists, since nil is the most
1118 ;; common symbol that might appear in this wrong context.
1119 (defun viper-set-unread-command-events (arg)
1120 (if viper-emacs-p
1121 (setq
1122 unread-command-events
1123 (let ((new-events
1124 (cond ((eventp arg) (list arg))
1125 ((listp arg) arg)
1126 ((sequencep arg)
1127 (listify-key-sequence arg))
1128 (t (error
1129 "viper-set-unread-command-events: Invalid argument, %S"
1130 arg)))))
1131 (if (not (eventp nil))
1132 (setq new-events (delq nil new-events)))
1133 (append new-events unread-command-events)))
1134 ;; XEmacs
1135 (setq
1136 unread-command-events
1137 (append
1138 (cond ((viper-characterp arg) (list (character-to-event arg)))
1139 ((eventp arg) (list arg))
1140 ((stringp arg) (mapcar 'character-to-event arg))
1141 ((vectorp arg) (append arg nil)) ; turn into list
1142 ((listp arg) (viper-eventify-list-xemacs arg))
1143 (t (error
1144 "viper-set-unread-command-events: Invalid argument, %S" arg)))
1145 unread-command-events))))
1146
1147
1148 ;; Check if vec is a vector of key-press events representing characters
1149 ;; XEmacs only
1150 (defun viper-event-vector-p (vec)
1151 (and (vectorp vec)
1152 (eval (cons 'and (mapcar '(lambda (elt) (if (eventp elt) t)) vec)))))
1153
1154
1155 ;; check if vec is a vector of character symbols
1156 (defun viper-char-symbol-sequence-p (vec)
1157 (and
1158 (sequencep vec)
1159 (eval
1160 (cons 'and
1161 (mapcar (lambda (elt)
1162 (and (symbolp elt) (= (length (symbol-name elt)) 1)))
1163 vec)))))
1164
1165
1166 (defun viper-char-array-p (array)
1167 (eval (cons 'and (mapcar 'viper-characterp array))))
1168
1169
1049 ;; Args can be a sequence of events, a string, or a Viper macro. Will try to 1170 ;; Args can be a sequence of events, a string, or a Viper macro. Will try to
1050 ;; convert events to keys and, if all keys are regular printable 1171 ;; convert events to keys and, if all keys are regular printable
1051 ;; characters, will return a string. Otherwise, will return a string 1172 ;; characters, will return a string. Otherwise, will return a string
1052 ;; representing a vector of converted events. If the input was a Viper macro, 1173 ;; representing a vector of converted events. If the input was a Viper macro,
1053 ;; will return a string that represents this macro as a vector. 1174 ;; will return a string that represents this macro as a vector.
1069 (setq temp (mapcar 'viper-key-to-character event-seq)))) 1190 (setq temp (mapcar 'viper-key-to-character event-seq))))
1070 (mapconcat 'char-to-string temp "")) 1191 (mapconcat 'char-to-string temp ""))
1071 (t (prin1-to-string event-seq))))) 1192 (t (prin1-to-string event-seq)))))
1072 1193
1073 (defun viper-key-press-events-to-chars (events) 1194 (defun viper-key-press-events-to-chars (events)
1074 (mapconcat (if viper-emacs-p 1195 (mapconcat (viper-cond-compile-for-xemacs-or-emacs
1075 'char-to-string 1196 (lambda (elt) (char-to-string (event-to-character elt))) ; xemacs
1076 (lambda (elt) (char-to-string (event-to-character elt)))) 1197 'char-to-string ; emacs
1198 )
1077 events 1199 events
1078 "")) 1200 ""))
1079 1201
1080
1081 ;; Uses different timeouts for ESC-sequences and others
1082 (defsubst viper-fast-keysequence-p ()
1083 (not (viper-sit-for-short
1084 (if (viper-ESC-event-p last-input-event)
1085 viper-ESC-keyseq-timeout
1086 viper-fast-keyseq-timeout)
1087 t)))
1088 1202
1089 (defun viper-read-char-exclusive () 1203 (defun viper-read-char-exclusive ()
1090 (let (char 1204 (let (char
1091 (echo-keystrokes 1)) 1205 (echo-keystrokes 1))
1092 (while (null char) 1206 (while (null char)