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