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