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