1 ;;; viper-ex.el --- functions implementing the Ex commands for Viper
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
27 (defvar read-file-name-map
)
28 (defvar viper-use-register
)
29 (defvar viper-s-string
)
30 (defvar viper-shift-width
)
31 (defvar viper-ex-history
)
32 (defvar viper-related-files-and-buffers-ring
)
33 (defvar viper-local-search-start-marker
)
34 (defvar viper-expert-level
)
35 (defvar viper-custom-file-name
)
36 (defvar viper-case-fold-search
)
37 (defvar explicit-shell-file-name
)
39 ;; loading happens only in non-interactive compilation
40 ;; in order to spare non-viperized emacs from being viperized
43 (let ((load-path (cons (expand-file-name ".") load-path
)))
44 (or (featurep 'viper-util
)
45 (load "viper-util.el" nil nil
'nosuffix
))
46 (or (featurep 'viper-keym
)
47 (load "viper-keym.el" nil nil
'nosuffix
))
48 (or (featurep 'viper-cmd
)
49 (load "viper-cmd.el" nil nil
'nosuffix
))
55 (defgroup viper-ex nil
56 "Viper support for Ex commands"
64 (defconst viper-ex-work-buf-name
" *ex-working-space*")
65 (defconst viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
66 (defconst viper-ex-tmp-buf-name
" *ex-tmp*")
69 ;;; Variable completion in :set command
71 ;; The list of Ex commands. Used for completing command names.
72 (defconst ex-token-alist
73 '(("!") ("=") (">") ("&") ("~")
74 ("yank") ("xit") ("WWrite") ("Write") ("write") ("wq") ("visual")
75 ("version") ("vglobal") ("unmap") ("undo") ("tag") ("transfer") ("suspend")
76 ("substitute") ("submitReport") ("stop") ("sr") ("source") ("shell")
77 ("set") ("rewind") ("recover") ("read") ("quit") ("pwd")
78 ("put") ("preserve") ("PreviousRelatedFile") ("RelatedFile")
79 ("next") ("Next") ("move") ("mark") ("map") ("kmark") ("join")
80 ("help") ("goto") ("global") ("file") ("edit") ("delete") ("copy")
81 ("chdir") ("cd") ("Buffer") ("buffer") ("args")) )
83 ;; A-list of Ex variables that can be set using the :set command.
84 (defconst ex-variable-alist
85 '(("wrapscan") ("ws") ("wrapmargin") ("wm")
86 ("tabstop-global") ("ts-g") ("tabstop") ("ts")
87 ("showmatch") ("sm") ("shiftwidth") ("sw") ("shell") ("sh")
89 ("nowrapscan") ("nows") ("noshowmatch") ("nosm")
90 ("noreadonly") ("noro") ("nomagic") ("noma")
91 ("noignorecase") ("noic")
92 ("noautoindent-global") ("noai-g") ("noautoindent") ("noai")
93 ("magic") ("ma") ("ignorecase") ("ic")
94 ("autoindent-global") ("ai-g") ("autoindent") ("ai")
100 ;; Token recognized during parsing of Ex commands (e.g., "read", "comma")
101 (defvar ex-token nil
)
104 ;; If non-nil, gives type of address; if nil, it is a command.
105 (defvar ex-token-type nil
)
107 ;; List of addresses passed to Ex command
108 (defvar ex-addresses nil
)
110 ;; This flag is supposed to be set only by `#', `print', and `list',
111 ;; none of which is implemented. So, it and the pices of the code it
112 ;; controls are dead weight. We keep it just in case this might be
113 ;; needed in the future.
116 ;; "buffer" where Ex commands keep deleted data.
117 ;; In Emacs terms, this is a register.
118 (defvar ex-buffer nil
)
120 ;; Value of ex count.
121 (defvar ex-count nil
)
123 ;; Flag indicating that :global Ex command is being executed.
124 (defvar ex-g-flag nil
)
125 ;; Flag indicating that :vglobal Ex command is being executed.
126 (defvar ex-g-variant nil
)
128 ;; Save reg-exp used in substitute.
129 (defvar ex-reg-exp nil
)
132 ;; Replace pattern for substitute.
135 ;; Pattern for global command.
136 (defvar ex-g-pat nil
)
138 (defcustom ex-unix-type-shell
139 (let ((case-fold-search t
))
140 (and (stringp shell-file-name
)
150 "[^a-z]sh$\\|[^a-z]sh.exe$"
155 "Is the user using a unix-type shell under a non-OS?"
159 (defcustom ex-unix-type-shell-options
160 (let ((case-fold-search t
))
161 (if ex-unix-type-shell
162 (cond ((string-match "\\(csh$\\|csh.exe$\\)" shell-file-name
)
163 "-f") ; csh: do it fast
164 ((string-match "\\(bash$\\|bash.exe$\\)" shell-file-name
)
165 "-noprofile") ; bash: ignore .profile
167 "Options to pass to the Unix-style shell.
168 Don't put `-c' here, as it is added automatically."
172 (defvar ex-nontrivial-find-file-function
173 (cond (ex-unix-type-shell 'viper-ex-nontrivial-find-file-unix
)
174 ((eq system-type
'emx
) 'viper-ex-nontrivial-find-file-ms
) ; OS/2
175 (viper-ms-style-os-p 'viper-ex-nontrivial-find-file-ms
) ; Microsoft OS
176 (viper-vms-os-p 'viper-ex-nontrivial-find-file-unix
) ; VMS
177 (t 'viper-ex-nontrivial-find-file-unix
) ; presumably UNIX
180 ;; Remembers the previous Ex tag.
183 ;; file used by Ex commands like :r, :w, :n
186 ;; If t, tells Ex that this is a variant-command, i.e., w>>, r!, etc.
187 (defvar ex-variant nil
)
189 ;; Specified the offset of an Ex command, such as :read.
190 (defvar ex-offset nil
)
192 ;; Tells Ex that this is a w>> command.
193 (defvar ex-append nil
)
195 ;; File containing the shell command to be executed at Ex prompt,
197 (defvar ex-cmdfile nil
)
198 (defvar ex-cmdfile-args
"")
200 ;; flag used in viper-ex-read-file-name to indicate that we may be reading
201 ;; multiple file names. Used for :edit and :next
202 (defvar viper-keep-reading-filename nil
)
204 (defcustom ex-cycle-other-window t
205 "*If t, :n and :b cycles through files and buffers in other window.
206 Then :N and :B cycles in the current window. If nil, this behavior is
211 (defcustom ex-cycle-through-non-files nil
212 "*Cycle through *scratch* and other buffers that don't visit any file."
216 ;; Last shell command executed with :! command.
217 (defvar viper-ex-last-shell-com nil
)
219 ;; Indicates if Minibuffer was exited temporarily in Ex-command.
220 (defvar viper-incomplete-ex-cmd nil
)
222 ;; Remembers the last ex-command prompt.
223 (defvar viper-last-ex-prompt
"")
228 ;; Check if ex-token is an initial segment of STR
229 (defun viper-check-sub (str)
230 (let ((length (length ex-token
)))
231 (if (and (<= length
(length str
))
232 (string= ex-token
(substring str
0 length
)))
234 (setq ex-token-type
'non-command
))))
236 ;; Get a complete ex command
237 (defun viper-get-ex-com-subr ()
238 (let (case-fold-search)
240 (re-search-forward "[a-zA-Z][a-zA-Z]*")
241 (setq ex-token-type
'command
)
242 (setq ex-token
(buffer-substring (point) (mark t
)))
243 (exchange-point-and-mark)
244 (cond ((looking-at "a")
245 (cond ((looking-at "ab") (viper-check-sub "abbreviate"))
246 ((looking-at "ar") (viper-check-sub "args"))
247 (t (viper-check-sub "append"))))
248 ((looking-at "h") (viper-check-sub "help"))
250 (cond ((looking-at "cd") (viper-check-sub "cd"))
251 ((looking-at "ch") (viper-check-sub "chdir"))
252 ((looking-at "co") (viper-check-sub "copy"))
253 (t (viper-check-sub "change"))))
254 ((looking-at "d") (viper-check-sub "delete"))
255 ((looking-at "b") (viper-check-sub "buffer"))
256 ((looking-at "B") (viper-check-sub "Buffer"))
258 (if (looking-at "ex") (viper-check-sub "ex")
259 (viper-check-sub "edit")))
260 ((looking-at "f") (viper-check-sub "file"))
261 ((looking-at "g") (viper-check-sub "global"))
262 ((looking-at "i") (viper-check-sub "insert"))
263 ((looking-at "j") (viper-check-sub "join"))
264 ((looking-at "l") (viper-check-sub "list"))
266 (cond ((looking-at "map") (viper-check-sub "map"))
267 ((looking-at "mar") (viper-check-sub "mark"))
268 (t (viper-check-sub "move"))))
269 ((looking-at "k[a-z][^a-z]")
270 (setq ex-token
"kmark")
272 (exchange-point-and-mark)) ; this is canceled out by another
273 ; exchange-point-and-mark at the end
274 ((looking-at "k") (viper-check-sub "kmark"))
275 ((looking-at "n") (if (looking-at "nu")
276 (viper-check-sub "number")
277 (viper-check-sub "next")))
278 ((looking-at "N") (viper-check-sub "Next"))
279 ((looking-at "o") (viper-check-sub "open"))
281 (cond ((looking-at "pre") (viper-check-sub "preserve"))
282 ((looking-at "pu") (viper-check-sub "put"))
283 ((looking-at "pw") (viper-check-sub "pwd"))
284 (t (viper-check-sub "print"))))
285 ((looking-at "P") (viper-check-sub "PreviousRelatedFile"))
286 ((looking-at "R") (viper-check-sub "RelatedFile"))
287 ((looking-at "q") (viper-check-sub "quit"))
289 (cond ((looking-at "rec") (viper-check-sub "recover"))
290 ((looking-at "rew") (viper-check-sub "rewind"))
291 (t (viper-check-sub "read"))))
293 (cond ((looking-at "se") (viper-check-sub "set"))
294 ((looking-at "sh") (viper-check-sub "shell"))
295 ((looking-at "so") (viper-check-sub "source"))
296 ((looking-at "sr") (viper-check-sub "sr"))
297 ((looking-at "st") (viper-check-sub "stop"))
298 ((looking-at "sus") (viper-check-sub "suspend"))
299 ((looking-at "subm") (viper-check-sub "submitReport"))
300 (t (viper-check-sub "substitute"))))
302 (if (looking-at "ta") (viper-check-sub "tag")
303 (viper-check-sub "transfer")))
305 (cond ((looking-at "una") (viper-check-sub "unabbreviate"))
306 ((looking-at "unm") (viper-check-sub "unmap"))
307 (t (viper-check-sub "undo"))))
309 (cond ((looking-at "ve") (viper-check-sub "version"))
310 ((looking-at "vi") (viper-check-sub "visual"))
311 (t (viper-check-sub "vglobal"))))
313 (if (looking-at "wq") (viper-check-sub "wq")
314 (viper-check-sub "write")))
316 (if (looking-at "WW")
317 (viper-check-sub "WWrite")
318 (viper-check-sub "Write")))
319 ((looking-at "x") (viper-check-sub "xit"))
320 ((looking-at "y") (viper-check-sub "yank"))
321 ((looking-at "z") (viper-check-sub "z")))
322 (exchange-point-and-mark)
325 ;; Get an ex-token which is either an address or a command.
326 ;; A token has a type, \(command, address, end-mark\), and a value
327 (defun viper-get-ex-token ()
328 (save-window-excursion
329 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
330 (set-buffer viper-ex-work-buf
)
331 (skip-chars-forward " \t|")
332 (let ((case-fold-search t
))
333 (cond ((looking-at "#")
334 (setq ex-token-type
'command
)
335 (setq ex-token
(char-to-string (following-char)))
337 ((looking-at "[a-z]") (viper-get-ex-com-subr))
340 (setq ex-token-type
'dot
))
341 ((looking-at "[0-9]")
343 (re-search-forward "[0-9]*")
345 (cond ((eq ex-token-type
'plus
) 'add-number
)
346 ((eq ex-token-type
'minus
) 'sub-number
)
349 (string-to-int (buffer-substring (point) (mark t
)))))
352 (setq ex-token-type
'end
))
355 (setq ex-token-type
'whole
))
357 (cond ((or (looking-at "+[-+]") (looking-at "+[\n|]"))
361 (setq ex-token-type
'plus
))
362 ((looking-at "+[0-9]")
364 (setq ex-token-type
'plus
))
366 (error viper-BadAddress
))))
368 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]"))
372 (setq ex-token-type
'minus
))
373 ((looking-at "-[0-9]")
375 (setq ex-token-type
'minus
))
377 (error viper-BadAddress
))))
382 (while (and (not (eolp)) cont
)
383 ;;(re-search-forward "[^/]*/")
384 (re-search-forward "[^/]*\\(/\\|\n\\)")
385 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"))
388 (setq ex-token
(buffer-substring (point) (mark t
)))
389 (if (looking-at "/") (forward-char 1))
390 (setq ex-token-type
'search-forward
))
395 (while (and (not (eolp)) cont
)
396 ;;(re-search-forward "[^\\?]*\\?")
397 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)")
398 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?"))
401 (if (not (looking-at "\n")) (forward-char 1))))
402 (setq ex-token-type
'search-backward
)
403 (setq ex-token
(buffer-substring (1- (point)) (mark t
))))
406 (setq ex-token-type
'comma
))
409 (setq ex-token-type
'semi-colon
))
410 ((looking-at "[!=><&~]")
411 (setq ex-token-type
'command
)
412 (setq ex-token
(char-to-string (following-char)))
415 (setq ex-token-type
'goto-mark
)
417 (cond ((looking-at "'") (setq ex-token nil
))
418 ((looking-at "[a-z]") (setq ex-token
(following-char)))
419 (t (error "Marks are ' and a-z")))
422 (setq ex-token-type
'end-mark
)
423 (setq ex-token
"goto"))
425 (error viper-BadExCommand
))))))
427 ;; Reads Ex command. Tries to determine if it has to exit because command
428 ;; is complete or invalid. If not, keeps reading command.
429 (defun ex-cmd-read-exit ()
431 (setq viper-incomplete-ex-cmd t
)
432 (let ((quit-regex1 (concat
435 "\\|" "[nN]ext[ \t]*"
448 "\\|" "[ktgjmsz][ \t]*$"
450 "\\|" "tr[ansfer \t]*"
453 "\\|" "^[ \t]*k?ma[^p]*"
460 ;; don't jump up in :s command
461 "\\|" "^[ \t]*\\([`'][a-z]\\|[.,%]\\)*[ \t]*su.*"
462 "\\|" "^[ \t]*\\([`'][a-z]\\|[.,%]\\)*[ \t]*s[^a-z].*"
463 "\\|" "['`][a-z][ \t]*"
464 ;; r! assumes that the next one is a shell command
465 "\\|" "\\(r\\|re\\|rea\\|read\\)[ \t]*!"
466 ;; w ! assumes that the next one is a shell command
467 "\\|" "\\(w\\|wr\\|wri\\|writ.?\\)[ \t]+!"
468 "\\|" "![ \t]*[a-zA-Z].*"
472 (save-window-excursion ;; put cursor at the end of the Ex working buffer
473 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
474 (set-buffer viper-ex-work-buf
)
475 (goto-char (point-max)))
476 (cond ((viper-looking-back quit-regex1
) (exit-minibuffer))
477 ((viper-looking-back stay-regex
) (insert " "))
478 ((viper-looking-back quit-regex2
) (exit-minibuffer))
481 ;; complete Ex command
482 (defun ex-cmd-complete ()
484 (let (save-pos dist compl-list string-to-complete completion-result
)
487 (setq dist
(skip-chars-backward "[a-zA-Z!=>&~]")
491 (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
493 "^[ \t]*[a-zA-Z!=>&~][ \t]*[/?]*+[ \t]+[a-zA-Z!=>&~]+"))
494 ;; Preceding characters are not the ones allowed in an Ex command
495 ;; or we have typed past command name.
496 ;; Note: we didn't do parsing, so there may be surprises.
497 (if (or (viper-looking-back "[a-zA-Z!=>&~][ \t]*[/?]*[ \t]*")
498 (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
499 (looking-at "[^ \t\n\C-m]"))
501 (with-output-to-temp-buffer "*Completions*"
502 (display-completion-list
503 (viper-alist-to-list ex-token-alist
))))
504 ;; Preceding chars may be part of a command name
505 (setq string-to-complete
(buffer-substring save-pos
(point)))
506 (setq completion-result
507 (try-completion string-to-complete ex-token-alist
))
509 (cond ((eq completion-result t
) ; exact match--do nothing
510 (viper-tmp-insert-at-eob " (Sole completion)"))
511 ((eq completion-result nil
)
512 (viper-tmp-insert-at-eob " (No match)"))
513 (t ;; partial completion
515 (delete-region (point) (point-max))
516 (insert completion-result
)
517 (let (case-fold-search)
519 (viper-filter-alist (concat "^" completion-result
)
521 (if (> (length compl-list
) 1)
522 (with-output-to-temp-buffer "*Completions*"
523 (display-completion-list
524 (viper-alist-to-list (reverse compl-list
)))))))
529 (defun viper-ex (arg &optional string
)
534 (let* ((map (copy-keymap minibuffer-local-map
))
538 reg-beg-line reg-end-line
541 prev-token-type com-str
)
542 (viper-add-keymap viper-ex-cmd-map map
)
546 (viper-enlarge-region (mark t
) (point))
547 (if (> (point) (mark t
))
548 (setq reg-beg
(mark t
)
550 (setq reg-end
(mark t
)
554 (setq reg-beg-line
(1+ (count-lines (point-min) (point)))
556 (+ reg-beg-line
(count-lines reg-beg reg-end
) -
1)))))
558 (setq initial-str
(format "%d,%d" reg-beg-line reg-end-line
)))
561 (or string
(viper-read-string-with-history
565 ;; no default when working on region
568 (car viper-ex-history
))
571 " [Type command to execute on current region]"))))
572 (save-window-excursion
574 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
575 (set-buffer viper-ex-work-buf
)
576 (delete-region (point-min) (point-max))
577 (insert com-str
"\n")
578 (goto-char (point-min)))
579 (setq ex-token-type nil
583 (cond ((memq ex-token-type
'(command end-mark
))
584 (if address
(setq ex-addresses
(cons address ex-addresses
)))
585 (cond ((string= ex-token
"global")
588 ((string= ex-token
"vglobal")
592 (viper-execute-ex-command)
593 (save-window-excursion
594 (setq viper-ex-work-buf
595 (get-buffer-create viper-ex-work-buf-name
))
596 (set-buffer viper-ex-work-buf
)
597 (skip-chars-forward " \t")
598 (cond ((looking-at "|")
602 (t (error "`%s': %s" ex-token viper-SpuriousText
)))
605 ((eq ex-token-type
'non-command
)
606 (error "`%s': %s" ex-token viper-BadExCommand
))
607 ((eq ex-token-type
'whole
)
611 (cons (point-max) ex-addresses
)
612 (cons (point-max) (cons (point-min) ex-addresses
)))))
613 ((eq ex-token-type
'comma
)
614 (if (eq prev-token-type
'whole
)
615 (setq address
(point-min)))
617 (cons (if (null address
) (point) address
) ex-addresses
)))
618 ((eq ex-token-type
'semi-colon
)
619 (if (eq prev-token-type
'whole
)
620 (setq address
(point-min)))
621 (if address
(setq dot address
))
623 (cons (if (null address
) (point) address
) ex-addresses
)))
624 (t (let ((ans (viper-get-ex-address-subr address dot
)))
625 (if ans
(setq address ans
)))))
626 (setq prev-token-type ex-token-type
))))
629 ;; Get a regular expression and set `ex-variant', if found
630 (defun viper-get-ex-pat ()
631 (save-window-excursion
632 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
633 (set-buffer viper-ex-work-buf
)
634 (skip-chars-forward " \t")
636 ;; this is probably a variant command r!
638 (setq ex-g-variant
(not ex-g-variant
)
639 ex-g-flag
(not ex-g-flag
))
641 (skip-chars-forward " \t")))
642 (let ((c (following-char)))
643 (cond ((string-match "[0-9A-Za-z]" (format "%c" c
))
645 "Global regexp must be inside matching non-alphanumeric chars"))
646 ((= c ??
) (error "`?' is not an allowed pattern delimiter here")))
647 (if (looking-at "[^\\\\\n]")
652 ;; the use of eobp instead of eolp permits the use of newlines in
653 ;; pat2 in s/pat1/pat2/
654 (while (and (not (eobp)) cont
)
655 (if (not (re-search-forward (format "[^%c]*%c" c c
) nil t
))
656 (if (member ex-token
'("global" "vglobal"))
657 (error "Missing closing delimiter for global regexp")
658 (goto-char (point-max))))
659 (if (not (viper-looking-back
660 (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c
)))
662 ;; we are at an escaped delimiter: unescape it and continue
663 (delete-backward-char 2)
666 ;; if at eol, exit loop and go to next line
667 ;; later, delim will be inserted at the end
673 (if (= (mark t
) (point)) ""
674 (buffer-substring (1- (point)) (mark t
))))
676 ;; if the user didn't insert the final pattern delimiter, we're
677 ;; at newline now. In this case, insert the initial delimiter
678 ;; specified in variable c
688 (defun viper-get-ex-command ()
689 (save-window-excursion
690 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
691 (set-buffer viper-ex-work-buf
)
692 (if (looking-at "/") (forward-char 1))
693 (skip-chars-forward " \t")
694 (cond ((looking-at "[a-z]")
695 (viper-get-ex-com-subr)
696 (if (eq ex-token-type
'non-command
)
697 (error "`%s': %s" ex-token viper-BadExCommand
)))
698 ((looking-at "[!=><&~]")
699 (setq ex-token
(char-to-string (following-char)))
701 (t (error viper-BadExCommand
)))))
703 ;; Get an Ex option g or c
704 (defun viper-get-ex-opt-gc (c)
705 (save-window-excursion
706 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
707 (set-buffer viper-ex-work-buf
)
708 (if (looking-at (format "%c" c
)) (forward-char 1))
709 (skip-chars-forward " \t")
710 (cond ((looking-at "g")
720 ;; Compute default addresses. WHOLE-FLAG means use the whole buffer
721 (defun viper-default-ex-addresses (&optional whole-flag
)
722 (cond ((null ex-addresses
)
725 (list (point-max) (point-min))
726 (list (point) (point)))))
727 ((null (cdr ex-addresses
))
729 (cons (car ex-addresses
) ex-addresses
)))))
731 ;; Get an ex-address as a marker and set ex-flag if a flag is found
732 (defun viper-get-ex-address ()
733 (let ((address (point-marker))
739 (cond ((eq ex-token-type
'command
)
740 (if (member ex-token
'("print" "list" "#"))
744 (error "Address expected in this Ex command")))
745 ((eq ex-token-type
'end-mark
)
747 ((eq ex-token-type
'whole
)
748 (error "Trailing address expected"))
749 ((eq ex-token-type
'comma
)
750 (error "`%s': %s" ex-token viper-SpuriousText
))
751 (t (let ((ans (viper-get-ex-address-subr address
(point-marker))))
752 (if ans
(setq address ans
))))))
755 ;; Returns an address as a point
756 (defun viper-get-ex-address-subr (old-address dot
)
758 (if (null old-address
) (setq old-address dot
))
759 (cond ((eq ex-token-type
'dot
)
761 ((eq ex-token-type
'add-number
)
763 (goto-char old-address
)
764 (forward-line (if (= old-address
0) (1- ex-token
) ex-token
))
765 (setq address
(point-marker))))
766 ((eq ex-token-type
'sub-number
)
768 (goto-char old-address
)
769 (forward-line (- ex-token
))
770 (setq address
(point-marker))))
771 ((eq ex-token-type
'abs-number
)
773 (goto-char (point-min))
774 (if (= ex-token
0) (setq address
0)
775 (forward-line (1- ex-token
))
776 (setq address
(point-marker)))))
777 ((eq ex-token-type
'end
)
778 (setq address
(point-max-marker)))
779 ((eq ex-token-type
'plus
) t
) ; do nothing
780 ((eq ex-token-type
'minus
) t
) ; do nothing
781 ((eq ex-token-type
'search-forward
)
783 (ex-search-address t
)
784 (setq address
(point-marker))))
785 ((eq ex-token-type
'search-backward
)
787 (ex-search-address nil
)
788 (setq address
(point-marker))))
789 ((eq ex-token-type
'goto-mark
)
792 (exchange-point-and-mark)
793 (goto-char (viper-register-to-point
794 (1+ (- ex-token ?a
)) 'enforce-buffer
)))
795 (setq address
(point-marker)))))
799 ;; Search pattern and set address
800 (defun ex-search-address (forward)
801 (if (string= ex-token
"")
802 (if (null viper-s-string
)
803 (error viper-NoPrevSearch
)
804 (setq ex-token viper-s-string
))
805 (setq viper-s-string ex-token
))
809 (re-search-forward ex-token
))
811 (re-search-backward ex-token
)))
813 ;; Get a buffer name and set `ex-count' and `ex-flag' if found
814 (defun viper-get-ex-buffer ()
818 (save-window-excursion
819 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
820 (set-buffer viper-ex-work-buf
)
821 (skip-chars-forward " \t")
822 (if (looking-at "[a-zA-Z]")
824 (setq ex-buffer
(following-char))
826 (skip-chars-forward " \t")))
827 (if (looking-at "[0-9]")
830 (re-search-forward "[0-9][0-9]*")
831 (setq ex-count
(string-to-int (buffer-substring (point) (mark t
))))
832 (skip-chars-forward " \t")))
833 (if (looking-at "[pl#]")
837 (if (not (looking-at "[\n|]"))
838 (error "`%s': %s" ex-token viper-SpuriousText
))))
840 (defun viper-get-ex-count ()
844 (save-window-excursion
845 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
846 (set-buffer viper-ex-work-buf
)
847 (skip-chars-forward " \t")
852 (skip-chars-forward " \t")
853 (if (looking-at "[0-9]")
856 (re-search-forward "[0-9][0-9]*")
857 (setq ex-count
(string-to-int (buffer-substring (point) (mark t
))))
858 (skip-chars-forward " \t")))
859 (if (looking-at "[pl#]")
863 (if (not (looking-at "[\n|]"))
866 (point-min) (1- (point-max))) viper-BadExCommand
))))
868 ;; Expand \% and \# in ex command
869 (defun ex-expand-filsyms (cmd buf
)
873 (setq cf buffer-file-name
)
874 (setq pf
(ex-next nil t
))) ; this finds alternative file name
875 (if (and (null cf
) (string-match "[^\\]%\\|\\`%" cmd
))
876 (error "No current file to substitute for `%%'"))
877 (if (and (null pf
) (string-match "[^\\]#\\|\\`#" cmd
))
878 (error "No alternate file to substitute for `#'"))
880 (set-buffer (get-buffer-create viper-ex-tmp-buf-name
))
883 (goto-char (point-min))
884 (while (re-search-forward "%\\|#" nil t
)
885 (let ((data (match-data))
886 (char (buffer-substring (match-beginning 0) (match-end 0))))
887 (if (viper-looking-back (concat "\\\\" char
))
889 (store-match-data data
)
890 (if (string= char
"%")
892 (replace-match pf
)))))
894 (setq ret
(buffer-substring (point-min) (point)))
898 ;; Get a file name and set `ex-variant', `ex-append' and `ex-offset' if found
899 ;; If it is r!, then get the command name and whatever args
900 (defun viper-get-ex-file ()
909 (save-window-excursion
910 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
911 (set-buffer viper-ex-work-buf
)
912 (skip-chars-forward " \t")
914 (if (and (not (viper-looking-back "[ \t]"))
915 ;; read doesn't have a corresponding :r! form, so ! is
916 ;; immediately interpreted as a shell command.
917 (not (string= ex-token
"read")))
921 (skip-chars-forward " \t"))
924 (skip-chars-forward " \t")))
925 (if (looking-at ">>")
930 (skip-chars-forward " \t")))
935 (re-search-forward "[ \t\n]")
937 (setq ex-offset
(buffer-substring (point) (mark t
)))
939 (skip-chars-forward " \t")))
940 ;; this takes care of :r, :w, etc., when they get file names
941 ;; from the history list
942 (if (member ex-token
'("read" "write" "edit" "visual" "next"))
944 (setq ex-file
(buffer-substring (point) (1- (point-max))))
946 ;; For :e, match multiple non-white strings separated
947 ;; by white. For others, find the first non-white string
949 (if (string= ex-token
"edit")
950 "[^ \t\n]+\\([ \t]+[^ \t\n]+\\)*"
954 ;; if file name comes from history, don't leave
955 ;; minibuffer when the user types space
956 (setq viper-incomplete-ex-cmd nil
)
957 (setq ex-cmdfile-args
958 (substring ex-file
(match-end 0) nil
))
959 ;; this must be the last clause in this progn
960 (substring ex-file
(match-beginning 0) (match-end 0))
963 ;; this leaves only the command name in the work area
964 ;; file names are gone
965 (delete-region (point) (1- (point-max)))
967 (goto-char (point-max))
968 (skip-chars-backward " \t\n")
969 (setq prompt
(buffer-substring (point-min) (point)))
972 (setq viper-last-ex-prompt prompt
)
974 ;; If we just finished reading command, redisplay prompt
975 (if viper-incomplete-ex-cmd
976 (setq ex-file
(viper-ex-read-file-name (format ":%s " prompt
)))
977 ;; file was typed in-line
978 (setq ex-file
(or ex-file
"")))
982 ;; Completes file name or exits minibuffer. If Ex command accepts multiple
983 ;; file names, arranges to re-enter the minibuffer.
984 (defun viper-complete-filename-or-exit ()
986 (setq viper-keep-reading-filename t
)
987 ;; don't exit if directory---ex-commands don't
988 (cond ((ex-cmd-accepts-multiple-files-p ex-token
) (exit-minibuffer))
989 ;; apparently the argument to an Ex command is
990 ;; supposed to be a shell command
991 ((viper-looking-back "^[ \t]*!.*")
995 (setq ex-cmdfile nil
)
996 (minibuffer-complete-word))))
998 (defun viper-handle-! ()
1001 (buffer-string) (viper-abbreviate-file-name default-directory
))
1002 (member ex-token
'("read" "write")))
1006 (defun ex-cmd-accepts-multiple-files-p (token)
1007 (member token
'("edit" "next" "Next")))
1009 ;; Read file name from the minibuffer in an ex command.
1010 ;; If user doesn't enter anything, then "" is returned, i.e., the
1011 ;; prompt-directory is not returned.
1012 (defun viper-ex-read-file-name (prompt)
1014 (minibuffer-local-completion-map
1015 (copy-keymap minibuffer-local-completion-map
))
1018 (viper-add-keymap ex-read-filename-map
1020 minibuffer-local-completion-map
1021 read-file-name-map
))
1023 (setq cont
(setq viper-keep-reading-filename t
))
1025 (setq viper-keep-reading-filename nil
1026 val
(read-file-name (concat prompt str
) nil default-directory
))
1027 (setq val
(expand-file-name val
))
1028 (if (and (string-match " " val
)
1029 (ex-cmd-accepts-multiple-files-p ex-token
))
1030 (setq val
(concat "\"" val
"\"")))
1031 (setq str
(concat str
(if (equal val
"") "" " ")
1032 val
(if (equal val
"") "" " ")))
1034 ;; Only edit, next, and Next commands accept multiple files.
1035 ;; viper-keep-reading-filename is set in the anonymous function that is
1036 ;; bound to " " in ex-read-filename-map.
1037 (setq cont
(and viper-keep-reading-filename
1038 (ex-cmd-accepts-multiple-files-p ex-token
)))
1041 (setq beg
(string-match "[^ \t]" str
) ; delete leading blanks
1042 end
(string-match "[ \t]*$" str
)) ; delete trailing blanks
1043 (if (member ex-token
'("read" "write"))
1044 (if (string-match "[\t ]*!" str
)
1045 ;; this is actually a shell command
1049 (setq viper-last-ex-prompt
1050 (concat viper-last-ex-prompt
" !")))))
1051 (substring str
(or beg
0) end
)))
1053 ;; Execute ex command using the value of addresses
1054 (defun viper-execute-ex-command ()
1055 (viper-deactivate-mark)
1056 (cond ((string= ex-token
"args") (ex-args))
1057 ((string= ex-token
"copy") (ex-copy nil
))
1058 ((string= ex-token
"cd") (ex-cd))
1059 ((string= ex-token
"chdir") (ex-cd))
1060 ((string= ex-token
"delete") (ex-delete))
1061 ((string= ex-token
"edit") (ex-edit))
1062 ((string= ex-token
"file") (viper-info-on-file))
1063 ((string= ex-token
"goto") (ex-goto))
1064 ((string= ex-token
"help") (ex-help))
1065 ((string= ex-token
"join") (ex-line "join"))
1066 ((string= ex-token
"kmark") (ex-mark))
1067 ((string= ex-token
"mark") (ex-mark))
1068 ((string= ex-token
"map") (ex-map))
1069 ((string= ex-token
"move") (ex-copy t
))
1070 ((string= ex-token
"next") (ex-next ex-cycle-other-window
))
1071 ((string= ex-token
"Next") (ex-next (not ex-cycle-other-window
)))
1072 ((string= ex-token
"RelatedFile") (ex-next-related-buffer 1))
1073 ((string= ex-token
"put") (ex-put))
1074 ((string= ex-token
"pwd") (ex-pwd))
1075 ((string= ex-token
"preserve") (ex-preserve))
1076 ((string= ex-token
"PreviousRelatedFile") (ex-next-related-buffer -
1))
1077 ((string= ex-token
"quit") (ex-quit))
1078 ((string= ex-token
"read") (ex-read))
1079 ((string= ex-token
"recover") (ex-recover))
1080 ((string= ex-token
"rewind") (ex-rewind))
1081 ((string= ex-token
"submitReport") (viper-submit-report))
1082 ((string= ex-token
"set") (ex-set))
1083 ((string= ex-token
"shell") (ex-shell))
1084 ((string= ex-token
"source") (ex-source))
1085 ((string= ex-token
"sr") (ex-substitute t t
))
1086 ((string= ex-token
"substitute") (ex-substitute))
1087 ((string= ex-token
"suspend") (suspend-emacs))
1088 ((string= ex-token
"stop") (suspend-emacs))
1089 ((string= ex-token
"transfer") (ex-copy nil
))
1090 ((string= ex-token
"buffer") (if ex-cycle-other-window
1091 (viper-switch-to-buffer-other-window)
1092 (viper-switch-to-buffer)))
1093 ((string= ex-token
"Buffer") (if ex-cycle-other-window
1094 (viper-switch-to-buffer)
1095 (viper-switch-to-buffer-other-window)))
1096 ((string= ex-token
"tag") (ex-tag))
1097 ((string= ex-token
"undo") (viper-undo))
1098 ((string= ex-token
"unmap") (ex-unmap))
1099 ((string= ex-token
"version") (viper-version))
1100 ((string= ex-token
"visual") (ex-edit))
1101 ((string= ex-token
"write") (ex-write nil
))
1102 ((string= ex-token
"Write") (save-some-buffers))
1103 ((string= ex-token
"wq") (ex-write t
))
1104 ((string= ex-token
"WWrite") (save-some-buffers t
)) ; don't ask
1105 ((string= ex-token
"xit") (ex-write t
))
1106 ((string= ex-token
"yank") (ex-yank))
1107 ((string= ex-token
"!") (ex-command))
1108 ((string= ex-token
"=") (ex-line-no))
1109 ((string= ex-token
">") (ex-line "right"))
1110 ((string= ex-token
"<") (ex-line "left"))
1111 ((string= ex-token
"&") (ex-substitute t
))
1112 ((string= ex-token
"~") (ex-substitute t t
))
1113 ((or (string= ex-token
"append")
1114 (string= ex-token
"change")
1115 (string= ex-token
"insert")
1116 (string= ex-token
"open"))
1117 (error "`%s': Obsolete command, not supported by Viper" ex-token
))
1118 ((or (string= ex-token
"abbreviate")
1119 (string= ex-token
"unabbreviate"))
1121 "`%s': Vi abbrevs are obsolete. Use the more powerful Emacs abbrevs"
1123 ((or (string= ex-token
"list")
1124 (string= ex-token
"print")
1125 (string= ex-token
"z")
1126 (string= ex-token
"#"))
1127 (error "`%s': Command not implemented in Viper" ex-token
))
1128 (t (error "`%s': %s" ex-token viper-BadExCommand
))))
1130 (defun viper-undisplayed-files ()
1134 (if (null (get-buffer-window b
))
1135 (let ((f (buffer-file-name b
)))
1137 (if ex-cycle-through-non-files
1138 (let ((s (buffer-name b
)))
1139 (if (string= " " (substring s
0 1))
1148 (let ((l (viper-undisplayed-files))
1151 (while (not (null l
))
1153 (setq args
(format "%s %d) %s\n" args file-count
(car l
))
1154 file-count
(1+ file-count
)))
1156 (if (string= args
"")
1157 (message "All files are already displayed")
1159 (save-window-excursion
1160 (with-output-to-temp-buffer " *viper-info*"
1161 (princ "\n\nThese files are not displayed in any window.\n")
1162 (princ "\n=============\n")
1164 (princ "\n=============\n")
1165 (princ "\nThe numbers can be given as counts to :next. ")
1166 (princ "\n\nPress any key to continue...\n\n"))
1167 (viper-read-event))))))
1169 ;; Ex cd command. Default directory of this buffer changes
1172 (if (string= ex-file
"")
1174 (setq default-directory
(file-name-as-directory (expand-file-name ex-file
))))
1176 ;; Ex copy and move command. DEL-FLAG means delete
1177 (defun ex-copy (del-flag)
1178 (viper-default-ex-addresses)
1179 (let ((address (viper-get-ex-address))
1180 (end (car ex-addresses
)) (beg (car (cdr ex-addresses
))))
1184 (viper-enlarge-region (mark t
) (point))
1186 (kill-region (point) (mark t
))
1187 (copy-region-as-kill (point) (mark t
)))
1190 (with-output-to-temp-buffer " *copy text*"
1192 (if (or del-flag ex-g-flag ex-g-variant
)
1194 (buffer-substring (point) (mark t
)))))
1197 (read-string "[Hit return to confirm] ")
1198 (save-excursion (kill-buffer " *copy text*")))
1199 (quit (save-excursion (kill-buffer " *copy text*"))
1200 (signal 'quit nil
))))))
1202 (goto-char (point-min))
1205 (insert (current-kill 0))))
1207 ;; Ex delete command
1209 (viper-default-ex-addresses)
1210 (viper-get-ex-buffer)
1211 (let ((end (car ex-addresses
)) (beg (car (cdr ex-addresses
))))
1212 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
1214 (viper-enlarge-region beg end
)
1215 (exchange-point-and-mark)
1219 (forward-line (1- ex-count
)))
1221 (viper-enlarge-region (point) (mark t
))
1223 ;; show text to be deleted and ask for confirmation
1225 (with-output-to-temp-buffer " *delete text*"
1226 (princ (buffer-substring (point) (mark t
))))
1228 (read-string "[Hit return to confirm] ")
1230 (save-excursion (kill-buffer " *delete text*"))
1232 (save-excursion (kill-buffer " *delete text*")))
1234 (cond ((viper-valid-register ex-buffer
'(Letter))
1235 (viper-append-to-register
1236 (downcase ex-buffer
) (point) (mark t
)))
1237 ((viper-valid-register ex-buffer
)
1238 (copy-to-register ex-buffer
(point) (mark t
) nil
))
1239 (t (error viper-InvalidRegister ex-buffer
))))
1240 (kill-region (point) (mark t
))))))
1245 ;; In Viper, `e' and `e!' behave identically. In both cases, the user is
1246 ;; asked if current buffer should really be discarded.
1247 ;; This command can take multiple file names. It replaces the current buffer
1248 ;; with the first file in its argument list
1249 (defun ex-edit (&optional file
)
1251 (viper-get-ex-file))
1252 (cond ((and (string= ex-file
"") buffer-file-name
)
1253 (setq ex-file
(viper-abbreviate-file-name (buffer-file-name))))
1254 ((string= ex-file
"")
1255 (error viper-NoFileSpecified
)))
1257 ;;; (let (msg do-edit)
1258 ;;; (if buffer-file-name
1259 ;;; (cond ((buffer-modified-p)
1261 ;;; (format "Buffer %s is modified. Discard changes? "
1264 ;;; ((not (verify-visited-file-modtime (current-buffer)))
1266 ;;; (format "File %s changed on disk. Reread from disk? "
1267 ;;; buffer-file-name)
1269 ;;; (t (setq do-edit nil))))
1272 ;;; (if (yes-or-no-p msg)
1274 ;;; (set-buffer-modified-p nil)
1275 ;;; (kill-buffer (current-buffer)))
1276 ;;; (message "Buffer %s was left intact" (buffer-name))))
1279 (if (null (setq file
(get-file-buffer ex-file
)))
1281 (ex-find-file ex-file
)
1282 (or (eq major-mode
'dired-mode
)
1283 (viper-change-state-to-vi))
1284 (goto-char (point-min)))
1285 (switch-to-buffer file
))
1288 (save-window-excursion
1289 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1290 (set-buffer viper-ex-work-buf
)
1291 (delete-region (point-min) (point-max))
1292 (insert ex-offset
"\n")
1293 (goto-char (point-min)))
1294 (goto-char (viper-get-ex-address))
1295 (beginning-of-line)))
1296 (ex-fixup-history viper-last-ex-prompt ex-file
))
1298 ;; Find-file FILESPEC if it appears to specify a single file.
1299 ;; Otherwise, assume that FILESPEC is a wildcard.
1300 ;; In this case, split it into substrings separated by newlines.
1301 ;; Each line is assumed to be a file name. find-file's each file thus obtained.
1302 (defun ex-find-file (filespec)
1303 (let ((nonstandard-filename-chars "[^-a-zA-Z0-9_./,~$\\]"))
1304 (cond ((file-exists-p filespec
) (find-file filespec
))
1305 ((string-match nonstandard-filename-chars filespec
)
1306 (funcall ex-nontrivial-find-file-function filespec
))
1307 (t (find-file filespec
)))
1311 ;; Ex global command
1312 ;; This is executed in response to:
1313 ;; :global "pattern" ex-command
1314 ;; :vglobal "pattern" ex-command
1315 ;; :global executes ex-command on all lines matching <pattern>
1316 ;; :vglobal executes ex-command on all lines that don't match <pattern>
1318 ;; With VARIANT nil, this functions executes :global
1319 ;; With VARIANT t, executes :vglobal
1320 (defun ex-global (variant)
1321 (let ((gcommand ex-token
))
1322 (if (or ex-g-flag ex-g-variant
)
1323 (error "`%s' within `global' is not allowed" gcommand
)
1331 (error "`%s': Missing regular expression" gcommand
)))
1333 (if (string= ex-token
"")
1334 (if (null viper-s-string
)
1335 (error viper-NoPrevSearch
)
1336 (setq ex-g-pat viper-s-string
))
1337 (setq ex-g-pat ex-token
1338 viper-s-string ex-token
))
1339 (if (null ex-addresses
)
1340 (setq ex-addresses
(list (point-max) (point-min)))
1341 (viper-default-ex-addresses))
1344 (end (car ex-addresses
))
1345 (beg (car (cdr ex-addresses
)))
1347 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
1349 (viper-enlarge-region beg end
)
1350 (exchange-point-and-mark)
1351 (let ((cont t
) (limit (point-marker)))
1352 (exchange-point-and-mark)
1353 ;; skip the last line if empty
1355 (if (eobp) (viper-backward-char-carefully))
1356 (while (and cont
(not (bobp)) (>= (point) limit
))
1360 (let ((found (re-search-backward ex-g-pat
(mark t
) t
)))
1361 (if (or (and ex-g-flag found
)
1362 (and ex-g-variant
(not found
)))
1365 (setq mark-count
(1+ mark-count
))
1366 (setq marks
(cons (point-marker) marks
)))))
1368 (if (bobp) (setq cont nil
)
1371 (save-window-excursion
1372 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1373 (set-buffer viper-ex-work-buf
)
1374 (setq com-str
(buffer-substring (1+ (point)) (1- (point-max)))))
1376 (goto-char (car marks
))
1378 (setq mark-count
(1- mark-count
))
1379 (setq marks
(cdr marks
)))))
1383 (if (null ex-addresses
)
1384 (setq ex-addresses
(cons (point) nil
)))
1385 (push-mark (point) t
)
1386 (goto-char (car ex-addresses
))
1387 (beginning-of-line))
1389 ;; Ex line commands. COM is join, shift-right or shift-left
1390 (defun ex-line (com)
1391 (viper-default-ex-addresses)
1392 (viper-get-ex-count)
1393 (let ((end (car ex-addresses
)) (beg (car (cdr ex-addresses
))) point
)
1394 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
1396 (viper-enlarge-region beg end
)
1397 (exchange-point-and-mark)
1401 (forward-line ex-count
)))
1403 ;; show text to be joined and ask for confirmation
1405 (with-output-to-temp-buffer " *join text*"
1406 (princ (buffer-substring (point) (mark t
))))
1409 (read-string "[Hit return to confirm] ")
1410 (ex-line-subr com
(point) (mark t
)))
1412 (save-excursion (kill-buffer " *join text*")))
1413 (ex-line-subr com
(point) (mark t
)))
1414 (setq point
(point)))
1415 (goto-char (1- point
))
1416 (beginning-of-line)))
1418 (defun ex-line-subr (com beg end
)
1419 (cond ((string= com
"join")
1420 (goto-char (min beg end
))
1421 (while (and (not (eobp)) (< (point) (max beg end
)))
1423 (if (and (<= (point) (max beg end
)) (not (eobp)))
1426 (delete-region (point) (1- (point)))
1427 (if (not ex-variant
) (fixup-whitespace))))))
1428 ((or (string= com
"right") (string= com
"left"))
1430 (min beg end
) (max beg end
)
1431 (if (string= com
"right") viper-shift-width
(- viper-shift-width
)))
1432 (goto-char (max beg end
))
1434 (viper-forward-char-carefully))))
1440 (if (null ex-addresses
)
1442 (cons (point) nil
)))
1443 (save-window-excursion
1444 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1445 (set-buffer viper-ex-work-buf
)
1446 (skip-chars-forward " \t")
1447 (if (looking-at "[a-z]")
1449 (setq char
(following-char))
1451 (skip-chars-forward " \t")
1452 (if (not (looking-at "[\n|]"))
1453 (error "`%s': %s" ex-token viper-SpuriousText
)))
1454 (error "`%s' requires a following letter" ex-token
)))
1456 (goto-char (car ex-addresses
))
1457 (point-to-register (1+ (- char ?a
))))))
1461 ;; Alternate file is the file next to the first one in the buffer ring
1462 (defun ex-next (cycle-other-window &optional find-alt-file
)
1465 (if (not find-alt-file
)
1468 (if (or (char-or-string-p ex-offset
)
1469 (and (not (string= "" ex-file
))
1470 (not (string-match "^[0-9]+$" ex-file
))))
1473 (throw 'ex-edit nil
))
1474 (setq count
(string-to-int ex-file
))
1475 (if (= count
0) (setq count
1))
1476 (if (< count
0) (error "Usage: `next <count>' (count >= 0)"))))
1478 (setq l
(viper-undisplayed-files))
1480 (while (and (not (null l
)) (null (car l
)))
1482 (setq count
(1- count
))
1485 (if find-alt-file
(car l
)
1487 (if (and (car l
) (get-file-buffer (car l
)))
1488 (let* ((w (if cycle-other-window
1489 (get-lru-window) (selected-window)))
1490 (b (window-buffer w
)))
1491 (set-window-buffer w
(get-file-buffer (car l
)))
1493 ;; this puts "next <count>" in the ex-command history
1494 (ex-fixup-history viper-last-ex-prompt ex-file
))
1495 (error "Not that many undisplayed files")))))))
1498 (defun ex-next-related-buffer (direction &optional no-recursion
)
1500 (viper-ring-rotate1 viper-related-files-and-buffers-ring direction
)
1502 (let ((file-or-buffer-name
1503 (viper-current-ring-item viper-related-files-and-buffers-ring
))
1504 (old-ring viper-related-files-and-buffers-ring
)
1505 (old-win (selected-window))
1508 (or (and (ring-p viper-related-files-and-buffers-ring
)
1509 (> (ring-length viper-related-files-and-buffers-ring
) 0))
1510 (error "This buffer has no related files or buffers"))
1512 (or (stringp file-or-buffer-name
)
1514 "File and buffer names must be strings, %S" file-or-buffer-name
))
1516 (setq buf
(cond ((get-buffer file-or-buffer-name
))
1517 ((file-exists-p file-or-buffer-name
)
1518 (find-file-noselect file-or-buffer-name
))
1521 (if (not (viper-buffer-live-p buf
))
1522 (error "Didn't find buffer %S or file %S"
1524 (viper-abbreviate-file-name
1525 (expand-file-name file-or-buffer-name
))))
1527 (if (equal buf
(current-buffer))
1532 (ex-next-related-buffer direction
'norecursion
))))
1537 (if (setq wind
(viper-get-visible-buffer-window buf
))
1539 (setq wind
(get-lru-window (if viper-xemacs-p nil
'visible
)))
1540 (set-window-buffer wind buf
))
1542 (if (viper-window-display-p)
1544 (raise-frame (window-frame wind
))
1545 (if (equal (window-frame wind
) (window-frame old-win
))
1546 (save-window-excursion (select-window wind
) (sit-for 1))
1547 (select-window wind
)))
1548 (save-window-excursion (select-window wind
) (sit-for 1)))
1552 (setq viper-related-files-and-buffers-ring old-ring
))
1554 (setq viper-local-search-start-marker
(point-marker))
1559 (defun ex-preserve ()
1560 (message "Autosaving all buffers that need to be saved...")
1565 (let ((point (if (null ex-addresses
) (point) (car ex-addresses
))))
1566 (viper-get-ex-buffer)
1567 (setq viper-use-register ex-buffer
)
1569 (if (bobp) (viper-Put-back 1) (viper-put-back 1))))
1571 ;; Ex print working directory
1573 (message default-directory
))
1577 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc.
1579 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1580 (set-buffer viper-ex-work-buf
)
1581 (if (looking-at "!") (forward-char 1)))
1582 (if (< viper-expert-level
3)
1583 (save-buffers-kill-emacs)
1584 (kill-buffer (current-buffer))))
1590 (let ((point (if (null ex-addresses
) (point) (car ex-addresses
)))
1593 (viper-add-newline-at-eob-if-necessary)
1594 (if (not (or (bobp) (eobp))) (forward-line 1))
1595 (if (and (not ex-variant
) (string= ex-file
""))
1597 (if (null buffer-file-name
)
1598 (error viper-NoFileSpecified
))
1599 (setq ex-file buffer-file-name
)))
1603 (concat (ex-expand-filsyms ex-file
(current-buffer))
1605 (shell-command command t
))
1606 (insert-file-contents ex-file
)))
1607 (ex-fixup-history viper-last-ex-prompt ex-file ex-cmdfile-args
))
1609 ;; this function fixes ex-history for some commands like ex-read, ex-edit
1610 (defun ex-fixup-history (&rest args
)
1611 (setq viper-ex-history
1612 (cons (mapconcat 'identity args
" ") (cdr viper-ex-history
))))
1615 ;; Ex recover from emacs \#file\#
1616 (defun ex-recover ()
1618 (if (or ex-append ex-offset
)
1619 (error "`recover': %s" viper-SpuriousText
))
1620 (if (string= ex-file
"")
1622 (if (null buffer-file-name
)
1623 (error "This buffer isn't visiting any file"))
1624 (setq ex-file buffer-file-name
))
1625 (setq ex-file
(expand-file-name ex-file
)))
1626 (if (and (not (string= ex-file
(buffer-file-name)))
1629 (error "No write since last change \(:rec! overrides\)"))
1630 (recover-file ex-file
))
1632 ;; Tell that `rewind' is obsolete and to use `:next count' instead
1635 "Use `:n <count>' instead. Counts are obtained from the `:args' command"))
1638 ;; read variable name for ex-set
1639 (defun ex-set-read-variable ()
1640 (let ((minibuffer-local-completion-map
1641 (copy-keymap minibuffer-local-completion-map
))
1642 (cursor-in-echo-area t
)
1645 minibuffer-local-completion-map
" " 'minibuffer-complete-and-exit
)
1646 (define-key minibuffer-local-completion-map
"=" 'exit-minibuffer
)
1647 (if (viper-set-unread-command-events
1648 (ex-get-inline-cmd-args "[ \t]*[a-zA-Z]*[ \t]*" nil
"\C-m"))
1651 (viper-set-unread-command-events ?\C-m
)))
1652 (message ":set <Variable> [= <Value>]")
1653 (or batch
(sit-for 2))
1655 (while (string-match "^[ \\t\\n]*$"
1657 (completing-read ":set " ex-variable-alist
)))
1658 (message ":set <Variable> [= <Value>]")
1659 ;; if there are unread events, don't wait
1660 (or (viper-set-unread-command-events "") (sit-for 2))
1666 (let ((var (ex-set-read-variable))
1670 (auto-cmd-label "; don't touch or else...")
1671 (delete-turn-on-auto-fill-pattern
1672 "([ \t]*add-hook[ \t]+'viper-insert-state-hook[ \t]+'turn-on-auto-fill.*)")
1673 actual-lisp-cmd lisp-cmd-del-pattern
1676 (cond ((string= var
"all")
1677 (setq ask-if-save nil
1679 ((member var
'("ai" "autoindent"))
1680 (setq var
"viper-auto-indent"
1684 ((member var
'("ai-g" "autoindent-global"))
1685 (kill-local-variable 'viper-auto-indent
)
1686 (setq var
"viper-auto-indent"
1687 set-cmd
"setq-default"
1689 ((member var
'("noai" "noautoindent"))
1690 (setq var
"viper-auto-indent"
1693 ((member var
'("noai-g" "noautoindent-global"))
1694 (kill-local-variable 'viper-auto-indent
)
1695 (setq var
"viper-auto-indent"
1696 set-cmd
"setq-default"
1698 ((member var
'("ic" "ignorecase"))
1699 (setq var
"viper-case-fold-search"
1701 ((member var
'("noic" "noignorecase"))
1702 (setq var
"viper-case-fold-search"
1704 ((member var
'("ma" "magic"))
1705 (setq var
"viper-re-search"
1707 ((member var
'("noma" "nomagic"))
1708 (setq var
"viper-re-search"
1710 ((member var
'("ro" "readonly"))
1711 (setq var
"buffer-read-only"
1713 ((member var
'("noro" "noreadonly"))
1714 (setq var
"buffer-read-only"
1716 ((member var
'("sm" "showmatch"))
1717 (setq var
"blink-matching-paren"
1719 ((member var
'("nosm" "noshowmatch"))
1720 (setq var
"blink-matching-paren"
1722 ((member var
'("ws" "wrapscan"))
1723 (setq var
"viper-search-wrap-around-t"
1725 ((member var
'("nows" "nowrapscan"))
1726 (setq var
"viper-search-wrap-around-t"
1728 (if (and set-cmd
(eq val
0)) ; value must be set by the user
1729 (let ((cursor-in-echo-area t
))
1730 (message ":set %s = <Value>" var
)
1731 ;; if there are unread events, don't wait
1732 (or (viper-set-unread-command-events "") (sit-for 2))
1733 (setq val
(read-string (format ":set %s = " var
)))
1734 (ex-fixup-history "set" orig-var val
)
1736 ;; check numerical values
1740 "ts-g" "tabstop-global"
1743 (or (numberp (setq val2
(car (read-from-string val
))))
1744 (error "%s: Invalid value, numberp, %S" var val
))
1746 (error "%s: Invalid value, numberp, %S" var val
))))
1749 ((member var
'("sw" "shiftwidth"))
1750 (setq var
"viper-shift-width"))
1751 ((member var
'("ts" "tabstop"))
1752 ;; make it take effect in curr buff and new bufs
1753 (setq var
"tab-width"
1756 ((member var
'("ts-g" "tabstop-global"))
1757 (kill-local-variable 'tab-width
)
1758 (setq var
"tab-width"
1759 set-cmd
"setq-default"))
1760 ((member var
'("wm" "wrapmargin"))
1761 ;; make it take effect in curr buff and new bufs
1762 (kill-local-variable 'fill-column
)
1763 (setq var
"fill-column"
1764 val
(format "(- (window-width) %s)" val
)
1765 set-cmd
"setq-default"))
1766 ((member var
'("sh" "shell"))
1767 (setq var
"explicit-shell-file-name"
1768 val
(format "\"%s\"" val
)))))
1769 (ex-fixup-history "set" orig-var
))
1772 (setq actual-lisp-cmd
1773 (format "\n(%s %s %s) %s" set-cmd var val auto-cmd-label
)
1774 lisp-cmd-del-pattern
1775 (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s"
1776 set-cmd var auto-cmd-label
)))
1778 (if (and ask-if-save
1779 (y-or-n-p (format "Do you want to save this setting in %s "
1780 viper-custom-file-name
)))
1782 (viper-save-string-in-file
1783 actual-lisp-cmd viper-custom-file-name
1785 lisp-cmd-del-pattern
)
1786 (if (string= var
"fill-column")
1788 (viper-save-string-in-file
1790 "(add-hook 'viper-insert-state-hook 'turn-on-auto-fill) "
1792 viper-custom-file-name
1793 delete-turn-on-auto-fill-pattern
)
1794 (viper-save-string-in-file
1795 nil viper-custom-file-name delete-turn-on-auto-fill-pattern
)
1796 (viper-save-string-in-file
1797 nil viper-custom-file-name
1799 lisp-cmd-del-pattern
)
1806 (if (string-match "^[ \t]*$" val
)
1810 (eval (car (read-from-string actual-lisp-cmd
))))
1811 (if (string= var
"fill-column")
1814 (auto-fill-mode -
1)))
1815 (if (string= var
"all") (ex-show-vars))
1818 ;; In inline args, skip regex-forw and (optionally) chars-back.
1819 ;; Optional 3d arg is a string that should replace ' ' to prevent its
1821 (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str
)
1823 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1824 (set-buffer viper-ex-work-buf
)
1825 (goto-char (point-min))
1826 (re-search-forward regex-forw nil t
)
1829 (goto-char (point-max))
1831 (skip-chars-backward chars-back
)
1832 (skip-chars-backward " \t\n\C-m"))
1834 ;; replace SPC with `=' to suppress the special meaning SPC has
1838 (while (re-search-forward " +" nil t
)
1839 (replace-match replace-str nil t
)
1840 (viper-forward-char-carefully)))
1842 (buffer-substring beg end
))))
1849 ;; Viper help. Invokes Info
1853 (pop-to-buffer (get-buffer-create "*info*"))
1854 (info (if viper-xemacs-p
"viper.info" "viper"))
1855 (message "Type `i' to search for a specific topic"))
1857 (with-output-to-temp-buffer " *viper-info*"
1859 The Info file for Viper does not seem to be installed.
1861 This file is part of the standard distribution of %sEmacs.
1862 Please contact your system administrator. "
1863 (if viper-xemacs-p
"X" "")
1866 ;; Ex source command. Loads the file specified as argument or `~/.viper'
1869 (if (string= ex-file
"")
1870 (load viper-custom-file-name
)
1873 ;; Ex substitute command
1874 ;; If REPEAT use previous regexp which is ex-reg-exp or viper-s-string
1875 (defun ex-substitute (&optional repeat r-flag
)
1879 (case-fold-search viper-case-fold-search
)
1881 (if repeat
(setq ex-token nil
) (setq delim
(viper-get-ex-pat)))
1884 (setq pat
(if r-flag viper-s-string ex-reg-exp
))
1886 (error "No previous pattern to use in substitution"))
1888 delim
(string-to-char pat
)))
1889 (setq pat
(if (string= ex-token
"") viper-s-string ex-token
))
1890 (setq viper-s-string pat
1892 (setq delim
(viper-get-ex-pat))
1898 (while (viper-get-ex-opt-gc delim
)
1899 (if (string= ex-token
"g") (setq opt-g t
) (setq opt-c t
)))
1900 (viper-get-ex-count)
1903 (if ex-addresses
(goto-char (car ex-addresses
)))
1905 (forward-line (1- ex-count
))
1906 (setq ex-addresses
(cons (point) (cons (mark t
) nil
))))
1907 (if (null ex-addresses
)
1908 (setq ex-addresses
(cons (point) (cons (point) nil
)))
1909 (if (null (cdr ex-addresses
))
1910 (setq ex-addresses
(cons (car ex-addresses
) ex-addresses
)))))
1912 (let ((beg (car ex-addresses
))
1913 (end (car (cdr ex-addresses
)))
1916 (viper-enlarge-region beg end
)
1917 (let ((limit (save-excursion
1918 (goto-char (max (point) (mark t
)))
1920 (goto-char (min (point) (mark t
)))
1921 (while (< (point) limit
)
1924 ;; This move allows the use of newline as the last character in
1925 ;; the substitution pattern
1926 (viper-forward-char-carefully)
1927 (setq eol-mark
(point-marker)))
1931 (while (and (not (eolp))
1932 (re-search-forward pat eol-mark t
))
1933 (if (or (not opt-c
) (y-or-n-p "Replace? "))
1935 (setq matched-pos
(point))
1936 (if (not (stringp repl
))
1937 (error "Can't perform Ex substitution: No previous replacement pattern"))
1938 (replace-match repl t
))))
1940 (viper-forward-char-carefully))
1943 "Can't repeat Ex substitution: No previous regular expression"))
1944 (if (and (re-search-forward pat eol-mark t
)
1945 (or (not opt-c
) (y-or-n-p "Replace? ")))
1947 (setq matched-pos
(point))
1948 (if (not (stringp repl
))
1949 (error "Can't perform Ex substitution: No previous replacement pattern"))
1950 (replace-match repl t
)))
1952 ;;(viper-forward-char-carefully)
1953 (goto-char eol-mark
)
1955 (if matched-pos
(goto-char matched-pos
))
1957 (if opt-c
(message "done"))))
1962 (save-window-excursion
1963 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1964 (set-buffer viper-ex-work-buf
)
1965 (skip-chars-forward " \t")
1967 (skip-chars-forward "^ |\t\n")
1968 (setq tag
(buffer-substring (mark t
) (point))))
1969 (if (not (string= tag
"")) (setq ex-tag tag
))
1970 (viper-change-state-to-emacs)
1971 (condition-case conds
1973 (if (string= tag
"")
1975 (find-tag-other-window ex-tag
))
1976 (viper-change-state-to-vi))
1978 (viper-change-state-to-vi)
1979 (viper-message-conditions conds
)))))
1982 (defun ex-write (q-flag)
1983 (viper-default-ex-addresses t
)
1985 (let ((end (car ex-addresses
))
1986 (beg (car (cdr ex-addresses
)))
1987 (orig-buf (current-buffer))
1988 (orig-buf-file-name (buffer-file-name))
1989 (orig-buf-name (buffer-name))
1990 (buff-changed-p (buffer-modified-p))
1991 temp-buf writing-same-file region
1992 file-exists writing-whole-file
)
1993 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
1996 (viper-enlarge-region beg end
)
1997 (shell-command-on-region (point) (mark t
)
1998 (concat ex-file ex-cmdfile-args
)))
1999 (if (and (string= ex-file
"") (not (buffer-file-name)))
2002 (format "Buffer %s isn't visiting any file. File to save in: "
2005 (setq writing-whole-file
(and (= (point-min) beg
) (= (point-max) end
))
2006 ex-file
(if (string= ex-file
"")
2008 (expand-file-name ex-file
)))
2009 ;; if ex-file is a directory use the file portion of the buffer file name
2010 (if (and (file-directory-p ex-file
)
2012 (not (file-directory-p buffer-file-name
)))
2014 (concat (file-name-as-directory ex-file
)
2015 (file-name-nondirectory buffer-file-name
))))
2017 (setq file-exists
(file-exists-p ex-file
)
2018 writing-same-file
(string= ex-file
(buffer-file-name)))
2020 ;; do actual writing
2021 (if (and writing-whole-file writing-same-file
)
2022 ;; saving whole buffer in visited file
2023 (if (not (buffer-modified-p))
2024 (message "(No changes need to be saved)")
2025 (viper-maybe-checkout (current-buffer))
2029 (ex-write-info file-exists ex-file
(point-min) (point-max))
2031 ;; writing to non-visited file and it already exists
2032 (if (and file-exists
(not writing-same-file
)
2034 (format "File %s exists. Overwrite? " ex-file
))))
2036 ;; writing a region or whole buffer to non-visited file
2039 (viper-enlarge-region beg end
)
2040 (setq region
(buffer-substring (point) (mark t
)))
2041 ;; create temp buffer for the region
2042 (setq temp-buf
(get-buffer-create " *ex-write*"))
2043 (set-buffer temp-buf
)
2044 (set-visited-file-name ex-file
'noquerry
)
2046 (if (and file-exists ex-append
)
2047 (insert-file-contents ex-file
))
2048 (goto-char (point-max))
2051 (viper-maybe-checkout (current-buffer))
2054 file-exists ex-file
(point-min) (point-max))
2056 ;; this must be under unwind-protect so that
2057 ;; temp-buf will be deleted in case of an error
2058 (set-buffer temp-buf
)
2059 (set-buffer-modified-p nil
)
2060 (kill-buffer temp-buf
)
2061 ;; buffer/region has been written, now take care of details
2062 (set-buffer orig-buf
)))
2063 ;; set the right file modification time
2064 (if (and (buffer-file-name) writing-same-file
)
2065 (set-visited-file-modtime))
2066 ;; prevent loss of data if saving part of the buffer in visited file
2067 (or writing-whole-file
2068 (not writing-same-file
)
2071 (message "Warning: you have saved only part of the buffer!")
2072 (set-buffer-modified-p t
)))
2074 (if (< viper-expert-level
2)
2075 (save-buffers-kill-emacs)
2076 (kill-buffer (current-buffer))))
2080 (defun ex-write-info (exists file-name beg end
)
2081 (message "`%s'%s %d lines, %d characters"
2082 (viper-abbreviate-file-name file-name
)
2083 (if exists
"" " [New file]")
2084 (count-lines beg
(min (1+ end
) (point-max)))
2089 (viper-default-ex-addresses)
2090 (viper-get-ex-buffer)
2091 (let ((end (car ex-addresses
)) (beg (car (cdr ex-addresses
))))
2092 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
2094 (viper-enlarge-region beg end
)
2095 (exchange-point-and-mark)
2096 (if (or ex-g-flag ex-g-variant
)
2097 (error "Can't execute `yank' within `global'"))
2101 (forward-line (1- ex-count
)))
2103 (viper-enlarge-region (point) (mark t
))
2104 (if ex-flag
(error "`yank': %s" viper-SpuriousText
))
2106 (cond ((viper-valid-register ex-buffer
'(Letter))
2107 (viper-append-to-register
2108 (downcase ex-buffer
) (point) (mark t
)))
2109 ((viper-valid-register ex-buffer
)
2110 (copy-to-register ex-buffer
(point) (mark t
) nil
))
2111 (t (error viper-InvalidRegister ex-buffer
))))
2112 (copy-region-as-kill (point) (mark t
)))))
2114 ;; Execute shell command
2115 (defun ex-command ()
2117 (save-window-excursion
2118 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
2119 (set-buffer viper-ex-work-buf
)
2120 (skip-chars-forward " \t")
2121 (setq command
(buffer-substring (point) (point-max)))
2123 (setq command
(ex-expand-filsyms command
(current-buffer)))
2124 (if (and (> (length command
) 0) (string= "!" (substring command
0 1)))
2125 (if viper-ex-last-shell-com
2127 (concat viper-ex-last-shell-com
(substring command
1)))
2128 (error "No previous shell command")))
2129 (setq viper-ex-last-shell-com command
)
2130 (if (null ex-addresses
)
2131 (shell-command command
)
2132 (let ((end (car ex-addresses
)) (beg (car (cdr ex-addresses
))))
2133 (if (null beg
) (setq beg end
))
2137 (viper-enlarge-region (point) (mark t
))
2138 (shell-command-on-region (point) (mark t
) command t
))
2141 ;; Print line number
2142 (defun ex-line-no ()
2146 (if (null ex-addresses
) (point-max) (car ex-addresses
))))))
2148 ;; Give information on the file visited by the current buffer
2149 (defun viper-info-on-file ()
2151 (let ((pos1 (viper-line-pos 'start
))
2152 (pos2 (viper-line-pos 'end
))
2154 (setq lines
(count-lines (point-min) (viper-line-pos 'end
))
2155 file
(if (buffer-file-name)
2156 (concat (viper-abbreviate-file-name (buffer-file-name)) ":")
2157 (concat (buffer-name) " [Not visiting any file]:"))
2158 info
(format "line=%d/%d pos=%d/%d col=%d %s"
2162 (count-lines (point-min) (point-max))
2163 (point) (1- (point-max))
2164 (1+ (current-column))
2165 (if (buffer-modified-p) "[Modified]" "[Unchanged]")))
2166 (if (< (+ 1 (length info
) (length file
))
2167 (window-width (minibuffer-window)))
2168 (message (concat file
" " info
))
2169 (save-window-excursion
2170 (with-output-to-temp-buffer " *viper-info*"
2171 (princ (concat "\n" file
"\n\n\t" info
"\n\n")))
2172 (let ((inhibit-quit t
))
2173 (viper-set-unread-command-events (viper-read-event)))
2174 (kill-buffer " *viper-info*")))
2177 ;; display all variables set through :set
2178 (defun ex-show-vars ()
2179 (with-output-to-temp-buffer " *viper-info*"
2180 (princ (if viper-auto-indent
2181 "autoindent (local)\n" "noautoindent (local)\n"))
2182 (princ (if (default-value 'viper-auto-indent
)
2183 "autoindent (global) \n" "noautoindent (global) \n"))
2184 (princ (if viper-case-fold-search
"ignorecase\n" "noignorecase\n"))
2185 (princ (if viper-re-search
"magic\n" "nomagic\n"))
2186 (princ (if buffer-read-only
"readonly\n" "noreadonly\n"))
2187 (princ (if blink-matching-paren
"showmatch\n" "noshowmatch\n"))
2188 (princ (if viper-search-wrap-around-t
"wrapscan\n" "nowrapscan\n"))
2189 (princ (format "shiftwidth \t\t= %S\n" viper-shift-width
))
2190 (princ (format "tabstop (local) \t= %S\n" tab-width
))
2191 (princ (format "tabstop (global) \t= %S\n" (default-value 'tab-width
)))
2192 (princ (format "wrapmargin (local) \t= %S\n"
2193 (- (window-width) fill-column
)))
2194 (princ (format "wrapmargin (global) \t= %S\n"
2195 (- (window-width) (default-value 'fill-column
))))
2196 (princ (format "shell \t\t\t= %S\n" (if (boundp 'explicit-shell-file-name
)
2197 explicit-shell-file-name
2205 ;;; viper-ex.el ends here