Function: viper-replace-mode-spy-after
viper-replace-mode-spy-after is a byte-compiled function defined in
viper-cmd.el.gz.
Signature
(viper-replace-mode-spy-after BEG END LENGTH)
Source Code
;; Defined in /usr/src/emacs/lisp/emulation/viper-cmd.el.gz
;; Invoked as an after-change-function to calculate how many chars have to be
;; deleted. This function may be called several times within a single command,
;; if this command performs several separate buffer changes. Therefore, if
;; adds up the number of chars inserted and subtracts the number of chars
;; deleted.
(defun viper-replace-mode-spy-after (beg end length)
(if (memq viper-intermediate-command
'(dabbrev-expand hippie-expand repeating-insertion-from-ring))
;; Take special care of text insertion from insertion ring inside
;; replacement overlays.
(progn
(setq viper-replace-chars-to-delete 0)
(viper-move-marker-locally
'viper-last-posn-in-replace-region (point)))
(let* ((real-end (min end (viper-replace-end)))
(column-shift (- (save-excursion (goto-char real-end)
(current-column))
(save-excursion (goto-char beg)
(current-column))))
(chars-deleted 0))
(if (> length 0)
(setq chars-deleted viper-replace-region-chars-deleted))
(setq viper-replace-region-chars-deleted 0)
(setq viper-replace-chars-to-delete
(+ viper-replace-chars-to-delete
(-
;; if column shift is bigger, due to a TAB insertion, take
;; column-shift instead of the number of inserted chars
(max (viper-chars-in-region beg real-end)
;; This test accounts for Chinese/Japanese/... chars,
;; which occupy 2 columns instead of one. If we use
;; column-shift here, we may delete two chars instead of
;; one when the user types one Chinese character.
;; Deleting two would be OK, if they were European chars,
;; but it is not OK if they are Chinese chars.
;; Since it is hard to
;; figure out which characters are being deleted in any
;; given region, we decided to treat Eastern and European
;; characters equally, even though Eastern chars may
;; occupy more columns.
(if (memq this-command '(self-insert-command
quoted-insert viper-insert-tab))
column-shift
0))
;; the number of deleted chars
chars-deleted)))
(viper-move-marker-locally
'viper-last-posn-in-replace-region
(max (if (> end (viper-replace-end)) (viper-replace-end) end)
(or (marker-position viper-last-posn-in-replace-region)
(viper-replace-start))
))
)))