annotate lisp/viper/viper-util.el @ 71:bae944334fa4

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