Mercurial > emacs
annotate lisp/emulation/viper-util.el @ 14581:4951b11970a1
*** empty log message ***
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Fri, 16 Feb 1996 05:25:08 +0000 |
parents | 854325337547 |
children | 6674e3119d9e |
rev | line source |
---|---|
10789 | 1 ;;; viper-util.el --- Utilities used by viper.el |
14169 | 2 |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
3 ;; Copyright (C) 1994, 1995 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 |
22 (require 'ring) | |
23 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
24 ;; Whether it is XEmacs or not |
12204
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
25 (defconst vip-xemacs-p (string-match "\\(Lucid\\|XEmacs\\)" emacs-version)) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
26 ;; Whether it is Emacs or not |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
27 (defconst vip-emacs-p (not vip-xemacs-p)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
28 ;; Tell whether we are running as a window application or on a TTY |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
29 (defsubst vip-device-type () |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
30 (if vip-emacs-p |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
31 window-system |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
32 (device-type (selected-device)))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
33 ;; in XEmacs: device-type is tty on tty and stream in batch. |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
34 (defun vip-window-display-p () |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
35 (and (vip-device-type) (not (memq (vip-device-type) '(tty stream))))) |
10789 | 36 |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
37 (defvar vip-force-faces nil |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
38 "If t, Viper will think that it is running on a display that supports faces. |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
39 This is provided as a temporary relief for users of face-capable displays |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
40 that Viper doesn't know about.") |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
41 |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
42 (defun vip-has-face-support-p () |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
43 (cond ((vip-window-display-p)) |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
44 (vip-force-faces) |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
45 (vip-emacs-p (memq (vip-device-type) '(pc))) |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
46 (vip-xemacs-p (memq (vip-device-type) '(tty pc))))) |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
47 |
10789 | 48 |
49 ;;; Macros | |
50 | |
51 (defmacro vip-deflocalvar (var default-value &optional documentation) | |
52 (` (progn | |
53 (defvar (, var) (, default-value) | |
54 (, (format "%s\n\(buffer local\)" documentation))) | |
55 (make-variable-buffer-local '(, var)) | |
56 ))) | |
57 | |
58 (defmacro vip-loop (count body) | |
59 "(vip-loop COUNT BODY) Execute BODY COUNT times." | |
60 (list 'let (list (list 'count count)) | |
61 (list 'while '(> count 0) | |
62 body | |
63 '(setq count (1- count)) | |
64 ))) | |
65 | |
66 (defmacro vip-buffer-live-p (buf) | |
67 (` (and (, buf) (get-buffer (, buf)) (buffer-name (get-buffer (, buf)))))) | |
68 | |
69 ;; return buffer-specific macro definition, given a full macro definition | |
70 (defmacro vip-kbd-buf-alist (macro-elt) | |
71 (` (nth 1 (, macro-elt)))) | |
72 ;; get a pair: (curr-buffer . macro-definition) | |
73 (defmacro vip-kbd-buf-pair (macro-elt) | |
74 (` (assoc (buffer-name) (vip-kbd-buf-alist (, macro-elt))))) | |
75 ;; get macro definition for current buffer | |
76 (defmacro vip-kbd-buf-definition (macro-elt) | |
77 (` (cdr (vip-kbd-buf-pair (, macro-elt))))) | |
78 | |
79 ;; return mode-specific macro definitions, given a full macro definition | |
80 (defmacro vip-kbd-mode-alist (macro-elt) | |
81 (` (nth 2 (, macro-elt)))) | |
82 ;; get a pair: (major-mode . macro-definition) | |
83 (defmacro vip-kbd-mode-pair (macro-elt) | |
84 (` (assoc major-mode (vip-kbd-mode-alist (, macro-elt))))) | |
85 ;; get macro definition for the current major mode | |
86 (defmacro vip-kbd-mode-definition (macro-elt) | |
87 (` (cdr (vip-kbd-mode-pair (, macro-elt))))) | |
88 | |
89 ;; return global macro definition, given a full macro definition | |
90 (defmacro vip-kbd-global-pair (macro-elt) | |
91 (` (nth 3 (, macro-elt)))) | |
92 ;; get global macro definition from an elt of macro-alist | |
93 (defmacro vip-kbd-global-definition (macro-elt) | |
94 (` (cdr (vip-kbd-global-pair (, macro-elt))))) | |
95 | |
96 ;; last elt of a sequence | |
97 (defsubst vip-seq-last-elt (seq) | |
98 (elt seq (1- (length seq)))) | |
99 | |
100 ;; Check if arg is a valid character for register | |
101 ;; TYPE is a list that can contain `letter', `Letter', and `digit'. | |
102 ;; Letter means lowercase letters, Letter means uppercase letters, and | |
103 ;; digit means digits from 1 to 9. | |
104 ;; If TYPE is nil, then down/uppercase letters and digits are allowed. | |
105 (defun vip-valid-register (reg &optional type) | |
106 (or type (setq type '(letter Letter digit))) | |
107 (or (if (memq 'letter type) | |
108 (and (<= ?a reg) (<= reg ?z))) | |
109 (if (memq 'digit type) | |
110 (and (<= ?1 reg) (<= reg ?9))) | |
111 (if (memq 'Letter type) | |
112 (and (<= ?A reg) (<= reg ?Z))) | |
113 )) | |
114 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
115 ;; checks if object is a marker, has a buffer, and points to within that buffer |
10789 | 116 (defun vip-valid-marker (marker) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
117 (if (and (markerp marker) (marker-buffer marker)) |
10789 | 118 (let ((buf (marker-buffer marker)) |
119 (pos (marker-position marker))) | |
120 (save-excursion | |
121 (set-buffer buf) | |
122 (and (<= pos (point-max)) (<= (point-min) pos)))))) | |
123 | |
124 | |
125 (defvar vip-minibuffer-overlay-priority 300) | |
126 (defvar vip-replace-overlay-priority 400) | |
127 (defvar vip-search-overlay-priority 500) | |
128 | |
129 | |
130 ;;; XEmacs support | |
131 | |
132 (if vip-xemacs-p | |
133 (progn | |
134 (fset 'vip-read-event (symbol-function 'next-command-event)) | |
135 (fset 'vip-make-overlay (symbol-function 'make-extent)) | |
136 (fset 'vip-overlay-start (symbol-function 'extent-start-position)) | |
137 (fset 'vip-overlay-end (symbol-function 'extent-end-position)) | |
138 (fset 'vip-overlay-put (symbol-function 'set-extent-property)) | |
139 (fset 'vip-overlay-p (symbol-function 'extentp)) | |
140 (fset 'vip-overlay-get (symbol-function 'extent-property)) | |
141 (fset 'vip-move-overlay (symbol-function 'set-extent-endpoints)) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
142 (if (vip-window-display-p) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
143 (fset 'vip-iconify (symbol-function 'iconify-frame))) |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
144 (cond ((vip-has-face-support-p) |
10789 | 145 (fset 'vip-get-face (symbol-function 'get-face)) |
146 (fset 'vip-color-defined-p | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
147 (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
|
148 ))) |
10789 | 149 (fset 'vip-read-event (symbol-function 'read-event)) |
150 (fset 'vip-make-overlay (symbol-function 'make-overlay)) | |
151 (fset 'vip-overlay-start (symbol-function 'overlay-start)) | |
152 (fset 'vip-overlay-end (symbol-function 'overlay-end)) | |
153 (fset 'vip-overlay-put (symbol-function 'overlay-put)) | |
154 (fset 'vip-overlay-p (symbol-function 'overlayp)) | |
155 (fset 'vip-overlay-get (symbol-function 'overlay-get)) | |
156 (fset 'vip-move-overlay (symbol-function 'move-overlay)) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
157 (if (vip-window-display-p) |
10789 | 158 (fset 'vip-iconify (symbol-function 'iconify-or-deiconify-frame))) |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
159 (cond ((vip-has-face-support-p) |
10789 | 160 (fset 'vip-get-face (symbol-function 'internal-get-face)) |
161 (fset 'vip-color-defined-p (symbol-function 'x-color-defined-p)) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
162 ))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
163 |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
164 (defsubst vip-color-display-p () |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
165 (if vip-emacs-p |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
166 (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
|
167 (eq (device-class (selected-device)) 'color))) |
10789 | 168 |
169 ;; OS/2 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
170 (cond ((eq (vip-device-type) 'pm) |
10789 | 171 (fset 'vip-color-defined-p |
172 (function (lambda (color) (assoc color pm-color-alist)))))) | |
173 | |
174 ;; needed to smooth out the difference between Emacs and XEmacs | |
175 (defsubst vip-italicize-face (face) | |
176 (if vip-xemacs-p | |
177 (make-face-italic face) | |
178 (make-face-italic face nil 'noerror))) | |
179 | |
180 ;; test if display is color and the colors are defined | |
181 (defsubst vip-can-use-colors (&rest colors) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
182 (if (vip-color-display-p) |
10789 | 183 (not (memq nil (mapcar 'vip-color-defined-p colors))) |
184 )) | |
185 | |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
186 (defun vip-hide-face (face) |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
187 (if (and (vip-has-face-support-p) vip-emacs-p) |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
188 (add-to-list 'facemenu-unlisted-faces face))) |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
189 |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
190 ;; cursor colors |
10789 | 191 (defun vip-change-cursor-color (new-color) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
192 (if (and (vip-window-display-p) (vip-color-display-p) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
193 (stringp new-color) (vip-color-defined-p new-color) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
194 (not (string= new-color (vip-get-cursor-color)))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
195 (modify-frame-parameters |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
196 (selected-frame) (list (cons 'cursor-color new-color))))) |
10789 | 197 |
198 (defsubst vip-save-cursor-color () | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
199 (if (and (vip-window-display-p) (vip-color-display-p)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
200 (let ((color (vip-get-cursor-color))) |
10789 | 201 (if (and (stringp color) (vip-color-defined-p color) |
202 (not (string= color vip-replace-overlay-cursor-color))) | |
203 (vip-overlay-put vip-replace-overlay 'vip-cursor-color color))))) | |
204 | |
205 (defsubst vip-restore-cursor-color () | |
206 (vip-change-cursor-color | |
207 (vip-overlay-get vip-replace-overlay 'vip-cursor-color))) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
208 |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
209 (defsubst vip-get-cursor-color () |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
210 (cdr (assoc 'cursor-color (frame-parameters)))) |
10789 | 211 |
212 | |
213 ;; Check the current version against the major and minor version numbers | |
214 ;; using op: cur-vers op major.minor If emacs-major-version or | |
215 ;; emacs-minor-version are not defined, we assume that the current version | |
216 ;; is hopelessly outdated. We assume that emacs-major-version and | |
217 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the | |
218 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value | |
219 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be | |
220 ;; incorrect. However, this gives correct result in our cases, since we are | |
221 ;; testing for sufficiently high Emacs versions. | |
222 (defun vip-check-version (op major minor &optional type-of-emacs) | |
223 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version)) | |
224 (and (cond ((eq type-of-emacs 'xemacs) vip-xemacs-p) | |
225 ((eq type-of-emacs 'emacs) vip-emacs-p) | |
226 (t t)) | |
227 (cond ((eq op '=) (and (= emacs-minor-version minor) | |
228 (= emacs-major-version major))) | |
229 ((memq op '(> >= < <=)) | |
230 (and (or (funcall op emacs-major-version major) | |
231 (= emacs-major-version major)) | |
232 (if (= emacs-major-version major) | |
233 (funcall op emacs-minor-version minor) | |
234 t))) | |
235 (t | |
236 (error "%S: Invalid op in vip-check-version" op)))) | |
237 (cond ((memq op '(= > >=)) nil) | |
238 ((memq op '(< <=)) t)))) | |
12693
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
239 |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
240 ;;;; warn if it is a wrong version of emacs |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
241 ;;(if (or (vip-check-version '< 19 29 'emacs) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
242 ;; (vip-check-version '< 19 12 'xemacs)) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
243 ;; (progn |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
244 ;; (with-output-to-temp-buffer " *vip-info*" |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
245 ;; (switch-to-buffer " *vip-info*") |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
246 ;; (insert |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
247 ;; (format " |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
248 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
249 ;;This version of Viper requires |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
250 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
251 ;;\t Emacs 19.29 and higher |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
252 ;;\t OR |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
253 ;;\t XEmacs 19.12 and higher |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
254 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
255 ;;It is unlikely to work under Emacs version %s |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
256 ;;that you are using... " emacs-version)) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
257 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
258 ;; (if noninteractive |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
259 ;; () |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
260 ;; (beep 1) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
261 ;; (beep 1) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
262 ;; (insert "\n\nType any key to continue... ") |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
263 ;; (vip-read-event))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
264 ;; (kill-buffer " *vip-info*"))) |
10789 | 265 |
266 | |
267 (defun vip-get-visible-buffer-window (wind) | |
268 (if vip-xemacs-p | |
269 (get-buffer-window wind t) | |
270 (get-buffer-window wind 'visible))) | |
271 | |
272 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
273 ;; Return line position. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
274 ;; If pos is 'start then returns position of line start. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
275 ;; If pos is 'end, returns line end. If pos is 'mid, returns line center. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
276 ;; Pos = 'indent returns beginning of indentation. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
277 ;; Otherwise, returns point. Current point is not moved in any case." |
10789 | 278 (defun vip-line-pos (pos) |
279 (let ((cur-pos (point)) | |
280 (result)) | |
281 (cond | |
282 ((equal pos 'start) | |
283 (beginning-of-line)) | |
284 ((equal pos 'end) | |
285 (end-of-line)) | |
286 ((equal pos 'mid) | |
287 (goto-char (+ (vip-line-pos 'start) (vip-line-pos 'end) 2))) | |
288 ((equal pos 'indent) | |
289 (back-to-indentation)) | |
290 (t nil)) | |
291 (setq result (point)) | |
292 (goto-char cur-pos) | |
293 result)) | |
294 | |
295 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
296 ;; 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
|
297 ;; 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
|
298 ;; 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
|
299 ;; |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
300 ;; 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
|
301 ;; For this, VAR-NAME should be made buffer-local with nil as a default. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
302 ;; Then, each time this var is used in `vip-move-marker-locally' in a new |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
303 ;; buffer, a new marker will be created. |
10789 | 304 (defun vip-move-marker-locally (var pos &optional buffer) |
305 (if (markerp (eval var)) | |
306 () | |
307 (set var (make-marker))) | |
308 (move-marker (eval var) pos buffer)) | |
309 | |
310 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
311 ;; Print CONDITIONS as a message. |
10789 | 312 (defun vip-message-conditions (conditions) |
313 (let ((case (car conditions)) (msg (cdr conditions))) | |
314 (if (null msg) | |
315 (message "%s" case) | |
316 (message "%s: %s" case (mapconcat 'prin1-to-string msg " "))) | |
317 (beep 1))) | |
318 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
319 |
10789 | 320 |
321 ;;; List/alist utilities | |
322 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
323 ;; Convert LIST to an alist |
10789 | 324 (defun vip-list-to-alist (lst) |
325 (let ((alist)) | |
326 (while lst | |
327 (setq alist (cons (list (car lst)) alist)) | |
328 (setq lst (cdr lst))) | |
329 alist)) | |
330 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
331 ;; Convert ALIST to a list. |
10789 | 332 (defun vip-alist-to-list (alst) |
333 (let ((lst)) | |
334 (while alst | |
335 (setq lst (cons (car (car alst)) lst)) | |
336 (setq alst (cdr alst))) | |
337 lst)) | |
338 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
339 ;; Filter ALIST using REGEXP. Return alist whose elements match the regexp. |
10789 | 340 (defun vip-filter-alist (regexp alst) |
341 (interactive "s x") | |
342 (let ((outalst) (inalst alst)) | |
343 (while (car inalst) | |
344 (if (string-match regexp (car (car inalst))) | |
345 (setq outalst (cons (car inalst) outalst))) | |
346 (setq inalst (cdr inalst))) | |
347 outalst)) | |
348 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
349 ;; Filter LIST using REGEXP. Return list whose elements match the regexp. |
10789 | 350 (defun vip-filter-list (regexp lst) |
351 (interactive "s x") | |
352 (let ((outlst) (inlst lst)) | |
353 (while (car inlst) | |
354 (if (string-match regexp (car inlst)) | |
355 (setq outlst (cons (car inlst) outlst))) | |
356 (setq inlst (cdr inlst))) | |
357 outlst)) | |
358 | |
359 | |
360 ;; Append LIS2 to LIS1, both alists, by side-effect and returns LIS1 | |
361 ;; LIS2 is modified by filtering it: deleting its members of the form | |
362 ;; \(car elt\) such that (car elt') is in LIS1. | |
363 (defun vip-append-filter-alist (lis1 lis2) | |
364 (let ((temp lis1) | |
365 elt) | |
366 | |
367 ;;filter-append the second list | |
368 (while temp | |
369 ;; delete all occurrences | |
370 (while (setq elt (assoc (car (car temp)) lis2)) | |
371 (setq lis2 (delq elt lis2))) | |
372 (setq temp (cdr temp))) | |
373 | |
374 (nconc lis1 lis2))) | |
375 | |
376 | |
377 | |
378 | |
379 ;;; Insertion ring | |
380 | |
381 ;; Rotate RING's index. DIRection can be positive or negative. | |
382 (defun vip-ring-rotate1 (ring dir) | |
383 (if (and (ring-p ring) (> (ring-length ring) 0)) | |
384 (progn | |
385 (setcar ring (cond ((> dir 0) | |
386 (ring-plus1 (car ring) (ring-length ring))) | |
387 ((< dir 0) | |
388 (ring-minus1 (car ring) (ring-length ring))) | |
389 ;; don't rotate if dir = 0 | |
390 (t (car ring)))) | |
391 (vip-current-ring-item ring) | |
392 ))) | |
393 | |
394 (defun vip-special-ring-rotate1 (ring dir) | |
395 (if (memq vip-intermediate-command | |
396 '(repeating-display-destructive-command | |
397 repeating-insertion-from-ring)) | |
398 (vip-ring-rotate1 ring dir) | |
399 ;; don't rotate otherwise | |
400 (vip-ring-rotate1 ring 0))) | |
401 | |
402 ;; current ring item; if N is given, then so many items back from the | |
403 ;; current | |
404 (defun vip-current-ring-item (ring &optional n) | |
405 (setq n (or n 0)) | |
406 (if (and (ring-p ring) (> (ring-length ring) 0)) | |
407 (aref (cdr (cdr ring)) (mod (- (car ring) 1 n) (ring-length ring))))) | |
408 | |
409 ;; push item onto ring. the second argument is a ring-variable, not value. | |
410 (defun vip-push-onto-ring (item ring-var) | |
411 (or (ring-p (eval ring-var)) | |
412 (set ring-var (make-ring (eval (intern (format "%S-size" ring-var)))))) | |
413 (or (null item) ; don't push nil | |
414 (and (stringp item) (string= item "")) ; or empty strings | |
415 (equal item (vip-current-ring-item (eval ring-var))) ; or old stuff | |
416 ;; Since vip-set-destructive-command checks if we are inside vip-repeat, | |
417 ;; we don't check whether this-command-keys is a `.'. | |
418 ;; The cmd vip-repeat makes a call to the current function only if | |
419 ;; `.' is executing a command from the command history. It doesn't | |
420 ;; call the push-onto-ring function if `.' is simply repeating the | |
421 ;; last destructive command. | |
422 ;; We only check for ESC (which happens when we do insert with a | |
423 ;; prefix argument, or if this-command-keys doesn't give anything | |
424 ;; meaningful (in that case we don't know what to show to the user). | |
425 (and (eq ring-var 'vip-command-ring) | |
426 (string-match "\\([0-9]*\e\\|^[ \t]*$\\|escape\\)" | |
427 (vip-array-to-string (this-command-keys)))) | |
428 (vip-ring-insert (eval ring-var) item)) | |
429 ) | |
430 | |
431 | |
432 ;; removing elts from ring seems to break it | |
433 (defun vip-cleanup-ring (ring) | |
434 (or (< (ring-length ring) 2) | |
435 (null (vip-current-ring-item ring)) | |
436 ;; last and previous equal | |
437 (if (equal (vip-current-ring-item ring) (vip-current-ring-item ring 1)) | |
438 (vip-ring-pop ring)))) | |
439 | |
440 ;; ring-remove seems to be buggy, so we concocted this for our purposes. | |
441 (defun vip-ring-pop (ring) | |
442 (let* ((ln (ring-length ring)) | |
443 (vec (cdr (cdr ring))) | |
444 (veclen (length vec)) | |
445 (hd (car ring)) | |
446 (idx (max 0 (ring-minus1 hd ln))) | |
447 (top-elt (aref vec idx))) | |
448 | |
449 ;; shift elements | |
450 (while (< (1+ idx) veclen) | |
451 (aset vec idx (aref vec (1+ idx))) | |
452 (setq idx (1+ idx))) | |
453 (aset vec idx nil) | |
454 | |
455 (setq hd (max 0 (ring-minus1 hd ln))) | |
456 (if (= hd (1- ln)) (setq hd 0)) | |
457 (setcar ring hd) ; move head | |
458 (setcar (cdr ring) (max 0 (1- ln))) ; adjust length | |
459 top-elt | |
460 )) | |
461 | |
462 (defun vip-ring-insert (ring item) | |
463 (let* ((ln (ring-length ring)) | |
464 (vec (cdr (cdr ring))) | |
465 (veclen (length vec)) | |
466 (hd (car ring)) | |
467 (vecpos-after-hd (if (= hd 0) ln hd)) | |
468 (idx ln)) | |
469 | |
470 (if (= ln veclen) | |
471 (progn | |
472 (aset vec hd item) ; hd is always 1+ the actual head index in vec | |
473 (setcar ring (ring-plus1 hd ln))) | |
474 (setcar (cdr ring) (1+ ln)) | |
475 (setcar ring (ring-plus1 vecpos-after-hd (1+ ln))) | |
476 (while (and (>= idx vecpos-after-hd) (> ln 0)) | |
477 (aset vec idx (aref vec (1- idx))) | |
478 (setq idx (1- idx))) | |
479 (aset vec vecpos-after-hd item)) | |
480 item)) | |
481 | |
482 | |
483 ;;; String utilities | |
484 | |
485 ;; If STRING is longer than MAX-LEN, truncate it and print ...... instead | |
486 ;; PRE-STRING is a string to prepend to the abbrev string. | |
487 ;; POST-STRING is a string to append to the abbrev string. | |
488 ;; ABBREV_SIGN is a string to be inserted before POST-STRING | |
489 ;; if the orig string was truncated. | |
490 (defun vip-abbreviate-string (string max-len | |
491 pre-string post-string abbrev-sign) | |
492 (let (truncated-str) | |
493 (setq truncated-str | |
494 (if (stringp string) | |
495 (substring string 0 (min max-len (length string))))) | |
496 (cond ((null truncated-str) "") | |
497 ((> (length string) max-len) | |
498 (format "%s%s%s%s" | |
499 pre-string truncated-str abbrev-sign post-string)) | |
500 (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
|
501 |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
502 ;; tells if we are over a whitespace-only line |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
503 (defsubst vip-over-whitespace-line () |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
504 (save-excursion |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
505 (beginning-of-line) |
a7bd91d4af97
(vip-over-whitespace-line): new function.
Karl Heuer <kwzh@gnu.org>
parents:
12139
diff
changeset
|
506 (looking-at "^[ \t]*$"))) |
10789 | 507 |
508 | |
509 ;;; Saving settings in custom file | |
510 | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
511 ;; 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
|
512 ;; 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
|
513 ;; 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
|
514 ;; Arguments: var message custom-file &optional erase-message |
10789 | 515 (defun vip-save-setting (var message custom-file &optional erase-msg) |
516 (let* ((var-name (symbol-name var)) | |
517 (var-val (if (boundp var) (eval var))) | |
518 (regexp (format "^[^;]*%s[ \t\n]*[a-zA-Z---_']*[ \t\n)]" var-name)) | |
519 (buf (find-file-noselect (substitute-in-file-name custom-file))) | |
520 ) | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14336
diff
changeset
|
521 (message message) |
10789 | 522 (save-excursion |
523 (set-buffer buf) | |
524 (goto-char (point-min)) | |
525 (if (re-search-forward regexp nil t) | |
526 (let ((reg-end (1- (match-end 0)))) | |
527 (search-backward var-name) | |
528 (delete-region (match-beginning 0) reg-end) | |
529 (goto-char (match-beginning 0)) | |
530 (insert (format "%s '%S" var-name var-val))) | |
531 (goto-char (point-max)) | |
532 (if (not (bolp)) (insert "\n")) | |
533 (insert (format "(setq %s '%S)\n" var-name var-val))) | |
534 (save-buffer)) | |
535 (kill-buffer buf) | |
536 (if erase-msg | |
537 (progn | |
538 (sit-for 2) | |
539 (message ""))) | |
540 )) | |
541 | |
542 ;; Save STRING in CUSTOM-FILE. If PATTERN is non-nil, remove strings that | |
543 ;; match this pattern. | |
544 (defun vip-save-string-in-file (string custom-file &optional pattern) | |
545 (let ((buf (find-file-noselect (substitute-in-file-name custom-file)))) | |
546 (save-excursion | |
547 (set-buffer buf) | |
548 (goto-char (point-min)) | |
549 (if pattern (delete-matching-lines pattern)) | |
550 (goto-char (point-max)) | |
551 (if string (insert string)) | |
552 (save-buffer)) | |
553 (kill-buffer buf) | |
554 )) | |
555 | |
556 | |
557 ;;; Overlays | |
558 | |
559 ;; Search | |
560 | |
561 (defun vip-flash-search-pattern () | |
562 (if (vip-overlay-p vip-search-overlay) | |
563 (vip-move-overlay vip-search-overlay (match-beginning 0) (match-end 0)) | |
564 (setq vip-search-overlay | |
565 (vip-make-overlay | |
566 (match-beginning 0) (match-end 0) (current-buffer)))) | |
567 | |
568 (vip-overlay-put vip-search-overlay 'priority vip-search-overlay-priority) | |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
569 (if (vip-has-face-support-p) |
10789 | 570 (progn |
571 (vip-overlay-put vip-search-overlay 'face vip-search-face) | |
572 (sit-for 2) | |
573 (vip-overlay-put vip-search-overlay 'face nil)))) | |
574 | |
575 ;; Replace state | |
576 | |
577 (defun vip-set-replace-overlay (beg end) | |
578 (if (vip-overlay-p vip-replace-overlay) | |
579 (vip-move-replace-overlay beg end) | |
580 (setq vip-replace-overlay (vip-make-overlay beg end (current-buffer))) | |
581 (vip-overlay-put | |
582 vip-replace-overlay 'priority vip-replace-overlay-priority)) | |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
583 (if (vip-has-face-support-p) |
10789 | 584 (vip-overlay-put vip-replace-overlay 'face vip-replace-overlay-face)) |
585 (vip-save-cursor-color) | |
586 (vip-change-cursor-color vip-replace-overlay-cursor-color) | |
587 ) | |
588 | |
589 | |
590 (defsubst vip-hide-replace-overlay () | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
591 (vip-set-replace-overlay-glyphs nil nil) |
10789 | 592 (vip-restore-cursor-color) |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
593 (if (vip-has-face-support-p) |
10789 | 594 (vip-overlay-put vip-replace-overlay 'face nil))) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
595 |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
596 (defsubst vip-set-replace-overlay-glyphs (before-glyph after-glyph) |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
597 (if (or (not (vip-has-face-support-p)) |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
598 vip-use-replace-region-delimiters) |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
599 (let ((before-name (if vip-xemacs-p 'begin-glyph 'before-string)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
600 (after-name (if vip-xemacs-p 'end-glyph 'after-string))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
601 (vip-overlay-put vip-replace-overlay before-name before-glyph) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
602 (vip-overlay-put vip-replace-overlay after-name after-glyph)))) |
10789 | 603 |
604 | |
605 (defsubst vip-replace-start () | |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
606 (vip-overlay-start vip-replace-overlay)) |
10789 | 607 (defsubst vip-replace-end () |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
608 (vip-overlay-end vip-replace-overlay)) |
10789 | 609 |
610 (defsubst vip-move-replace-overlay (beg end) | |
611 (vip-move-overlay vip-replace-overlay beg end) | |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
612 ) |
10789 | 613 |
614 | |
615 ;; Minibuffer | |
616 | |
617 (defun vip-set-minibuffer-overlay () | |
618 (vip-check-minibuffer-overlay) | |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
619 (if (vip-has-face-support-p) |
10789 | 620 (progn |
621 (vip-overlay-put | |
622 vip-minibuffer-overlay 'face vip-minibuffer-current-face) | |
623 (vip-overlay-put | |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
624 vip-minibuffer-overlay 'priority vip-minibuffer-overlay-priority) |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
625 ;; prevent detachment and make vip-minibuffer-overlay open-ended |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
626 ;; In emacs, it is made open ended at creation time |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
627 (if vip-emacs-p |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
628 (vip-overlay-put vip-minibuffer-overlay 'evaporate nil) |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
629 (vip-overlay-put vip-minibuffer-overlay 'detachable nil) |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
630 (vip-overlay-put vip-minibuffer-overlay 'start-open nil) |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
631 (vip-overlay-put vip-minibuffer-overlay 'end-open nil)) |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
632 ))) |
10789 | 633 |
634 (defun vip-check-minibuffer-overlay () | |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
635 (or (vip-overlay-p vip-minibuffer-overlay) |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
636 (setq vip-minibuffer-overlay |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
637 (if vip-xemacs-p |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
638 (vip-make-overlay 1 (1+ (buffer-size)) (current-buffer)) |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
639 ;; don't move front, move rear |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
640 (vip-make-overlay 1 (1+ (buffer-size)) (current-buffer) nil t))) |
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
641 )) |
10789 | 642 |
643 | |
644 (defsubst vip-is-in-minibuffer () | |
645 (string-match "\*Minibuf-" (buffer-name))) | |
646 | |
647 | |
648 | |
649 ;;; XEmacs compatibility | |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
650 |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
651 (defun vip-abbreviate-file-name (file) |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
652 (if vip-emacs-p |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
653 (abbreviate-file-name file) |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
654 ;; XEmacs requires addl argument |
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14384
diff
changeset
|
655 (abbreviate-file-name file t))) |
10789 | 656 |
12899
e0dfd3c3837e
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12693
diff
changeset
|
657 ;; 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
|
658 ;; in sit-for, so this function smoothes out the differences. |
10789 | 659 (defsubst vip-sit-for-short (val &optional nodisp) |
660 (if vip-xemacs-p | |
661 (sit-for (/ val 1000.0) nodisp) | |
662 (sit-for 0 val nodisp))) | |
663 | |
664 ;; EVENT may be a single event of a sequence of events | |
665 (defsubst vip-ESC-event-p (event) | |
666 (let ((ESC-keys '(?\e (control \[) escape)) | |
667 (key (vip-event-key event))) | |
668 (member key ESC-keys))) | |
669 | |
670 ;; like (set-mark-command nil) but doesn't push twice, if (car mark-ring) | |
671 ;; is the same as (mark t). | |
672 (defsubst vip-set-mark-if-necessary () | |
673 (setq mark-ring (delete (vip-mark-marker) mark-ring)) | |
674 (set-mark-command nil)) | |
675 | |
676 (defsubst vip-mark-marker () | |
677 (if vip-xemacs-p | |
678 (mark-marker t) | |
679 (mark-marker))) | |
680 | |
681 ;; In transient mark mode (zmacs mode), it is annoying when regions become | |
682 ;; highlighted due to Viper's pushing marks. So, we deactivate marks, unless | |
683 ;; the user explicitly wants highlighting, e.g., by hitting '' or `` | |
684 (defun vip-deactivate-mark () | |
685 (if vip-xemacs-p | |
686 (zmacs-deactivate-region) | |
687 (deactivate-mark))) | |
688 | |
12899
e0dfd3c3837e
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12693
diff
changeset
|
689 (defsubst vip-leave-region-active () |
e0dfd3c3837e
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12693
diff
changeset
|
690 (if vip-xemacs-p |
e0dfd3c3837e
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12693
diff
changeset
|
691 (setq zmacs-region-stays t))) |
e0dfd3c3837e
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12693
diff
changeset
|
692 |
10789 | 693 |
694 (defsubst vip-events-to-keys (events) | |
695 (cond (vip-xemacs-p (events-to-keys events)) | |
696 (t events))) | |
697 | |
698 | |
699 (defun vip-eval-after-load (file form) | |
700 (if vip-emacs-p | |
701 (eval-after-load file form) | |
702 (or (assoc file after-load-alist) | |
703 (setq after-load-alist (cons (list file) after-load-alist))) | |
704 (let ((elt (assoc file after-load-alist))) | |
705 (or (member form (cdr elt)) | |
706 (setq elt (nconc elt (list form))))) | |
707 form | |
708 )) | |
12693
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
709 |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
710 ;; This is here because Emacs changed the way local hooks work. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
711 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
712 ;;Add to the value of HOOK the function FUNCTION. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
713 ;;FUNCTION is not added if already present. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
714 ;;FUNCTION is added (if necessary) at the beginning of the hook list |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
715 ;;unless the optional argument APPEND is non-nil, in which case |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
716 ;;FUNCTION is added at the end. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
717 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
718 ;;HOOK should be a symbol, and FUNCTION may be any valid function. If |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
719 ;;HOOK is void, it is first set to nil. If HOOK's value is a single |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
720 ;;function, it is changed to a list of functions." |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
721 (defun vip-add-hook (hook function &optional append) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
722 (if (not (boundp hook)) (set hook nil)) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
723 ;; If the hook value is a single function, turn it into a list. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
724 (let ((old (symbol-value hook))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
725 (if (or (not (listp old)) (eq (car old) 'lambda)) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
726 (setq old (list old))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
727 (if (member function old) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
728 nil |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
729 (set hook (if append |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
730 (append old (list function)) ; don't nconc |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
731 (cons function old)))))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
732 |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
733 ;; This is here because of Emacs's changes in the semantics of add/remove-hooks |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
734 ;; and due to the bugs they introduced. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
735 ;; |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
736 ;; Remove from the value of HOOK the function FUNCTION. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
737 ;; HOOK should be a symbol, and FUNCTION may be any valid function. If |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
738 ;; FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
739 ;; list of hooks to run in HOOK, then nothing is done. See `vip-add-hook'." |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
740 (defun vip-remove-hook (hook function) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
741 (if (or (not (boundp hook)) ;unbound symbol, or |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
742 (null (symbol-value hook)) ;value is nil, or |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
743 (null function)) ;function is nil, then |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
744 nil ;Do nothing. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
745 (let ((hook-value (symbol-value hook))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
746 (if (consp hook-value) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
747 ;; don't side-effect the list |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
748 (setq hook-value (delete function (copy-sequence hook-value))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
749 (if (equal hook-value function) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
750 (setq hook-value nil))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
751 (set hook hook-value)))) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
752 |
10789 | 753 |
754 | |
755 ;; like read-event, but in XEmacs also try to convert to char, if possible | |
756 (defun vip-read-event-convert-to-char () | |
757 (let (event) | |
758 (if vip-emacs-p | |
759 (read-event) | |
760 (setq event (next-command-event)) | |
761 (or (event-to-character event) | |
762 event)) | |
763 )) | |
764 | |
12693
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
765 ;; This function lets function-key-map convert key sequences into logical |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
766 ;; keys. This does a better job than vip-read-event when it comes to kbd |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
767 ;; macros, since it enables certain macros to be shared between X and TTY |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
768 ;; modes. |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
769 (defun vip-read-key () |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
770 (let ((overriding-local-map vip-overriding-map) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
771 key) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
772 (use-global-map vip-overriding-map) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
773 (setq key (elt (read-key-sequence nil) 0)) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
774 (use-global-map global-map) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
775 key)) |
321b2ad48a9c
(vip-add-hook,vip-remove-hook): new functions.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12212
diff
changeset
|
776 |
10789 | 777 |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
778 ;; Emacs has a bug in eventp, which causes (eventp nil) to return (nil) |
14233
396316e5fbe6
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
779 ;; instead of nil, if '(nil) was previously inadvertantly assigned to |
10789 | 780 ;; unread-command-events |
781 (defun vip-event-key (event) | |
782 (or (and event (eventp event)) | |
783 (error "vip-event-key: Wrong type argument, eventp, %S" event)) | |
784 (let ((mod (event-modifiers event)) | |
785 basis) | |
786 (setq basis | |
787 (cond | |
788 (vip-xemacs-p | |
789 (cond ((key-press-event-p event) | |
790 (event-key event)) | |
791 ((button-event-p event) | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
792 (concat "mouse-" (prin1-to-string (event-button event)))) |
10789 | 793 (t |
794 (error "vip-event-key: Unknown event, %S" event)))) | |
795 (t | |
796 ;; Emacs doesn't handle capital letters correctly, since | |
797 ;; \S-a isn't considered the same as A (it behaves as | |
798 ;; plain `a' instead). So we take care of this here | |
12139
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
799 (cond ((and (numberp event) (<= ?A event) (<= event ?Z)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
800 (setq mod nil |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
801 event event)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
802 ;; Emacs has the oddity whereby characters 128+char |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
803 ;; represent M-char *if* this appears inside a string. |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
804 ;; So, we convert them manually into (mata char). |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
805 ((and (numberp event) (< ?\C-? event) (<= event 255)) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
806 (setq mod '(meta) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
807 event (- event ?\C-? 1))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
808 (t (event-basic-type event))) |
e16c06646396
(vip-event-key): now handles keys 128--255 as meta-chars.
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
809 ))) |
10789 | 810 |
811 (if (numberp basis) | |
812 (setq basis | |
813 (if (= basis ?\C-?) | |
814 (list 'control '\?) ; taking care of an emacs bug | |
815 (intern (char-to-string basis))))) | |
816 | |
817 (if mod | |
818 (append mod (list basis)) | |
819 basis) | |
820 )) | |
821 | |
822 (defun vip-key-to-emacs-key (key) | |
823 (let (key-name char-p modifiers mod-char-list base-key base-key-name) | |
824 (cond (vip-xemacs-p key) | |
825 ((symbolp key) | |
826 (setq key-name (symbol-name key)) | |
827 (if (= (length key-name) 1) ; character event | |
828 (string-to-char key-name) | |
829 key)) | |
830 ((listp key) | |
831 (setq modifiers (subseq key 0 (1- (length key))) | |
832 base-key (vip-seq-last-elt key) | |
833 base-key-name (symbol-name base-key) | |
834 char-p (= (length base-key-name) 1)) | |
835 (setq mod-char-list | |
836 (mapcar | |
837 '(lambda (elt) (upcase (substring (symbol-name elt) 0 1))) | |
838 modifiers)) | |
839 (if char-p | |
840 (setq key-name | |
841 (car (read-from-string | |
842 (concat | |
843 "?\\" | |
844 (mapconcat 'identity mod-char-list "-\\") | |
845 "-" | |
846 base-key-name)))) | |
847 (setq key-name | |
848 (intern | |
849 (concat | |
850 (mapconcat 'identity mod-char-list "-") | |
851 "-" | |
852 base-key-name)))))) | |
853 )) | |
854 | |
855 | |
856 ;; Args can be a sequence of events, a string, or a Viper macro. Will try to | |
857 ;; convert events to keys and, if all keys are regular printable | |
858 ;; characters, will return a string. Otherwise, will return a string | |
859 ;; representing a vector of converted events. If the input was a Viper macro, | |
860 ;; will return a string that represents this macro as a vector. | |
861 (defun vip-array-to-string (event-seq &optional representation) | |
862 (let (temp) | |
863 (cond ((stringp event-seq) event-seq) | |
864 ((vip-event-vector-p event-seq) | |
865 (setq temp (mapcar 'vip-event-key event-seq)) | |
866 (if (vip-char-symbol-sequence-p temp) | |
867 (mapconcat 'symbol-name temp "") | |
868 (prin1-to-string (vconcat temp)))) | |
869 ((vip-char-symbol-sequence-p event-seq) | |
870 (mapconcat 'symbol-name event-seq "")) | |
871 (t (prin1-to-string event-seq))))) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
872 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
873 (defun vip-key-press-events-to-chars (events) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
874 (mapconcat (if vip-emacs-p |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
875 'char-to-string |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
876 (function |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
877 (lambda (elt) (char-to-string (event-to-character elt))))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
878 events |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
879 "")) |
10789 | 880 |
881 | |
882 (defsubst vip-fast-keysequence-p () | |
883 (not (vip-sit-for-short vip-fast-keyseq-timeout t))) | |
884 | |
885 (defun vip-read-char-exclusive () | |
886 (let (char | |
887 (echo-keystrokes 1)) | |
888 (while (null char) | |
889 (condition-case nil | |
890 (setq char (read-char)) | |
891 (error | |
892 ;; skip event if not char | |
893 (vip-read-event)))) | |
894 char)) | |
895 | |
896 | |
897 | |
898 (defun vip-setup-master-buffer (&rest other-files-or-buffers) | |
899 "Set up the current buffer as a master buffer. | |
900 Arguments become related buffers. This function should normally be used in | |
901 the `Local variables' section of a file." | |
902 (setq vip-related-files-and-buffers-ring | |
903 (make-ring (1+ (length other-files-or-buffers)))) | |
904 (mapcar '(lambda (elt) | |
905 (vip-ring-insert vip-related-files-and-buffers-ring elt)) | |
906 other-files-or-buffers) | |
907 (vip-ring-insert vip-related-files-and-buffers-ring (buffer-name)) | |
908 ) | |
13213
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
909 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
910 ;;; Movement utilities |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
911 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
912 (defvar vip-syntax-preference 'strict-vi |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
913 "*Syntax type characterizing Viper's alphanumeric symbols. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
914 `emacs' means only word constituents are considered to be alphanumeric. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
915 Word constituents are symbols specified as word constituents by the current |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
916 syntax table. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
917 `extended' means word and symbol constituents. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
918 `reformed-vi' means Vi-ish behavior: word constituents and the symbol `_'. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
919 However, word constituents are determined according to Emacs syntax tables, |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
920 which may be different from Vi in some major modes. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
921 `strict-vi' means Viper words are exactly as in Vi.") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
922 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
923 (vip-deflocalvar vip-ALPHA-char-class "w" |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
924 "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
|
925 In addition, the symbol `_' may be considered alphanumeric if |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
926 `vip-syntax-preference'is `reformed-vi'.") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
927 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
928 (vip-deflocalvar vip-strict-ALPHA-chars "a-zA-Z0-9_" |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
929 "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
|
930 Vi.") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
931 (vip-deflocalvar vip-strict-SEP-chars " \t\n" |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
932 "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
|
933 Vi.") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
934 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
935 (vip-deflocalvar vip-SEP-char-class " -" |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
936 "String of syntax classes for Vi separators. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
937 Usually contains ` ', linefeed, TAB or formfeed.") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
938 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
939 (defun vip-update-alphanumeric-class () |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
940 "Set the syntactic class of Viper alphanumeric symbols according to |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
941 the variable `vip-ALPHA-char-class'. Should be called in order for changes to |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
942 `vip-ALPHA-char-class' to take effect." |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
943 (interactive) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
944 (setq-default |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
945 vip-ALPHA-char-class |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
946 (cond ((eq vip-syntax-preference 'emacs) "w") ; only word constituents |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
947 ((eq vip-syntax-preference 'extended) "w_") ; word & symbol chars |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
948 (t "w")))) ; vi syntax: word constituents and the symbol `_' |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
949 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
950 ;; addl-chars are characters to be temporarily considered as alphanumerical |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
951 (defun vip-looking-at-alpha (&optional addl-chars) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
952 (or (stringp addl-chars) (setq addl-chars "")) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
953 (if (eq vip-syntax-preference 'reformed-vi) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
954 (setq addl-chars (concat addl-chars "_"))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
955 (let ((char (char-after (point)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
956 (if char |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
957 (if (eq vip-syntax-preference 'strict-vi) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
958 (looking-at (concat "[" vip-strict-ALPHA-chars addl-chars "]")) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
959 (or (memq char |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
960 ;; convert string to list |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
961 (append (vconcat addl-chars) nil)) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
962 (memq (char-syntax char) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
963 (append (vconcat vip-ALPHA-char-class) nil))))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
964 )) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
965 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
966 (defsubst vip-looking-at-separator () |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
967 (let ((char (char-after (point)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
968 (if char |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
969 (or (eq char ?\n) ; RET is always a separator in Vi |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
970 (memq (char-syntax char) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
971 (append (vconcat vip-SEP-char-class) nil)))))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
972 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
973 (defsubst vip-looking-at-alphasep (&optional addl-chars) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
974 (or (vip-looking-at-separator) (vip-looking-at-alpha addl-chars))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
975 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
976 (defsubst vip-skip-alpha-forward (&optional addl-chars) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
977 (or (stringp addl-chars) (setq addl-chars "")) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
978 (vip-skip-syntax |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
979 'forward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
980 (cond ((eq vip-syntax-preference 'strict-vi) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
981 "") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
982 (t vip-ALPHA-char-class )) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
983 (cond ((eq vip-syntax-preference 'strict-vi) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
984 (concat vip-strict-ALPHA-chars addl-chars)) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
985 (t addl-chars)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
986 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
987 (defsubst vip-skip-alpha-backward (&optional addl-chars) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
988 (or (stringp addl-chars) (setq addl-chars "")) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
989 (vip-skip-syntax |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
990 'backward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
991 (cond ((eq vip-syntax-preference 'strict-vi) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
992 "") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
993 (t vip-ALPHA-char-class )) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
994 (cond ((eq vip-syntax-preference 'strict-vi) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
995 (concat vip-strict-ALPHA-chars addl-chars)) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
996 (t addl-chars)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
997 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
998 ;; weird syntax tables may confuse strict-vi style |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
999 (defsubst vip-skip-all-separators-forward (&optional within-line) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1000 (vip-skip-syntax 'forward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1001 vip-SEP-char-class |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1002 (or within-line "\n") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1003 (if within-line (vip-line-pos 'end)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1004 (defsubst vip-skip-all-separators-backward (&optional within-line) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1005 (vip-skip-syntax 'backward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1006 vip-SEP-char-class |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1007 (or within-line "\n") |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1008 (if within-line (vip-line-pos 'start)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1009 (defun vip-skip-nonseparators (direction) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1010 (let ((func (intern (format "skip-syntax-%S" direction)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1011 (funcall func (concat "^" vip-SEP-char-class) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1012 (vip-line-pos (if (eq direction 'forward) 'end 'start))))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1013 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1014 (defsubst vip-skip-nonalphasep-forward () |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1015 (if (eq vip-syntax-preference 'strict-vi) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1016 (skip-chars-forward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1017 (concat "^" vip-strict-SEP-chars vip-strict-ALPHA-chars)) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1018 (skip-syntax-forward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1019 (concat |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1020 "^" vip-ALPHA-char-class vip-SEP-char-class) (vip-line-pos 'end)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1021 (defsubst vip-skip-nonalphasep-backward () |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1022 (if (eq vip-syntax-preference 'strict-vi) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1023 (skip-chars-backward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1024 (concat "^" vip-strict-SEP-chars vip-strict-ALPHA-chars)) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1025 (skip-syntax-backward |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1026 (concat |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1027 "^" vip-ALPHA-char-class vip-SEP-char-class) (vip-line-pos 'start)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1028 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1029 ;; 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
|
1030 ;; Return the number of chars traveled. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1031 ;; Either SYNTAX or ADDL-CHARS can be nil, in which case they are interpreted |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1032 ;; as an empty string. |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1033 (defun vip-skip-syntax (direction syntax addl-chars &optional limit) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1034 (let ((total 0) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1035 (local 1) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1036 (skip-chars-func (intern (format "skip-chars-%S" direction))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1037 (skip-syntax-func (intern (format "skip-syntax-%S" direction)))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1038 (or (stringp addl-chars) (setq addl-chars "")) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1039 (or (stringp syntax) (setq syntax "")) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1040 (while (and (not (= local 0)) (not (eobp))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1041 (setq local |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1042 (+ (funcall skip-syntax-func syntax limit) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1043 (funcall skip-chars-func addl-chars limit))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1044 (setq total (+ total local))) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1045 total |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1046 )) |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1047 |
68b3f6d9156f
(vip-leave-region-active): new function.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12899
diff
changeset
|
1048 |
10789 | 1049 |
1050 | |
1051 (provide 'viper-util) | |
1052 | |
1053 ;;; viper-util.el ends here |