Mercurial > emacs
annotate lisp/emulation/viper-util.el @ 12309:c78f7af6cee9
(quit_throw_to_read_char): Turn off the error check
testing poll_suppress_count.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 18 Jun 1995 22:28:53 +0000 |
parents | 5ab666b86a02 |
children | 321b2ad48a9c |
rev | line source |
---|---|
10789 | 1 ;;; viper-util.el --- Utilities used by viper.el |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
2 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
11288 | 3 |
10789 | 4 ;; This file is part of GNU Emacs. |
5 | |
6 ;; 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 | |
8 ;; the Free Software Foundation; either version 2, or (at your option) | |
9 ;; any later version. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 ;; GNU General Public License for more details. | |
15 | |
16 ;; You should have received a copy of the GNU General Public License | |
17 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | |
20 (require 'ring) | |
21 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
22 ;; Whether it is XEmacs or not |
12204
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
23 (defconst vip-xemacs-p (string-match "\\(Lucid\\|XEmacs\\)" emacs-version)) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
24 ;; Whether it is Emacs or not |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
25 (defconst vip-emacs-p (not vip-xemacs-p)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
26 ;; Tell whether we are running as a window application or on a TTY |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
27 (defsubst vip-device-type () |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
28 (if vip-emacs-p |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
29 window-system |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
30 (device-type (selected-device)))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
31 ;; in XEmacs: device-type is tty on tty and stream in batch. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
32 (defsubst vip-window-display-p () |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
33 (and (vip-device-type) (not (memq (vip-device-type) '(tty stream))))) |
10789 | 34 |
35 | |
36 ;;; Macros | |
37 | |
38 (defmacro vip-deflocalvar (var default-value &optional documentation) | |
39 (` (progn | |
40 (defvar (, var) (, default-value) | |
41 (, (format "%s\n\(buffer local\)" documentation))) | |
42 (make-variable-buffer-local '(, var)) | |
43 ))) | |
44 | |
45 (defmacro vip-loop (count body) | |
46 "(vip-loop COUNT BODY) Execute BODY COUNT times." | |
47 (list 'let (list (list 'count count)) | |
48 (list 'while '(> count 0) | |
49 body | |
50 '(setq count (1- count)) | |
51 ))) | |
52 | |
53 (defmacro vip-buffer-live-p (buf) | |
54 (` (and (, buf) (get-buffer (, buf)) (buffer-name (get-buffer (, buf)))))) | |
55 | |
56 ;; return buffer-specific macro definition, given a full macro definition | |
57 (defmacro vip-kbd-buf-alist (macro-elt) | |
58 (` (nth 1 (, macro-elt)))) | |
59 ;; get a pair: (curr-buffer . macro-definition) | |
60 (defmacro vip-kbd-buf-pair (macro-elt) | |
61 (` (assoc (buffer-name) (vip-kbd-buf-alist (, macro-elt))))) | |
62 ;; get macro definition for current buffer | |
63 (defmacro vip-kbd-buf-definition (macro-elt) | |
64 (` (cdr (vip-kbd-buf-pair (, macro-elt))))) | |
65 | |
66 ;; return mode-specific macro definitions, given a full macro definition | |
67 (defmacro vip-kbd-mode-alist (macro-elt) | |
68 (` (nth 2 (, macro-elt)))) | |
69 ;; get a pair: (major-mode . macro-definition) | |
70 (defmacro vip-kbd-mode-pair (macro-elt) | |
71 (` (assoc major-mode (vip-kbd-mode-alist (, macro-elt))))) | |
72 ;; get macro definition for the current major mode | |
73 (defmacro vip-kbd-mode-definition (macro-elt) | |
74 (` (cdr (vip-kbd-mode-pair (, macro-elt))))) | |
75 | |
76 ;; return global macro definition, given a full macro definition | |
77 (defmacro vip-kbd-global-pair (macro-elt) | |
78 (` (nth 3 (, macro-elt)))) | |
79 ;; get global macro definition from an elt of macro-alist | |
80 (defmacro vip-kbd-global-definition (macro-elt) | |
81 (` (cdr (vip-kbd-global-pair (, macro-elt))))) | |
82 | |
83 ;; last elt of a sequence | |
84 (defsubst vip-seq-last-elt (seq) | |
85 (elt seq (1- (length seq)))) | |
86 | |
87 ;; Check if arg is a valid character for register | |
88 ;; TYPE is a list that can contain `letter', `Letter', and `digit'. | |
89 ;; Letter means lowercase letters, Letter means uppercase letters, and | |
90 ;; digit means digits from 1 to 9. | |
91 ;; If TYPE is nil, then down/uppercase letters and digits are allowed. | |
92 (defun vip-valid-register (reg &optional type) | |
93 (or type (setq type '(letter Letter digit))) | |
94 (or (if (memq 'letter type) | |
95 (and (<= ?a reg) (<= reg ?z))) | |
96 (if (memq 'digit type) | |
97 (and (<= ?1 reg) (<= reg ?9))) | |
98 (if (memq 'Letter type) | |
99 (and (<= ?A reg) (<= reg ?Z))) | |
100 )) | |
101 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
102 ;; checks if object is a marker, has a buffer, and points to within that buffer |
10789 | 103 (defun vip-valid-marker (marker) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
104 (if (and (markerp marker) (marker-buffer marker)) |
10789 | 105 (let ((buf (marker-buffer marker)) |
106 (pos (marker-position marker))) | |
107 (save-excursion | |
108 (set-buffer buf) | |
109 (and (<= pos (point-max)) (<= (point-min) pos)))))) | |
110 | |
111 | |
112 (defvar vip-minibuffer-overlay-priority 300) | |
113 (defvar vip-replace-overlay-priority 400) | |
114 (defvar vip-search-overlay-priority 500) | |
115 | |
116 | |
117 ;;; XEmacs support | |
118 | |
119 (if vip-xemacs-p | |
120 (progn | |
121 (fset 'vip-read-event (symbol-function 'next-command-event)) | |
122 (fset 'vip-make-overlay (symbol-function 'make-extent)) | |
123 (fset 'vip-overlay-start (symbol-function 'extent-start-position)) | |
124 (fset 'vip-overlay-end (symbol-function 'extent-end-position)) | |
125 (fset 'vip-overlay-put (symbol-function 'set-extent-property)) | |
126 (fset 'vip-overlay-p (symbol-function 'extentp)) | |
127 (fset 'vip-overlay-get (symbol-function 'extent-property)) | |
128 (fset 'vip-move-overlay (symbol-function 'set-extent-endpoints)) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
129 (if (vip-window-display-p) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
130 (fset 'vip-iconify (symbol-function 'iconify-frame))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
131 (cond ((vip-window-display-p) |
10789 | 132 (fset 'vip-get-face (symbol-function 'get-face)) |
133 (fset 'vip-color-defined-p | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
134 (symbol-function 'valid-color-name-p)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
135 ))) |
10789 | 136 (fset 'vip-read-event (symbol-function 'read-event)) |
137 (fset 'vip-make-overlay (symbol-function 'make-overlay)) | |
138 (fset 'vip-overlay-start (symbol-function 'overlay-start)) | |
139 (fset 'vip-overlay-end (symbol-function 'overlay-end)) | |
140 (fset 'vip-overlay-put (symbol-function 'overlay-put)) | |
141 (fset 'vip-overlay-p (symbol-function 'overlayp)) | |
142 (fset 'vip-overlay-get (symbol-function 'overlay-get)) | |
143 (fset 'vip-move-overlay (symbol-function 'move-overlay)) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
144 (if (vip-window-display-p) |
10789 | 145 (fset 'vip-iconify (symbol-function 'iconify-or-deiconify-frame))) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
146 (cond ((vip-window-display-p) |
10789 | 147 (fset 'vip-get-face (symbol-function 'internal-get-face)) |
148 (fset 'vip-color-defined-p (symbol-function 'x-color-defined-p)) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
149 ))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
150 |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
151 (defsubst vip-color-display-p () |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
152 (if vip-emacs-p |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
153 (x-display-color-p) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
154 (eq (device-class (selected-device)) 'color))) |
10789 | 155 |
156 ;; OS/2 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
157 (cond ((eq (vip-device-type) 'pm) |
10789 | 158 (fset 'vip-color-defined-p |
159 (function (lambda (color) (assoc color pm-color-alist)))))) | |
160 | |
161 ;; needed to smooth out the difference between Emacs and XEmacs | |
162 (defsubst vip-italicize-face (face) | |
163 (if vip-xemacs-p | |
164 (make-face-italic face) | |
165 (make-face-italic face nil 'noerror))) | |
166 | |
167 ;; test if display is color and the colors are defined | |
168 (defsubst vip-can-use-colors (&rest colors) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
169 (if (vip-color-display-p) |
10789 | 170 (not (memq nil (mapcar 'vip-color-defined-p colors))) |
171 )) | |
172 | |
173 ;; currently doesn't work for XEmacs | |
174 (defun vip-change-cursor-color (new-color) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
175 (if (and (vip-window-display-p) (vip-color-display-p) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
176 (stringp new-color) (vip-color-defined-p new-color) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
177 (not (string= new-color (vip-get-cursor-color)))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
178 (modify-frame-parameters |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
179 (selected-frame) (list (cons 'cursor-color new-color))))) |
10789 | 180 |
181 (defsubst vip-save-cursor-color () | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
182 (if (and (vip-window-display-p) (vip-color-display-p)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
183 (let ((color (vip-get-cursor-color))) |
10789 | 184 (if (and (stringp color) (vip-color-defined-p color) |
185 (not (string= color vip-replace-overlay-cursor-color))) | |
186 (vip-overlay-put vip-replace-overlay 'vip-cursor-color color))))) | |
187 | |
188 (defsubst vip-restore-cursor-color () | |
189 (vip-change-cursor-color | |
190 (vip-overlay-get vip-replace-overlay 'vip-cursor-color))) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
191 |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
192 (defsubst vip-get-cursor-color () |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
193 (cdr (assoc 'cursor-color (frame-parameters)))) |
10789 | 194 |
195 | |
196 ;; Check the current version against the major and minor version numbers | |
197 ;; using op: cur-vers op major.minor If emacs-major-version or | |
198 ;; emacs-minor-version are not defined, we assume that the current version | |
199 ;; is hopelessly outdated. We assume that emacs-major-version and | |
200 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the | |
201 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value | |
202 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be | |
203 ;; incorrect. However, this gives correct result in our cases, since we are | |
204 ;; testing for sufficiently high Emacs versions. | |
205 (defun vip-check-version (op major minor &optional type-of-emacs) | |
206 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version)) | |
207 (and (cond ((eq type-of-emacs 'xemacs) vip-xemacs-p) | |
208 ((eq type-of-emacs 'emacs) vip-emacs-p) | |
209 (t t)) | |
210 (cond ((eq op '=) (and (= emacs-minor-version minor) | |
211 (= emacs-major-version major))) | |
212 ((memq op '(> >= < <=)) | |
213 (and (or (funcall op emacs-major-version major) | |
214 (= emacs-major-version major)) | |
215 (if (= emacs-major-version major) | |
216 (funcall op emacs-minor-version minor) | |
217 t))) | |
218 (t | |
219 (error "%S: Invalid op in vip-check-version" op)))) | |
220 (cond ((memq op '(= > >=)) nil) | |
221 ((memq op '(< <=)) t)))) | |
222 | |
223 | |
224 (defun vip-get-visible-buffer-window (wind) | |
225 (if vip-xemacs-p | |
226 (get-buffer-window wind t) | |
227 (get-buffer-window wind 'visible))) | |
228 | |
229 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
230 ;; Return line position. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
231 ;; If pos is 'start then returns position of line start. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
232 ;; If pos is 'end, returns line end. If pos is 'mid, returns line center. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
233 ;; Pos = 'indent returns beginning of indentation. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
234 ;; Otherwise, returns point. Current point is not moved in any case." |
10789 | 235 (defun vip-line-pos (pos) |
236 (let ((cur-pos (point)) | |
237 (result)) | |
238 (cond | |
239 ((equal pos 'start) | |
240 (beginning-of-line)) | |
241 ((equal pos 'end) | |
242 (end-of-line)) | |
243 ((equal pos 'mid) | |
244 (goto-char (+ (vip-line-pos 'start) (vip-line-pos 'end) 2))) | |
245 ((equal pos 'indent) | |
246 (back-to-indentation)) | |
247 (t nil)) | |
248 (setq result (point)) | |
249 (goto-char cur-pos) | |
250 result)) | |
251 | |
252 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
253 ;; Like move-marker but creates a virgin marker if arg isn't already a marker. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
254 ;; The first argument must eval to a variable name. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
255 ;; Arguments: (var-name position &optional buffer). |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
256 ;; |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
257 ;; This is useful for moving markers that are supposed to be local. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
258 ;; For this, VAR-NAME should be made buffer-local with nil as a default. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
259 ;; Then, each time this var is used in `vip-move-marker-locally' in a new |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
260 ;; buffer, a new marker will be created. |
10789 | 261 (defun vip-move-marker-locally (var pos &optional buffer) |
262 (if (markerp (eval var)) | |
263 () | |
264 (set var (make-marker))) | |
265 (move-marker (eval var) pos buffer)) | |
266 | |
267 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
268 ;; Print CONDITIONS as a message. |
10789 | 269 (defun vip-message-conditions (conditions) |
270 (let ((case (car conditions)) (msg (cdr conditions))) | |
271 (if (null msg) | |
272 (message "%s" case) | |
273 (message "%s: %s" case (mapconcat 'prin1-to-string msg " "))) | |
274 (beep 1))) | |
275 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
276 |
10789 | 277 |
278 ;;; List/alist utilities | |
279 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
280 ;; Convert LIST to an alist |
10789 | 281 (defun vip-list-to-alist (lst) |
282 (let ((alist)) | |
283 (while lst | |
284 (setq alist (cons (list (car lst)) alist)) | |
285 (setq lst (cdr lst))) | |
286 alist)) | |
287 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
288 ;; Convert ALIST to a list. |
10789 | 289 (defun vip-alist-to-list (alst) |
290 (let ((lst)) | |
291 (while alst | |
292 (setq lst (cons (car (car alst)) lst)) | |
293 (setq alst (cdr alst))) | |
294 lst)) | |
295 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
296 ;; Filter ALIST using REGEXP. Return alist whose elements match the regexp. |
10789 | 297 (defun vip-filter-alist (regexp alst) |
298 (interactive "s x") | |
299 (let ((outalst) (inalst alst)) | |
300 (while (car inalst) | |
301 (if (string-match regexp (car (car inalst))) | |
302 (setq outalst (cons (car inalst) outalst))) | |
303 (setq inalst (cdr inalst))) | |
304 outalst)) | |
305 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
306 ;; Filter LIST using REGEXP. Return list whose elements match the regexp. |
10789 | 307 (defun vip-filter-list (regexp lst) |
308 (interactive "s x") | |
309 (let ((outlst) (inlst lst)) | |
310 (while (car inlst) | |
311 (if (string-match regexp (car inlst)) | |
312 (setq outlst (cons (car inlst) outlst))) | |
313 (setq inlst (cdr inlst))) | |
314 outlst)) | |
315 | |
316 | |
317 ;; Append LIS2 to LIS1, both alists, by side-effect and returns LIS1 | |
318 ;; LIS2 is modified by filtering it: deleting its members of the form | |
319 ;; \(car elt\) such that (car elt') is in LIS1. | |
320 (defun vip-append-filter-alist (lis1 lis2) | |
321 (let ((temp lis1) | |
322 elt) | |
323 | |
324 ;;filter-append the second list | |
325 (while temp | |
326 ;; delete all occurrences | |
327 (while (setq elt (assoc (car (car temp)) lis2)) | |
328 (setq lis2 (delq elt lis2))) | |
329 (setq temp (cdr temp))) | |
330 | |
331 (nconc lis1 lis2))) | |
332 | |
333 | |
334 | |
335 | |
336 ;;; Insertion ring | |
337 | |
338 ;; Rotate RING's index. DIRection can be positive or negative. | |
339 (defun vip-ring-rotate1 (ring dir) | |
340 (if (and (ring-p ring) (> (ring-length ring) 0)) | |
341 (progn | |
342 (setcar ring (cond ((> dir 0) | |
343 (ring-plus1 (car ring) (ring-length ring))) | |
344 ((< dir 0) | |
345 (ring-minus1 (car ring) (ring-length ring))) | |
346 ;; don't rotate if dir = 0 | |
347 (t (car ring)))) | |
348 (vip-current-ring-item ring) | |
349 ))) | |
350 | |
351 (defun vip-special-ring-rotate1 (ring dir) | |
352 (if (memq vip-intermediate-command | |
353 '(repeating-display-destructive-command | |
354 repeating-insertion-from-ring)) | |
355 (vip-ring-rotate1 ring dir) | |
356 ;; don't rotate otherwise | |
357 (vip-ring-rotate1 ring 0))) | |
358 | |
359 ;; current ring item; if N is given, then so many items back from the | |
360 ;; current | |
361 (defun vip-current-ring-item (ring &optional n) | |
362 (setq n (or n 0)) | |
363 (if (and (ring-p ring) (> (ring-length ring) 0)) | |
364 (aref (cdr (cdr ring)) (mod (- (car ring) 1 n) (ring-length ring))))) | |
365 | |
366 ;; push item onto ring. the second argument is a ring-variable, not value. | |
367 (defun vip-push-onto-ring (item ring-var) | |
368 (or (ring-p (eval ring-var)) | |
369 (set ring-var (make-ring (eval (intern (format "%S-size" ring-var)))))) | |
370 (or (null item) ; don't push nil | |
371 (and (stringp item) (string= item "")) ; or empty strings | |
372 (equal item (vip-current-ring-item (eval ring-var))) ; or old stuff | |
373 ;; Since vip-set-destructive-command checks if we are inside vip-repeat, | |
374 ;; we don't check whether this-command-keys is a `.'. | |
375 ;; The cmd vip-repeat makes a call to the current function only if | |
376 ;; `.' is executing a command from the command history. It doesn't | |
377 ;; call the push-onto-ring function if `.' is simply repeating the | |
378 ;; last destructive command. | |
379 ;; We only check for ESC (which happens when we do insert with a | |
380 ;; prefix argument, or if this-command-keys doesn't give anything | |
381 ;; meaningful (in that case we don't know what to show to the user). | |
382 (and (eq ring-var 'vip-command-ring) | |
383 (string-match "\\([0-9]*\e\\|^[ \t]*$\\|escape\\)" | |
384 (vip-array-to-string (this-command-keys)))) | |
385 (vip-ring-insert (eval ring-var) item)) | |
386 ) | |
387 | |
388 | |
389 ;; removing elts from ring seems to break it | |
390 (defun vip-cleanup-ring (ring) | |
391 (or (< (ring-length ring) 2) | |
392 (null (vip-current-ring-item ring)) | |
393 ;; last and previous equal | |
394 (if (equal (vip-current-ring-item ring) (vip-current-ring-item ring 1)) | |
395 (vip-ring-pop ring)))) | |
396 | |
397 ;; ring-remove seems to be buggy, so we concocted this for our purposes. | |
398 (defun vip-ring-pop (ring) | |
399 (let* ((ln (ring-length ring)) | |
400 (vec (cdr (cdr ring))) | |
401 (veclen (length vec)) | |
402 (hd (car ring)) | |
403 (idx (max 0 (ring-minus1 hd ln))) | |
404 (top-elt (aref vec idx))) | |
405 | |
406 ;; shift elements | |
407 (while (< (1+ idx) veclen) | |
408 (aset vec idx (aref vec (1+ idx))) | |
409 (setq idx (1+ idx))) | |
410 (aset vec idx nil) | |
411 | |
412 (setq hd (max 0 (ring-minus1 hd ln))) | |
413 (if (= hd (1- ln)) (setq hd 0)) | |
414 (setcar ring hd) ; move head | |
415 (setcar (cdr ring) (max 0 (1- ln))) ; adjust length | |
416 top-elt | |
417 )) | |
418 | |
419 (defun vip-ring-insert (ring item) | |
420 (let* ((ln (ring-length ring)) | |
421 (vec (cdr (cdr ring))) | |
422 (veclen (length vec)) | |
423 (hd (car ring)) | |
424 (vecpos-after-hd (if (= hd 0) ln hd)) | |
425 (idx ln)) | |
426 | |
427 (if (= ln veclen) | |
428 (progn | |
429 (aset vec hd item) ; hd is always 1+ the actual head index in vec | |
430 (setcar ring (ring-plus1 hd ln))) | |
431 (setcar (cdr ring) (1+ ln)) | |
432 (setcar ring (ring-plus1 vecpos-after-hd (1+ ln))) | |
433 (while (and (>= idx vecpos-after-hd) (> ln 0)) | |
434 (aset vec idx (aref vec (1- idx))) | |
435 (setq idx (1- idx))) | |
436 (aset vec vecpos-after-hd item)) | |
437 item)) | |
438 | |
439 | |
440 ;;; String utilities | |
441 | |
442 ;; If STRING is longer than MAX-LEN, truncate it and print ...... instead | |
443 ;; PRE-STRING is a string to prepend to the abbrev string. | |
444 ;; POST-STRING is a string to append to the abbrev string. | |
445 ;; ABBREV_SIGN is a string to be inserted before POST-STRING | |
446 ;; if the orig string was truncated. | |
447 (defun vip-abbreviate-string (string max-len | |
448 pre-string post-string abbrev-sign) | |
449 (let (truncated-str) | |
450 (setq truncated-str | |
451 (if (stringp string) | |
452 (substring string 0 (min max-len (length string))))) | |
453 (cond ((null truncated-str) "") | |
454 ((> (length string) max-len) | |
455 (format "%s%s%s%s" | |
456 pre-string truncated-str abbrev-sign post-string)) | |
457 (t (format "%s%s%s" pre-string truncated-str post-string))))) | |
12204
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
458 |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
459 ;; tells if we are over a whitespace-only line |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
460 (defsubst vip-over-whitespace-line () |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
461 (save-excursion |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
462 (beginning-of-line) |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
463 (looking-at "^[ \t]*$"))) |
10789 | 464 |
465 | |
466 ;;; Saving settings in custom file | |
467 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
468 ;; Save the current setting of VAR in CUSTOM-FILE. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
469 ;; If given, MESSAGE is a message to be displayed after that. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
470 ;; This message is erased after 2 secs, if erase-msg is non-nil. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
471 ;; Arguments: var message custom-file &optional erase-message |
10789 | 472 (defun vip-save-setting (var message custom-file &optional erase-msg) |
473 (let* ((var-name (symbol-name var)) | |
474 (var-val (if (boundp var) (eval var))) | |
475 (regexp (format "^[^;]*%s[ \t\n]*[a-zA-Z---_']*[ \t\n)]" var-name)) | |
476 (buf (find-file-noselect (substitute-in-file-name custom-file))) | |
477 ) | |
478 (message message) | |
479 (save-excursion | |
480 (set-buffer buf) | |
481 (goto-char (point-min)) | |
482 (if (re-search-forward regexp nil t) | |
483 (let ((reg-end (1- (match-end 0)))) | |
484 (search-backward var-name) | |
485 (delete-region (match-beginning 0) reg-end) | |
486 (goto-char (match-beginning 0)) | |
487 (insert (format "%s '%S" var-name var-val))) | |
488 (goto-char (point-max)) | |
489 (if (not (bolp)) (insert "\n")) | |
490 (insert (format "(setq %s '%S)\n" var-name var-val))) | |
491 (save-buffer)) | |
492 (kill-buffer buf) | |
493 (if erase-msg | |
494 (progn | |
495 (sit-for 2) | |
496 (message ""))) | |
497 )) | |
498 | |
499 ;; Save STRING in CUSTOM-FILE. If PATTERN is non-nil, remove strings that | |
500 ;; match this pattern. | |
501 (defun vip-save-string-in-file (string custom-file &optional pattern) | |
502 (let ((buf (find-file-noselect (substitute-in-file-name custom-file)))) | |
503 (save-excursion | |
504 (set-buffer buf) | |
505 (goto-char (point-min)) | |
506 (if pattern (delete-matching-lines pattern)) | |
507 (goto-char (point-max)) | |
508 (if string (insert string)) | |
509 (save-buffer)) | |
510 (kill-buffer buf) | |
511 )) | |
512 | |
513 | |
514 ;;; Overlays | |
515 | |
516 ;; Search | |
517 | |
518 (defun vip-flash-search-pattern () | |
519 (if (vip-overlay-p vip-search-overlay) | |
520 (vip-move-overlay vip-search-overlay (match-beginning 0) (match-end 0)) | |
521 (setq vip-search-overlay | |
522 (vip-make-overlay | |
523 (match-beginning 0) (match-end 0) (current-buffer)))) | |
524 | |
525 (vip-overlay-put vip-search-overlay 'priority vip-search-overlay-priority) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
526 (if (vip-window-display-p) |
10789 | 527 (progn |
528 (vip-overlay-put vip-search-overlay 'face vip-search-face) | |
529 (sit-for 2) | |
530 (vip-overlay-put vip-search-overlay 'face nil)))) | |
531 | |
532 ;; Replace state | |
533 | |
534 (defun vip-set-replace-overlay (beg end) | |
535 (if (vip-overlay-p vip-replace-overlay) | |
536 (vip-move-replace-overlay beg end) | |
537 (setq vip-replace-overlay (vip-make-overlay beg end (current-buffer))) | |
538 (vip-overlay-put vip-replace-overlay | |
539 'vip-start | |
540 (move-marker (make-marker) | |
541 (vip-overlay-start vip-replace-overlay))) | |
542 (vip-overlay-put vip-replace-overlay | |
543 'vip-end | |
544 (move-marker (make-marker) | |
545 (vip-overlay-end vip-replace-overlay))) | |
546 (vip-overlay-put | |
547 vip-replace-overlay 'priority vip-replace-overlay-priority)) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
548 (if (vip-window-display-p) |
10789 | 549 (vip-overlay-put vip-replace-overlay 'face vip-replace-overlay-face)) |
550 (vip-save-cursor-color) | |
551 (vip-change-cursor-color vip-replace-overlay-cursor-color) | |
552 ) | |
553 | |
554 | |
555 (defsubst vip-hide-replace-overlay () | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
556 (vip-set-replace-overlay-glyphs nil nil) |
10789 | 557 (vip-restore-cursor-color) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
558 (if (vip-window-display-p) |
10789 | 559 (vip-overlay-put vip-replace-overlay 'face nil))) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
560 |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
561 (defsubst vip-set-replace-overlay-glyphs (before-glyph after-glyph) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
562 (if (or (not (vip-window-display-p)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
563 vip-use-replace-region-delimiters) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
564 (let ((before-name (if vip-xemacs-p 'begin-glyph 'before-string)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
565 (after-name (if vip-xemacs-p 'end-glyph 'after-string))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
566 (vip-overlay-put vip-replace-overlay before-name before-glyph) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
567 (vip-overlay-put vip-replace-overlay after-name after-glyph)))) |
10789 | 568 |
569 | |
570 (defsubst vip-replace-start () | |
571 (vip-overlay-get vip-replace-overlay 'vip-start)) | |
572 (defsubst vip-replace-end () | |
573 (vip-overlay-get vip-replace-overlay 'vip-end)) | |
574 | |
575 (defsubst vip-move-replace-overlay (beg end) | |
576 (vip-move-overlay vip-replace-overlay beg end) | |
577 (move-marker (vip-replace-start) (vip-overlay-start vip-replace-overlay)) | |
578 (move-marker (vip-replace-end) (vip-overlay-end vip-replace-overlay))) | |
579 | |
580 | |
581 ;; Minibuffer | |
582 | |
583 (defun vip-set-minibuffer-overlay () | |
584 (vip-check-minibuffer-overlay) | |
585 ;; We always move the minibuffer overlay, since in XEmacs | |
586 ;; this overlay may get detached. Moving will reattach it. | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
587 ;; This overlay is also moved via the vip-post-command-hook, |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
588 ;; to insure that it covers the whole minibuffer. |
10789 | 589 (vip-move-minibuffer-overlay) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
590 (if (vip-window-display-p) |
10789 | 591 (progn |
592 (vip-overlay-put | |
593 vip-minibuffer-overlay 'face vip-minibuffer-current-face) | |
594 (vip-overlay-put | |
595 vip-minibuffer-overlay 'priority vip-minibuffer-overlay-priority)) | |
596 )) | |
597 | |
598 (defun vip-check-minibuffer-overlay () | |
599 (if (vip-overlay-p vip-minibuffer-overlay) | |
600 () | |
601 (setq vip-minibuffer-overlay | |
602 (vip-make-overlay 1 (1+ (buffer-size)) (current-buffer))))) | |
603 | |
604 ;; arguments to this function are dummies. they are needed just because | |
605 ;; it is used as a insert-in-front-hook to vip-minibuffer-overlay, and such | |
606 ;; hooks require 3 arguments. | |
607 (defun vip-move-minibuffer-overlay (&optional overl beg end) | |
608 (if (vip-is-in-minibuffer) | |
609 (progn | |
610 (vip-check-minibuffer-overlay) | |
611 (vip-move-overlay vip-minibuffer-overlay 1 (1+ (buffer-size)))))) | |
612 | |
613 (defsubst vip-is-in-minibuffer () | |
614 (string-match "\*Minibuf-" (buffer-name))) | |
615 | |
616 | |
617 | |
618 ;;; XEmacs compatibility | |
619 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
620 ;; Sit for VAL miliseconds. XEmacs doesn't support the millisecond arg |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
621 ;; in sit-for, so this function smoothes out the differences. |
10789 | 622 (defsubst vip-sit-for-short (val &optional nodisp) |
623 (if vip-xemacs-p | |
624 (sit-for (/ val 1000.0) nodisp) | |
625 (sit-for 0 val nodisp))) | |
626 | |
627 ;; EVENT may be a single event of a sequence of events | |
628 (defsubst vip-ESC-event-p (event) | |
629 (let ((ESC-keys '(?\e (control \[) escape)) | |
630 (key (vip-event-key event))) | |
631 (member key ESC-keys))) | |
632 | |
633 ;; like (set-mark-command nil) but doesn't push twice, if (car mark-ring) | |
634 ;; is the same as (mark t). | |
635 (defsubst vip-set-mark-if-necessary () | |
636 (setq mark-ring (delete (vip-mark-marker) mark-ring)) | |
637 (set-mark-command nil)) | |
638 | |
639 (defsubst vip-mark-marker () | |
640 (if vip-xemacs-p | |
641 (mark-marker t) | |
642 (mark-marker))) | |
643 | |
644 ;; In transient mark mode (zmacs mode), it is annoying when regions become | |
645 ;; highlighted due to Viper's pushing marks. So, we deactivate marks, unless | |
646 ;; the user explicitly wants highlighting, e.g., by hitting '' or `` | |
647 (defun vip-deactivate-mark () | |
648 (if vip-xemacs-p | |
649 (zmacs-deactivate-region) | |
650 (deactivate-mark))) | |
651 | |
652 | |
653 (defsubst vip-events-to-keys (events) | |
654 (cond (vip-xemacs-p (events-to-keys events)) | |
655 (t events))) | |
656 | |
657 | |
658 (defun vip-eval-after-load (file form) | |
659 (if vip-emacs-p | |
660 (eval-after-load file form) | |
661 (or (assoc file after-load-alist) | |
662 (setq after-load-alist (cons (list file) after-load-alist))) | |
663 (let ((elt (assoc file after-load-alist))) | |
664 (or (member form (cdr elt)) | |
665 (setq elt (nconc elt (list form))))) | |
666 form | |
667 )) | |
668 | |
669 | |
670 ;; like read-event, but in XEmacs also try to convert to char, if possible | |
671 (defun vip-read-event-convert-to-char () | |
672 (let (event) | |
673 (if vip-emacs-p | |
674 (read-event) | |
675 (setq event (next-command-event)) | |
676 (or (event-to-character event) | |
677 event)) | |
678 )) | |
679 | |
680 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
681 ;; Emacs has a bug in eventp, which causes (eventp nil) to return (nil) |
10789 | 682 ;; instead of nil, if '(nil) was previously inadvertantly assigned to |
683 ;; unread-command-events | |
684 (defun vip-event-key (event) | |
685 (or (and event (eventp event)) | |
686 (error "vip-event-key: Wrong type argument, eventp, %S" event)) | |
687 (let ((mod (event-modifiers event)) | |
688 basis) | |
689 (setq basis | |
690 (cond | |
691 (vip-xemacs-p | |
692 (cond ((key-press-event-p event) | |
693 (event-key event)) | |
694 ((button-event-p event) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
695 (concat "mouse-" (prin1-to-string (event-button event)))) |
10789 | 696 (t |
697 (error "vip-event-key: Unknown event, %S" event)))) | |
698 (t | |
699 ;; Emacs doesn't handle capital letters correctly, since | |
700 ;; \S-a isn't considered the same as A (it behaves as | |
701 ;; plain `a' instead). So we take care of this here | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
702 (cond ((and (numberp event) (<= ?A event) (<= event ?Z)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
703 (setq mod nil |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
704 event event)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
705 ;; Emacs has the oddity whereby characters 128+char |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
706 ;; represent M-char *if* this appears inside a string. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
707 ;; So, we convert them manually into (mata char). |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
708 ((and (numberp event) (< ?\C-? event) (<= event 255)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
709 (setq mod '(meta) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
710 event (- event ?\C-? 1))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
711 (t (event-basic-type event))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
712 ))) |
10789 | 713 |
714 (if (numberp basis) | |
715 (setq basis | |
716 (if (= basis ?\C-?) | |
717 (list 'control '\?) ; taking care of an emacs bug | |
718 (intern (char-to-string basis))))) | |
719 | |
720 (if mod | |
721 (append mod (list basis)) | |
722 basis) | |
723 )) | |
724 | |
725 (defun vip-key-to-emacs-key (key) | |
726 (let (key-name char-p modifiers mod-char-list base-key base-key-name) | |
727 (cond (vip-xemacs-p key) | |
728 ((symbolp key) | |
729 (setq key-name (symbol-name key)) | |
730 (if (= (length key-name) 1) ; character event | |
731 (string-to-char key-name) | |
732 key)) | |
733 ((listp key) | |
734 (setq modifiers (subseq key 0 (1- (length key))) | |
735 base-key (vip-seq-last-elt key) | |
736 base-key-name (symbol-name base-key) | |
737 char-p (= (length base-key-name) 1)) | |
738 (setq mod-char-list | |
739 (mapcar | |
740 '(lambda (elt) (upcase (substring (symbol-name elt) 0 1))) | |
741 modifiers)) | |
742 (if char-p | |
743 (setq key-name | |
744 (car (read-from-string | |
745 (concat | |
746 "?\\" | |
747 (mapconcat 'identity mod-char-list "-\\") | |
748 "-" | |
749 base-key-name)))) | |
750 (setq key-name | |
751 (intern | |
752 (concat | |
753 (mapconcat 'identity mod-char-list "-") | |
754 "-" | |
755 base-key-name)))))) | |
756 )) | |
757 | |
758 | |
759 ;; Args can be a sequence of events, a string, or a Viper macro. Will try to | |
760 ;; convert events to keys and, if all keys are regular printable | |
761 ;; characters, will return a string. Otherwise, will return a string | |
762 ;; representing a vector of converted events. If the input was a Viper macro, | |
763 ;; will return a string that represents this macro as a vector. | |
764 (defun vip-array-to-string (event-seq &optional representation) | |
765 (let (temp) | |
766 (cond ((stringp event-seq) event-seq) | |
767 ((vip-event-vector-p event-seq) | |
768 (setq temp (mapcar 'vip-event-key event-seq)) | |
769 (if (vip-char-symbol-sequence-p temp) | |
770 (mapconcat 'symbol-name temp "") | |
771 (prin1-to-string (vconcat temp)))) | |
772 ((vip-char-symbol-sequence-p event-seq) | |
773 (mapconcat 'symbol-name event-seq "")) | |
774 (t (prin1-to-string event-seq))))) | |
775 | |
776 | |
777 (defsubst vip-fast-keysequence-p () | |
778 (not (vip-sit-for-short vip-fast-keyseq-timeout t))) | |
779 | |
780 (defun vip-read-char-exclusive () | |
781 (let (char | |
782 (echo-keystrokes 1)) | |
783 (while (null char) | |
784 (condition-case nil | |
785 (setq char (read-char)) | |
786 (error | |
787 ;; skip event if not char | |
788 (vip-read-event)))) | |
789 char)) | |
790 | |
791 | |
792 | |
793 (defun vip-setup-master-buffer (&rest other-files-or-buffers) | |
794 "Set up the current buffer as a master buffer. | |
795 Arguments become related buffers. This function should normally be used in | |
796 the `Local variables' section of a file." | |
797 (setq vip-related-files-and-buffers-ring | |
798 (make-ring (1+ (length other-files-or-buffers)))) | |
799 (mapcar '(lambda (elt) | |
800 (vip-ring-insert vip-related-files-and-buffers-ring elt)) | |
801 other-files-or-buffers) | |
802 (vip-ring-insert vip-related-files-and-buffers-ring (buffer-name)) | |
803 ) | |
804 | |
805 | |
806 (provide 'viper-util) | |
807 | |
808 ;;; viper-util.el ends here |