annotate lisp/emulation/viper-util.el @ 15970:d54ae2343dff

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