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