annotate lisp/viper/viper-util.el @ 14:9ee227acff29 r19-15b90

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