Mercurial > emacs
annotate lisp/emulation/viper-util.el @ 19203:58c50205001d
new version
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Thu, 07 Aug 1997 04:48:48 +0000 |
parents | dfbef8117c6a |
children | eb1cef5fa337 |
rev | line source |
---|---|
10789 | 1 ;;; viper-util.el --- Utilities used by viper.el |
14169 | 2 |
18047 | 3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. |
11288 | 4 |
10789 | 5 ;; This file is part of GNU Emacs. |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 2, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
14169 | 18 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 ;; Boston, MA 02111-1307, USA. | |
10789 | 21 |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
22 |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
23 ;; Code |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
24 |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
25 ;; Compiler pacifier |
19079 | 26 (defvar viper-overriding-map) |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
27 (defvar pm-color-alist) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
28 (defvar zmacs-region-stays) |
19079 | 29 (defvar viper-minibuffer-current-face) |
30 (defvar viper-minibuffer-insert-face) | |
31 (defvar viper-minibuffer-vi-face) | |
32 (defvar viper-minibuffer-emacs-face) | |
33 (defvar viper-replace-overlay-face) | |
34 (defvar viper-fast-keyseq-timeout) | |
18047 | 35 (defvar ex-unix-type-shell) |
36 (defvar ex-unix-type-shell-options) | |
19079 | 37 (defvar viper-ex-tmp-buf-name) |
18047 | 38 |
39 (require 'cl) | |
40 (require 'ring) | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
41 |
18172 | 42 (if noninteractive |
43 (eval-when-compile | |
44 (let ((load-path (cons (expand-file-name ".") load-path))) | |
45 (or (featurep 'viper-init) | |
46 (load "viper-init.el" nil nil 'nosuffix)) | |
47 ))) | |
18047 | 48 ;; end pacifier |
10789 | 49 |
18047 | 50 (require 'viper-init) |
15747
a0933adcee9e
(vip-ms-style-os-p, vip-vms-os-p): Moved here from viper.el.
Karl Heuer <kwzh@gnu.org>
parents:
15728
diff
changeset
|
51 |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
52 |
19203 | 53 ;; A fix for NeXT Step |
54 ;; Should go away, when NS people fix the design flaw, which leaves the | |
55 ;; two x-* functions undefined. | |
56 (if (and (not (fboundp 'x-display-color-p)) (fboundp 'ns-display-color-p)) | |
57 (fset 'x-display-color-p (symbol-function 'ns-display-color-p))) | |
58 (if (and (not (fboundp 'x-color-defined-p)) (fboundp 'ns-color-defined-p)) | |
59 (fset 'x-color-defined-p (symbol-function 'ns-color-defined-p))) | |
60 | |
10789 | 61 |
18047 | 62 ;;; XEmacs support |
10789 | 63 |
64 | |
19079 | 65 (if viper-xemacs-p |
10789 | 66 (progn |
19079 | 67 (fset 'viper-read-event (symbol-function 'next-command-event)) |
68 (fset 'viper-make-overlay (symbol-function 'make-extent)) | |
69 (fset 'viper-overlay-start (symbol-function 'extent-start-position)) | |
70 (fset 'viper-overlay-end (symbol-function 'extent-end-position)) | |
71 (fset 'viper-overlay-put (symbol-function 'set-extent-property)) | |
72 (fset 'viper-overlay-p (symbol-function 'extentp)) | |
73 (fset 'viper-overlay-get (symbol-function 'extent-property)) | |
74 (fset 'viper-move-overlay (symbol-function 'set-extent-endpoints)) | |
75 (if (viper-window-display-p) | |
76 (fset 'viper-iconify (symbol-function 'iconify-frame))) | |
77 (cond ((viper-has-face-support-p) | |
78 (fset 'viper-get-face (symbol-function 'get-face)) | |
79 (fset 'viper-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
|
80 (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
|
81 ))) |
19079 | 82 (fset 'viper-read-event (symbol-function 'read-event)) |
83 (fset 'viper-make-overlay (symbol-function 'make-overlay)) | |
84 (fset 'viper-overlay-start (symbol-function 'overlay-start)) | |
85 (fset 'viper-overlay-end (symbol-function 'overlay-end)) | |
86 (fset 'viper-overlay-put (symbol-function 'overlay-put)) | |
87 (fset 'viper-overlay-p (symbol-function 'overlayp)) | |
88 (fset 'viper-overlay-get (symbol-function 'overlay-get)) | |
89 (fset 'viper-move-overlay (symbol-function 'move-overlay)) | |
90 (if (viper-window-display-p) | |
91 (fset 'viper-iconify (symbol-function 'iconify-or-deiconify-frame))) | |
92 (cond ((viper-has-face-support-p) | |
93 (fset 'viper-get-face (symbol-function 'internal-get-face)) | |
94 (fset 'viper-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
|
95 ))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
96 |
18047 | 97 |
19079 | 98 (fset 'viper-characterp |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
99 (symbol-function |
19079 | 100 (if viper-xemacs-p 'characterp 'integerp))) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
101 |
19079 | 102 (defsubst viper-color-display-p () |
103 (if viper-emacs-p | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
104 (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
|
105 (eq (device-class (selected-device)) 'color))) |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
106 |
19079 | 107 (defsubst viper-get-cursor-color () |
108 (if viper-emacs-p | |
15578
fadc581e380e
(vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
109 (cdr (assoc 'cursor-color (frame-parameters))) |
fadc581e380e
(vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
110 (color-instance-name (frame-property (selected-frame) 'cursor-color)))) |
fadc581e380e
(vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
111 |
19203 | 112 ;;(defun viper-set-face-pixmap (face pixmap) |
113 ;; "Set face pixmap on a monochrome display." | |
114 ;; (if (and (viper-window-display-p) (not (viper-color-display-p))) | |
115 ;; (condition-case nil | |
116 ;; (set-face-background-pixmap face pixmap) | |
117 ;; (error | |
118 ;; (message "Pixmap not found for %S: %s" (face-name face) pixmap) | |
119 ;; (sit-for 1))))) | |
16136
de1340e6ddb4
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15747
diff
changeset
|
120 |
10789 | 121 |
122 ;; OS/2 | |
19079 | 123 (cond ((eq (viper-device-type) 'pm) |
124 (fset 'viper-color-defined-p | |
10789 | 125 (function (lambda (color) (assoc color pm-color-alist)))))) |
126 | |
127 ;; needed to smooth out the difference between Emacs and XEmacs | |
19203 | 128 ;;(defsubst viper-italicize-face (face) |
129 ;; (if viper-xemacs-p | |
130 ;; (make-face-italic face) | |
131 ;; (make-face-italic face nil 'noerror))) | |
10789 | 132 |
133 ;; test if display is color and the colors are defined | |
19203 | 134 ;;(defsubst viper-can-use-colors (&rest colors) |
135 ;; (if (viper-color-display-p) | |
136 ;; (not (memq nil (mapcar 'viper-color-defined-p colors))) | |
137 ;; )) | |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
138 |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
139 ;; cursor colors |
19079 | 140 (defun viper-change-cursor-color (new-color) |
141 (if (and (viper-window-display-p) (viper-color-display-p) | |
142 (stringp new-color) (viper-color-defined-p new-color) | |
143 (not (string= new-color (viper-get-cursor-color)))) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
144 (modify-frame-parameters |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
145 (selected-frame) (list (cons 'cursor-color new-color))))) |
10789 | 146 |
19079 | 147 (defun viper-save-cursor-color () |
148 (if (and (viper-window-display-p) (viper-color-display-p)) | |
149 (let ((color (viper-get-cursor-color))) | |
150 (if (and (stringp color) (viper-color-defined-p color) | |
151 (not (string= color viper-replace-overlay-cursor-color))) | |
152 (viper-overlay-put viper-replace-overlay 'viper-cursor-color color))))) | |
10789 | 153 |
16766
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16329
diff
changeset
|
154 ;; restore cursor color from replace overlay |
19079 | 155 (defsubst viper-restore-cursor-color-after-replace () |
156 (viper-change-cursor-color | |
157 (viper-overlay-get viper-replace-overlay 'viper-cursor-color))) | |
158 (defsubst viper-restore-cursor-color-after-insert () | |
159 (viper-change-cursor-color viper-saved-cursor-color)) | |
10789 | 160 |
18047 | 161 |
162 | |
10789 | 163 ;; Check the current version against the major and minor version numbers |
164 ;; using op: cur-vers op major.minor If emacs-major-version or | |
165 ;; emacs-minor-version are not defined, we assume that the current version | |
166 ;; is hopelessly outdated. We assume that emacs-major-version and | |
167 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the | |
168 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value | |
169 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be | |
170 ;; incorrect. However, this gives correct result in our cases, since we are | |
171 ;; testing for sufficiently high Emacs versions. | |
19079 | 172 (defun viper-check-version (op major minor &optional type-of-emacs) |
10789 | 173 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version)) |
19079 | 174 (and (cond ((eq type-of-emacs 'xemacs) viper-xemacs-p) |
175 ((eq type-of-emacs 'emacs) viper-emacs-p) | |
10789 | 176 (t t)) |
177 (cond ((eq op '=) (and (= emacs-minor-version minor) | |
178 (= emacs-major-version major))) | |
179 ((memq op '(> >= < <=)) | |
180 (and (or (funcall op emacs-major-version major) | |
181 (= emacs-major-version major)) | |
182 (if (= emacs-major-version major) | |
183 (funcall op emacs-minor-version minor) | |
184 t))) | |
185 (t | |
19079 | 186 (error "%S: Invalid op in viper-check-version" op)))) |
10789 | 187 (cond ((memq op '(= > >=)) nil) |
188 ((memq op '(< <=)) t)))) | |
12693
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
189 |
10789 | 190 |
19079 | 191 (defun viper-get-visible-buffer-window (wind) |
192 (if viper-xemacs-p | |
10789 | 193 (get-buffer-window wind t) |
194 (get-buffer-window wind 'visible))) | |
195 | |
196 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
197 ;; Return line position. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
198 ;; 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
|
199 ;; 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
|
200 ;; 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
|
201 ;; Otherwise, returns point. Current point is not moved in any case." |
19079 | 202 (defun viper-line-pos (pos) |
10789 | 203 (let ((cur-pos (point)) |
204 (result)) | |
205 (cond | |
206 ((equal pos 'start) | |
207 (beginning-of-line)) | |
208 ((equal pos 'end) | |
209 (end-of-line)) | |
210 ((equal pos 'mid) | |
19079 | 211 (goto-char (+ (viper-line-pos 'start) (viper-line-pos 'end) 2))) |
10789 | 212 ((equal pos 'indent) |
213 (back-to-indentation)) | |
214 (t nil)) | |
215 (setq result (point)) | |
216 (goto-char cur-pos) | |
217 result)) | |
218 | |
219 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
220 ;; 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
|
221 ;; 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
|
222 ;; 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
|
223 ;; |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
224 ;; 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
|
225 ;; For this, VAR-NAME should be made buffer-local with nil as a default. |
19079 | 226 ;; Then, each time this var is used in `viper-move-marker-locally' in a new |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
227 ;; buffer, a new marker will be created. |
19079 | 228 (defun viper-move-marker-locally (var pos &optional buffer) |
10789 | 229 (if (markerp (eval var)) |
230 () | |
231 (set var (make-marker))) | |
232 (move-marker (eval var) pos buffer)) | |
233 | |
234 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
235 ;; Print CONDITIONS as a message. |
19079 | 236 (defun viper-message-conditions (conditions) |
10789 | 237 (let ((case (car conditions)) (msg (cdr conditions))) |
238 (if (null msg) | |
239 (message "%s" case) | |
240 (message "%s: %s" case (mapconcat 'prin1-to-string msg " "))) | |
241 (beep 1))) | |
242 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
243 |
10789 | 244 |
245 ;;; List/alist utilities | |
246 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
247 ;; Convert LIST to an alist |
19079 | 248 (defun viper-list-to-alist (lst) |
10789 | 249 (let ((alist)) |
250 (while lst | |
251 (setq alist (cons (list (car lst)) alist)) | |
252 (setq lst (cdr lst))) | |
253 alist)) | |
254 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
255 ;; Convert ALIST to a list. |
19079 | 256 (defun viper-alist-to-list (alst) |
10789 | 257 (let ((lst)) |
258 (while alst | |
259 (setq lst (cons (car (car alst)) lst)) | |
260 (setq alst (cdr alst))) | |
261 lst)) | |
262 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
263 ;; Filter ALIST using REGEXP. Return alist whose elements match the regexp. |
19079 | 264 (defun viper-filter-alist (regexp alst) |
10789 | 265 (interactive "s x") |
266 (let ((outalst) (inalst alst)) | |
267 (while (car inalst) | |
268 (if (string-match regexp (car (car inalst))) | |
269 (setq outalst (cons (car inalst) outalst))) | |
270 (setq inalst (cdr inalst))) | |
271 outalst)) | |
272 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
273 ;; Filter LIST using REGEXP. Return list whose elements match the regexp. |
19079 | 274 (defun viper-filter-list (regexp lst) |
10789 | 275 (interactive "s x") |
276 (let ((outlst) (inlst lst)) | |
277 (while (car inlst) | |
278 (if (string-match regexp (car inlst)) | |
279 (setq outlst (cons (car inlst) outlst))) | |
280 (setq inlst (cdr inlst))) | |
281 outlst)) | |
282 | |
283 | |
284 ;; Append LIS2 to LIS1, both alists, by side-effect and returns LIS1 | |
285 ;; LIS2 is modified by filtering it: deleting its members of the form | |
286 ;; \(car elt\) such that (car elt') is in LIS1. | |
19079 | 287 (defun viper-append-filter-alist (lis1 lis2) |
10789 | 288 (let ((temp lis1) |
289 elt) | |
290 | |
291 ;;filter-append the second list | |
292 (while temp | |
293 ;; delete all occurrences | |
294 (while (setq elt (assoc (car (car temp)) lis2)) | |
295 (setq lis2 (delq elt lis2))) | |
296 (setq temp (cdr temp))) | |
297 | |
298 (nconc lis1 lis2))) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
299 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
300 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
301 ;;; Support for :e and file globbing |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
302 |
19079 | 303 (defun viper-ex-nontrivial-find-file-unix (filespec) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
304 "Glob the file spec and visit all files matching the spec. |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
305 This function is designed to work under Unix. It may also work under VMS. |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
306 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
307 Users who prefer other types of shells should write their own version of this |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
308 function and set the variable `ex-nontrivial-find-file-function' |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
309 appropriately." |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
310 (let ((gshell |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
311 (cond (ex-unix-type-shell shell-file-name) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
312 ((memq system-type '(vax-vms axp-vms)) "*dcl*") ; VAX VMS |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
313 (t "sh"))) ; probably Unix anyway |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
314 (gshell-options |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
315 ;; using cond in anticipation of further additions |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
316 (cond (ex-unix-type-shell-options) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
317 )) |
19079 | 318 (command (cond (viper-ms-style-os-p (format "\"ls -1 -d %s\"" filespec)) |
16136
de1340e6ddb4
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15747
diff
changeset
|
319 (t (format "ls -1 -d %s" filespec)))) |
de1340e6ddb4
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15747
diff
changeset
|
320 file-list status) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
321 (save-excursion |
19079 | 322 (set-buffer (get-buffer-create viper-ex-tmp-buf-name)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
323 (erase-buffer) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
324 (setq status |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
325 (if gshell-options |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
326 (call-process gshell nil t nil |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
327 gshell-options |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
328 "-c" |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
329 command) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
330 (call-process gshell nil t nil |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
331 "-c" |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
332 command))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
333 (goto-char (point-min)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
334 ;; Issue an error, if no match. |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
335 (if (> status 0) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
336 (save-excursion |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
337 (skip-chars-forward " \t\n\j") |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
338 (if (looking-at "ls:") |
19079 | 339 (viper-forward-Word 1)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
340 (error "%s: %s" |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
341 (if (stringp gshell) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
342 gshell |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
343 "shell") |
19079 | 344 (buffer-substring (point) (viper-line-pos 'end))) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
345 )) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
346 (goto-char (point-min)) |
19079 | 347 (setq file-list (viper-get-filenames-from-buffer 'one-per-line))) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
348 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
349 (mapcar 'find-file file-list) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
350 )) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
351 |
19079 | 352 (defun viper-ex-nontrivial-find-file-ms (filespec) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
353 "Glob the file spec and visit all files matching the spec. |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
354 This function is designed to work under MS type systems, such as NT, W95, and |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
355 DOS. It may also work under OS/2. |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
356 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
357 The users of Unix-type shells should be able to use |
19079 | 358 `viper-ex-nontrivial-find-file-unix', making it into the value of the variable |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
359 `ex-nontrivial-find-file-function'. If this doesn't work, the user may have |
19079 | 360 to write a custom function, similar to `viper-ex-nontrivial-find-file-unix'." |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
361 (save-excursion |
19079 | 362 (set-buffer (get-buffer-create viper-ex-tmp-buf-name)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
363 (erase-buffer) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
364 (insert filespec) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
365 (goto-char (point-min)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
366 (mapcar 'find-file |
19079 | 367 (viper-glob-ms-windows-files (viper-get-filenames-from-buffer))) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
368 )) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
369 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
370 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
371 ;; Interpret the stuff in the buffer as a list of file names |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
372 ;; return a list of file names listed in the buffer beginning at point |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
373 ;; If optional arg is supplied, assume each filename is listed on a separate |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
374 ;; line |
19079 | 375 (defun viper-get-filenames-from-buffer (&optional one-per-line) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
376 (let ((skip-chars (if one-per-line "\t\n" " \t\n")) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
377 result fname delim) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
378 (skip-chars-forward skip-chars) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
379 (while (not (eobp)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
380 (if (cond ((looking-at "\"") |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
381 (setq delim ?\") |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
382 (re-search-forward "[^\"]+" nil t)) ; noerror |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
383 ((looking-at "'") |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
384 (setq delim ?') |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
385 (re-search-forward "[^']+" nil t)) ; noerror |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
386 (t |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
387 (re-search-forward |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
388 (concat "[^" skip-chars "]+") nil t))) ;noerror |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
389 (setq fname |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
390 (buffer-substring (match-beginning 0) (match-end 0)))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
391 (if delim |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
392 (forward-char 1)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
393 (skip-chars-forward " \t\n") |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
394 (setq result (cons fname result))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
395 result)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
396 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
397 ;; convert MS-DOS wildcards to regexp |
19079 | 398 (defun viper-wildcard-to-regexp (wcard) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
399 (save-excursion |
19079 | 400 (set-buffer (get-buffer-create viper-ex-tmp-buf-name)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
401 (erase-buffer) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
402 (insert wcard) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
403 (goto-char (point-min)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
404 (while (not (eobp)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
405 (skip-chars-forward "^*?.\\\\") |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
406 (cond ((eq (char-after (point)) ?*) (insert ".")(forward-char 1)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
407 ((eq (char-after (point)) ?.) (insert "\\")(forward-char 1)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
408 ((eq (char-after (point)) ?\\) (insert "\\")(forward-char 1)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
409 ((eq (char-after (point)) ??) (delete-char 1)(insert "."))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
410 ) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
411 (buffer-string) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
412 )) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
413 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
414 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
415 ;; glob windows files |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
416 ;; LIST is expected to be in reverse order |
19079 | 417 (defun viper-glob-ms-windows-files (list) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
418 (let ((tmp list) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
419 (case-fold-search t) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
420 tmp2) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
421 (while tmp |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
422 (setq tmp2 (cons (directory-files |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
423 ;; the directory part |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
424 (or (file-name-directory (car tmp)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
425 "") |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
426 t ; return full names |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
427 ;; the regexp part: globs the file names |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
428 (concat "^" |
19079 | 429 (viper-wildcard-to-regexp |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
430 (file-name-nondirectory (car tmp))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
431 "$")) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
432 tmp2)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
433 (setq tmp (cdr tmp))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
434 (reverse (apply 'append tmp2)))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
435 |
10789 | 436 |
437 ;;; Insertion ring | |
438 | |
439 ;; Rotate RING's index. DIRection can be positive or negative. | |
19079 | 440 (defun viper-ring-rotate1 (ring dir) |
10789 | 441 (if (and (ring-p ring) (> (ring-length ring) 0)) |
442 (progn | |
443 (setcar ring (cond ((> dir 0) | |
444 (ring-plus1 (car ring) (ring-length ring))) | |
445 ((< dir 0) | |
446 (ring-minus1 (car ring) (ring-length ring))) | |
447 ;; don't rotate if dir = 0 | |
448 (t (car ring)))) | |
19079 | 449 (viper-current-ring-item ring) |
10789 | 450 ))) |
451 | |
19079 | 452 (defun viper-special-ring-rotate1 (ring dir) |
453 (if (memq viper-intermediate-command | |
10789 | 454 '(repeating-display-destructive-command |
455 repeating-insertion-from-ring)) | |
19079 | 456 (viper-ring-rotate1 ring dir) |
10789 | 457 ;; don't rotate otherwise |
19079 | 458 (viper-ring-rotate1 ring 0))) |
10789 | 459 |
460 ;; current ring item; if N is given, then so many items back from the | |
461 ;; current | |
19079 | 462 (defun viper-current-ring-item (ring &optional n) |
10789 | 463 (setq n (or n 0)) |
464 (if (and (ring-p ring) (> (ring-length ring) 0)) | |
465 (aref (cdr (cdr ring)) (mod (- (car ring) 1 n) (ring-length ring))))) | |
466 | |
467 ;; push item onto ring. the second argument is a ring-variable, not value. | |
19079 | 468 (defun viper-push-onto-ring (item ring-var) |
10789 | 469 (or (ring-p (eval ring-var)) |
470 (set ring-var (make-ring (eval (intern (format "%S-size" ring-var)))))) | |
471 (or (null item) ; don't push nil | |
472 (and (stringp item) (string= item "")) ; or empty strings | |
19079 | 473 (equal item (viper-current-ring-item (eval ring-var))) ; or old stuff |
474 ;; Since viper-set-destructive-command checks if we are inside | |
475 ;; viper-repeat, we don't check whether this-command-keys is a `.'. The | |
476 ;; cmd viper-repeat makes a call to the current function only if `.' is | |
477 ;; executing a command from the command history. It doesn't call the | |
478 ;; push-onto-ring function if `.' is simply repeating the last | |
479 ;; destructive command. We only check for ESC (which happens when we do | |
480 ;; insert with a prefix argument, or if this-command-keys doesn't give | |
481 ;; anything meaningful (in that case we don't know what to show to the | |
482 ;; user). | |
483 (and (eq ring-var 'viper-command-ring) | |
10789 | 484 (string-match "\\([0-9]*\e\\|^[ \t]*$\\|escape\\)" |
19079 | 485 (viper-array-to-string (this-command-keys)))) |
486 (viper-ring-insert (eval ring-var) item)) | |
10789 | 487 ) |
488 | |
489 | |
490 ;; removing elts from ring seems to break it | |
19079 | 491 (defun viper-cleanup-ring (ring) |
10789 | 492 (or (< (ring-length ring) 2) |
19079 | 493 (null (viper-current-ring-item ring)) |
10789 | 494 ;; last and previous equal |
19079 | 495 (if (equal (viper-current-ring-item ring) |
496 (viper-current-ring-item ring 1)) | |
497 (viper-ring-pop ring)))) | |
10789 | 498 |
499 ;; ring-remove seems to be buggy, so we concocted this for our purposes. | |
19079 | 500 (defun viper-ring-pop (ring) |
10789 | 501 (let* ((ln (ring-length ring)) |
502 (vec (cdr (cdr ring))) | |
503 (veclen (length vec)) | |
504 (hd (car ring)) | |
505 (idx (max 0 (ring-minus1 hd ln))) | |
506 (top-elt (aref vec idx))) | |
507 | |
508 ;; shift elements | |
509 (while (< (1+ idx) veclen) | |
510 (aset vec idx (aref vec (1+ idx))) | |
511 (setq idx (1+ idx))) | |
512 (aset vec idx nil) | |
513 | |
514 (setq hd (max 0 (ring-minus1 hd ln))) | |
515 (if (= hd (1- ln)) (setq hd 0)) | |
516 (setcar ring hd) ; move head | |
517 (setcar (cdr ring) (max 0 (1- ln))) ; adjust length | |
518 top-elt | |
519 )) | |
520 | |
19079 | 521 (defun viper-ring-insert (ring item) |
10789 | 522 (let* ((ln (ring-length ring)) |
523 (vec (cdr (cdr ring))) | |
524 (veclen (length vec)) | |
525 (hd (car ring)) | |
526 (vecpos-after-hd (if (= hd 0) ln hd)) | |
527 (idx ln)) | |
528 | |
529 (if (= ln veclen) | |
530 (progn | |
531 (aset vec hd item) ; hd is always 1+ the actual head index in vec | |
532 (setcar ring (ring-plus1 hd ln))) | |
533 (setcar (cdr ring) (1+ ln)) | |
534 (setcar ring (ring-plus1 vecpos-after-hd (1+ ln))) | |
535 (while (and (>= idx vecpos-after-hd) (> ln 0)) | |
536 (aset vec idx (aref vec (1- idx))) | |
537 (setq idx (1- idx))) | |
538 (aset vec vecpos-after-hd item)) | |
539 item)) | |
540 | |
541 | |
542 ;;; String utilities | |
543 | |
544 ;; If STRING is longer than MAX-LEN, truncate it and print ...... instead | |
545 ;; PRE-STRING is a string to prepend to the abbrev string. | |
546 ;; POST-STRING is a string to append to the abbrev string. | |
547 ;; ABBREV_SIGN is a string to be inserted before POST-STRING | |
548 ;; if the orig string was truncated. | |
19079 | 549 (defun viper-abbreviate-string (string max-len |
10789 | 550 pre-string post-string abbrev-sign) |
551 (let (truncated-str) | |
552 (setq truncated-str | |
553 (if (stringp string) | |
554 (substring string 0 (min max-len (length string))))) | |
555 (cond ((null truncated-str) "") | |
556 ((> (length string) max-len) | |
557 (format "%s%s%s%s" | |
558 pre-string truncated-str abbrev-sign post-string)) | |
559 (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
|
560 |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
561 ;; tells if we are over a whitespace-only line |
19079 | 562 (defsubst viper-over-whitespace-line () |
12204
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
563 (save-excursion |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
564 (beginning-of-line) |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
565 (looking-at "^[ \t]*$"))) |
10789 | 566 |
567 | |
568 ;;; Saving settings in custom file | |
569 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
570 ;; 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
|
571 ;; 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
|
572 ;; 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
|
573 ;; Arguments: var message custom-file &optional erase-message |
19079 | 574 (defun viper-save-setting (var message custom-file &optional erase-msg) |
10789 | 575 (let* ((var-name (symbol-name var)) |
576 (var-val (if (boundp var) (eval var))) | |
577 (regexp (format "^[^;]*%s[ \t\n]*[a-zA-Z---_']*[ \t\n)]" var-name)) | |
578 (buf (find-file-noselect (substitute-in-file-name custom-file))) | |
579 ) | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14336
diff
changeset
|
580 (message message) |
10789 | 581 (save-excursion |
582 (set-buffer buf) | |
583 (goto-char (point-min)) | |
584 (if (re-search-forward regexp nil t) | |
585 (let ((reg-end (1- (match-end 0)))) | |
586 (search-backward var-name) | |
587 (delete-region (match-beginning 0) reg-end) | |
588 (goto-char (match-beginning 0)) | |
589 (insert (format "%s '%S" var-name var-val))) | |
590 (goto-char (point-max)) | |
591 (if (not (bolp)) (insert "\n")) | |
592 (insert (format "(setq %s '%S)\n" var-name var-val))) | |
593 (save-buffer)) | |
594 (kill-buffer buf) | |
595 (if erase-msg | |
596 (progn | |
597 (sit-for 2) | |
598 (message ""))) | |
599 )) | |
600 | |
601 ;; Save STRING in CUSTOM-FILE. If PATTERN is non-nil, remove strings that | |
602 ;; match this pattern. | |
19079 | 603 (defun viper-save-string-in-file (string custom-file &optional pattern) |
10789 | 604 (let ((buf (find-file-noselect (substitute-in-file-name custom-file)))) |
605 (save-excursion | |
606 (set-buffer buf) | |
607 (goto-char (point-min)) | |
608 (if pattern (delete-matching-lines pattern)) | |
609 (goto-char (point-max)) | |
610 (if string (insert string)) | |
611 (save-buffer)) | |
612 (kill-buffer buf) | |
613 )) | |
614 | |
615 | |
616 ;;; Overlays | |
617 | |
618 ;; Search | |
619 | |
19079 | 620 (defun viper-flash-search-pattern () |
621 (if (viper-overlay-p viper-search-overlay) | |
622 (viper-move-overlay | |
623 viper-search-overlay (match-beginning 0) (match-end 0)) | |
624 (setq viper-search-overlay | |
625 (viper-make-overlay | |
10789 | 626 (match-beginning 0) (match-end 0) (current-buffer)))) |
627 | |
19079 | 628 (viper-overlay-put |
629 viper-search-overlay 'priority viper-search-overlay-priority) | |
630 (if (viper-has-face-support-p) | |
10789 | 631 (progn |
19079 | 632 (viper-overlay-put viper-search-overlay 'face viper-search-face) |
10789 | 633 (sit-for 2) |
19079 | 634 (viper-overlay-put viper-search-overlay 'face nil)))) |
10789 | 635 |
16136
de1340e6ddb4
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15747
diff
changeset
|
636 |
10789 | 637 ;; Replace state |
638 | |
19079 | 639 (defsubst viper-move-replace-overlay (beg end) |
640 (viper-move-overlay viper-replace-overlay beg end)) | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
641 |
19079 | 642 (defun viper-set-replace-overlay (beg end) |
643 (if (viper-overlay-p viper-replace-overlay) | |
644 (viper-move-replace-overlay beg end) | |
645 (setq viper-replace-overlay (viper-make-overlay beg end (current-buffer))) | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
646 ;; never detach |
19079 | 647 (viper-overlay-put |
648 viper-replace-overlay (if viper-emacs-p 'evaporate 'detachable) nil) | |
649 (viper-overlay-put | |
650 viper-replace-overlay 'priority viper-replace-overlay-priority) | |
18047 | 651 ;; If Emacs will start supporting overlay maps, as it currently supports |
19079 | 652 ;; text-property maps, we could do away with viper-replace-minor-mode and |
18047 | 653 ;; just have keymap attached to replace overlay. |
19079 | 654 ;;(viper-overlay-put |
655 ;; viper-replace-overlay | |
656 ;; (if viper-xemacs-p 'keymap 'local-map) | |
657 ;; viper-replace-map) | |
18047 | 658 ) |
19079 | 659 (if (viper-has-face-support-p) |
660 (viper-overlay-put | |
661 viper-replace-overlay 'face viper-replace-overlay-face)) | |
662 (viper-save-cursor-color) | |
663 (viper-change-cursor-color viper-replace-overlay-cursor-color) | |
10789 | 664 ) |
665 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
666 |
19079 | 667 (defun viper-set-replace-overlay-glyphs (before-glyph after-glyph) |
668 (if (or (not (viper-has-face-support-p)) | |
669 viper-use-replace-region-delimiters) | |
670 (let ((before-name (if viper-xemacs-p 'begin-glyph 'before-string)) | |
671 (after-name (if viper-xemacs-p 'end-glyph 'after-string))) | |
672 (viper-overlay-put viper-replace-overlay before-name before-glyph) | |
673 (viper-overlay-put viper-replace-overlay after-name after-glyph)))) | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
674 |
19079 | 675 (defun viper-hide-replace-overlay () |
676 (viper-set-replace-overlay-glyphs nil nil) | |
677 (viper-restore-cursor-color-after-replace) | |
678 (viper-restore-cursor-color-after-insert) | |
679 (if (viper-has-face-support-p) | |
680 (viper-overlay-put viper-replace-overlay 'face nil))) | |
10789 | 681 |
682 | |
19079 | 683 (defsubst viper-replace-start () |
684 (viper-overlay-start viper-replace-overlay)) | |
685 (defsubst viper-replace-end () | |
686 (viper-overlay-end viper-replace-overlay)) | |
10789 | 687 |
688 | |
689 ;; Minibuffer | |
690 | |
19079 | 691 (defun viper-set-minibuffer-overlay () |
692 (viper-check-minibuffer-overlay) | |
693 (if (viper-has-face-support-p) | |
10789 | 694 (progn |
19079 | 695 (viper-overlay-put |
696 viper-minibuffer-overlay 'face viper-minibuffer-current-face) | |
697 (viper-overlay-put | |
698 viper-minibuffer-overlay 'priority viper-minibuffer-overlay-priority) | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
699 ;; never detach |
19079 | 700 (viper-overlay-put |
701 viper-minibuffer-overlay | |
702 (if viper-emacs-p 'evaporate 'detachable) | |
703 nil) | |
704 ;; make viper-minibuffer-overlay open-ended | |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
705 ;; In emacs, it is made open ended at creation time |
19079 | 706 (if viper-xemacs-p |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
707 (progn |
19079 | 708 (viper-overlay-put viper-minibuffer-overlay 'start-open nil) |
709 (viper-overlay-put viper-minibuffer-overlay 'end-open nil))) | |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
710 ))) |
10789 | 711 |
19079 | 712 (defun viper-check-minibuffer-overlay () |
713 (or (viper-overlay-p viper-minibuffer-overlay) | |
714 (setq viper-minibuffer-overlay | |
715 (if viper-xemacs-p | |
716 (viper-make-overlay 1 (1+ (buffer-size)) (current-buffer)) | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
717 ;; make overlay open-ended |
19079 | 718 (viper-make-overlay |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
719 1 (1+ (buffer-size)) (current-buffer) nil 'rear-advance))) |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
720 )) |
10789 | 721 |
722 | |
19079 | 723 (defsubst viper-is-in-minibuffer () |
10789 | 724 (string-match "\*Minibuf-" (buffer-name))) |
725 | |
726 | |
727 | |
728 ;;; XEmacs compatibility | |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
729 |
19079 | 730 (defun viper-abbreviate-file-name (file) |
731 (if viper-emacs-p | |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
732 (abbreviate-file-name file) |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
733 ;; XEmacs requires addl argument |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
734 (abbreviate-file-name file t))) |
10789 | 735 |
12899
e0dfd3c3837e
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12693
diff
changeset
|
736 ;; Sit for VAL milliseconds. XEmacs doesn't support the millisecond arg |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
737 ;; in sit-for, so this function smoothes out the differences. |
19079 | 738 (defsubst viper-sit-for-short (val &optional nodisp) |
739 (if viper-xemacs-p | |
10789 | 740 (sit-for (/ val 1000.0) nodisp) |
741 (sit-for 0 val nodisp))) | |
742 | |
743 ;; EVENT may be a single event of a sequence of events | |
19079 | 744 (defsubst viper-ESC-event-p (event) |
10789 | 745 (let ((ESC-keys '(?\e (control \[) escape)) |
19079 | 746 (key (viper-event-key event))) |
10789 | 747 (member key ESC-keys))) |
18047 | 748 |
749 ;; checks if object is a marker, has a buffer, and points to within that buffer | |
19079 | 750 (defun viper-valid-marker (marker) |
18047 | 751 (if (and (markerp marker) (marker-buffer marker)) |
752 (let ((buf (marker-buffer marker)) | |
753 (pos (marker-position marker))) | |
754 (save-excursion | |
755 (set-buffer buf) | |
756 (and (<= pos (point-max)) (<= (point-min) pos)))))) | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
757 |
19079 | 758 (defsubst viper-mark-marker () |
759 (if viper-xemacs-p | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
760 (mark-marker t) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
761 (mark-marker))) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14588
diff
changeset
|
762 |
10789 | 763 ;; like (set-mark-command nil) but doesn't push twice, if (car mark-ring) |
764 ;; is the same as (mark t). | |
19079 | 765 (defsubst viper-set-mark-if-necessary () |
766 (setq mark-ring (delete (viper-mark-marker) mark-ring)) | |
10789 | 767 (set-mark-command nil)) |
768 | |
769 ;; In transient mark mode (zmacs mode), it is annoying when regions become | |
770 ;; highlighted due to Viper's pushing marks. So, we deactivate marks, unless | |
771 ;; the user explicitly wants highlighting, e.g., by hitting '' or `` | |
19079 | 772 (defun viper-deactivate-mark () |
773 (if viper-xemacs-p | |
10789 | 774 (zmacs-deactivate-region) |
775 (deactivate-mark))) | |
776 | |
19079 | 777 (defsubst viper-leave-region-active () |
778 (if viper-xemacs-p | |
12899
e0dfd3c3837e
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12693
diff
changeset
|
779 (setq zmacs-region-stays t))) |
e0dfd3c3837e
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12693
diff
changeset
|
780 |
18047 | 781 ;; Check if arg is a valid character for register |
782 ;; TYPE is a list that can contain `letter', `Letter', and `digit'. | |
783 ;; Letter means lowercase letters, Letter means uppercase letters, and | |
784 ;; digit means digits from 1 to 9. | |
785 ;; If TYPE is nil, then down/uppercase letters and digits are allowed. | |
19079 | 786 (defun viper-valid-register (reg &optional type) |
18047 | 787 (or type (setq type '(letter Letter digit))) |
788 (or (if (memq 'letter type) | |
789 (and (<= ?a reg) (<= reg ?z))) | |
790 (if (memq 'digit type) | |
791 (and (<= ?1 reg) (<= reg ?9))) | |
792 (if (memq 'Letter type) | |
793 (and (<= ?A reg) (<= reg ?Z))) | |
794 )) | |
795 | |
10789 | 796 |
19079 | 797 (defsubst viper-events-to-keys (events) |
798 (cond (viper-xemacs-p (events-to-keys events)) | |
10789 | 799 (t events))) |
800 | |
801 | |
12693
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
802 ;; This is here because Emacs changed the way local hooks work. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
803 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
804 ;;Add to the value of HOOK the function FUNCTION. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
805 ;;FUNCTION is not added if already present. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
806 ;;FUNCTION is added (if necessary) at the beginning of the hook list |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
807 ;;unless the optional argument APPEND is non-nil, in which case |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
808 ;;FUNCTION is added at the end. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
809 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
810 ;;HOOK should be a symbol, and FUNCTION may be any valid function. If |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
811 ;;HOOK is void, it is first set to nil. If HOOK's value is a single |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
812 ;;function, it is changed to a list of functions." |
19079 | 813 (defun viper-add-hook (hook function &optional append) |
12693
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
814 (if (not (boundp hook)) (set hook nil)) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
815 ;; If the hook value is a single function, turn it into a list. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
816 (let ((old (symbol-value hook))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
817 (if (or (not (listp old)) (eq (car old) 'lambda)) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
818 (setq old (list old))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
819 (if (member function old) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
820 nil |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
821 (set hook (if append |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
822 (append old (list function)) ; don't nconc |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
823 (cons function old)))))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
824 |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
825 ;; This is here because of Emacs's changes in the semantics of add/remove-hooks |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
826 ;; and due to the bugs they introduced. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
827 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
828 ;; Remove from the value of HOOK the function FUNCTION. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
829 ;; HOOK should be a symbol, and FUNCTION may be any valid function. If |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
830 ;; FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the |
19079 | 831 ;; list of hooks to run in HOOK, then nothing is done. See `viper-add-hook'." |
832 (defun viper-remove-hook (hook function) | |
12693
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
833 (if (or (not (boundp hook)) ;unbound symbol, or |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
834 (null (symbol-value hook)) ;value is nil, or |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
835 (null function)) ;function is nil, then |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
836 nil ;Do nothing. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
837 (let ((hook-value (symbol-value hook))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
838 (if (consp hook-value) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
839 ;; don't side-effect the list |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
840 (setq hook-value (delete function (copy-sequence hook-value))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
841 (if (equal hook-value function) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
842 (setq hook-value nil))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
843 (set hook hook-value)))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
844 |
10789 | 845 |
18047 | 846 ;; it is suggested that an event must be copied before it is assigned to |
847 ;; last-command-event in XEmacs | |
19079 | 848 (defun viper-copy-event (event) |
849 (if viper-xemacs-p | |
18047 | 850 (copy-event event) |
851 event)) | |
10789 | 852 |
853 ;; like read-event, but in XEmacs also try to convert to char, if possible | |
19079 | 854 (defun viper-read-event-convert-to-char () |
10789 | 855 (let (event) |
19079 | 856 (if viper-emacs-p |
10789 | 857 (read-event) |
858 (setq event (next-command-event)) | |
859 (or (event-to-character event) | |
860 event)) | |
861 )) | |
862 | |
12693
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
863 ;; This function lets function-key-map convert key sequences into logical |
19079 | 864 ;; keys. This does a better job than viper-read-event when it comes to kbd |
15578
fadc581e380e
(vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
865 ;; macros, since it enables certain macros to be shared between X and TTY modes |
fadc581e380e
(vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
866 ;; by correctly mapping key sequences for Left/Right/... (one an ascii |
fadc581e380e
(vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
867 ;; terminal) into logical keys left, right, etc. |
19079 | 868 (defun viper-read-key () |
869 (let ((overriding-local-map viper-overriding-map) | |
15578
fadc581e380e
(vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
870 (inhibit-quit t) |
19203 | 871 help-char key) |
19079 | 872 (use-global-map viper-overriding-map) |
19203 | 873 (unwind-protect |
874 (setq key (elt (read-key-sequence nil) 0)) | |
875 (use-global-map global-map)) | |
15578
fadc581e380e
(vip-read-key): inhibit quit added.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
876 key)) |
12693
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
877 |
10789 | 878 |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
879 ;; Emacs has a bug in eventp, which causes (eventp nil) to return (nil) |
14584
6674e3119d9e
(vip-event-key): ignore consp events.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
880 ;; instead of nil, if '(nil) was previously inadvertently assigned to |
10789 | 881 ;; unread-command-events |
19079 | 882 (defun viper-event-key (event) |
10789 | 883 (or (and event (eventp event)) |
19079 | 884 (error "viper-event-key: Wrong type argument, eventp, %S" event)) |
885 (when (cond (viper-xemacs-p (or (key-press-event-p event) | |
886 (mouse-event-p event))) | |
18047 | 887 (t t)) |
888 (let ((mod (event-modifiers event)) | |
889 basis) | |
890 (setq basis | |
891 (cond | |
19079 | 892 (viper-xemacs-p |
18047 | 893 (cond ((key-press-event-p event) |
894 (event-key event)) | |
895 ((button-event-p event) | |
896 (concat "mouse-" (prin1-to-string (event-button event)))) | |
897 (t | |
19079 | 898 (error "viper-event-key: Unknown event, %S" event)))) |
18047 | 899 (t |
900 ;; Emacs doesn't handle capital letters correctly, since | |
901 ;; \S-a isn't considered the same as A (it behaves as | |
902 ;; plain `a' instead). So we take care of this here | |
19079 | 903 (cond ((and (viper-characterp event) (<= ?A event) (<= event ?Z)) |
18047 | 904 (setq mod nil |
905 event event)) | |
906 ;; Emacs has the oddity whereby characters 128+char | |
907 ;; represent M-char *if* this appears inside a string. | |
908 ;; So, we convert them manually to (meta char). | |
19079 | 909 ((and (viper-characterp event) |
18047 | 910 (< ?\C-? event) (<= event 255)) |
911 (setq mod '(meta) | |
912 event (- event ?\C-? 1))) | |
19079 | 913 ((and (null mod) (eq event 'return)) |
914 (setq event ?\C-m)) | |
915 ((and (null mod) (eq event 'space)) | |
916 (setq event ?\ )) | |
917 ((and (null mod) (eq event 'delete)) | |
918 (setq event ?\C-?)) | |
919 ((and (null mod) (eq event 'backspace)) | |
920 (setq event ?\C-h)) | |
18047 | 921 (t (event-basic-type event))) |
922 ))) | |
19079 | 923 (if (viper-characterp basis) |
18047 | 924 (setq basis |
925 (if (= basis ?\C-?) | |
926 (list 'control '\?) ; taking care of an emacs bug | |
927 (intern (char-to-string basis))))) | |
928 (if mod | |
929 (append mod (list basis)) | |
930 basis)))) | |
10789 | 931 |
19079 | 932 (defun viper-key-to-emacs-key (key) |
10789 | 933 (let (key-name char-p modifiers mod-char-list base-key base-key-name) |
19079 | 934 (cond (viper-xemacs-p key) |
18839 | 935 |
10789 | 936 ((symbolp key) |
937 (setq key-name (symbol-name key)) | |
18839 | 938 (cond ((= (length key-name) 1) ; character event |
939 (string-to-char key-name)) | |
940 ;; Emacs doesn't recognize `return' and `escape' as events on | |
941 ;; dumb terminals, so we translate them into characters | |
19079 | 942 ((and viper-emacs-p (not (viper-window-display-p)) |
18839 | 943 (string= key-name "return")) |
944 ?\C-m) | |
19079 | 945 ((and viper-emacs-p (not (viper-window-display-p)) |
18839 | 946 (string= key-name "escape")) |
947 ?\e) | |
948 ;; pass symbol-event as is | |
949 (t key))) | |
950 | |
10789 | 951 ((listp key) |
952 (setq modifiers (subseq key 0 (1- (length key))) | |
19079 | 953 base-key (viper-seq-last-elt key) |
10789 | 954 base-key-name (symbol-name base-key) |
955 char-p (= (length base-key-name) 1)) | |
956 (setq mod-char-list | |
957 (mapcar | |
958 '(lambda (elt) (upcase (substring (symbol-name elt) 0 1))) | |
959 modifiers)) | |
960 (if char-p | |
961 (setq key-name | |
962 (car (read-from-string | |
963 (concat | |
964 "?\\" | |
965 (mapconcat 'identity mod-char-list "-\\") | |
966 "-" | |
967 base-key-name)))) | |
968 (setq key-name | |
969 (intern | |
970 (concat | |
971 (mapconcat 'identity mod-char-list "-") | |
972 "-" | |
973 base-key-name)))))) | |
974 )) | |
975 | |
976 | |
977 ;; Args can be a sequence of events, a string, or a Viper macro. Will try to | |
978 ;; convert events to keys and, if all keys are regular printable | |
979 ;; characters, will return a string. Otherwise, will return a string | |
980 ;; representing a vector of converted events. If the input was a Viper macro, | |
981 ;; will return a string that represents this macro as a vector. | |
19079 | 982 (defun viper-array-to-string (event-seq) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
983 (let (temp temp2) |
10789 | 984 (cond ((stringp event-seq) event-seq) |
19079 | 985 ((viper-event-vector-p event-seq) |
986 (setq temp (mapcar 'viper-event-key event-seq)) | |
987 (cond ((viper-char-symbol-sequence-p temp) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
988 (mapconcat 'symbol-name temp "")) |
19079 | 989 ((and (viper-char-array-p |
990 (setq temp2 (mapcar 'viper-key-to-character temp)))) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
991 (mapconcat 'char-to-string temp2 "")) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
992 (t (prin1-to-string (vconcat temp))))) |
19079 | 993 ((viper-char-symbol-sequence-p event-seq) |
10789 | 994 (mapconcat 'symbol-name event-seq "")) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
995 ((and (vectorp event-seq) |
19079 | 996 (viper-char-array-p |
997 (setq temp (mapcar 'viper-key-to-character event-seq)))) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
998 (mapconcat 'char-to-string temp "")) |
10789 | 999 (t (prin1-to-string event-seq))))) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1000 |
19079 | 1001 (defun viper-key-press-events-to-chars (events) |
1002 (mapconcat (if viper-emacs-p | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1003 'char-to-string |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1004 (function |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1005 (lambda (elt) (char-to-string (event-to-character elt))))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1006 events |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1007 "")) |
10789 | 1008 |
1009 | |
18839 | 1010 ;; Uses different timeouts for ESC-sequences and others |
19079 | 1011 (defsubst viper-fast-keysequence-p () |
1012 (not (viper-sit-for-short | |
1013 (if (viper-ESC-event-p last-input-event) | |
1014 viper-ESC-keyseq-timeout | |
1015 viper-fast-keyseq-timeout) | |
18839 | 1016 t))) |
10789 | 1017 |
19079 | 1018 (defun viper-read-char-exclusive () |
10789 | 1019 (let (char |
1020 (echo-keystrokes 1)) | |
1021 (while (null char) | |
1022 (condition-case nil | |
1023 (setq char (read-char)) | |
1024 (error | |
1025 ;; skip event if not char | |
19079 | 1026 (viper-read-event)))) |
10789 | 1027 char)) |
1028 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1029 ;; key is supposed to be in viper's representation, e.g., (control l), a |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1030 ;; character, etc. |
19079 | 1031 (defun viper-key-to-character (key) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1032 (cond ((eq key 'space) ?\ ) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1033 ((eq key 'delete) ?\C-?) |
19079 | 1034 ((eq key 'return) ?\C-m) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1035 ((eq key 'backspace) ?\C-h) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1036 ((and (symbolp key) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1037 (= 1 (length (symbol-name key)))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1038 (string-to-char (symbol-name key))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1039 ((and (listp key) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1040 (eq (car key) 'control) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1041 (symbol-name (nth 1 key)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1042 (= 1 (length (symbol-name (nth 1 key))))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1043 (read (format "?\\C-%s" (symbol-name (nth 1 key))))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1044 (t key))) |
10789 | 1045 |
1046 | |
19079 | 1047 (defun viper-setup-master-buffer (&rest other-files-or-buffers) |
10789 | 1048 "Set up the current buffer as a master buffer. |
1049 Arguments become related buffers. This function should normally be used in | |
1050 the `Local variables' section of a file." | |
19079 | 1051 (setq viper-related-files-and-buffers-ring |
10789 | 1052 (make-ring (1+ (length other-files-or-buffers)))) |
1053 (mapcar '(lambda (elt) | |
19079 | 1054 (viper-ring-insert viper-related-files-and-buffers-ring elt)) |
10789 | 1055 other-files-or-buffers) |
19079 | 1056 (viper-ring-insert viper-related-files-and-buffers-ring (buffer-name)) |
10789 | 1057 ) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1058 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1059 ;;; Movement utilities |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1060 |
19079 | 1061 (defcustom viper-syntax-preference 'strict-vi |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1062 "*Syntax type characterizing Viper's alphanumeric symbols. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1063 `emacs' means only word constituents are considered to be alphanumeric. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1064 Word constituents are symbols specified as word constituents by the current |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1065 syntax table. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1066 `extended' means word and symbol constituents. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1067 `reformed-vi' means Vi-ish behavior: word constituents and the symbol `_'. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1068 However, word constituents are determined according to Emacs syntax tables, |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1069 which may be different from Vi in some major modes. |
18839 | 1070 `strict-vi' means Viper words are exactly as in Vi." |
1071 :type '(radio (const strict-vi) (const reformed-vi) | |
1072 (const extended) (const emacs)) | |
1073 :group 'viper) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1074 |
19079 | 1075 (viper-deflocalvar viper-ALPHA-char-class "w" |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1076 "String of syntax classes characterizing Viper's alphanumeric symbols. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1077 In addition, the symbol `_' may be considered alphanumeric if |
19079 | 1078 `viper-syntax-preference'is `reformed-vi'.") |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1079 |
19079 | 1080 (viper-deflocalvar viper-strict-ALPHA-chars "a-zA-Z0-9_" |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1081 "Regexp matching the set of alphanumeric characters acceptable to strict |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1082 Vi.") |
19079 | 1083 (viper-deflocalvar viper-strict-SEP-chars " \t\n" |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1084 "Regexp matching the set of alphanumeric characters acceptable to strict |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1085 Vi.") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1086 |
19079 | 1087 (viper-deflocalvar viper-SEP-char-class " -" |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1088 "String of syntax classes for Vi separators. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1089 Usually contains ` ', linefeed, TAB or formfeed.") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1090 |
19079 | 1091 (defun viper-update-alphanumeric-class () |
1092 "Set the syntax class of Viper alphanumerals according to `viper-syntax-preference'. | |
1093 Must be called in order for changes to `viper-syntax-preference' to take effect." | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1094 (interactive) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1095 (setq-default |
19079 | 1096 viper-ALPHA-char-class |
1097 (cond ((eq viper-syntax-preference 'emacs) "w") ; only word constituents | |
1098 ((eq viper-syntax-preference 'extended) "w_") ; word & symbol chars | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1099 (t "w")))) ; vi syntax: word constituents and the symbol `_' |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1100 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1101 ;; addl-chars are characters to be temporarily considered as alphanumerical |
19079 | 1102 (defun viper-looking-at-alpha (&optional addl-chars) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1103 (or (stringp addl-chars) (setq addl-chars "")) |
19079 | 1104 (if (eq viper-syntax-preference 'reformed-vi) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1105 (setq addl-chars (concat addl-chars "_"))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1106 (let ((char (char-after (point)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1107 (if char |
19079 | 1108 (if (eq viper-syntax-preference 'strict-vi) |
1109 (looking-at (concat "[" viper-strict-ALPHA-chars addl-chars "]")) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1110 (or (memq char |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1111 ;; convert string to list |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1112 (append (vconcat addl-chars) nil)) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1113 (memq (char-syntax char) |
19079 | 1114 (append (vconcat viper-ALPHA-char-class) nil))))) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1115 )) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1116 |
19079 | 1117 (defun viper-looking-at-separator () |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1118 (let ((char (char-after (point)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1119 (if char |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1120 (or (eq char ?\n) ; RET is always a separator in Vi |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1121 (memq (char-syntax char) |
19079 | 1122 (append (vconcat viper-SEP-char-class) nil)))))) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1123 |
19079 | 1124 (defsubst viper-looking-at-alphasep (&optional addl-chars) |
1125 (or (viper-looking-at-separator) (viper-looking-at-alpha addl-chars))) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1126 |
19079 | 1127 (defun viper-skip-alpha-forward (&optional addl-chars) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1128 (or (stringp addl-chars) (setq addl-chars "")) |
19079 | 1129 (viper-skip-syntax |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1130 'forward |
19079 | 1131 (cond ((eq viper-syntax-preference 'strict-vi) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1132 "") |
19079 | 1133 (t viper-ALPHA-char-class )) |
1134 (cond ((eq viper-syntax-preference 'strict-vi) | |
1135 (concat viper-strict-ALPHA-chars addl-chars)) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1136 (t addl-chars)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1137 |
19079 | 1138 (defun viper-skip-alpha-backward (&optional addl-chars) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1139 (or (stringp addl-chars) (setq addl-chars "")) |
19079 | 1140 (viper-skip-syntax |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1141 'backward |
19079 | 1142 (cond ((eq viper-syntax-preference 'strict-vi) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1143 "") |
19079 | 1144 (t viper-ALPHA-char-class )) |
1145 (cond ((eq viper-syntax-preference 'strict-vi) | |
1146 (concat viper-strict-ALPHA-chars addl-chars)) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1147 (t addl-chars)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1148 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1149 ;; weird syntax tables may confuse strict-vi style |
19079 | 1150 (defsubst viper-skip-all-separators-forward (&optional within-line) |
1151 (viper-skip-syntax 'forward | |
1152 viper-SEP-char-class | |
1153 (or within-line "\n") | |
1154 (if within-line (viper-line-pos 'end)))) | |
1155 (defsubst viper-skip-all-separators-backward (&optional within-line) | |
1156 (viper-skip-syntax 'backward | |
1157 viper-SEP-char-class | |
1158 (or within-line "\n") | |
1159 (if within-line (viper-line-pos 'start)))) | |
1160 (defun viper-skip-nonseparators (direction) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1161 (let ((func (intern (format "skip-syntax-%S" direction)))) |
19079 | 1162 (funcall func (concat "^" viper-SEP-char-class) |
1163 (viper-line-pos (if (eq direction 'forward) 'end 'start))))) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1164 |
19079 | 1165 (defun viper-skip-nonalphasep-forward () |
1166 (if (eq viper-syntax-preference 'strict-vi) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1167 (skip-chars-forward |
19079 | 1168 (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars)) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1169 (skip-syntax-forward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1170 (concat |
19079 | 1171 "^" viper-ALPHA-char-class viper-SEP-char-class) (viper-line-pos 'end)))) |
1172 (defun viper-skip-nonalphasep-backward () | |
1173 (if (eq viper-syntax-preference 'strict-vi) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1174 (skip-chars-backward |
19079 | 1175 (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars)) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1176 (skip-syntax-backward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1177 (concat |
19079 | 1178 "^" |
1179 viper-ALPHA-char-class viper-SEP-char-class) | |
1180 (viper-line-pos 'start)))) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1181 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1182 ;; Skip SYNTAX like skip-syntax-* and ADDL-CHARS like skip-chars-* |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1183 ;; Return the number of chars traveled. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1184 ;; Either SYNTAX or ADDL-CHARS can be nil, in which case they are interpreted |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1185 ;; as an empty string. |
19079 | 1186 (defun viper-skip-syntax (direction syntax addl-chars &optional limit) |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1187 (let ((total 0) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1188 (local 1) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1189 (skip-chars-func (intern (format "skip-chars-%S" direction))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1190 (skip-syntax-func (intern (format "skip-syntax-%S" direction)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1191 (or (stringp addl-chars) (setq addl-chars "")) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1192 (or (stringp syntax) (setq syntax "")) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1193 (while (and (not (= local 0)) (not (eobp))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1194 (setq local |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1195 (+ (funcall skip-syntax-func syntax limit) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1196 (funcall skip-chars-func addl-chars limit))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1197 (setq total (+ total local))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1198 total |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1199 )) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1200 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1201 |
10789 | 1202 |
18839 | 1203 (provide 'viper-util) |
10789 | 1204 |
18839 | 1205 |
1206 ;;; Local Variables: | |
19079 | 1207 ;;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun) |
18839 | 1208 ;;; End: |
10789 | 1209 |
1210 ;;; viper-util.el ends here |