Function: vcursor-compare-windows
vcursor-compare-windows is an interactive and byte-compiled function
defined in vcursor.el.gz.
Signature
(vcursor-compare-windows &optional IGNORE-WHITESPACE)
Documentation
Compare text in current window with text in window with vcursor.
Compares the text starting at point in the current window and at the vcursor position in the other window, moving over text in each one as far as they match.
A prefix argument, if any, means ignore changes in whitespace.
The variable compare-windows-whitespace controls how whitespace is skipped.
If compare-ignore-case is non-nil, changes in case are also ignored.
Probably introduced at or before Emacs version 20.3.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/vcursor.el.gz
;; vcursor-compare-windows is copied from compare-w.el with only
;; minor modifications; these are too bound up with the function
;; to make it really useful to call compare-windows itself.
(defun vcursor-compare-windows (&optional ignore-whitespace)
"Compare text in current window with text in window with vcursor.
Compares the text starting at point in the current window and at the
vcursor position in the other window, moving over text in each one as
far as they match.
A prefix argument, if any, means ignore changes in whitespace.
The variable `compare-windows-whitespace' controls how whitespace is skipped.
If `compare-ignore-case' is non-nil, changes in case are also ignored."
(interactive "P")
;; (vcursor-window-funcall #'compare-windows arg)
(require 'compare-w)
(let* (p1 p2 maxp1 maxp2 b1 b2 w2
success
(opoint1 (point))
opoint2
(skip-whitespace (if ignore-whitespace
compare-windows-whitespace)))
(setq p1 (point) b1 (current-buffer))
(setq w2 (vcursor-find-window t t))
(if (or (eq w2 (selected-window)) (not w2))
(error "No other window with vcursor"))
(save-excursion
(vcursor-locate)
(setq p2 (point) b2 (current-buffer)))
(setq opoint2 p2)
(setq maxp1 (point-max))
(with-current-buffer b2
(setq maxp2 (point-max)))
(setq success t)
(while success
(setq success nil)
;; if interrupted, show how far we've gotten
(goto-char p1)
(vcursor-move p2 t)
;; If both buffers have whitespace next to point,
;; optionally skip over it.
(and skip-whitespace
(save-excursion
(let (p1a p2a result1 result2)
(setq result1
(if (stringp skip-whitespace)
(compare-windows-skip-whitespace opoint1)
(funcall skip-whitespace opoint1)))
(setq p1a (point))
(set-buffer b2)
(goto-char p2)
(setq result2
(if (stringp skip-whitespace)
(compare-windows-skip-whitespace opoint2)
(funcall skip-whitespace opoint2)))
(setq p2a (point))
(if (or (stringp skip-whitespace)
(and result1 result2 (eq result1 result2)))
(setq p1 p1a
p2 p2a)))))
;; Try advancing comparing 1000 chars at a time.
;; When that fails, go 500 chars at a time, and so on.
(let ((size 1000)
success-1
(case-fold-search compare-ignore-case))
(while (> size 0)
(setq success-1 t)
;; Try comparing SIZE chars at a time, repeatedly, till that fails.
(while success-1
(setq size (min size (- maxp1 p1) (- maxp2 p2)))
(setq success-1
(and (> size 0)
(= 0 (compare-buffer-substrings b2 p2 (+ size p2)
b1 p1 (+ size p1)))))
(if success-1
(setq p1 (+ p1 size) p2 (+ p2 size)
success t)))
;; If SIZE chars don't match, try fewer.
(setq size (/ size 2)))))
(goto-char p1)
(vcursor-move p2 t)
(if (= (point) opoint1)
(ding)))
)