Function: ex-global
ex-global is a byte-compiled function defined in viper-ex.el.gz.
Signature
(ex-global VARIANT)
Source Code
;; Defined in /usr/src/emacs/lisp/emulation/viper-ex.el.gz
;; Ex global command
;; This is executed in response to:
;; :global "pattern" ex-command
;; :vglobal "pattern" ex-command
;; :global executes ex-command on all lines matching <pattern>
;; :vglobal executes ex-command on all lines that don't match <pattern>
;;
;; With VARIANT nil, this functions executes :global
;; With VARIANT t, executes :vglobal
(defun ex-global (variant)
(let ((gcommand ex-token))
(if (or ex-g-flag ex-g-variant)
(error "`%s' within `global' is not allowed" gcommand)
(if variant
(setq ex-g-flag nil
ex-g-variant t)
(setq ex-g-flag t
ex-g-variant nil)))
(viper-get-ex-pat)
(if (null ex-token)
(error "`%s': Missing regular expression" gcommand)))
(if (string= ex-token "")
(if (null viper-s-string)
(error viper-NoPrevSearch)
(setq ex-g-pat viper-s-string))
(setq ex-g-pat ex-token
viper-s-string ex-token))
(if (null ex-addresses)
(setq ex-addresses (list (point-max) (point-min)))
(viper-default-ex-addresses))
(setq ex-g-marks nil)
(let ((mark-count 0)
(end (car ex-addresses))
(beg (car (cdr ex-addresses)))
com-str)
(if (> beg end) (error viper-FirstAddrExceedsSecond))
(save-excursion
(viper-enlarge-region beg end)
(exchange-point-and-mark)
(let ((cont t) (limit (point-marker)))
(exchange-point-and-mark)
;; skip the last line if empty
(beginning-of-line)
(if (eobp) (viper-backward-char-carefully))
(while (and cont (not (bobp)) (>= (point) limit))
(beginning-of-line)
(set-mark (point))
(end-of-line)
(let ((found (re-search-backward ex-g-pat (mark t) t)))
(if (or (and ex-g-flag found)
(and ex-g-variant (not found)))
(progn
(end-of-line)
(setq mark-count (1+ mark-count))
(setq ex-g-marks (cons (point-marker) ex-g-marks)))))
(beginning-of-line)
(if (bobp) (setq cont nil)
(forward-line -1)
(end-of-line)))))
(with-current-buffer (setq viper-ex-work-buf
(get-buffer-create viper-ex-work-buf-name))
;; com-str is the command string, i.e., g/pattern/ or v/pattern'
(setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
(while ex-g-marks
(goto-char (car ex-g-marks))
(viper-ex nil com-str)
(setq mark-count (1- mark-count))
(setq ex-g-marks (cdr ex-g-marks)))))