1 ;;; viper-ex.el --- functions implementing the Ex commands for Viper
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
32 (defvar read-file-name-map
)
33 (defvar viper-use-register
)
34 (defvar viper-s-string
)
35 (defvar viper-shift-width
)
36 (defvar viper-ex-history
)
37 (defvar viper-related-files-and-buffers-ring
)
38 (defvar viper-local-search-start-marker
)
39 (defvar viper-expert-level
)
40 (defvar viper-custom-file-name
)
41 (defvar viper-case-fold-search
)
42 (defvar explicit-shell-file-name
)
43 (defvar compile-command
)
45 ;; loading happens only in non-interactive compilation
46 ;; in order to spare non-viperized emacs from being viperized
49 (let ((load-path (cons (expand-file-name ".") load-path
)))
50 (or (featurep 'viper-util
)
51 (load "viper-util.el" nil nil
'nosuffix
))
52 (or (featurep 'viper-keym
)
53 (load "viper-keym.el" nil nil
'nosuffix
))
54 (or (featurep 'viper-cmd
)
55 (load "viper-cmd.el" nil nil
'nosuffix
))
61 (defgroup viper-ex nil
62 "Viper support for Ex commands."
70 (defconst viper-ex-work-buf-name
" *ex-working-space*")
71 (defvar viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
72 (defconst viper-ex-tmp-buf-name
" *ex-tmp*")
73 (defconst viper-ex-print-buf-name
" *ex-print*")
74 (defvar viper-ex-print-buf
(get-buffer-create viper-ex-print-buf-name
))
79 (defun ex-cmd-obsolete (name)
80 (error "`%s': Obsolete command, not supported by Viper" name
))
82 (defun ex-cmd-not-yet (name)
83 (error "`%s': Command not implemented in Viper" name
))
85 ;; alist entries: name (in any order), command, cont(??)
86 ;; If command is a string, then that is an alias to the real command
87 ;; to execute (for instance, ":m" -> ":move").
88 ;; command attributes:
89 ;; is-mashed: the command's args may be jammed right up against the command
90 ;; one-letter: this is a one-letter token. Any text appearing after
91 ;; the name gets appended as an argument for the command
92 ;; i.e. ":kabc" gets turned into (ex-mark "abc")
93 (defconst ex-token-alist
'(
95 ("&" (ex-substitute t
))
97 (">" (ex-line "right"))
98 ("<" (ex-line "left"))
99 ("Buffer" (if ex-cycle-other-window
100 (viper-switch-to-buffer)
101 (viper-switch-to-buffer-other-window)))
102 ("Next" (ex-next (not ex-cycle-other-window
)))
103 ("PreviousRelatedFile" (ex-next-related-buffer -
1))
104 ("RelatedFile" (ex-next-related-buffer 1))
106 ("WWrite" (save-some-buffers t
))
107 ("Write" (save-some-buffers))
110 ("buffer" (if ex-cycle-other-window
111 (viper-switch-to-buffer-other-window)
112 (viper-switch-to-buffer)))
114 ;; ch should be "change" but maintain old viper compatibility
118 ("copy" (ex-copy nil
))
119 ("customize" (customize-group "viper"))
120 ("delete" (ex-delete))
122 ("file" (ex-set-visited-file-name))
124 ("global" (ex-global nil
) is-mashed
)
127 ("join" (ex-line "join"))
128 ("k" (ex-mark) one-letter
)
131 ("make" (ex-compile))
132 ; old viper doesn't specify a default for "ma" so leave it undefined
136 ("next" (ex-next ex-cycle-other-window
))
138 ("preserve" (ex-preserve))
146 ("recover" (ex-recover))
147 ("rewind" (ex-rewind))
153 ("source" (ex-source))
154 ("stop" (suspend-emacs))
155 ("sr" (ex-substitute t t
))
156 ("submitReport" (viper-submit-report))
157 ("substitute" (ex-substitute) is-mashed
)
158 ("suspend" (suspend-emacs))
161 ("transfer" (ex-copy nil
))
164 ("undo" (viper-undo))
167 ("version" (viper-version))
168 ("vglobal" (ex-global t
) is-mashed
)
172 ("write" (ex-write nil
))
175 ("~" (ex-substitute t t
))
177 ("append" (ex-cmd-obsolete "append"))
178 ("change" (ex-cmd-obsolete "change"))
179 ("insert" (ex-cmd-obsolete "insert"))
180 ("open" (ex-cmd-obsolete "open"))
182 ("list" (ex-cmd-not-yet "list"))
183 ("z" (ex-cmd-not-yet "z"))
184 ("#" (ex-cmd-not-yet "#"))
186 ("abbreviate" (error "`%s': Vi abbreviations are obsolete. Use the more powerful Emacs abbrevs" ex-token
))
187 ("unabbreviate" (error "`%s': Vi abbreviations are obsolete. Use the more powerful Emacs abbrevs" ex-token
))
190 ;; No code should touch anything in the alist entry! (other than the name,
191 ;; "car entry", of course) This way, changing this data structure
192 ;; requires changing only the following ex-cmd functions...
194 ;; Returns cmd if the command may be jammed right up against its
195 ;; arguments, nil if there must be a space.
196 ;; examples of mashable commands: g// g!// v// s// sno// sm//
197 (defun ex-cmd-is-mashed-with-args (cmd)
198 (if (eq 'is-mashed
(car (nthcdr 2 cmd
))) cmd
))
200 ;; Returns true if this is a one-letter command that may be followed
201 ;; by anything, no whitespace needed. This is a special-case for ":k".
202 (defun ex-cmd-is-one-letter (cmd)
203 (if (eq 'one-letter
(car (nthcdr 2 cmd
))) cmd
))
205 ;; Executes the function associated with the command
206 (defun ex-cmd-execute (cmd)
209 ;; If this is a one-letter magic command, splice in args.
210 (defun ex-splice-args-in-1-letr-cmd (key list
)
211 (let ((oneletter (ex-cmd-is-one-letter (assoc (substring key
0 1) list
))))
214 (append (cadr oneletter
)
215 (if (< 1 (length key
)) (list (substring key
1))))
216 (car (cdr (cdr oneletter
))) ))
220 ;; Returns the alist entry for the appropriate key.
221 ;; Tries to complete the key before using it in the alist.
222 ;; If there is no appropriate key (no match or duplicate matches) return nil
223 (defun ex-cmd-assoc (key list
)
224 (let ((entry (try-completion key list
))
227 ((eq entry t
) (assoc key list
))
228 ((stringp entry
) (or (ex-splice-args-in-1-letr-cmd key list
)
230 ((eq entry nil
) (ex-splice-args-in-1-letr-cmd key list
))
233 ;; If we end up with an alias, look up the alias...
234 (if (stringp (cadr result
))
235 (setq result
(ex-cmd-assoc (cadr result
) list
)))
236 ;; and return the corresponding alist entry
241 ;; A-list of Ex variables that can be set using the :set command.
242 (defconst ex-variable-alist
243 '(("wrapscan") ("ws") ("wrapmargin") ("wm")
244 ("tabstop-global") ("ts-g") ("tabstop") ("ts")
245 ("showmatch") ("sm") ("shiftwidth") ("sw") ("shell") ("sh")
247 ("nowrapscan") ("nows") ("noshowmatch") ("nosm")
248 ("noreadonly") ("noro") ("nomagic") ("noma")
249 ("noignorecase") ("noic")
250 ("noautoindent-global") ("noai-g") ("noautoindent") ("noai")
251 ("magic") ("ma") ("ignorecase") ("ic")
252 ("autoindent-global") ("ai-g") ("autoindent") ("ai")
258 ;; Token recognized during parsing of Ex commands (e.g., "read", "comma")
259 (defvar ex-token nil
)
262 ;; If non-nil, gives type of address; if nil, it is a command.
263 (defvar ex-token-type nil
)
265 ;; List of addresses passed to Ex command
266 (defvar ex-addresses nil
)
268 ;; This flag is supposed to be set only by `#', `print', and `list',
269 ;; none of which is implemented. So, it and the pices of the code it
270 ;; controls are dead weight. We keep it just in case this might be
271 ;; needed in the future.
274 ;; "buffer" where Ex commands keep deleted data.
275 ;; In Emacs terms, this is a register.
276 (defvar ex-buffer nil
)
278 ;; Value of ex count.
279 (defvar ex-count nil
)
281 ;; Flag indicating that :global Ex command is being executed.
282 (defvar ex-g-flag nil
)
283 ;; Flag indicating that :vglobal Ex command is being executed.
284 (defvar ex-g-variant nil
)
285 ;; Marks to operate on during a :global Ex command.
286 (defvar ex-g-marks nil
)
288 ;; Save reg-exp used in substitute.
289 (defvar ex-reg-exp nil
)
292 ;; Replace pattern for substitute.
295 ;; Pattern for global command.
296 (defvar ex-g-pat nil
)
298 (defcustom ex-unix-type-shell
299 (let ((case-fold-search t
))
300 (and (stringp shell-file-name
)
310 "[^a-z]sh$\\|[^a-z]sh.exe$"
315 "Is the user using a unix-type shell under a non-OS?"
319 (defcustom ex-unix-type-shell-options
320 (let ((case-fold-search t
))
321 (if ex-unix-type-shell
322 (cond ((string-match "\\(csh$\\|csh.exe$\\)" shell-file-name
)
323 "-f") ; csh: do it fast
324 ((string-match "\\(bash$\\|bash.exe$\\)" shell-file-name
)
325 "-noprofile") ; bash: ignore .profile
327 "Options to pass to the Unix-style shell.
328 Don't put `-c' here, as it is added automatically."
329 :type
'(choice (const nil
) string
)
332 (defcustom ex-compile-command
"make"
333 "The command to run when the user types :make."
337 (defcustom viper-glob-function
338 (cond (ex-unix-type-shell 'viper-glob-unix-files
)
339 ((eq system-type
'emx
) 'viper-glob-mswindows-files
) ; OS/2
340 (viper-ms-style-os-p 'viper-glob-mswindows-files
) ; Microsoft OS
341 (viper-vms-os-p 'viper-glob-unix-files
) ; VMS
342 (t 'viper-glob-unix-files
) ; presumably UNIX
344 "Expand the file spec containing wildcard symbols.
345 The default tries to set this variable to work with Unix, Windows,
348 However, if it doesn't work right for some types of Unix shells or some OS,
349 the user should supply the appropriate function and set this variable to the
350 corresponding function symbol."
355 ;; Remembers the previous Ex tag.
358 ;; file used by Ex commands like :r, :w, :n
361 ;; If t, tells Ex that this is a variant-command, i.e., w>>, r!, etc.
362 (defvar ex-variant nil
)
364 ;; Specified the offset of an Ex command, such as :read.
365 (defvar ex-offset nil
)
367 ;; Tells Ex that this is a w>> command.
368 (defvar ex-append nil
)
370 ;; File containing the shell command to be executed at Ex prompt,
372 (defvar ex-cmdfile nil
)
373 (defvar ex-cmdfile-args
"")
375 ;; flag used in viper-ex-read-file-name to indicate that we may be reading
376 ;; multiple file names. Used for :edit and :next
377 (defvar viper-keep-reading-filename nil
)
379 (defcustom ex-cycle-other-window t
380 "*If t, :n and :b cycles through files and buffers in other window.
381 Then :N and :B cycles in the current window. If nil, this behavior is
386 (defcustom ex-cycle-through-non-files nil
387 "*Cycle through *scratch* and other buffers that don't visit any file."
391 ;; Last shell command executed with :! command.
392 (defvar viper-ex-last-shell-com nil
)
394 ;; Indicates if Minibuffer was exited temporarily in Ex-command.
395 (defvar viper-incomplete-ex-cmd nil
)
397 ;; Remembers the last ex-command prompt.
398 (defvar viper-last-ex-prompt
"")
401 ;; Get a complete ex command
402 (defun viper-get-ex-com-subr ()
403 (let (cmd case-fold-search
)
405 (re-search-forward "[a-zA-Z][a-zA-Z]*")
406 (setq ex-token-type
'command
)
407 (setq ex-token
(buffer-substring (point) (mark t
)))
408 (setq cmd
(ex-cmd-assoc ex-token ex-token-alist
))
410 (setq ex-token
(car cmd
))
411 (setq ex-token-type
'non-command
))
414 ;; Get an ex-token which is either an address or a command.
415 ;; A token has a type, \(command, address, end-mark\), and a value
416 (defun viper-get-ex-token ()
417 (save-window-excursion
418 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
419 (set-buffer viper-ex-work-buf
)
420 (skip-chars-forward " \t|")
421 (let ((case-fold-search t
))
422 (cond ((looking-at "#")
423 (setq ex-token-type
'command
)
424 (setq ex-token
(char-to-string (following-char)))
426 ((looking-at "[a-z]") (viper-get-ex-com-subr))
429 (setq ex-token-type
'dot
))
430 ((looking-at "[0-9]")
432 (re-search-forward "[0-9]*")
434 (cond ((eq ex-token-type
'plus
) 'add-number
)
435 ((eq ex-token-type
'minus
) 'sub-number
)
438 (string-to-number (buffer-substring (point) (mark t
)))))
441 (setq ex-token-type
'end
))
444 (setq ex-token-type
'whole
))
446 (cond ((or (looking-at "+[-+]") (looking-at "+[\n|]"))
450 (setq ex-token-type
'plus
))
451 ((looking-at "+[0-9]")
453 (setq ex-token-type
'plus
))
455 (error viper-BadAddress
))))
457 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]"))
461 (setq ex-token-type
'minus
))
462 ((looking-at "-[0-9]")
464 (setq ex-token-type
'minus
))
466 (error viper-BadAddress
))))
471 (while (and (not (eolp)) cont
)
472 ;;(re-search-forward "[^/]*/")
473 (re-search-forward "[^/]*\\(/\\|\n\\)")
474 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"))
477 (setq ex-token
(buffer-substring (point) (mark t
)))
478 (if (looking-at "/") (forward-char 1))
479 (setq ex-token-type
'search-forward
))
484 (while (and (not (eolp)) cont
)
485 ;;(re-search-forward "[^\\?]*\\?")
486 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)")
487 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?"))
490 (if (not (looking-at "\n")) (forward-char 1))))
491 (setq ex-token-type
'search-backward
)
492 (setq ex-token
(buffer-substring (1- (point)) (mark t
))))
495 (setq ex-token-type
'comma
))
498 (setq ex-token-type
'semi-colon
))
499 ((looking-at "[!=><&~]")
500 (setq ex-token-type
'command
)
501 (setq ex-token
(char-to-string (following-char)))
504 (setq ex-token-type
'goto-mark
)
506 (cond ((looking-at "'") (setq ex-token nil
))
507 ((looking-at "[a-z]") (setq ex-token
(following-char)))
508 (t (error "Marks are ' and a-z")))
511 (setq ex-token-type
'end-mark
)
512 (setq ex-token
"goto"))
514 (error viper-BadExCommand
))))))
516 ;; Reads Ex command. Tries to determine if it has to exit because command
517 ;; is complete or invalid. If not, keeps reading command.
518 (defun ex-cmd-read-exit ()
520 (setq viper-incomplete-ex-cmd t
)
521 (let ((quit-regex1 (concat
524 "\\|" "[nN]ext[ \t]*"
537 "\\|" "[ktgjmsz][ \t]*$"
539 "\\|" "tr[ansfer \t]*"
542 "\\|" "^[ \t]*k?ma[^p]*"
549 ;; don't jump up in :s command
550 "\\|" "^[ \t]*\\([`'][a-z]\\|[.,%]\\)*[ \t]*su.*"
551 "\\|" "^[ \t]*\\([`'][a-z]\\|[.,%]\\)*[ \t]*s[^a-z].*"
552 "\\|" "['`][a-z][ \t]*"
553 ;; r! assumes that the next one is a shell command
554 "\\|" "\\(r\\|re\\|rea\\|read\\)[ \t]*!"
555 ;; w ! assumes that the next one is a shell command
556 "\\|" "\\(w\\|wr\\|wri\\|writ.?\\)[ \t]+!"
557 "\\|" "![ \t]*[a-zA-Z].*"
561 (save-window-excursion ;; put cursor at the end of the Ex working buffer
562 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
563 (set-buffer viper-ex-work-buf
)
564 (goto-char (point-max)))
565 (cond ((viper-looking-back quit-regex1
) (exit-minibuffer))
566 ((viper-looking-back stay-regex
) (insert " "))
567 ((viper-looking-back quit-regex2
) (exit-minibuffer))
570 ;; complete Ex command
571 (defun ex-cmd-complete ()
573 (let (save-pos dist compl-list string-to-complete completion-result
)
576 (setq dist
(skip-chars-backward "[a-zA-Z!=>&~]")
580 (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
582 "^[ \t]*[a-zA-Z!=>&~][ \t]*[/?]*[ \t]+[a-zA-Z!=>&~]+"))
583 ;; Preceding characters are not the ones allowed in an Ex command
584 ;; or we have typed past command name.
585 ;; Note: we didn't do parsing, so there can be surprises.
586 (if (or (viper-looking-back "[a-zA-Z!=>&~][ \t]*[/?]*[ \t]*")
587 (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
588 (looking-at "[^ \t\n\C-m]"))
590 (with-output-to-temp-buffer "*Completions*"
591 (display-completion-list
592 (viper-alist-to-list ex-token-alist
))))
593 ;; Preceding chars may be part of a command name
594 (setq string-to-complete
(buffer-substring save-pos
(point)))
595 (setq completion-result
596 (try-completion string-to-complete ex-token-alist
))
598 (cond ((eq completion-result t
) ; exact match--do nothing
599 (viper-tmp-insert-at-eob " (Sole completion)"))
600 ((eq completion-result nil
)
601 (viper-tmp-insert-at-eob " (No match)"))
602 (t ;; partial completion
604 (delete-region (point) (point-max))
605 (insert completion-result
)
606 (let (case-fold-search)
608 (viper-filter-alist (concat "^" completion-result
)
610 (if (> (length compl-list
) 1)
611 (with-output-to-temp-buffer "*Completions*"
612 (display-completion-list
613 (viper-alist-to-list (reverse compl-list
)))))))
618 ;; ARG is a prefix argument. If given, the ex command runs on the region
619 ;;(without the user having to specify the address :a,b
620 ;; STRING is the command to execute. If nil, then Viper asks you to enter the
622 (defun viper-ex (arg &optional string
)
627 (let* ((map (copy-keymap minibuffer-local-map
))
631 reg-beg-line reg-end-line
634 prev-token-type com-str
)
635 (viper-add-keymap viper-ex-cmd-map map
)
639 (viper-enlarge-region (mark t
) (point))
640 (if (> (point) (mark t
))
641 (setq reg-beg
(mark t
)
643 (setq reg-end
(mark t
)
647 (setq reg-beg-line
(1+ (count-lines (point-min) (point)))
649 (+ reg-beg-line
(count-lines reg-beg reg-end
) -
1)))))
651 (setq initial-str
(format "%d,%d" reg-beg-line reg-end-line
)))
654 (or string
(viper-read-string-with-history
658 ;; no default when working on region
661 (car viper-ex-history
))
664 " [Type command to execute on current region]"))))
665 (save-window-excursion
667 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
668 (set-buffer viper-ex-work-buf
)
669 (delete-region (point-min) (point-max))
670 (insert com-str
"\n")
671 (goto-char (point-min)))
672 (setq ex-token-type nil
676 (cond ((memq ex-token-type
'(command end-mark
))
677 (if address
(setq ex-addresses
(cons address ex-addresses
)))
678 (viper-deactivate-mark)
679 (let ((cmd (ex-cmd-assoc ex-token ex-token-alist
)))
681 (error "`%s': %s" ex-token viper-BadExCommand
))
683 (if (or (ex-cmd-is-mashed-with-args cmd
)
684 (ex-cmd-is-one-letter cmd
))
687 (save-window-excursion
688 (setq viper-ex-work-buf
689 (get-buffer-create viper-ex-work-buf-name
))
690 (set-buffer viper-ex-work-buf
)
691 (skip-chars-forward " \t")
692 (cond ((looking-at "|")
697 "`%s': %s" ex-token viper-SpuriousText
)))
700 ((eq ex-token-type
'non-command
)
701 (error "`%s': %s" ex-token viper-BadExCommand
))
702 ((eq ex-token-type
'whole
)
706 (cons (point-max) ex-addresses
)
707 (cons (point-max) (cons (point-min) ex-addresses
)))))
708 ((eq ex-token-type
'comma
)
709 (if (eq prev-token-type
'whole
)
710 (setq address
(point-min)))
712 (cons (if (null address
) (point) address
) ex-addresses
)))
713 ((eq ex-token-type
'semi-colon
)
714 (if (eq prev-token-type
'whole
)
715 (setq address
(point-min)))
716 (if address
(setq dot address
))
718 (cons (if (null address
) (point) address
) ex-addresses
)))
719 (t (let ((ans (viper-get-ex-address-subr address dot
)))
720 (if ans
(setq address ans
)))))
721 (setq prev-token-type ex-token-type
))))
724 ;; Get a regular expression and set `ex-variant', if found
725 ;; Viper doesn't parse the substitution or search patterns.
726 ;; In particular, it doesn't expand ~ into the last substitution.
727 (defun viper-get-ex-pat ()
728 (save-window-excursion
729 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
730 (set-buffer viper-ex-work-buf
)
731 (skip-chars-forward " \t")
733 ;; this is probably a variant command r!
735 (setq ex-g-variant
(not ex-g-variant
)
736 ex-g-flag
(not ex-g-flag
))
738 (skip-chars-forward " \t")))
739 (let ((c (following-char)))
740 (cond ((string-match "[0-9A-Za-z]" (format "%c" c
))
742 "Global regexp must be inside matching non-alphanumeric chars"))
743 ((= c ??
) (error "`?' is not an allowed pattern delimiter here")))
744 (if (looking-at "[^\\\\\n]")
749 ;; the use of eobp instead of eolp permits the use of newlines in
750 ;; pat2 in s/pat1/pat2/
751 (while (and (not (eobp)) cont
)
752 (if (not (re-search-forward (format "[^%c]*%c" c c
) nil t
))
753 (if (member ex-token
'("global" "vglobal"))
754 (error "Missing closing delimiter for global regexp")
755 (goto-char (point-max))))
756 (if (not (viper-looking-back
757 (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c
)))
759 ;; we are at an escaped delimiter: unescape it and continue
760 (delete-backward-char 2)
763 ;; if at eol, exit loop and go to next line
764 ;; later, delim will be inserted at the end
770 (if (= (mark t
) (point)) ""
771 (buffer-substring (1- (point)) (mark t
))))
773 ;; if the user didn't insert the final pattern delimiter, we're
774 ;; at newline now. In this case, insert the initial delimiter
775 ;; specified in variable c
784 ;; Get an Ex option g or c
785 (defun viper-get-ex-opt-gc (c)
786 (save-window-excursion
787 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
788 (set-buffer viper-ex-work-buf
)
789 (if (looking-at (format "%c" c
)) (forward-char 1))
790 (skip-chars-forward " \t")
791 (cond ((looking-at "g")
801 ;; Compute default addresses. WHOLE-FLAG means use the whole buffer
802 (defun viper-default-ex-addresses (&optional whole-flag
)
803 (cond ((null ex-addresses
)
806 (list (point-max) (point-min))
807 (list (point) (point)))))
808 ((null (cdr ex-addresses
))
810 (cons (car ex-addresses
) ex-addresses
)))))
812 ;; Get an ex-address as a marker and set ex-flag if a flag is found
813 (defun viper-get-ex-address ()
814 (let ((address (point-marker))
820 (cond ((eq ex-token-type
'command
)
821 (if (member ex-token
'("print" "list" "#"))
825 (error "Address expected in this Ex command")))
826 ((eq ex-token-type
'end-mark
)
828 ((eq ex-token-type
'whole
)
829 (error "Trailing address expected"))
830 ((eq ex-token-type
'comma
)
831 (error "`%s': %s" ex-token viper-SpuriousText
))
832 (t (let ((ans (viper-get-ex-address-subr address
(point-marker))))
833 (if ans
(setq address ans
))))))
836 ;; Returns an address as a point
837 (defun viper-get-ex-address-subr (old-address dot
)
839 (if (null old-address
) (setq old-address dot
))
840 (cond ((eq ex-token-type
'dot
)
842 ((eq ex-token-type
'add-number
)
844 (goto-char old-address
)
845 (forward-line (if (= old-address
0) (1- ex-token
) ex-token
))
846 (setq address
(point-marker))))
847 ((eq ex-token-type
'sub-number
)
849 (goto-char old-address
)
850 (forward-line (- ex-token
))
851 (setq address
(point-marker))))
852 ((eq ex-token-type
'abs-number
)
854 (goto-char (point-min))
855 (if (= ex-token
0) (setq address
0)
856 (forward-line (1- ex-token
))
857 (setq address
(point-marker)))))
858 ((eq ex-token-type
'end
)
860 (goto-char (1- (point-max)))
861 (setq address
(point-marker))))
862 ((eq ex-token-type
'plus
) t
) ; do nothing
863 ((eq ex-token-type
'minus
) t
) ; do nothing
864 ((eq ex-token-type
'search-forward
)
866 (ex-search-address t
)
867 (setq address
(point-marker))))
868 ((eq ex-token-type
'search-backward
)
870 (ex-search-address nil
)
871 (setq address
(point-marker))))
872 ((eq ex-token-type
'goto-mark
)
875 (exchange-point-and-mark)
877 (viper-register-to-point
878 (viper-int-to-char (1+ (- ex-token ?a
))) 'enforce-buffer
)))
879 (setq address
(point-marker)))))
883 ;; Search pattern and set address
884 ;; Doesn't wrap around. Should it?
885 (defun ex-search-address (forward)
886 (if (string= ex-token
"")
887 (if (null viper-s-string
)
888 (error viper-NoPrevSearch
)
889 (setq ex-token viper-s-string
))
890 (setq viper-s-string ex-token
))
894 (re-search-forward ex-token
))
896 (re-search-backward ex-token
)))
898 ;; Get a buffer name and set `ex-count' and `ex-flag' if found
899 (defun viper-get-ex-buffer ()
903 (save-window-excursion
904 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
905 (set-buffer viper-ex-work-buf
)
906 (skip-chars-forward " \t")
907 (if (looking-at "[a-zA-Z]")
909 (setq ex-buffer
(following-char))
911 (skip-chars-forward " \t")))
912 (if (looking-at "[0-9]")
915 (re-search-forward "[0-9][0-9]*")
916 (setq ex-count
(string-to-number (buffer-substring (point) (mark t
))))
917 (skip-chars-forward " \t")))
918 (if (looking-at "[pl#]")
922 (if (not (looking-at "[\n|]"))
923 (error "`%s': %s" ex-token viper-SpuriousText
))))
925 (defun viper-get-ex-count ()
929 (save-window-excursion
930 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
931 (set-buffer viper-ex-work-buf
)
932 (skip-chars-forward " \t")
937 (skip-chars-forward " \t")
938 (if (looking-at "[0-9]")
941 (re-search-forward "[0-9][0-9]*")
942 (setq ex-count
(string-to-number (buffer-substring (point) (mark t
))))
943 (skip-chars-forward " \t")))
944 (if (looking-at "[pl#]")
948 (if (not (looking-at "[\n|]"))
951 (point-min) (1- (point-max))) viper-BadExCommand
))))
953 ;; Expand \% and \# in ex command
954 (defun ex-expand-filsyms (cmd buf
)
958 (setq cf buffer-file-name
)
959 (setq pf
(ex-next nil t
))) ; this finds alternative file name
960 (if (and (null cf
) (string-match "[^\\]%\\|\\`%" cmd
))
961 (error "No current file to substitute for `%%'"))
962 (if (and (null pf
) (string-match "[^\\]#\\|\\`#" cmd
))
963 (error "No alternate file to substitute for `#'"))
965 (set-buffer (get-buffer-create viper-ex-tmp-buf-name
))
968 (goto-char (point-min))
969 (while (re-search-forward "%\\|#" nil t
)
970 (let ((data (match-data))
971 (char (buffer-substring (match-beginning 0) (match-end 0))))
972 (if (viper-looking-back (concat "\\\\" char
))
974 (store-match-data data
)
975 (if (string= char
"%")
977 (replace-match pf
)))))
979 (setq ret
(buffer-substring (point-min) (point)))
983 ;; Get a file name and set `ex-variant', `ex-append' and `ex-offset' if found
984 ;; If it is r!, then get the command name and whatever args
985 (defun viper-get-ex-file ()
994 (save-window-excursion
995 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
996 (set-buffer viper-ex-work-buf
)
997 (skip-chars-forward " \t")
999 (if (and (not (viper-looking-back "[ \t]"))
1000 ;; read doesn't have a corresponding :r! form, so ! is
1001 ;; immediately interpreted as a shell command.
1002 (not (string= ex-token
"read")))
1006 (skip-chars-forward " \t"))
1009 (skip-chars-forward " \t")))
1010 (if (looking-at ">>")
1015 (skip-chars-forward " \t")))
1016 (if (looking-at "+")
1020 (re-search-forward "[ \t\n]")
1022 (setq ex-offset
(buffer-substring (point) (mark t
)))
1024 (skip-chars-forward " \t")))
1025 ;; this takes care of :r, :w, etc., when they get file names
1026 ;; from the history list
1027 (if (member ex-token
'("read" "write" "edit" "visual" "next"))
1029 (setq ex-file
(buffer-substring (point) (1- (point-max))))
1031 ;; For :e, match multiple non-white strings separated
1032 ;; by white. For others, find the first non-white string
1034 (if (string= ex-token
"edit")
1035 "[^ \t\n]+\\([ \t]+[^ \t\n]+\\)*"
1039 ;; if file name comes from history, don't leave
1040 ;; minibuffer when the user types space
1041 (setq viper-incomplete-ex-cmd nil
)
1042 (setq ex-cmdfile-args
1043 (substring ex-file
(match-end 0) nil
))
1044 ;; this must be the last clause in this progn
1045 (substring ex-file
(match-beginning 0) (match-end 0))
1048 ;; this leaves only the command name in the work area
1049 ;; file names are gone
1050 (delete-region (point) (1- (point-max)))
1052 (goto-char (point-max))
1053 (skip-chars-backward " \t\n")
1054 (setq prompt
(buffer-substring (point-min) (point)))
1057 (setq viper-last-ex-prompt prompt
)
1059 ;; If we just finished reading command, redisplay prompt
1060 (if viper-incomplete-ex-cmd
1061 (setq ex-file
(viper-ex-read-file-name (format ":%s " prompt
)))
1062 ;; file was typed in-line
1063 (setq ex-file
(or ex-file
"")))
1067 ;; Completes file name or exits minibuffer. If Ex command accepts multiple
1068 ;; file names, arranges to re-enter the minibuffer.
1069 (defun viper-complete-filename-or-exit ()
1071 (setq viper-keep-reading-filename t
)
1072 ;; don't exit if directory---ex-commands don't
1073 (cond ((ex-cmd-accepts-multiple-files-p ex-token
) (exit-minibuffer))
1074 ;; apparently the argument to an Ex command is
1075 ;; supposed to be a shell command
1076 ((viper-looking-back "^[ \t]*!.*")
1080 (setq ex-cmdfile nil
)
1081 (minibuffer-complete-word))))
1083 (defun viper-handle-! ()
1086 (buffer-string) (viper-abbreviate-file-name default-directory
))
1087 (member ex-token
'("read" "write")))
1091 (defun ex-cmd-accepts-multiple-files-p (token)
1092 (member token
'("edit" "next" "Next")))
1094 ;; Read file name from the minibuffer in an ex command.
1095 ;; If user doesn't enter anything, then "" is returned, i.e., the
1096 ;; prompt-directory is not returned.
1097 (defun viper-ex-read-file-name (prompt)
1099 (minibuffer-local-completion-map
1100 (copy-keymap minibuffer-local-completion-map
))
1103 (viper-add-keymap ex-read-filename-map
1105 minibuffer-local-completion-map
1106 read-file-name-map
))
1108 (setq cont
(setq viper-keep-reading-filename t
))
1110 (setq viper-keep-reading-filename nil
1111 val
(read-file-name (concat prompt str
) nil default-directory
))
1112 (setq val
(expand-file-name val
))
1113 (if (and (string-match " " val
)
1114 (ex-cmd-accepts-multiple-files-p ex-token
))
1115 (setq val
(concat "\"" val
"\"")))
1116 (setq str
(concat str
(if (equal val
"") "" " ")
1117 val
(if (equal val
"") "" " ")))
1119 ;; Only edit, next, and Next commands accept multiple files.
1120 ;; viper-keep-reading-filename is set in the anonymous function that is
1121 ;; bound to " " in ex-read-filename-map.
1122 (setq cont
(and viper-keep-reading-filename
1123 (ex-cmd-accepts-multiple-files-p ex-token
)))
1126 (setq beg
(string-match "[^ \t]" str
) ; delete leading blanks
1127 end
(string-match "[ \t]*$" str
)) ; delete trailing blanks
1128 (if (member ex-token
'("read" "write"))
1129 (if (string-match "[\t ]*!" str
)
1130 ;; this is actually a shell command
1134 (setq viper-last-ex-prompt
1135 (concat viper-last-ex-prompt
" !")))))
1136 (substring str
(or beg
0) end
)))
1139 (defun viper-undisplayed-files ()
1142 (if (null (get-buffer-window b
))
1143 (let ((f (buffer-file-name b
)))
1145 (if ex-cycle-through-non-files
1146 (let ((s (buffer-name b
)))
1147 (if (string= " " (substring s
0 1))
1156 (let ((l (viper-undisplayed-files))
1159 (while (not (null l
))
1161 (setq args
(format "%s %d) %s\n" args file-count
(car l
))
1162 file-count
(1+ file-count
)))
1164 (if (string= args
"")
1165 (message "All files are already displayed")
1167 (save-window-excursion
1168 (with-output-to-temp-buffer " *viper-info*"
1169 (princ "\n\nThese files are not displayed in any window.\n")
1170 (princ "\n=============\n")
1172 (princ "\n=============\n")
1173 (princ "\nThe numbers can be given as counts to :next. ")
1174 (princ "\n\nPress any key to continue...\n\n"))
1175 (viper-read-event))))))
1177 ;; Ex cd command. Default directory of this buffer changes
1180 (if (string= ex-file
"")
1182 (setq default-directory
(file-name-as-directory (expand-file-name ex-file
))))
1184 ;; Ex copy and move command. DEL-FLAG means delete
1185 (defun ex-copy (del-flag)
1186 (viper-default-ex-addresses)
1187 (let ((address (viper-get-ex-address))
1188 (end (car ex-addresses
)) (beg (car (cdr ex-addresses
))))
1192 (viper-enlarge-region (mark t
) (point))
1194 (kill-region (point) (mark t
))
1195 (copy-region-as-kill (point) (mark t
)))
1198 (with-output-to-temp-buffer " *copy text*"
1200 (if (or del-flag ex-g-flag ex-g-variant
)
1202 (buffer-substring (point) (mark t
)))))
1205 (read-string "[Hit return to confirm] ")
1206 (save-excursion (kill-buffer " *copy text*")))
1207 (quit (save-excursion (kill-buffer " *copy text*"))
1208 (signal 'quit nil
))))))
1210 (goto-char (point-min))
1213 (insert (current-kill 0))))
1215 ;; Ex delete command
1217 (viper-default-ex-addresses)
1218 (viper-get-ex-buffer)
1219 (let ((end (car ex-addresses
)) (beg (car (cdr ex-addresses
))))
1220 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
1222 (viper-enlarge-region beg end
)
1223 (exchange-point-and-mark)
1227 (forward-line (1- ex-count
)))
1229 (viper-enlarge-region (point) (mark t
))
1231 ;; show text to be deleted and ask for confirmation
1233 (with-output-to-temp-buffer " *delete text*"
1234 (princ (buffer-substring (point) (mark t
))))
1236 (read-string "[Hit return to confirm] ")
1238 (save-excursion (kill-buffer " *delete text*"))
1240 (save-excursion (kill-buffer " *delete text*")))
1242 (cond ((viper-valid-register ex-buffer
'(Letter))
1243 (viper-append-to-register
1244 (downcase ex-buffer
) (point) (mark t
)))
1245 ((viper-valid-register ex-buffer
)
1246 (copy-to-register ex-buffer
(point) (mark t
) nil
))
1247 (t (error viper-InvalidRegister ex-buffer
))))
1248 (kill-region (point) (mark t
))))))
1253 ;; In Viper, `e' and `e!' behave identically. In both cases, the user is
1254 ;; asked if current buffer should really be discarded.
1255 ;; This command can take multiple file names. It replaces the current buffer
1256 ;; with the first file in its argument list
1257 (defun ex-edit (&optional file
)
1259 (viper-get-ex-file))
1260 (cond ((and (string= ex-file
"") buffer-file-name
)
1261 (setq ex-file
(viper-abbreviate-file-name (buffer-file-name))))
1262 ((string= ex-file
"")
1263 (error viper-NoFileSpecified
)))
1266 (if buffer-file-name
1267 (cond ((buffer-modified-p)
1269 (format "Buffer %s is modified. Discard changes? "
1272 ((not (verify-visited-file-modtime (current-buffer)))
1274 (format "File %s changed on disk. Reread from disk? "
1277 (t (setq do-edit nil
))))
1280 (if (yes-or-no-p msg
)
1282 (set-buffer-modified-p nil
)
1283 (kill-buffer (current-buffer)))
1284 (message "Buffer %s was left intact" (buffer-name))))
1287 (if (null (setq file
(get-file-buffer ex-file
)))
1289 ;; this also does shell-style globbing
1291 ;; replace # and % with the previous/current file
1292 (ex-expand-filsyms ex-file
(current-buffer)))
1293 (or (eq major-mode
'dired-mode
)
1294 (viper-change-state-to-vi))
1295 (goto-char (point-min)))
1296 (switch-to-buffer file
))
1299 (save-window-excursion
1300 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1301 (set-buffer viper-ex-work-buf
)
1302 (delete-region (point-min) (point-max))
1303 (insert ex-offset
"\n")
1304 (goto-char (point-min)))
1305 (goto-char (viper-get-ex-address))
1306 (beginning-of-line)))
1307 (ex-fixup-history viper-last-ex-prompt ex-file
))
1309 ;; Find-file FILESPEC if it appears to specify a single file.
1310 ;; Otherwise, assume that FILESPEC is a wildcard.
1311 ;; In this case, split it into substrings separated by newlines.
1312 ;; Each line is assumed to be a file name.
1313 (defun ex-find-file (filespec)
1314 (let ((nonstandard-filename-chars "[^-a-zA-Z0-9_./,~$\\]"))
1315 (cond ((file-exists-p filespec
) (find-file filespec
))
1316 ((string-match nonstandard-filename-chars filespec
)
1317 (mapcar 'find-file
(funcall viper-glob-function filespec
)))
1318 (t (find-file filespec
)))
1322 ;; Ex global command
1323 ;; This is executed in response to:
1324 ;; :global "pattern" ex-command
1325 ;; :vglobal "pattern" ex-command
1326 ;; :global executes ex-command on all lines matching <pattern>
1327 ;; :vglobal executes ex-command on all lines that don't match <pattern>
1329 ;; With VARIANT nil, this functions executes :global
1330 ;; With VARIANT t, executes :vglobal
1331 (defun ex-global (variant)
1332 (let ((gcommand ex-token
))
1333 (if (or ex-g-flag ex-g-variant
)
1334 (error "`%s' within `global' is not allowed" gcommand
)
1342 (error "`%s': Missing regular expression" gcommand
)))
1344 (if (string= ex-token
"")
1345 (if (null viper-s-string
)
1346 (error viper-NoPrevSearch
)
1347 (setq ex-g-pat viper-s-string
))
1348 (setq ex-g-pat ex-token
1349 viper-s-string ex-token
))
1350 (if (null ex-addresses
)
1351 (setq ex-addresses
(list (point-max) (point-min)))
1352 (viper-default-ex-addresses))
1353 (setq ex-g-marks nil
)
1354 (let ((mark-count 0)
1355 (end (car ex-addresses
))
1356 (beg (car (cdr ex-addresses
)))
1358 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
1360 (viper-enlarge-region beg end
)
1361 (exchange-point-and-mark)
1362 (let ((cont t
) (limit (point-marker)))
1363 (exchange-point-and-mark)
1364 ;; skip the last line if empty
1366 (if (eobp) (viper-backward-char-carefully))
1367 (while (and cont
(not (bobp)) (>= (point) limit
))
1371 (let ((found (re-search-backward ex-g-pat
(mark t
) t
)))
1372 (if (or (and ex-g-flag found
)
1373 (and ex-g-variant
(not found
)))
1376 (setq mark-count
(1+ mark-count
))
1377 (setq ex-g-marks
(cons (point-marker) ex-g-marks
)))))
1379 (if (bobp) (setq cont nil
)
1382 (save-window-excursion
1383 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1384 (set-buffer viper-ex-work-buf
)
1385 ;; com-str is the command string, i.e., g/pattern/ or v/pattern'
1386 (setq com-str
(buffer-substring (1+ (point)) (1- (point-max)))))
1388 (goto-char (car ex-g-marks
))
1389 (viper-ex nil com-str
)
1390 (setq mark-count
(1- mark-count
))
1391 (setq ex-g-marks
(cdr ex-g-marks
)))))
1395 (if (null ex-addresses
)
1396 (setq ex-addresses
(cons (point) nil
)))
1397 (push-mark (point) t
)
1398 (goto-char (car ex-addresses
))
1402 ;; Ex line commands. COM is join, shift-right or shift-left
1403 (defun ex-line (com)
1404 (viper-default-ex-addresses)
1405 (viper-get-ex-count)
1406 (let ((end (car ex-addresses
)) (beg (car (cdr ex-addresses
))) point
)
1407 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
1409 (viper-enlarge-region beg end
)
1410 (exchange-point-and-mark)
1414 (forward-line ex-count
)))
1416 ;; show text to be joined and ask for confirmation
1418 (with-output-to-temp-buffer " *join text*"
1419 (princ (buffer-substring (point) (mark t
))))
1422 (read-string "[Hit return to confirm] ")
1423 (ex-line-subr com
(point) (mark t
)))
1425 (save-excursion (kill-buffer " *join text*")))
1426 (ex-line-subr com
(point) (mark t
)))
1427 (setq point
(point)))
1428 (goto-char (1- point
))
1429 (beginning-of-line)))
1431 (defun ex-line-subr (com beg end
)
1432 (cond ((string= com
"join")
1433 (goto-char (min beg end
))
1434 (while (and (not (eobp)) (< (point) (max beg end
)))
1436 (if (and (<= (point) (max beg end
)) (not (eobp)))
1439 (delete-region (point) (1- (point)))
1440 (if (not ex-variant
) (fixup-whitespace))))))
1441 ((or (string= com
"right") (string= com
"left"))
1443 (min beg end
) (max beg end
)
1444 (if (string= com
"right") viper-shift-width
(- viper-shift-width
)))
1445 (goto-char (max beg end
))
1447 (viper-forward-char-carefully))))
1451 ;; Sets the mark to the current point.
1452 ;; If name is omitted, get the name straight from the work buffer."
1453 (defun ex-mark (&optional name
)
1455 (if (null ex-addresses
)
1457 (cons (point) nil
)))
1459 (if (eq 1 (length name
))
1460 (setq char
(string-to-char name
))
1461 (error "`%s': Spurious text \"%s\" after mark name"
1462 name
(substring name
1)))
1463 (save-window-excursion
1464 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1465 (set-buffer viper-ex-work-buf
)
1466 (skip-chars-forward " \t")
1467 (if (looking-at "[a-z]")
1469 (setq char
(following-char))
1471 (skip-chars-forward " \t")
1472 (if (not (looking-at "[\n|]"))
1473 (error "`%s': %s" ex-token viper-SpuriousText
)))
1474 (error "`%s' requires a following letter" ex-token
))))
1476 (goto-char (car ex-addresses
))
1477 (point-to-register (viper-int-to-char (1+ (- char ?a
)))))))
1481 ;; Alternate file is the file next to the first one in the buffer ring
1482 (defun ex-next (cycle-other-window &optional find-alt-file
)
1485 (if (not find-alt-file
)
1488 (if (or (char-or-string-p ex-offset
)
1489 (and (not (string= "" ex-file
))
1490 (not (string-match "^[0-9]+$" ex-file
))))
1493 (throw 'ex-edit nil
))
1494 (setq count
(string-to-number ex-file
))
1495 (if (= count
0) (setq count
1))
1496 (if (< count
0) (error "Usage: `next <count>' (count >= 0)"))))
1498 (setq l
(viper-undisplayed-files))
1500 (while (and (not (null l
)) (null (car l
)))
1502 (setq count
(1- count
))
1505 (if find-alt-file
(car l
)
1507 (if (and (car l
) (get-file-buffer (car l
)))
1508 (let* ((w (if cycle-other-window
1509 (get-lru-window) (selected-window)))
1510 (b (window-buffer w
)))
1511 (set-window-buffer w
(get-file-buffer (car l
)))
1513 ;; this puts "next <count>" in the ex-command history
1514 (ex-fixup-history viper-last-ex-prompt ex-file
))
1515 (error "Not that many undisplayed files")))))))
1518 (defun ex-next-related-buffer (direction &optional no-recursion
)
1520 (viper-ring-rotate1 viper-related-files-and-buffers-ring direction
)
1522 (let ((file-or-buffer-name
1523 (viper-current-ring-item viper-related-files-and-buffers-ring
))
1524 (old-ring viper-related-files-and-buffers-ring
)
1525 (old-win (selected-window))
1528 (or (and (ring-p viper-related-files-and-buffers-ring
)
1529 (> (ring-length viper-related-files-and-buffers-ring
) 0))
1530 (error "This buffer has no related files or buffers"))
1532 (or (stringp file-or-buffer-name
)
1534 "File and buffer names must be strings, %S" file-or-buffer-name
))
1536 (setq buf
(cond ((get-buffer file-or-buffer-name
))
1537 ((file-exists-p file-or-buffer-name
)
1538 (find-file-noselect file-or-buffer-name
))
1541 (if (not (viper-buffer-live-p buf
))
1542 (error "Didn't find buffer %S or file %S"
1544 (viper-abbreviate-file-name
1545 (expand-file-name file-or-buffer-name
))))
1547 (if (equal buf
(current-buffer))
1552 (ex-next-related-buffer direction
'norecursion
))))
1557 (if (setq wind
(viper-get-visible-buffer-window buf
))
1559 (setq wind
(get-lru-window (if viper-xemacs-p nil
'visible
)))
1560 (set-window-buffer wind buf
))
1562 (if (viper-window-display-p)
1564 (raise-frame (window-frame wind
))
1565 (if (equal (window-frame wind
) (window-frame old-win
))
1566 (save-window-excursion (select-window wind
) (sit-for 1))
1567 (select-window wind
)))
1568 (save-window-excursion (select-window wind
) (sit-for 1)))
1572 (setq viper-related-files-and-buffers-ring old-ring
))
1574 (setq viper-local-search-start-marker
(point-marker))
1579 (defun ex-preserve ()
1580 (message "Autosaving all buffers that need to be saved...")
1585 (let ((point (if (null ex-addresses
) (point) (car ex-addresses
))))
1586 (viper-get-ex-buffer)
1587 (setq viper-use-register ex-buffer
)
1589 (if (bobp) (viper-Put-back 1) (viper-put-back 1))))
1591 ;; Ex print working directory
1593 (message "%s" default-directory
))
1597 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc.
1599 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1600 (set-buffer viper-ex-work-buf
)
1601 (if (looking-at "!") (forward-char 1)))
1602 (if (< viper-expert-level
3)
1603 (save-buffers-kill-emacs)
1604 (kill-buffer (current-buffer))))
1608 ;; ex-read doesn't support wildcards, because file completion is a better
1609 ;; mechanism. We also don't support # and % (except in :r <shell-command>
1610 ;; because file history is a better mechanism.
1613 (let ((point (if (null ex-addresses
) (point) (car ex-addresses
)))
1616 (viper-add-newline-at-eob-if-necessary)
1617 (if (not (or (bobp) (eobp))) (forward-line 1))
1618 (if (and (not ex-variant
) (string= ex-file
""))
1620 (if (null buffer-file-name
)
1621 (error viper-NoFileSpecified
))
1622 (setq ex-file buffer-file-name
)))
1626 ;; replace # and % with the previous/current file
1627 (ex-expand-filsyms (concat ex-file ex-cmdfile-args
)
1629 (shell-command command t
))
1630 (insert-file-contents ex-file
)))
1631 (ex-fixup-history viper-last-ex-prompt ex-file ex-cmdfile-args
))
1633 ;; this function fixes ex-history for some commands like ex-read, ex-edit
1634 (defun ex-fixup-history (&rest args
)
1635 (setq viper-ex-history
1636 (cons (mapconcat 'identity args
" ") (cdr viper-ex-history
))))
1639 ;; Ex recover from emacs \#file\#
1640 (defun ex-recover ()
1642 (if (or ex-append ex-offset
)
1643 (error "`recover': %s" viper-SpuriousText
))
1644 (if (string= ex-file
"")
1646 (if (null buffer-file-name
)
1647 (error "This buffer isn't visiting any file"))
1648 (setq ex-file buffer-file-name
))
1649 (setq ex-file
(expand-file-name ex-file
)))
1650 (if (and (not (string= ex-file
(buffer-file-name)))
1653 (error "No write since last change \(:rec! overrides\)"))
1654 (recover-file ex-file
))
1656 ;; Tell that `rewind' is obsolete and to use `:next count' instead
1659 "Use `:n <count>' instead. Counts are obtained from the `:args' command"))
1662 ;; read variable name for ex-set
1663 (defun ex-set-read-variable ()
1664 (let ((minibuffer-local-completion-map
1665 (copy-keymap minibuffer-local-completion-map
))
1666 (cursor-in-echo-area t
)
1669 minibuffer-local-completion-map
" " 'minibuffer-complete-and-exit
)
1670 (define-key minibuffer-local-completion-map
"=" 'exit-minibuffer
)
1671 (if (viper-set-unread-command-events
1672 (ex-get-inline-cmd-args "[ \t]*[a-zA-Z]*[ \t]*" nil
"\C-m"))
1675 (viper-set-unread-command-events ?\C-m
)))
1676 (message ":set <Variable> [= <Value>]")
1677 (or batch
(sit-for 2))
1679 (while (string-match "^[ \\t\\n]*$"
1681 (completing-read ":set " ex-variable-alist
)))
1682 (message ":set <Variable> [= <Value>]")
1683 ;; if there are unread events, don't wait
1684 (or (viper-set-unread-command-events "") (sit-for 2))
1690 (let ((var (ex-set-read-variable))
1694 (auto-cmd-label "; don't touch or else...")
1695 (delete-turn-on-auto-fill-pattern
1696 "([ \t]*add-hook[ \t]+'viper-insert-state-hook[ \t]+'turn-on-auto-fill.*)")
1697 actual-lisp-cmd lisp-cmd-del-pattern
1700 (cond ((string= var
"all")
1701 (setq ask-if-save nil
1703 ((member var
'("ai" "autoindent"))
1704 (setq var
"viper-auto-indent"
1708 ((member var
'("ai-g" "autoindent-global"))
1709 (kill-local-variable 'viper-auto-indent
)
1710 (setq var
"viper-auto-indent"
1711 set-cmd
"setq-default"
1713 ((member var
'("noai" "noautoindent"))
1714 (setq var
"viper-auto-indent"
1717 ((member var
'("noai-g" "noautoindent-global"))
1718 (kill-local-variable 'viper-auto-indent
)
1719 (setq var
"viper-auto-indent"
1720 set-cmd
"setq-default"
1722 ((member var
'("ic" "ignorecase"))
1723 (setq var
"viper-case-fold-search"
1725 ((member var
'("noic" "noignorecase"))
1726 (setq var
"viper-case-fold-search"
1728 ((member var
'("ma" "magic"))
1729 (setq var
"viper-re-search"
1731 ((member var
'("noma" "nomagic"))
1732 (setq var
"viper-re-search"
1734 ((member var
'("ro" "readonly"))
1735 (setq var
"buffer-read-only"
1737 ((member var
'("noro" "noreadonly"))
1738 (setq var
"buffer-read-only"
1740 ((member var
'("sm" "showmatch"))
1741 (setq var
"blink-matching-paren"
1743 ((member var
'("nosm" "noshowmatch"))
1744 (setq var
"blink-matching-paren"
1746 ((member var
'("ws" "wrapscan"))
1747 (setq var
"viper-search-wrap-around-t"
1749 ((member var
'("nows" "nowrapscan"))
1750 (setq var
"viper-search-wrap-around-t"
1752 (if (and set-cmd
(eq val
0)) ; value must be set by the user
1753 (let ((cursor-in-echo-area t
))
1754 (message ":set %s = <Value>" var
)
1755 ;; if there are unread events, don't wait
1756 (or (viper-set-unread-command-events "") (sit-for 2))
1757 (setq val
(read-string (format ":set %s = " var
)))
1758 (ex-fixup-history "set" orig-var val
)
1760 ;; check numerical values
1764 "ts-g" "tabstop-global"
1767 (or (numberp (setq val2
(car (read-from-string val
))))
1768 (error "%s: Invalid value, numberp, %S" var val
))
1770 (error "%s: Invalid value, numberp, %S" var val
))))
1773 ((member var
'("sw" "shiftwidth"))
1774 (setq var
"viper-shift-width"))
1775 ((member var
'("ts" "tabstop"))
1776 ;; make it take effect in curr buff and new bufs
1777 (setq var
"tab-width"
1780 ((member var
'("ts-g" "tabstop-global"))
1781 (kill-local-variable 'tab-width
)
1782 (setq var
"tab-width"
1783 set-cmd
"setq-default"))
1784 ((member var
'("wm" "wrapmargin"))
1785 ;; make it take effect in curr buff and new bufs
1786 (kill-local-variable 'fill-column
)
1787 (setq var
"fill-column"
1788 val
(format "(- (window-width) %s)" val
)
1789 set-cmd
"setq-default"))
1790 ((member var
'("sh" "shell"))
1791 (setq var
"explicit-shell-file-name"
1792 val
(format "\"%s\"" val
)))))
1793 (ex-fixup-history "set" orig-var
))
1796 (setq actual-lisp-cmd
1797 (format "\n(%s %s %s) %s" set-cmd var val auto-cmd-label
)
1798 lisp-cmd-del-pattern
1799 (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s"
1800 set-cmd var auto-cmd-label
)))
1802 (if (and ask-if-save
1803 (y-or-n-p (format "Do you want to save this setting in %s "
1804 viper-custom-file-name
)))
1806 (viper-save-string-in-file
1807 actual-lisp-cmd viper-custom-file-name
1809 lisp-cmd-del-pattern
)
1810 (if (string= var
"fill-column")
1812 (viper-save-string-in-file
1814 "(add-hook 'viper-insert-state-hook 'turn-on-auto-fill) "
1816 viper-custom-file-name
1817 delete-turn-on-auto-fill-pattern
)
1818 (viper-save-string-in-file
1819 nil viper-custom-file-name delete-turn-on-auto-fill-pattern
)
1820 (viper-save-string-in-file
1821 nil viper-custom-file-name
1823 lisp-cmd-del-pattern
)
1830 (if (string-match "^[ \t]*$" val
)
1834 (eval (car (read-from-string actual-lisp-cmd
))))
1835 (if (string= var
"fill-column")
1838 (auto-fill-mode -
1)))
1839 (if (string= var
"all") (ex-show-vars))
1842 ;; In inline args, skip regex-forw and (optionally) chars-back.
1843 ;; Optional 3d arg is a string that should replace ' ' to prevent its
1845 (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str
)
1847 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1848 (set-buffer viper-ex-work-buf
)
1849 (goto-char (point-min))
1850 (re-search-forward regex-forw nil t
)
1853 (goto-char (point-max))
1855 (skip-chars-backward chars-back
)
1856 (skip-chars-backward " \t\n\C-m"))
1858 ;; replace SPC with `=' to suppress the special meaning SPC has
1862 (while (re-search-forward " +" nil t
)
1863 (replace-match replace-str nil t
)
1864 (viper-forward-char-carefully)))
1866 (buffer-substring beg end
))))
1873 ;; Viper help. Invokes Info
1877 (pop-to-buffer (get-buffer-create "*info*"))
1878 (info (if viper-xemacs-p
"viper.info" "viper"))
1879 (message "Type `i' to search for a specific topic"))
1881 (with-output-to-temp-buffer " *viper-info*"
1883 The Info file for Viper does not seem to be installed.
1885 This file is part of the standard distribution of %sEmacs.
1886 Please contact your system administrator. "
1887 (if viper-xemacs-p
"X" "")
1890 ;; Ex source command. Loads the file specified as argument or `~/.viper'
1893 (if (string= ex-file
"")
1894 (load viper-custom-file-name
)
1897 ;; Ex substitute command
1898 ;; If REPEAT use previous regexp which is ex-reg-exp or viper-s-string
1899 (defun ex-substitute (&optional repeat r-flag
)
1903 (case-fold-search viper-case-fold-search
)
1905 (if repeat
(setq ex-token nil
) (setq delim
(viper-get-ex-pat)))
1908 (setq pat
(if r-flag viper-s-string ex-reg-exp
))
1910 (error "No previous pattern to use in substitution"))
1912 delim
(string-to-char pat
)))
1913 (setq pat
(if (string= ex-token
"") viper-s-string ex-token
))
1914 (setq viper-s-string pat
1916 (setq delim
(viper-get-ex-pat))
1922 (while (viper-get-ex-opt-gc delim
)
1923 (if (string= ex-token
"g") (setq opt-g t
) (setq opt-c t
)))
1924 (viper-get-ex-count)
1927 (if ex-addresses
(goto-char (car ex-addresses
)))
1929 (forward-line (1- ex-count
))
1930 (setq ex-addresses
(cons (point) (cons (mark t
) nil
))))
1931 (if (null ex-addresses
)
1932 (setq ex-addresses
(cons (point) (cons (point) nil
)))
1933 (if (null (cdr ex-addresses
))
1934 (setq ex-addresses
(cons (car ex-addresses
) ex-addresses
)))))
1936 (let ((beg (car ex-addresses
))
1937 (end (car (cdr ex-addresses
)))
1940 (viper-enlarge-region beg end
)
1941 (let ((limit (save-excursion
1942 (goto-char (max (point) (mark t
)))
1944 (goto-char (min (point) (mark t
)))
1945 (while (< (point) limit
)
1948 ;; This move allows the use of newline as the last character in
1949 ;; the substitution pattern
1950 (viper-forward-char-carefully)
1951 (setq eol-mark
(point-marker)))
1955 (while (and (not (eolp))
1956 (re-search-forward pat eol-mark t
))
1959 (viper-put-on-search-overlay (match-beginning 0)
1961 (y-or-n-p "Replace? ")))
1963 (viper-hide-search-overlay)
1964 (setq matched-pos
(point))
1965 (if (not (stringp repl
))
1966 (error "Can't perform Ex substitution: No previous replacement pattern"))
1967 (replace-match repl t
))))
1969 (viper-forward-char-carefully))
1972 "Can't repeat Ex substitution: No previous regular expression"))
1973 (if (and (re-search-forward pat eol-mark t
)
1976 (viper-put-on-search-overlay (match-beginning 0)
1978 (y-or-n-p "Replace? "))))
1980 (viper-hide-search-overlay)
1981 (setq matched-pos
(point))
1982 (if (not (stringp repl
))
1983 (error "Can't perform Ex substitution: No previous replacement pattern"))
1984 (replace-match repl t
)))
1986 ;;(viper-forward-char-carefully)
1987 (goto-char eol-mark
)
1989 (if matched-pos
(goto-char matched-pos
))
1991 (if opt-c
(message "done"))))
1996 (save-window-excursion
1997 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
1998 (set-buffer viper-ex-work-buf
)
1999 (skip-chars-forward " \t")
2001 (skip-chars-forward "^ |\t\n")
2002 (setq tag
(buffer-substring (mark t
) (point))))
2003 (if (not (string= tag
"")) (setq ex-tag tag
))
2004 (viper-change-state-to-emacs)
2005 (condition-case conds
2007 (if (string= tag
"")
2009 (find-tag-other-window ex-tag
))
2010 (viper-change-state-to-vi))
2012 (viper-change-state-to-vi)
2013 (viper-message-conditions conds
)))))
2016 ;; ex-write doesn't support wildcards, because file completion is a better
2017 ;; mechanism. We also don't support # and %
2018 ;; because file history is a better mechanism.
2019 (defun ex-write (q-flag)
2020 (viper-default-ex-addresses t
)
2022 (let ((end (car ex-addresses
))
2023 (beg (car (cdr ex-addresses
)))
2024 (orig-buf (current-buffer))
2025 ;;(orig-buf-file-name (buffer-file-name))
2026 ;;(orig-buf-name (buffer-name))
2027 ;;(buff-changed-p (buffer-modified-p))
2028 temp-buf writing-same-file region
2029 file-exists writing-whole-file
)
2030 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
2033 (viper-enlarge-region beg end
)
2034 (shell-command-on-region (point) (mark t
)
2035 (concat ex-file ex-cmdfile-args
)))
2036 (if (and (string= ex-file
"") (not (buffer-file-name)))
2039 (format "Buffer %s isn't visiting any file. File to save in: "
2042 (setq writing-whole-file
(and (= (point-min) beg
) (= (point-max) end
))
2043 ex-file
(if (string= ex-file
"")
2045 (expand-file-name ex-file
)))
2046 ;; if ex-file is a directory use the file portion of the buffer file name
2047 (if (and (file-directory-p ex-file
)
2049 (not (file-directory-p buffer-file-name
)))
2051 (concat (file-name-as-directory ex-file
)
2052 (file-name-nondirectory buffer-file-name
))))
2054 (setq file-exists
(file-exists-p ex-file
)
2055 writing-same-file
(string= ex-file
(buffer-file-name)))
2057 ;; do actual writing
2058 (if (and writing-whole-file writing-same-file
)
2059 ;; saving whole buffer in visited file
2060 (if (not (buffer-modified-p))
2061 (message "(No changes need to be saved)")
2062 (viper-maybe-checkout (current-buffer))
2066 (ex-write-info file-exists ex-file
(point-min) (point-max))
2068 ;; writing to non-visited file and it already exists
2069 (if (and file-exists
(not writing-same-file
)
2071 (format "File %s exists. Overwrite? " ex-file
))))
2073 ;; writing a region or whole buffer to non-visited file
2076 (viper-enlarge-region beg end
)
2077 (setq region
(buffer-substring (point) (mark t
)))
2078 ;; create temp buffer for the region
2079 (setq temp-buf
(get-buffer-create " *ex-write*"))
2080 (set-buffer temp-buf
)
2081 (viper-cond-compile-for-xemacs-or-emacs
2082 (set-visited-file-name ex-file
) ; xemacs
2083 (set-visited-file-name ex-file
'noquerry
) ; emacs
2086 (if (and file-exists ex-append
)
2087 (insert-file-contents ex-file
))
2088 (goto-char (point-max))
2091 (viper-maybe-checkout (current-buffer))
2092 (setq selective-display nil
)
2095 file-exists ex-file
(point-min) (point-max))
2097 ;; this must be under unwind-protect so that
2098 ;; temp-buf will be deleted in case of an error
2099 (set-buffer temp-buf
)
2100 (set-buffer-modified-p nil
)
2101 (kill-buffer temp-buf
)
2102 ;; buffer/region has been written, now take care of details
2103 (set-buffer orig-buf
)))
2104 ;; set the right file modification time
2105 (if (and (buffer-file-name) writing-same-file
)
2106 (set-visited-file-modtime))
2107 ;; prevent loss of data if saving part of the buffer in visited file
2108 (or writing-whole-file
2109 (not writing-same-file
)
2112 (message "Warning: you have saved only part of the buffer!")
2113 (set-buffer-modified-p t
)))
2115 (if (< viper-expert-level
2)
2116 (save-buffers-kill-emacs)
2117 (kill-buffer (current-buffer))))
2121 (defun ex-write-info (exists file-name beg end
)
2122 (message "`%s'%s %d lines, %d characters"
2123 (viper-abbreviate-file-name file-name
)
2124 (if exists
"" " [New file]")
2125 (count-lines beg
(min (1+ end
) (point-max)))
2130 (viper-default-ex-addresses)
2131 (viper-get-ex-buffer)
2132 (let ((end (car ex-addresses
)) (beg (car (cdr ex-addresses
))))
2133 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
2135 (viper-enlarge-region beg end
)
2136 (exchange-point-and-mark)
2137 (if (or ex-g-flag ex-g-variant
)
2138 (error "Can't execute `yank' within `global'"))
2142 (forward-line (1- ex-count
)))
2144 (viper-enlarge-region (point) (mark t
))
2145 (if ex-flag
(error "`yank': %s" viper-SpuriousText
))
2147 (cond ((viper-valid-register ex-buffer
'(Letter))
2148 (viper-append-to-register
2149 (downcase ex-buffer
) (point) (mark t
)))
2150 ((viper-valid-register ex-buffer
)
2151 (copy-to-register ex-buffer
(point) (mark t
) nil
))
2152 (t (error viper-InvalidRegister ex-buffer
))))
2153 (copy-region-as-kill (point) (mark t
)))))
2155 ;; Execute shell command
2156 (defun ex-command ()
2158 (save-window-excursion
2159 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
2160 (set-buffer viper-ex-work-buf
)
2161 (skip-chars-forward " \t")
2162 (setq command
(buffer-substring (point) (point-max)))
2164 ;; replace # and % with the previous/current file
2165 (setq command
(ex-expand-filsyms command
(current-buffer)))
2166 (if (and (> (length command
) 0) (string= "!" (substring command
0 1)))
2167 (if viper-ex-last-shell-com
2169 (concat viper-ex-last-shell-com
(substring command
1)))
2170 (error "No previous shell command")))
2171 (setq viper-ex-last-shell-com command
)
2172 (if (null ex-addresses
)
2173 (shell-command command
)
2174 (let ((end (car ex-addresses
)) (beg (car (cdr ex-addresses
))))
2175 (if (null beg
) (setq beg end
))
2179 (viper-enlarge-region (point) (mark t
))
2180 (shell-command-on-region (point) (mark t
) command t
))
2183 (defun ex-compile ()
2184 "Reads args from the command line, then runs make with the args.
2185 If no args are given, then it runs the last compile command.
2186 Type 'mak ' (including the space) to run make with no args."
2188 (save-window-excursion
2189 (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name
))
2190 (set-buffer viper-ex-work-buf
)
2191 (setq args
(buffer-substring (point) (point-max)))
2193 ;; Remove the newline that may (will?) be at the end of the args
2194 (if (string= "\n" (substring args
(1- (length args
))))
2195 (setq args
(substring args
0 (1- (length args
)))))
2196 ;; Run last command if no args given, else construct a new command.
2198 (if (string= "" args
)
2199 (if (boundp 'compile-command
)
2202 (concat ex-compile-command
" " args
)))
2206 ;; Print line number
2207 (defun ex-line-no ()
2211 (if (null ex-addresses
) (point-max) (car ex-addresses
))))))
2213 ;; Give information on the file visited by the current buffer
2214 (defun viper-info-on-file ()
2216 (let ((pos1 (viper-line-pos 'start
))
2217 (pos2 (viper-line-pos 'end
))
2219 (setq lines
(count-lines (point-min) (viper-line-pos 'end
))
2220 file
(if (buffer-file-name)
2221 (concat (viper-abbreviate-file-name (buffer-file-name)) ":")
2222 (concat (buffer-name) " [Not visiting any file]:"))
2223 info
(format "line=%d/%d pos=%d/%d col=%d %s"
2227 (count-lines (point-min) (point-max))
2228 (point) (1- (point-max))
2229 (1+ (current-column))
2230 (if (buffer-modified-p) "[Modified]" "[Unchanged]")))
2231 (if (< (+ 1 (length info
) (length file
))
2232 (window-width (minibuffer-window)))
2233 (message "%s" (concat file
" " info
))
2234 (save-window-excursion
2235 (with-output-to-temp-buffer " *viper-info*"
2236 (princ (concat "\n" file
"\n\n\t" info
"\n\n")))
2237 (let ((inhibit-quit t
))
2238 (viper-set-unread-command-events (viper-read-event)))
2239 (kill-buffer " *viper-info*")))
2243 ;; Without arguments displays info on file. With an arg, sets the visited file
2245 (defun ex-set-visited-file-name ()
2247 (if (string= ex-file
"")
2248 (viper-info-on-file)
2249 ;; If ex-file is a directory, use the file portion of the buffer
2250 ;; file name (like ex-write). Do this even if ex-file is a
2251 ;; non-existent directory, since set-visited-file-name signals an
2252 ;; error on this condition, too.
2253 (if (and (string= (file-name-nondirectory ex-file
) "")
2255 (not (file-directory-p buffer-file-name
)))
2256 (setq ex-file
(concat (file-name-as-directory ex-file
)
2257 (file-name-nondirectory buffer-file-name
))))
2258 (set-visited-file-name ex-file
)))
2261 ;; display all variables set through :set
2262 (defun ex-show-vars ()
2263 (with-output-to-temp-buffer " *viper-info*"
2264 (princ (if viper-auto-indent
2265 "autoindent (local)\n" "noautoindent (local)\n"))
2266 (princ (if (default-value 'viper-auto-indent
)
2267 "autoindent (global) \n" "noautoindent (global) \n"))
2268 (princ (if viper-case-fold-search
"ignorecase\n" "noignorecase\n"))
2269 (princ (if viper-re-search
"magic\n" "nomagic\n"))
2270 (princ (if buffer-read-only
"readonly\n" "noreadonly\n"))
2271 (princ (if blink-matching-paren
"showmatch\n" "noshowmatch\n"))
2272 (princ (if viper-search-wrap-around-t
"wrapscan\n" "nowrapscan\n"))
2273 (princ (format "shiftwidth \t\t= %S\n" viper-shift-width
))
2274 (princ (format "tabstop (local) \t= %S\n" tab-width
))
2275 (princ (format "tabstop (global) \t= %S\n" (default-value 'tab-width
)))
2276 (princ (format "wrapmargin (local) \t= %S\n"
2277 (- (window-width) fill-column
)))
2278 (princ (format "wrapmargin (global) \t= %S\n"
2279 (- (window-width) (default-value 'fill-column
))))
2280 (princ (format "shell \t\t\t= %S\n" (if (boundp 'explicit-shell-file-name
)
2281 explicit-shell-file-name
2286 (viper-default-ex-addresses)
2287 (let ((end (car ex-addresses
))
2288 (beg (car (cdr ex-addresses
))))
2289 (if (> beg end
) (error viper-FirstAddrExceedsSecond
))
2291 (viper-enlarge-region beg end
)
2292 (if (or ex-g-flag ex-g-variant
)
2293 ;; When executing a global command, collect output of each
2294 ;; print in viper-ex-print-buf.
2296 (append-to-buffer viper-ex-print-buf
(point) (mark t
))
2297 ;; Is this the last mark for the global command?
2298 (unless (cdr ex-g-marks
)
2299 (with-current-buffer viper-ex-print-buf
2300 (ex-print-display-lines (buffer-string))
2302 (ex-print-display-lines (buffer-substring (point) (mark t
)))))))
2304 (defun ex-print-display-lines (lines)
2306 ;; String doesn't contain a newline.
2307 ((not (string-match "\n" lines
))
2308 (message "%s" lines
))
2309 ;; String contains only one newline at the end. Strip it off.
2310 ((= (string-match "\n" lines
) (1- (length lines
)))
2311 (message "%s" (substring lines
0 -
1)))
2312 ;; String spans more than one line. Use a temporary buffer.
2314 (save-current-buffer
2315 (with-output-to-temp-buffer " *viper-info*"
2322 ;;; arch-tag: 56b80d36-f880-4d10-bd66-85ad91a295db
2323 ;;; viper-ex.el ends here