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