Function: viper-change
viper-change is a byte-compiled function defined in viper-cmd.el.gz.
Signature
(viper-change BEG END)
Source Code
;; Defined in /usr/src/emacs/lisp/emulation/viper-cmd.el.gz
;; Replace state
(defun viper-change (beg end)
(if (markerp beg) (setq beg (marker-position beg)))
(if (markerp end) (setq end (marker-position end)))
;; beg is sometimes (mark t), which may be nil
(or beg (setq beg end))
(viper-set-complex-command-for-undo)
(if viper-use-register
(progn
(copy-to-register viper-use-register beg end nil)
(setq viper-use-register nil)))
(viper-set-replace-overlay beg end)
(setq last-command nil) ; separate repl text from prev kills
(if (= (viper-replace-start) (point-max))
(error "End of buffer"))
(setq viper-last-replace-region
(buffer-substring (viper-replace-start)
(viper-replace-end)))
;; protect against error while inserting "@" and other disasters
;; (e.g., read-only buff)
(condition-case conds
(if (or viper-allow-multiline-replace-regions
(viper-same-line (viper-replace-start)
(viper-replace-end)))
(progn
;; tabs cause problems in replace, so untabify
(goto-char (viper-replace-end))
(insert-before-markers "@") ; put placeholder after the TAB
(untabify (viper-replace-start) (point))
;; del @, don't put on kill ring
(delete-char -1)
(viper-set-replace-overlay-glyphs
viper-replace-region-start-delimiter
viper-replace-region-end-delimiter)
;; this move takes care of the last posn in the overlay, which
;; has to be shifted because of insert. We can't simply insert
;; "$" before-markers because then overlay-start will shift the
;; beginning of the overlay in case we are replacing a single
;; character. This fixes the bug with `s' and `cl' commands.
(viper-move-replace-overlay (viper-replace-start) (point))
(goto-char (viper-replace-start))
(viper-change-state-to-replace t))
(kill-region (viper-replace-start)
(viper-replace-end))
(viper-hide-replace-overlay)
(viper-change-state-to-insert))
(error ;; make sure that the overlay doesn't stay.
;; go back to the original point
(goto-char (viper-replace-start))
(viper-hide-replace-overlay)
(viper-message-conditions conds))))