annotate lisp/viper/viper-ex.el @ 192:9d35321dd38c

Added tag r20-3b22 for changeset ecf6ba7b0a10
author cvs
date Mon, 13 Aug 2007 09:57:40 +0200
parents 3d6bfa290dbd
children acd284d43ca1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; viper-ex.el --- functions implementing the Ex commands for Viper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
22 ;; Code
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
23
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
24 (provide 'viper-ex)
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
25
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
26 ;; Compiler pacifier
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
27 (defvar read-file-name-map)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
28 (defvar viper-use-register)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
29 (defvar viper-s-string)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
30 (defvar viper-shift-width)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
31 (defvar viper-ex-history)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
32 (defvar viper-related-files-and-buffers-ring)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
33 (defvar viper-local-search-start-marker)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
34 (defvar viper-expert-level)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
35 (defvar viper-custom-file-name)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
36 (defvar viper-case-fold-search)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
37 (defvar explicit-shell-file-name)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
38
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
39 ;; loading happens only in non-interactive compilation
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
40 ;; in order to spare non-viperized emacs from being viperized
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
41 (if noninteractive
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
42 (eval-when-compile
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
43 (let ((load-path (cons (expand-file-name ".") load-path)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
44 (or (featurep 'viper-util)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
45 (load "viper-util.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
46 (or (featurep 'viper-keym)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
47 (load "viper-keym.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
48 (or (featurep 'viper-cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
49 (load "viper-cmd.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
50 )))
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
51 ;; end pacifier
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
52
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
53 (require 'viper-util)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
54
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
55 (defgroup viper-ex nil
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
56 "Viper support for Ex commands"
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
57 :prefix "ex-"
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
58 :group 'viper)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
59
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
60
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
64 (defconst viper-ex-work-buf-name " *ex-working-space*")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
65 (defconst viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
66 (defconst viper-ex-tmp-buf-name " *ex-tmp*")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; Variable completion in :set command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; The list of Ex commands. Used for completing command names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defconst ex-token-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 '(("!") ("=") (">") ("&") ("~")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ("yank") ("xit") ("WWrite") ("Write") ("write") ("wq") ("visual")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ("version") ("vglobal") ("unmap") ("undo") ("tag") ("transfer") ("suspend")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ("substitute") ("submitReport") ("stop") ("sr") ("source") ("shell")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ("set") ("rewind") ("recover") ("read") ("quit") ("pwd")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ("put") ("preserve") ("PreviousRelatedFile") ("RelatedFile")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ("next") ("Next") ("move") ("mark") ("map") ("kmark") ("join")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ("help") ("goto") ("global") ("file") ("edit") ("delete") ("copy")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ("chdir") ("cd") ("Buffer") ("buffer") ("args")) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; A-list of Ex variables that can be set using the :set command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defconst ex-variable-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 '(("wrapscan") ("ws") ("wrapmargin") ("wm")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
86 ("tabstop-global") ("ts-g") ("tabstop") ("ts")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ("showmatch") ("sm") ("shiftwidth") ("sw") ("shell") ("sh")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ("readonly") ("ro")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ("nowrapscan") ("nows") ("noshowmatch") ("nosm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ("noreadonly") ("noro") ("nomagic") ("noma")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ("noignorecase") ("noic")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
92 ("noautoindent-global") ("noai-g") ("noautoindent") ("noai")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ("magic") ("ma") ("ignorecase") ("ic")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
94 ("autoindent-global") ("ai-g") ("autoindent") ("ai")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
95 ("all")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; Token recognized during parsing of Ex commands (e.g., "read", "comma")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defvar ex-token nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; Type of token.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; If non-nil, gives type of address; if nil, it is a command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defvar ex-token-type nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; List of addresses passed to Ex command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defvar ex-addresses nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; It seems that this flag is used only for `#', `print', and `list', which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; aren't implemented. Check later.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (defvar ex-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; "buffer" where Ex commands keep deleted data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; In Emacs terms, this is a register.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (defvar ex-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; Value of ex count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (defvar ex-count nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
121 ;; Flag indicating that :global Ex command is being executed.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (defvar ex-g-flag nil)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
123 ;; Flag indicating that :vglobal Ex command is being executed.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (defvar ex-g-variant nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; Save reg-exp used in substitute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defvar ex-reg-exp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; Replace pattern for substitute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defvar ex-repl nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; Pattern for global command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defvar ex-g-pat nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
136 (defcustom ex-unix-type-shell
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (and (stringp shell-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 "\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 "csh$\\|csh.exe$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 "ksh$\\|ksh.exe$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 "\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "^sh$\\|sh.exe$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 "[^a-z]sh$\\|[^a-z]sh.exe$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 "\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "bash$\\|bash.exe$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 shell-file-name)))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
153 "Is the user using a unix-type shell under a non-OS?"
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
154 :type 'string
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
155 :group 'viper-ex)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
157 (defcustom ex-unix-type-shell-options
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (if ex-unix-type-shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (cond ((string-match "\\(csh$\\|csh.exe$\\)" shell-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 "-f") ; csh: do it fast
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ((string-match "\\(bash$\\|bash.exe$\\)" shell-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "-noprofile") ; bash: ignore .profile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 "Options to pass to the Unix-style shell.
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
166 Don't put `-c' here, as it is added automatically."
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
167 :type 'string
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
168 :group 'viper-ex)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defvar ex-nontrivial-find-file-function
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
171 (cond (ex-unix-type-shell 'viper-ex-nontrivial-find-file-unix)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
172 ((eq system-type 'emx) 'viper-ex-nontrivial-find-file-ms) ; OS/2
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
173 (viper-ms-style-os-p 'viper-ex-nontrivial-find-file-ms) ; Microsoft OS
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
174 (viper-vms-os-p 'viper-ex-nontrivial-find-file-unix) ; VMS
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
175 (t 'viper-ex-nontrivial-find-file-unix) ; presumably UNIX
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; Remembers the previous Ex tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (defvar ex-tag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;; file used by Ex commands like :r, :w, :n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (defvar ex-file nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; If t, tells Ex that this is a variant-command, i.e., w>>, r!, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (defvar ex-variant nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; Specified the offset of an Ex command, such as :read.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (defvar ex-offset nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; Tells Ex that this is a w>> command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defvar ex-append nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; File containing the shell command to be executed at Ex prompt,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; e.g., :r !date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (defvar ex-cmdfile nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
197 ;; flag used in viper-ex-read-file-name to indicate that we may be reading
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; multiple file names. Used for :edit and :next
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
199 (defvar viper-keep-reading-filename nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
201 (defcustom ex-cycle-other-window t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 "*If t, :n and :b cycles through files and buffers in other window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Then :N and :B cycles in the current window. If nil, this behavior is
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
204 reversed."
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
205 :type 'boolean
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
206 :group 'viper-ex)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
208 (defcustom ex-cycle-through-non-files nil
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
209 "*Cycle through *scratch* and other buffers that don't visit any file."
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
210 :type 'boolean
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
211 :group 'viper-ex)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; Last shell command executed with :! command.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
214 (defvar viper-ex-last-shell-com nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; Indicates if Minibuffer was exited temporarily in Ex-command.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
217 (defvar viper-incomplete-ex-cmd nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; Remembers the last ex-command prompt.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
220 (defvar viper-last-ex-prompt "")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;;; Code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;; Check if ex-token is an initial segment of STR
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
226 (defun viper-check-sub (str)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (let ((length (length ex-token)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (if (and (<= length (length str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (string= ex-token (substring str 0 length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setq ex-token str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (setq ex-token-type 'non-command))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;; Get a complete ex command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
234 (defun viper-get-ex-com-subr ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (re-search-forward "[a-zA-Z][a-zA-Z]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setq ex-token-type 'command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq ex-token (buffer-substring (point) (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (cond ((looking-at "a")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
242 (cond ((looking-at "ab") (viper-check-sub "abbreviate"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
243 ((looking-at "ar") (viper-check-sub "args"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
244 (t (viper-check-sub "append"))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
245 ((looking-at "h") (viper-check-sub "help"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ((looking-at "c")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
247 (cond ((looking-at "cd") (viper-check-sub "cd"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
248 ((looking-at "ch") (viper-check-sub "chdir"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
249 ((looking-at "co") (viper-check-sub "copy"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
250 (t (viper-check-sub "change"))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
251 ((looking-at "d") (viper-check-sub "delete"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
252 ((looking-at "b") (viper-check-sub "buffer"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
253 ((looking-at "B") (viper-check-sub "Buffer"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ((looking-at "e")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
255 (if (looking-at "ex") (viper-check-sub "ex")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
256 (viper-check-sub "edit")))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
257 ((looking-at "f") (viper-check-sub "file"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
258 ((looking-at "g") (viper-check-sub "global"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
259 ((looking-at "i") (viper-check-sub "insert"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
260 ((looking-at "j") (viper-check-sub "join"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
261 ((looking-at "l") (viper-check-sub "list"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ((looking-at "m")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
263 (cond ((looking-at "map") (viper-check-sub "map"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
264 ((looking-at "mar") (viper-check-sub "mark"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
265 (t (viper-check-sub "move"))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ((looking-at "k[a-z][^a-z]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (setq ex-token "kmark")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (exchange-point-and-mark)) ; this is canceled out by another
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ; exchange-point-and-mark at the end
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
271 ((looking-at "k") (viper-check-sub "kmark"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ((looking-at "n") (if (looking-at "nu")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
273 (viper-check-sub "number")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
274 (viper-check-sub "next")))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
275 ((looking-at "N") (viper-check-sub "Next"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
276 ((looking-at "o") (viper-check-sub "open"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ((looking-at "p")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
278 (cond ((looking-at "pre") (viper-check-sub "preserve"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
279 ((looking-at "pu") (viper-check-sub "put"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
280 ((looking-at "pw") (viper-check-sub "pwd"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
281 (t (viper-check-sub "print"))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
282 ((looking-at "P") (viper-check-sub "PreviousRelatedFile"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
283 ((looking-at "R") (viper-check-sub "RelatedFile"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
284 ((looking-at "q") (viper-check-sub "quit"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ((looking-at "r")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
286 (cond ((looking-at "rec") (viper-check-sub "recover"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
287 ((looking-at "rew") (viper-check-sub "rewind"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
288 (t (viper-check-sub "read"))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ((looking-at "s")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
290 (cond ((looking-at "se") (viper-check-sub "set"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
291 ((looking-at "sh") (viper-check-sub "shell"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
292 ((looking-at "so") (viper-check-sub "source"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
293 ((looking-at "sr") (viper-check-sub "sr"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
294 ((looking-at "st") (viper-check-sub "stop"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
295 ((looking-at "sus") (viper-check-sub "suspend"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
296 ((looking-at "subm") (viper-check-sub "submitReport"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
297 (t (viper-check-sub "substitute"))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ((looking-at "t")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
299 (if (looking-at "ta") (viper-check-sub "tag")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
300 (viper-check-sub "transfer")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ((looking-at "u")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
302 (cond ((looking-at "una") (viper-check-sub "unabbreviate"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
303 ((looking-at "unm") (viper-check-sub "unmap"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
304 (t (viper-check-sub "undo"))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ((looking-at "v")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
306 (cond ((looking-at "ve") (viper-check-sub "version"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
307 ((looking-at "vi") (viper-check-sub "visual"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
308 (t (viper-check-sub "vglobal"))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ((looking-at "w")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
310 (if (looking-at "wq") (viper-check-sub "wq")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
311 (viper-check-sub "write")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 ((looking-at "W")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (if (looking-at "WW")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
314 (viper-check-sub "WWrite")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
315 (viper-check-sub "Write")))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
316 ((looking-at "x") (viper-check-sub "xit"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
317 ((looking-at "y") (viper-check-sub "yank"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
318 ((looking-at "z") (viper-check-sub "z")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ;; Get an ex-token which is either an address or a command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ;; A token has a type, \(command, address, end-mark\), and a value
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
324 (defun viper-get-ex-token ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
326 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
327 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (skip-chars-forward " \t|")
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
329 (let ((case-fold-search t))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
330 (cond ((looking-at "#")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
331 (setq ex-token-type 'command)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
332 (setq ex-token (char-to-string (following-char)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
333 (forward-char 1))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
334 ((looking-at "[a-z]") (viper-get-ex-com-subr))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
335 ((looking-at "\\.")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
336 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
337 (setq ex-token-type 'dot))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
338 ((looking-at "[0-9]")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
339 (set-mark (point))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
340 (re-search-forward "[0-9]*")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
341 (setq ex-token-type
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
342 (cond ((eq ex-token-type 'plus) 'add-number)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
343 ((eq ex-token-type 'minus) 'sub-number)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
344 (t 'abs-number)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
345 (setq ex-token
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
346 (string-to-int (buffer-substring (point) (mark t)))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
347 ((looking-at "\\$")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
348 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
349 (setq ex-token-type 'end))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
350 ((looking-at "%")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
351 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
352 (setq ex-token-type 'whole))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
353 ((looking-at "+")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
354 (cond ((or (looking-at "+[-+]") (looking-at "+[\n|]"))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
355 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
356 (insert "1")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
357 (backward-char 1)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (setq ex-token-type 'plus))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
359 ((looking-at "+[0-9]")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
360 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
361 (setq ex-token-type 'plus))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
362 (t
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
363 (error viper-BadAddress))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
364 ((looking-at "-")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
365 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]"))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
366 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
367 (insert "1")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
368 (backward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
369 (setq ex-token-type 'minus))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
370 ((looking-at "-[0-9]")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
371 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
372 (setq ex-token-type 'minus))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
373 (t
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
374 (error viper-BadAddress))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
375 ((looking-at "/")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
376 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
377 (set-mark (point))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
378 (let ((cont t))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
379 (while (and (not (eolp)) cont)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
380 ;;(re-search-forward "[^/]*/")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
381 (re-search-forward "[^/]*\\(/\\|\n\\)")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
382 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
383 (setq cont nil))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
384 (backward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
385 (setq ex-token (buffer-substring (point) (mark t)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
386 (if (looking-at "/") (forward-char 1))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
387 (setq ex-token-type 'search-forward))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
388 ((looking-at "\\?")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
389 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
390 (set-mark (point))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
391 (let ((cont t))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
392 (while (and (not (eolp)) cont)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
393 ;;(re-search-forward "[^\\?]*\\?")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
394 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
395 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?"))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
396 (setq cont nil))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
397 (backward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
398 (if (not (looking-at "\n")) (forward-char 1))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
399 (setq ex-token-type 'search-backward)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
400 (setq ex-token (buffer-substring (1- (point)) (mark t))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
401 ((looking-at ",")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
402 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
403 (setq ex-token-type 'comma))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
404 ((looking-at ";")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
405 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
406 (setq ex-token-type 'semi-colon))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
407 ((looking-at "[!=><&~]")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
408 (setq ex-token-type 'command)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
409 (setq ex-token (char-to-string (following-char)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
410 (forward-char 1))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
411 ((looking-at "'")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
412 (setq ex-token-type 'goto-mark)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
413 (forward-char 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
414 (cond ((looking-at "'") (setq ex-token nil))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
415 ((looking-at "[a-z]") (setq ex-token (following-char)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
416 (t (error "Marks are ' and a-z")))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
417 (forward-char 1))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
418 ((looking-at "\n")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
419 (setq ex-token-type 'end-mark)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
420 (setq ex-token "goto"))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
421 (t
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
422 (error viper-BadExCommand))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ;; Reads Ex command. Tries to determine if it has to exit because command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; is complete or invalid. If not, keeps reading command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (defun ex-cmd-read-exit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
428 (setq viper-incomplete-ex-cmd t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (let ((quit-regex1 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 "\\(" "set[ \t]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 "\\|" "edit[ \t]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 "\\|" "[nN]ext[ \t]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 "\\|" "unm[ \t]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 "\\|" "^[ \t]*rep"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (quit-regex2 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 "[a-zA-Z][ \t]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 "\\(" "!" "\\|" ">>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 "\\|" "\\+[0-9]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 "\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 "*[ \t]*$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (stay-regex (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 "\\(" "^[ \t]*$"
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
444 "\\|" "[?/].*"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 "\\|" "[ktgjmsz][ \t]*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 "\\|" "^[ \t]*ab.*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 "\\|" "tr[ansfer \t]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 "\\|" "sr[ \t]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 "\\|" "mo.*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 "\\|" "^[ \t]*k?ma[^p]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 "\\|" "^[ \t]*fi.*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 "\\|" "v?gl.*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 "\\|" "[vg][ \t]*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 "\\|" "jo.*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 "\\|" "^[ \t]*ta.*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 "\\|" "^[ \t]*una.*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 "\\|" "^[ \t]*su.*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 "\\|['`][a-z][ \t]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 "\\|" "![ \t]*[a-zA-Z].*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 "\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 "!*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (save-window-excursion ;; put cursor at the end of the Ex working buffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
464 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
465 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (goto-char (point-max)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
467 (cond ((viper-looking-back quit-regex1) (exit-minibuffer))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
468 ((viper-looking-back stay-regex) (insert " "))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
469 ((viper-looking-back quit-regex2) (exit-minibuffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (t (insert " ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; complete Ex command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (defun ex-cmd-complete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (let (save-pos dist compl-list string-to-complete completion-result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (setq dist (skip-chars-backward "[a-zA-Z!=>&~]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 save-pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (if (or (= dist 0)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
482 (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
483 (viper-looking-back
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 "^[ \t]*[a-zA-Z!=>&~][ \t]*[/?]*+[ \t]+[a-zA-Z!=>&~]+"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;; Preceding characters are not the ones allowed in an Ex command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ;; or we have typed past command name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; Note: we didn't do parsing, so there may be surprises.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
488 (if (or (viper-looking-back "[a-zA-Z!=>&~][ \t]*[/?]*[ \t]*")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
489 (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (looking-at "[^ \t\n\C-m]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (with-output-to-temp-buffer "*Completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (display-completion-list
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
494 (viper-alist-to-list ex-token-alist))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ;; Preceding chars may be part of a command name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (setq string-to-complete (buffer-substring save-pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (setq completion-result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (try-completion string-to-complete ex-token-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (cond ((eq completion-result t) ; exact match--do nothing
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
501 (viper-tmp-insert-at-eob " (Sole completion)"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ((eq completion-result nil)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
503 (viper-tmp-insert-at-eob " (No match)"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (t ;; partial completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (goto-char save-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (insert completion-result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (setq compl-list
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
510 (viper-filter-alist (concat "^" completion-result)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ex-token-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (if (> (length compl-list) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (with-output-to-temp-buffer "*Completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (display-completion-list
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
515 (viper-alist-to-list (reverse compl-list)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;; Read Ex commands
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
520 (defun viper-ex (&optional string)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (or string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (setq ex-g-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ex-g-variant nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (let* ((map (copy-keymap minibuffer-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (address nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (cont t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (dot (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 prev-token-type com-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
531 (viper-add-keymap viper-ex-cmd-map map)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
533 (setq com-str (or string (viper-read-string-with-history
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 nil
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
536 'viper-ex-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
537 (car viper-ex-history)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ;; just a precaution
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
541 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
542 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (insert com-str "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (setq ex-token-type nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ex-addresses nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (while cont
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
549 (viper-get-ex-token)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (cond ((memq ex-token-type '(command end-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (if address (setq ex-addresses (cons address ex-addresses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (cond ((string= ex-token "global")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (ex-global nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (setq cont nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ((string= ex-token "vglobal")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (ex-global t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (setq cont nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (t
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
559 (viper-execute-ex-command)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
561 (setq viper-ex-work-buf
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
562 (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
563 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (cond ((looking-at "|")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 ((looking-at "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (setq cont nil))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
569 (t (error "`%s': %s" ex-token viper-SpuriousText)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 ((eq ex-token-type 'non-command)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
573 (error "`%s': %s" ex-token viper-BadExCommand))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 ((eq ex-token-type 'whole)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (setq address nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (setq ex-addresses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (if ex-addresses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (cons (point-max) ex-addresses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (cons (point-max) (cons (point-min) ex-addresses)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 ((eq ex-token-type 'comma)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (if (eq prev-token-type 'whole)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (setq address (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (setq ex-addresses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (cons (if (null address) (point) address) ex-addresses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ((eq ex-token-type 'semi-colon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (if (eq prev-token-type 'whole)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (setq address (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (if address (setq dot address))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (setq ex-addresses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (cons (if (null address) (point) address) ex-addresses)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
591 (t (let ((ans (viper-get-ex-address-subr address dot)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (if ans (setq address ans)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (setq prev-token-type ex-token-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ;; Get a regular expression and set `ex-variant', if found
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
597 (defun viper-get-ex-pat ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
599 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
600 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (if (looking-at "!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (setq ex-g-variant (not ex-g-variant)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 ex-g-flag (not ex-g-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (let ((c (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (if (string-match "[0-9A-Za-z]" (format "%c" c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 "Global regexp must be inside matching non-alphanumeric chars"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (if (looking-at "[^\\\\\n]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (let ((cont t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (while (and (not (eolp)) cont)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (if (not (re-search-forward (format "[^%c]*%c" c c) nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (if (member ex-token '("global" "vglobal"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 "Missing closing delimiter for global regexp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (goto-char (point-max))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
623 (if (not (viper-looking-back
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (setq cont nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (setq ex-token
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (if (= (mark t) (point)) ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (buffer-substring (1- (point)) (mark t))))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
629 (backward-char 1)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
630 ;; if the user doesn't specify the final pattern delimiter, we're
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
631 ;; at newline now. In this case, insert the initial delimiter
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
632 ;; specified in variable c
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
633 (if (looking-at "\n")
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
634 (progn
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
635 (insert c)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
636 (backward-char 1)))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
637 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (setq ex-token nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;; get an ex command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
642 (defun viper-get-ex-command ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
644 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
645 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (if (looking-at "/") (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (cond ((looking-at "[a-z]")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
649 (viper-get-ex-com-subr)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (if (eq ex-token-type 'non-command)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
651 (error "`%s': %s" ex-token viper-BadExCommand)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ((looking-at "[!=><&~]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (setq ex-token (char-to-string (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (forward-char 1))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
655 (t (error viper-BadExCommand)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 ;; Get an Ex option g or c
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
658 (defun viper-get-ex-opt-gc (c)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
660 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
661 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (if (looking-at (format "%c" c)) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (cond ((looking-at "g")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (setq ex-token "g")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 ((looking-at "c")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (setq ex-token "c")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 ;; Compute default addresses. WHOLE-FLAG means use the whole buffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
675 (defun viper-default-ex-addresses (&optional whole-flag)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (cond ((null ex-addresses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (setq ex-addresses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (if whole-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (cons (point-max) (cons (point-min) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (cons (point) (cons (point) nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 ((null (cdr ex-addresses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (setq ex-addresses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (cons (car ex-addresses) ex-addresses)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 ;; Get an ex-address as a marker and set ex-flag if a flag is found
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
686 (defun viper-get-ex-address ()
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
687 (let ((address (point-marker))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
688 (cont t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (setq ex-token "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (setq ex-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (while cont
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
692 (viper-get-ex-token)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (cond ((eq ex-token-type 'command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (if (member ex-token '("print" "list" "#"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (setq ex-flag t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 cont nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (error "Address expected in this Ex command")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 ((eq ex-token-type 'end-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (setq cont nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 ((eq ex-token-type 'whole)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (error "Trailing address expected"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 ((eq ex-token-type 'comma)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
704 (error "`%s': %s" ex-token viper-SpuriousText))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
705 (t (let ((ans (viper-get-ex-address-subr address (point-marker))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (if ans (setq address ans))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 address))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 ;; Returns an address as a point
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
710 (defun viper-get-ex-address-subr (old-address dot)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (let ((address nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (if (null old-address) (setq old-address dot))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (cond ((eq ex-token-type 'dot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (setq address dot))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ((eq ex-token-type 'add-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (goto-char old-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (forward-line (if (= old-address 0) (1- ex-token) ex-token))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (setq address (point-marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ((eq ex-token-type 'sub-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (goto-char old-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (forward-line (- ex-token))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (setq address (point-marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 ((eq ex-token-type 'abs-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (if (= ex-token 0) (setq address 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (forward-line (1- ex-token))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (setq address (point-marker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ((eq ex-token-type 'end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (setq address (point-max-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ((eq ex-token-type 'plus) t) ; do nothing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ((eq ex-token-type 'minus) t) ; do nothing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ((eq ex-token-type 'search-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (ex-search-address t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (setq address (point-marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ((eq ex-token-type 'search-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (ex-search-address nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (setq address (point-marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ((eq ex-token-type 'goto-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (if (null ex-token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (exchange-point-and-mark)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
747 (goto-char (viper-register-to-point
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (1+ (- ex-token ?a)) 'enforce-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (setq address (point-marker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 address))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 ;; Search pattern and set address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (defun ex-search-address (forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (if (string= ex-token "")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
756 (if (null viper-s-string)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
757 (error viper-NoPrevSearch)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
758 (setq ex-token viper-s-string))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
759 (setq viper-s-string ex-token))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (if forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (re-search-forward ex-token))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (re-search-backward ex-token)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 ;; Get a buffer name and set `ex-count' and `ex-flag' if found
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
768 (defun viper-get-ex-buffer ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (setq ex-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (setq ex-count nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (setq ex-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
773 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
774 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (if (looking-at "[a-zA-Z]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (setq ex-buffer (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (if (looking-at "[0-9]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (re-search-forward "[0-9][0-9]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (setq ex-count (string-to-int (buffer-substring (point) (mark t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (if (looking-at "[pl#]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (setq ex-flag t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (if (not (looking-at "[\n|]"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
792 (error "`%s': %s" ex-token viper-SpuriousText))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
794 (defun viper-get-ex-count ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (setq ex-variant nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ex-count nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ex-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
799 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
800 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (if (looking-at "!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (setq ex-variant t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (if (looking-at "[0-9]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (re-search-forward "[0-9][0-9]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (setq ex-count (string-to-int (buffer-substring (point) (mark t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (if (looking-at "[pl#]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (setq ex-flag t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (if (not (looking-at "[\n|]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (error "`%s': %s"
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
819 (buffer-substring
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
820 (point-min) (1- (point-max))) viper-BadExCommand))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 ;; Expand \% and \# in ex command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (defun ex-expand-filsyms (cmd buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (let (cf pf ret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (setq cf buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (setq pf (ex-next nil t))) ; this finds alternative file name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (if (and (null cf) (string-match "[^\\]%\\|\\`%" cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (error "No current file to substitute for `%%'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (error "No alternate file to substitute for `#'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
834 (set-buffer (get-buffer-create viper-ex-tmp-buf-name))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (insert cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (while (re-search-forward "%\\|#" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (let ((data (match-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (char (buffer-substring (match-beginning 0) (match-end 0))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
841 (if (viper-looking-back (concat "\\\\" char))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (replace-match char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (store-match-data data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (if (string= char "%")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (replace-match cf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (replace-match pf)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (setq ret (buffer-substring (point-min) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (message "%s" ret))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 ret))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 ;; Get a file name and set ex-variant, `ex-append' and `ex-offset' if found
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
853 (defun viper-get-ex-file ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (let (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (setq ex-file nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ex-variant nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 ex-append nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 ex-offset nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 ex-cmdfile nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
862 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
863 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (if (looking-at "!")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
866 (if (and (not (viper-looking-back "[ \t]"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 ;; read doesn't have a corresponding :r! form, so ! is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 ;; immediately interpreted as a shell command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (not (string= ex-token "read")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (setq ex-variant t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (skip-chars-forward " \t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (setq ex-cmdfile t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (if (looking-at ">>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (setq ex-append t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ex-variant t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (forward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (if (looking-at "+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (re-search-forward "[ \t\n]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (setq ex-offset (buffer-substring (point) (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ;; this takes care of :r, :w, etc., when they get file names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 ;; from the history list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (if (member ex-token '("read" "write" "edit" "visual" "next"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (setq ex-file (buffer-substring (point) (1- (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (setq ex-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 ;; For :e, match multiple non-white strings separated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 ;; by white. For others, find the first non-white string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (if (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (if (string= ex-token "edit")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 "[^ \t\n]+\\([ \t]+[^ \t\n]+\\)*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 "[^ \t\n]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 ex-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 ;; if file name comes from history, don't leave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 ;; minibuffer when the user types space
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
908 (setq viper-incomplete-ex-cmd nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 ;; this must be the last clause in this progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (substring ex-file (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 ;; this leaves only the command name in the work area
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 ;; file names are gone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (delete-region (point) (1- (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (setq prompt (buffer-substring (point-min) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
922 (setq viper-last-ex-prompt prompt)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 ;; If we just finished reading command, redisplay prompt
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
925 (if viper-incomplete-ex-cmd
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
926 (setq ex-file (viper-ex-read-file-name (format ":%s " prompt)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ;; file was typed in-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (setq ex-file (or ex-file "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 ;; Completes file name or exits minibuffer. If Ex command accepts multiple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 ;; file names, arranges to re-enter the minibuffer.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
934 (defun viper-complete-filename-or-exit ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
936 (setq viper-keep-reading-filename t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 ;; don't exit if directory---ex-commands don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (cond ((ex-cmd-accepts-multiple-files-p ex-token) (exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 ;; apparently the argument to an Ex command is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 ;; supposed to be a shell command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
941 ((viper-looking-back "^[ \t]*!.*")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (setq ex-cmdfile t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (insert " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (setq ex-cmdfile nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (minibuffer-complete-word))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
948 (defun viper-handle-! ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (if (and (string=
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
951 (buffer-string) (viper-abbreviate-file-name default-directory))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (member ex-token '("read" "write")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (erase-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (insert "!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (defun ex-cmd-accepts-multiple-files-p (token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (member token '("edit" "next" "Next")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 ;; If user doesn't enter anything, then "" is returned, i.e., the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 ;; prompt-directory is not returned.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
961 (defun viper-ex-read-file-name (prompt)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (let* ((str "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (minibuffer-local-completion-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (copy-keymap minibuffer-local-completion-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 beg end cont val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
967 (viper-add-keymap ex-read-filename-map
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
968 (if viper-emacs-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 minibuffer-local-completion-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 read-file-name-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
972 (setq cont (setq viper-keep-reading-filename t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (while cont
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
974 (setq viper-keep-reading-filename nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 val (read-file-name (concat prompt str) nil default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (if (string-match " " val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (setq val (concat "\\\"" val "\\\"")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (setq str (concat str (if (equal val "") "" " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 val (if (equal val "") "" " ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ;; Only edit, next, and Next commands accept multiple files.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
982 ;; viper-keep-reading-filename is set in the anonymous function that is
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 ;; bound to " " in ex-read-filename-map.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
984 (setq cont (and viper-keep-reading-filename
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (ex-cmd-accepts-multiple-files-p ex-token)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (setq beg (string-match "[^ \t]" str) ; delete leading blanks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 end (string-match "[ \t]*$" str)) ; delete trailing blanks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (if (member ex-token '("read" "write"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (if (string-match "[\t ]*!" str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 ;; this is actually a shell command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (setq ex-cmdfile t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (setq beg (1+ beg))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
996 (setq viper-last-ex-prompt
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
997 (concat viper-last-ex-prompt " !")))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (substring str (or beg 0) end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 ;; Execute ex command using the value of addresses
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1001 (defun viper-execute-ex-command ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1002 (viper-deactivate-mark)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (cond ((string= ex-token "args") (ex-args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 ((string= ex-token "copy") (ex-copy nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 ((string= ex-token "cd") (ex-cd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 ((string= ex-token "chdir") (ex-cd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 ((string= ex-token "delete") (ex-delete))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ((string= ex-token "edit") (ex-edit))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1009 ((string= ex-token "file") (viper-info-on-file))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 ((string= ex-token "goto") (ex-goto))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ((string= ex-token "help") (ex-help))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ((string= ex-token "join") (ex-line "join"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 ((string= ex-token "kmark") (ex-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 ((string= ex-token "mark") (ex-mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 ((string= ex-token "map") (ex-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 ((string= ex-token "move") (ex-copy t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 ((string= ex-token "next") (ex-next ex-cycle-other-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 ((string= ex-token "Next") (ex-next (not ex-cycle-other-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 ((string= ex-token "RelatedFile") (ex-next-related-buffer 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ((string= ex-token "put") (ex-put))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ((string= ex-token "pwd") (ex-pwd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ((string= ex-token "preserve") (ex-preserve))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 ((string= ex-token "PreviousRelatedFile") (ex-next-related-buffer -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ((string= ex-token "quit") (ex-quit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 ((string= ex-token "read") (ex-read))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ((string= ex-token "recover") (ex-recover))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 ((string= ex-token "rewind") (ex-rewind))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1028 ((string= ex-token "submitReport") (viper-submit-report))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 ((string= ex-token "set") (ex-set))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 ((string= ex-token "shell") (ex-shell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 ((string= ex-token "source") (ex-source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 ((string= ex-token "sr") (ex-substitute t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 ((string= ex-token "substitute") (ex-substitute))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 ((string= ex-token "suspend") (suspend-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 ((string= ex-token "stop") (suspend-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 ((string= ex-token "transfer") (ex-copy nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ((string= ex-token "buffer") (if ex-cycle-other-window
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1038 (viper-switch-to-buffer-other-window)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1039 (viper-switch-to-buffer)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ((string= ex-token "Buffer") (if ex-cycle-other-window
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1041 (viper-switch-to-buffer)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1042 (viper-switch-to-buffer-other-window)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 ((string= ex-token "tag") (ex-tag))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1044 ((string= ex-token "undo") (viper-undo))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ((string= ex-token "unmap") (ex-unmap))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1046 ((string= ex-token "version") (viper-version))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 ((string= ex-token "visual") (ex-edit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 ((string= ex-token "write") (ex-write nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 ((string= ex-token "Write") (save-some-buffers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 ((string= ex-token "wq") (ex-write t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 ((string= ex-token "WWrite") (save-some-buffers t)) ; don't ask
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ((string= ex-token "xit") (ex-write t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ((string= ex-token "yank") (ex-yank))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ((string= ex-token "!") (ex-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 ((string= ex-token "=") (ex-line-no))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 ((string= ex-token ">") (ex-line "right"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 ((string= ex-token "<") (ex-line "left"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 ((string= ex-token "&") (ex-substitute t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 ((string= ex-token "~") (ex-substitute t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 ((or (string= ex-token "append")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (string= ex-token "change")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (string= ex-token "insert")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (string= ex-token "open"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (error "`%s': Obsolete command, not supported by Viper" ex-token))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 ((or (string= ex-token "abbreviate")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (string= ex-token "unabbreviate"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 "`%s': Vi abbrevs are obsolete. Use the more powerful Emacs abbrevs"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 ex-token))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 ((or (string= ex-token "list")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (string= ex-token "print")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (string= ex-token "z")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (string= ex-token "#"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (error "`%s': Command not implemented in Viper" ex-token))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1075 (t (error "`%s': %s" ex-token viper-BadExCommand))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1077 (defun viper-undisplayed-files ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (lambda (b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (if (null (get-buffer-window b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (let ((f (buffer-file-name b)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (if f f
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (if ex-cycle-through-non-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (let ((s (buffer-name b)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (if (string= " " (substring s 0 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (defun ex-args ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1095 (let ((l (viper-undisplayed-files))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (args "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (file-count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (while (not (null l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (if (car l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (setq args (format "%s %d) %s\n" args file-count (car l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 file-count (1+ file-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (setq l (cdr l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (if (string= args "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (message "All files are already displayed")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1107 (with-output-to-temp-buffer " *viper-info*"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (princ "\n\nThese files are not displayed in any window.\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (princ "\n=============\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (princ args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (princ "\n=============\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (princ "\nThe numbers can be given as counts to :next. ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (princ "\n\nPress any key to continue...\n\n"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1114 (viper-read-event))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ;; Ex cd command. Default directory of this buffer changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (defun ex-cd ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1118 (viper-get-ex-file)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (if (string= ex-file "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (setq ex-file "~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (setq default-directory (file-name-as-directory (expand-file-name ex-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ;; Ex copy and move command. DEL-FLAG means delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (defun ex-copy (del-flag)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1125 (viper-default-ex-addresses)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1126 (let ((address (viper-get-ex-address))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (end (car ex-addresses)) (beg (car (cdr ex-addresses))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (push-mark beg t)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1131 (viper-enlarge-region (mark t) (point))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (if del-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (kill-region (point) (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (copy-region-as-kill (point) (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (if ex-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (with-output-to-temp-buffer "*copy text*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (princ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (if (or del-flag ex-g-flag ex-g-variant)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (current-kill 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (buffer-substring (point) (mark t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (read-string "[Hit return to continue] ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (save-excursion (kill-buffer "*copy text*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (quit (save-excursion (kill-buffer "*copy text*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (signal 'quit nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (if (= address 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (goto-char address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (insert (current-kill 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 ;; Ex delete command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (defun ex-delete ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1156 (viper-default-ex-addresses)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1157 (viper-get-ex-buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1159 (if (> beg end) (error viper-FirstAddrExceedsSecond))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1161 (viper-enlarge-region beg end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (if ex-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (forward-line (1- ex-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (set-mark end))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1168 (viper-enlarge-region (point) (mark t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (if ex-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 ;; show text to be deleted and ask for confirmation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (with-output-to-temp-buffer " *delete text*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (princ (buffer-substring (point) (mark t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (read-string "[Hit return to continue] ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (quit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (save-excursion (kill-buffer " *delete text*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (error "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (save-excursion (kill-buffer " *delete text*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (if ex-buffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1181 (cond ((viper-valid-register ex-buffer '(Letter))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1182 (viper-append-to-register
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (downcase ex-buffer) (point) (mark t)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1184 ((viper-valid-register ex-buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (copy-to-register ex-buffer (point) (mark t) nil))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1186 (t (error viper-InvalidRegister ex-buffer))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (kill-region (point) (mark t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 ;; Ex edit command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 ;; In Viper, `e' and `e!' behave identically. In both cases, the user is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 ;; asked if current buffer should really be discarded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 ;; This command can take multiple file names. It replaces the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 ;; with the first file in its argument list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (defun ex-edit (&optional file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (if (not file)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1198 (viper-get-ex-file))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (cond ((and (string= ex-file "") buffer-file-name)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1200 (setq ex-file (viper-abbreviate-file-name (buffer-file-name))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 ((string= ex-file "")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1202 (error viper-NoFileSpecified)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (let (msg do-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (cond ((buffer-modified-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (setq msg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (format "Buffer %s is modified. Discard changes? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 do-edit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 ((not (verify-visited-file-modtime (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (setq msg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (format "File %s changed on disk. Reread from disk? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 do-edit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (t (setq do-edit nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (if do-edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (if (yes-or-no-p msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (kill-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (message "Buffer %s was left intact" (buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 ) ; let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (if (null (setq file (get-file-buffer ex-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (ex-find-file ex-file)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1229 (or (eq major-mode 'dired-mode)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1230 (viper-change-state-to-vi))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (switch-to-buffer file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (if ex-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1236 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1237 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (insert ex-offset "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (goto-char (point-min)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1241 (goto-char (viper-get-ex-address))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (beginning-of-line)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1243 (ex-fixup-history viper-last-ex-prompt ex-file))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1245 ;; Find-file FILESPEC if it appears to specify a single file.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1246 ;; Otherwise, assume that FILES{EC is a wildcard.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1247 ;; In this case, split it into substrings separated by newlines.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 ;; Each line is assumed to be a file name. find-file's each file thus obtained.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (defun ex-find-file (filespec)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1250 (let ((nonstandard-filename-chars "[^-a-zA-Z0-9_./,~$\\]"))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1251 (cond ((file-exists-p filespec) (find-file filespec))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1252 ((string-match nonstandard-filename-chars filespec)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1253 (funcall ex-nontrivial-find-file-function filespec))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
1254 (t (find-file filespec)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 ;; Ex global command
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1259 ;; This is executed in response to:
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1260 ;; :global "pattern" ex-command
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1261 ;; :vglobal "pattern" ex-command
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1262 ;; :global executes ex-command on all lines matching <pattern>
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1263 ;; :vglobal executes ex-command on all lines that don't match <pattern>
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1264 ;;
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1265 ;; With VARIANT nil, this functions executes :global
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1266 ;; With VARIANT t, executes :vglobal
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (defun ex-global (variant)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (let ((gcommand ex-token))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (if (or ex-g-flag ex-g-variant)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (error "`%s' within `global' is not allowed" gcommand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (if variant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (setq ex-g-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 ex-g-variant t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (setq ex-g-flag t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 ex-g-variant nil)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1276 (viper-get-ex-pat)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (if (null ex-token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (error "`%s': Missing regular expression" gcommand)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (if (string= ex-token "")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1281 (if (null viper-s-string)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1282 (error viper-NoPrevSearch)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1283 (setq ex-g-pat viper-s-string))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (setq ex-g-pat ex-token
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1285 viper-s-string ex-token))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (if (null ex-addresses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (setq ex-addresses (list (point-max) (point-min)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1288 (viper-default-ex-addresses))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1289 (let ((marks nil)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1290 (mark-count 0)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1291 (end (car ex-addresses))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1292 (beg (car (cdr ex-addresses)))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1293 com-str)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1294 (if (> beg end) (error viper-FirstAddrExceedsSecond))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1296 (viper-enlarge-region beg end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (let ((cont t) (limit (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 ;; skip the last line if empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (beginning-of-line)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1302 (if (eobp) (viper-backward-char-carefully))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (while (and cont (not (bobp)) (>= (point) limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (let ((found (re-search-backward ex-g-pat (mark t) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (if (or (and ex-g-flag found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (and ex-g-variant (not found)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (setq mark-count (1+ mark-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (setq marks (cons (point-marker) marks)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (if (bobp) (setq cont nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (end-of-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1319 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1320 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (while marks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (goto-char (car marks))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1324 (viper-ex com-str)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (setq mark-count (1- mark-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (setq marks (cdr marks)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 ;; Ex goto command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (defun ex-goto ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (if (null ex-addresses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (setq ex-addresses (cons (point) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (push-mark (point) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (goto-char (car ex-addresses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 ;; Ex line commands. COM is join, shift-right or shift-left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (defun ex-line (com)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1338 (viper-default-ex-addresses)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1339 (viper-get-ex-count)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) point)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1341 (if (> beg end) (error viper-FirstAddrExceedsSecond))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1343 (viper-enlarge-region beg end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (if ex-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 (forward-line ex-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (if ex-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 ;; show text to be joined and ask for confirmation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (with-output-to-temp-buffer " *text*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (princ (buffer-substring (point) (mark t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (read-string "[Hit return to continue] ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (ex-line-subr com (point) (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (quit (ding)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (save-excursion (kill-buffer " *text*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (ex-line-subr com (point) (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (setq point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (goto-char (1- point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (beginning-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (defun ex-line-subr (com beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (cond ((string= com "join")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (goto-char (min beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 (while (and (not (eobp)) (< (point) (max beg end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (if (and (<= (point) (max beg end)) (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (delete-region (point) (1- (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (if (not ex-variant) (fixup-whitespace))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 ((or (string= com "right") (string= com "left"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (indent-rigidly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (min beg end) (max beg end)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1378 (if (string= com "right") viper-shift-width (- viper-shift-width)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (goto-char (max beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (end-of-line)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1381 (viper-forward-char-carefully))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 ;; Ex mark command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (defun ex-mark ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (let (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (if (null ex-addresses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (setq ex-addresses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (cons (point) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1391 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1392 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (if (looking-at "[a-z]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (setq char (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (if (not (looking-at "[\n|]"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1400 (error "`%s': %s" ex-token viper-SpuriousText)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (error "`%s' requires a following letter" ex-token)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (goto-char (car ex-addresses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (point-to-register (1+ (- char ?a))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 ;; Alternate file is the file next to the first one in the buffer ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (defun ex-next (cycle-other-window &optional find-alt-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (catch 'ex-edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (let (count l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (if (not find-alt-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1414 (viper-get-ex-file)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (if (or (char-or-string-p ex-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (and (not (string= "" ex-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (not (string-match "^[0-9]+$" ex-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (ex-edit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (throw 'ex-edit nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 (setq count (string-to-int ex-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (if (= count 0) (setq count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (if (< count 0) (error "Usage: `next <count>' (count >= 0)"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (setq count 1))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1425 (setq l (viper-undisplayed-files))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (while (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (while (and (not (null l)) (null (car l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (setq l (cdr l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (setq count (1- count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (if (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (setq l (cdr l))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (if find-alt-file (car l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (if (and (car l) (get-file-buffer (car l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (let* ((w (if cycle-other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (get-lru-window) (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (b (window-buffer w)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (set-window-buffer w (get-file-buffer (car l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (bury-buffer b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 ;; this puts "next <count>" in the ex-command history
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1441 (ex-fixup-history viper-last-ex-prompt ex-file))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (error "Not that many undisplayed files")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 (defun ex-next-related-buffer (direction &optional no-recursion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1447 (viper-ring-rotate1 viper-related-files-and-buffers-ring direction)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (let ((file-or-buffer-name
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1450 (viper-current-ring-item viper-related-files-and-buffers-ring))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1451 (old-ring viper-related-files-and-buffers-ring)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (old-win (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 skip-rest buf wind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1455 (or (and (ring-p viper-related-files-and-buffers-ring)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1456 (> (ring-length viper-related-files-and-buffers-ring) 0))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (error "This buffer has no related files or buffers"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (or (stringp file-or-buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 "File and buffer names must be strings, %S" file-or-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (setq buf (cond ((get-buffer file-or-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 ((file-exists-p file-or-buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (find-file-noselect file-or-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1468 (if (not (viper-buffer-live-p buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (error "Didn't find buffer %S or file %S"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 file-or-buffer-name
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1471 (viper-abbreviate-file-name
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (expand-file-name file-or-buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (if (equal buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (or no-recursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 ;; try again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (setq skip-rest t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 (ex-next-related-buffer direction 'norecursion))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (if skip-rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 ;; setup buffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1484 (if (setq wind (viper-get-visible-buffer-window buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1486 (setq wind (get-lru-window (if viper-xemacs-p nil 'visible)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (set-window-buffer wind buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1489 (if (viper-window-display-p)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (raise-frame (window-frame wind))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (if (equal (window-frame wind) (window-frame old-win))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (save-window-excursion (select-window wind) (sit-for 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (select-window wind)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 (save-window-excursion (select-window wind) (sit-for 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (set-buffer buf)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1499 (setq viper-related-files-and-buffers-ring old-ring))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1501 (setq viper-local-search-start-marker (point-marker))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 ;; Force auto save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (defun ex-preserve ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (message "Autosaving all buffers that need to be saved...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (do-auto-save t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 ;; Ex put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (defun ex-put ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (let ((point (if (null ex-addresses) (point) (car ex-addresses))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1513 (viper-get-ex-buffer)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1514 (setq viper-use-register ex-buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (goto-char point)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1516 (if (bobp) (viper-Put-back 1) (viper-put-back 1))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 ;; Ex print working directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (defun ex-pwd ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (message default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 ;; Ex quit command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (defun ex-quit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1526 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1527 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (if (looking-at "!") (forward-char 1)))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1529 (if (< viper-expert-level 3)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (save-buffers-kill-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (kill-buffer (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 ;; Ex read command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (defun ex-read ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1536 (viper-get-ex-file)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (let ((point (if (null ex-addresses) (point) (car ex-addresses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (goto-char point)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1540 (viper-add-newline-at-eob-if-necessary)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (if (not (or (bobp) (eobp))) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (if (and (not ex-variant) (string= ex-file ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 (if (null buffer-file-name)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1545 (error viper-NoFileSpecified))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 (setq ex-file buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (if ex-cmdfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (setq command (ex-expand-filsyms ex-file (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (shell-command command t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (insert-file-contents ex-file)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1552 (ex-fixup-history viper-last-ex-prompt ex-file))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 ;; this function fixes ex-history for some commands like ex-read, ex-edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (defun ex-fixup-history (&rest args)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1556 (setq viper-ex-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1557 (cons (mapconcat 'identity args " ") (cdr viper-ex-history))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 ;; Ex recover from emacs \#file\#
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (defun ex-recover ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1562 (viper-get-ex-file)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (if (or ex-append ex-offset)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1564 (error "`recover': %s" viper-SpuriousText))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (if (string= ex-file "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (if (null buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (error "This buffer isn't visiting any file"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (setq ex-file buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (setq ex-file (expand-file-name ex-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (if (and (not (string= ex-file (buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (buffer-modified-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (not ex-variant))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (error "No write since last change \(:rec! overrides\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (recover-file ex-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 ;; Tell that `rewind' is obsolete and to use `:next count' instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (defun ex-rewind ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 "Use `:n <count>' instead. Counts are obtained from the `:args' command"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 ;; read variable name for ex-set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (defun ex-set-read-variable ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (let ((minibuffer-local-completion-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (copy-keymap minibuffer-local-completion-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (cursor-in-echo-area t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 str batch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (define-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 minibuffer-local-completion-map " " 'minibuffer-complete-and-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (define-key minibuffer-local-completion-map "=" 'exit-minibuffer)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1592 (if (viper-set-unread-command-events
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (ex-get-inline-cmd-args "[ \t]*[a-zA-Z]*[ \t]*" nil "\C-m"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (setq batch t)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1596 (viper-set-unread-command-events ?\C-m)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (message ":set <Variable> [= <Value>]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (or batch (sit-for 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (while (string-match "^[ \\t\\n]*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (setq str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (completing-read ":set " ex-variable-alist)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1603 (message ":set <Variable> [= <Value>]")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 ;; if there are unread events, don't wait
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1605 (or (viper-set-unread-command-events "") (sit-for 2))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 ) ; while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 (defun ex-set ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (let ((var (ex-set-read-variable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (val 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (set-cmd "setq")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (ask-if-save t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (auto-cmd-label "; don't touch or else...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (delete-turn-on-auto-fill-pattern
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1617 "([ \t]*add-hook[ \t]+'viper-insert-state-hooks[ \t]+'turn-on-auto-fill.*)")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 actual-lisp-cmd lisp-cmd-del-pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 val2 orig-var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 (setq orig-var var)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1621 (cond ((string= var "all")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1622 (setq ask-if-save nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1623 set-cmd nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1624 ((member var '("ai" "autoindent"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1625 (setq var "viper-auto-indent"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 set-cmd "setq"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 ask-if-save nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 val "t"))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1629 ((member var '("ai-g" "autoindent-global"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1630 (kill-local-variable 'viper-auto-indent)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1631 (setq var "viper-auto-indent"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 set-cmd "setq-default"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 val "t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 ((member var '("noai" "noautoindent"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1635 (setq var "viper-auto-indent"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 ask-if-save nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 val "nil"))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1638 ((member var '("noai-g" "noautoindent-global"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1639 (kill-local-variable 'viper-auto-indent)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1640 (setq var "viper-auto-indent"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 set-cmd "setq-default"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 val "nil"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 ((member var '("ic" "ignorecase"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1644 (setq var "viper-case-fold-search"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 val "t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 ((member var '("noic" "noignorecase"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1647 (setq var "viper-case-fold-search"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 val "nil"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 ((member var '("ma" "magic"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1650 (setq var "viper-re-search"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 val "t"))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1652 ((member var '("noma" "nomagic"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1653 (setq var "viper-re-search"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 val "nil"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 ((member var '("ro" "readonly"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (setq var "buffer-read-only"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 val "t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 ((member var '("noro" "noreadonly"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (setq var "buffer-read-only"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 val "nil"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 ((member var '("sm" "showmatch"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (setq var "blink-matching-paren"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 val "t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 ((member var '("nosm" "noshowmatch"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (setq var "blink-matching-paren"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 val "nil"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 ((member var '("ws" "wrapscan"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1668 (setq var "viper-search-wrap-around-t"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 val "t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 ((member var '("nows" "nowrapscan"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1671 (setq var "viper-search-wrap-around-t"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 val "nil")))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1673 (if (and set-cmd (eq val 0)) ; value must be set by the user
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (let ((cursor-in-echo-area t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (message ":set %s = <Value>" var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 ;; if there are unread events, don't wait
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1677 (or (viper-set-unread-command-events "") (sit-for 2))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (setq val (read-string (format ":set %s = " var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (ex-fixup-history "set" orig-var val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 ;; check numerical values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 (if (member var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 '("sw" "shiftwidth"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 "ts" "tabstop"
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1685 "ts-g" "tabstop-global"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 "wm" "wrapmargin"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (or (numberp (setq val2 (car (read-from-string val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (error "%s: Invalid value, numberp, %S" var val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 (error "%s: Invalid value, numberp, %S" var val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 ((member var '("sw" "shiftwidth"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1695 (setq var "viper-shift-width"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 ((member var '("ts" "tabstop"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 ;; make it take effect in curr buff and new bufs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (setq var "tab-width"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 set-cmd "setq"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 ask-if-save nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1701 ((member var '("ts-g" "tabstop-global"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 (kill-local-variable 'tab-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (setq var "tab-width"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 set-cmd "setq-default"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 ((member var '("wm" "wrapmargin"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 ;; make it take effect in curr buff and new bufs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (kill-local-variable 'fill-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (setq var "fill-column"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 val (format "(- (window-width) %s)" val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 set-cmd "setq-default"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 ((member var '("sh" "shell"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (setq var "explicit-shell-file-name"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 val (format "\"%s\"" val)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 (ex-fixup-history "set" orig-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1716 (if set-cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1717 (setq actual-lisp-cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1718 (format "\n(%s %s %s) %s" set-cmd var val auto-cmd-label)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1719 lisp-cmd-del-pattern
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1720 (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1721 set-cmd var auto-cmd-label)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (if (and ask-if-save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (y-or-n-p (format "Do you want to save this setting in %s "
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1725 viper-custom-file-name)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1727 (viper-save-string-in-file
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1728 actual-lisp-cmd viper-custom-file-name
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 ;; del pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 lisp-cmd-del-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (if (string= var "fill-column")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (if (> val2 0)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1733 (viper-save-string-in-file
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 (concat
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1735 "(add-hook 'viper-insert-state-hooks 'turn-on-auto-fill) "
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 auto-cmd-label)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1737 viper-custom-file-name
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 delete-turn-on-auto-fill-pattern)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1739 (viper-save-string-in-file
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1740 nil viper-custom-file-name delete-turn-on-auto-fill-pattern)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1741 (viper-save-string-in-file
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1742 nil viper-custom-file-name
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 ;; del pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 lisp-cmd-del-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1748 (if set-cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1749 (message "%s %s %s"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1750 set-cmd var
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1751 (if (string-match "^[ \t]*$" val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1752 (format "%S" val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1753 val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1754 (if actual-lisp-cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1755 (eval (car (read-from-string actual-lisp-cmd))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1756 (if (string= var "fill-column")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1757 (if (> val2 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1758 (auto-fill-mode 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1759 (auto-fill-mode -1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
1760 (if (string= var "all") (ex-show-vars))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 ;; In inline args, skip regex-forw and (optionally) chars-back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 ;; Optional 3d arg is a string that should replace ' ' to prevent its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 ;; special meaning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1768 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1769 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 (re-search-forward regex-forw nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 (let ((beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (if chars-back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 (skip-chars-backward chars-back)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (skip-chars-backward " \t\n\C-m"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 ;; replace SPC with `=' to suppress the special meaning SPC has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 ;; in Ex commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 (if replace-str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (while (re-search-forward " +" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (replace-match replace-str nil t)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1785 (viper-forward-char-carefully)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (buffer-substring beg end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 ;; Ex shell command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (defun ex-shell ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 (shell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 ;; Viper help. Invokes Info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (defun ex-help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (pop-to-buffer (get-buffer-create "*info*"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1799 (info (if viper-xemacs-p "viper.info" "viper"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (message "Type `i' to search for a specific topic"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (error (beep 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1802 (with-output-to-temp-buffer " *viper-info*"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (princ (format "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 The Info file for Viper does not seem to be installed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 This file is part of the standard distribution of %sEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 Please contact your system administrator. "
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1808 (if viper-xemacs-p "X" "")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1811 ;; Ex source command. Loads the file specified as argument or `~/.viper'
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (defun ex-source ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1813 (viper-get-ex-file)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (if (string= ex-file "")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1815 (load viper-custom-file-name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (load ex-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 ;; Ex substitute command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1819 ;; If REPEAT use previous regexp which is ex-reg-exp or viper-s-string
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (defun ex-substitute (&optional repeat r-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 (let ((opt-g nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (opt-c nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 (matched-pos nil)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1824 (case-fold-search viper-case-fold-search)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 delim pat repl)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1826 (if repeat (setq ex-token nil) (setq delim (viper-get-ex-pat)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 (if (null ex-token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1829 (setq pat (if r-flag viper-s-string ex-reg-exp))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (or (stringp pat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (error "No previous pattern to use in substitution"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (setq repl ex-repl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 delim (string-to-char pat)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1834 (setq pat (if (string= ex-token "") viper-s-string ex-token))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1835 (setq viper-s-string pat
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 ex-reg-exp pat)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1837 (setq delim (viper-get-ex-pat))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 (if (null ex-token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 (setq ex-token ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 ex-repl "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (setq repl ex-token
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 ex-repl ex-token)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1843 (while (viper-get-ex-opt-gc delim)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (if (string= ex-token "g") (setq opt-g t) (setq opt-c t)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1845 (viper-get-ex-count)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (if ex-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 (if ex-addresses (goto-char (car ex-addresses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 (forward-line (1- ex-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (setq ex-addresses (cons (point) (cons (mark t) nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 (if (null ex-addresses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 (setq ex-addresses (cons (point) (cons (point) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (if (null (cdr ex-addresses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (setq ex-addresses (cons (car ex-addresses) ex-addresses)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 ;(setq G opt-g)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (let ((beg (car ex-addresses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (end (car (cdr ex-addresses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 eol-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1861 (viper-enlarge-region beg end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 (let ((limit (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (goto-char (max (point) (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (point-marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (goto-char (min (point) (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (while (< (point) limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (setq eol-mark (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (if opt-g
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (while (and (not (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 (re-search-forward pat eol-mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (if (or (not opt-c) (y-or-n-p "Replace? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 (setq matched-pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (if (not (stringp repl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 (error "Can't perform Ex substitution: No previous replacement pattern"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 (replace-match repl t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (end-of-line)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1881 (viper-forward-char-carefully))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 (if (null pat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 "Can't repeat Ex substitution: No previous regular expression"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 (if (and (re-search-forward pat eol-mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (or (not opt-c) (y-or-n-p "Replace? ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 (setq matched-pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (if (not (stringp repl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (error "Can't perform Ex substitution: No previous replacement pattern"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (replace-match repl t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 (end-of-line)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1893 (viper-forward-char-carefully))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (if matched-pos (goto-char matched-pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (if opt-c (message "done"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 ;; Ex tag command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (defun ex-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (let (tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1902 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1903 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 (skip-chars-forward "^ |\t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (setq tag (buffer-substring (mark t) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 (if (not (string= tag "")) (setq ex-tag tag))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1909 (viper-change-state-to-emacs)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (condition-case conds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (if (string= tag "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 (find-tag ex-tag t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (find-tag-other-window ex-tag))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1915 (viper-change-state-to-vi))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1917 (viper-change-state-to-vi)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1918 (viper-message-conditions conds)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 ;; Ex write command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 (defun ex-write (q-flag)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1922 (viper-default-ex-addresses t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1923 (viper-get-ex-file)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1924 (let ((end (car ex-addresses))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1925 (beg (car (cdr ex-addresses)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1926 (orig-buf (current-buffer))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1927 (orig-buf-file-name (buffer-file-name))
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 82
diff changeset
1928 (orig-buf-name (buffer-name))
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1929 (buff-changed-p (buffer-modified-p))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 temp-buf writing-same-file region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 file-exists writing-whole-file)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1932 (if (> beg end) (error viper-FirstAddrExceedsSecond))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 (if ex-cmdfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1935 (viper-enlarge-region beg end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (shell-command-on-region (point) (mark t) ex-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (if (and (string= ex-file "") (not (buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 (setq ex-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 (read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 (format "Buffer %s isn't visiting any file. File to save in: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (buffer-name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (setq writing-whole-file (and (= (point-min) beg) (= (point-max) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 ex-file (if (string= ex-file "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 (expand-file-name ex-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 ;; if ex-file is a directory use the file portion of the buffer file name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 (if (and (file-directory-p ex-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (not (file-directory-p buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 (setq ex-file
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1952 (concat (file-name-as-directory ex-file)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1953 (file-name-nondirectory buffer-file-name))))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1954
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 (setq file-exists (file-exists-p ex-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 writing-same-file (string= ex-file (buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (if (and writing-whole-file writing-same-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (if (not (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 (message "(No changes need to be saved)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (save-buffer)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1962 (save-restriction
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1963 (widen)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1964 (ex-write-info file-exists ex-file (point-min) (point-max))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1965 ))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1966 ;; writing some other file or portion of the current file
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1967 (cond ((and file-exists
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1968 (not writing-same-file)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1969 (not (yes-or-no-p
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1970 (format "File %s exists. Overwrite? " ex-file))))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1971 (error "Quit"))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1972 ((and writing-whole-file (not ex-append))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1973 (unwind-protect
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1974 (progn
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1975 (set-visited-file-name ex-file)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1976 (set-buffer-modified-p t)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1977 (save-buffer))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1978 ;; restore the buffer file name
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1979 (set-visited-file-name orig-buf-file-name)
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 82
diff changeset
1980 (set-buffer-modified-p buff-changed-p)
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 82
diff changeset
1981 ;; If the buffer wasn't visiting a file, restore buffer name.
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 82
diff changeset
1982 ;; Name could've been changed by packages such as uniquify.
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 82
diff changeset
1983 (or orig-buf-file-name
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 82
diff changeset
1984 (progn
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 82
diff changeset
1985 (unlock-buffer)
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 82
diff changeset
1986 (rename-buffer orig-buf-name))))
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1987 (save-restriction
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1988 (widen)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1989 (ex-write-info
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1990 file-exists ex-file (point-min) (point-max))))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1991 (t ; writing a region
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1992 (unwind-protect
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1993 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1994 (viper-enlarge-region beg end)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1995 (setq region (buffer-substring (point) (mark t)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1996 ;; create temp buffer for the region
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1997 (setq temp-buf (get-buffer-create " *ex-write*"))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1998 (set-buffer temp-buf)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
1999 (set-visited-file-name ex-file 'noquerry)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2000 (erase-buffer)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2001 (if (and file-exists ex-append)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2002 (insert-file-contents ex-file))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2003 (goto-char (point-max))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2004 (insert region)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2005 (save-buffer)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2006 (ex-write-info
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2007 file-exists ex-file (point-min) (point-max))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2008 ))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2009 (set-buffer temp-buf)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2010 (set-buffer-modified-p nil)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2011 (kill-buffer temp-buf))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2012 ))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 80
diff changeset
2013 (set-buffer orig-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 ;; this prevents the loss of data if writing part of the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (if (and (buffer-file-name) writing-same-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 (set-visited-file-modtime))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (or writing-whole-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 (not writing-same-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (set-buffer-modified-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (if q-flag
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
2021 (if (< viper-expert-level 2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (save-buffers-kill-emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (kill-buffer (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (defun ex-write-info (exists file-name beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (message "`%s'%s %d lines, %d characters"
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2029 (viper-abbreviate-file-name file-name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 (if exists "" " [New file]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 (count-lines beg (min (1+ end) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (- end beg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 ;; Ex yank command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 (defun ex-yank ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2036 (viper-default-ex-addresses)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2037 (viper-get-ex-buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2039 (if (> beg end) (error viper-FirstAddrExceedsSecond))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2041 (viper-enlarge-region beg end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 (if (or ex-g-flag ex-g-variant)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 (error "Can't execute `yank' within `global'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (if ex-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (forward-line (1- ex-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (set-mark end))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2050 (viper-enlarge-region (point) (mark t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2051 (if ex-flag (error "`yank': %s" viper-SpuriousText))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (if ex-buffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2053 (cond ((viper-valid-register ex-buffer '(Letter))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2054 (viper-append-to-register
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 (downcase ex-buffer) (point) (mark t)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2056 ((viper-valid-register ex-buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (copy-to-register ex-buffer (point) (mark t) nil))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2058 (t (error viper-InvalidRegister ex-buffer))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (copy-region-as-kill (point) (mark t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 ;; Execute shell command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (defun ex-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (let (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2065 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2066 (set-buffer viper-ex-work-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (setq command (buffer-substring (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (setq command (ex-expand-filsyms command (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (if (and (> (length command) 0) (string= "!" (substring command 0 1)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2072 (if viper-ex-last-shell-com
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2073 (setq command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2074 (concat viper-ex-last-shell-com (substring command 1)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 (error "No previous shell command")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2076 (setq viper-ex-last-shell-com command)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (if (null ex-addresses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (shell-command command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (if (null beg) (setq beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (set-mark end)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2084 (viper-enlarge-region (point) (mark t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (shell-command-on-region (point) (mark t) command t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 (goto-char beg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 ;; Print line number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (defun ex-line-no ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 (message "%d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (1+ (count-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 (if (null ex-addresses) (point-max) (car ex-addresses))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 ;; Give information on the file visited by the current buffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2096 (defun viper-info-on-file ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2098 (let ((pos1 (viper-line-pos 'start))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2099 (pos2 (viper-line-pos 'end))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 lines file info)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2101 (setq lines (count-lines (point-min) (viper-line-pos 'end))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 file (if (buffer-file-name)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2103 (concat (viper-abbreviate-file-name (buffer-file-name)) ":")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 (concat (buffer-name) " [Not visiting any file]:"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 info (format "line=%d/%d pos=%d/%d col=%d %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 (if (= pos1 pos2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (1+ lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (count-lines (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 (point) (1- (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (1+ (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (if (buffer-modified-p) "[Modified]" "[Unchanged]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (if (< (+ 1 (length info) (length file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (window-width (minibuffer-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (message (concat file " " info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (save-window-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2117 (with-output-to-temp-buffer " *viper-info*"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (princ (concat "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 file "\n\n\t" info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 "\n\n\nPress any key to continue...\n\n")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2121 (viper-read-event)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2122 (kill-buffer " *viper-info*")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2125 ;; display all variables set through :set
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2126 (defun ex-show-vars ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2127 (with-output-to-temp-buffer " *viper-info*"
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2128 (princ (if viper-auto-indent
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2129 "autoindent (local)\n" "noautoindent (local)\n"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2130 (princ (if (default-value 'viper-auto-indent)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2131 "autoindent (global) \n" "noautoindent (global) \n"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2132 (princ (if viper-case-fold-search "ignorecase\n" "noignorecase\n"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2133 (princ (if viper-re-search "magic\n" "nomagic\n"))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2134 (princ (if buffer-read-only "readonly\n" "noreadonly\n"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2135 (princ (if blink-matching-paren "showmatch\n" "noshowmatch\n"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2136 (princ (if viper-search-wrap-around-t "wrapscan\n" "nowrapscan\n"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2137 (princ (format "shiftwidth \t\t= %S\n" viper-shift-width))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2138 (princ (format "tabstop (local) \t= %S\n" tab-width))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2139 (princ (format "tabstop (global) \t= %S\n" (default-value 'tab-width)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2140 (princ (format "wrapmargin (local) \t= %S\n"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2141 (- (window-width) fill-column)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2142 (princ (format "wrapmargin (global) \t= %S\n"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2143 (- (window-width) (default-value 'fill-column))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2144 (princ (format "shell \t\t\t= %S\n" (if (boundp 'explicit-shell-file-name)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2145 explicit-shell-file-name
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2146 'none)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2147 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2148
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2149
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2150
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 104
diff changeset
2151
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 ;;; viper-ex.el ends here