🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99713

two-way compare-windows

#99713
From: macrakis
Date: Fri, 25 May 1990 10:39
65 lines
3127 bytes
A few minor changes to compare-windows (compare-w.el) so that it can
compare forwards or backwards:

;; Compare text between windows for Emacs.
;; Copyright (C) 1986 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.

;; added backp -- macrakis@gr.osf.org, 25 May 90

(defun compare-windows (backp)
  "Compare text in current window with text in next window.
Compares the text starting at point in each window,
moving over text in each one as far as they match.
With argument, compare backwards."
  (interactive "P")
  (let (p1 p2 maxp1 maxp2 b1 b2 w2
	   success size size-bar	; size-bar is signed (vector) size
	   (opoint (point)))
    (setq p1 (point) b1 (current-buffer))
    (setq w2 (next-window (selected-window)))
    (if (eq w2 (selected-window))
	(error "No other window."))
    (setq p2 (window-point w2)
	  b2 (window-buffer w2))
    (setq maxp1 (if backp (point-min) (point-max)))
    (save-excursion
      (set-buffer b2)
      (setq maxp2 (if backp (point-min) (point-max))))
    ;; Try advancing comparing 1000 chars at a time.
    ;; When that fails, go 500 chars at a time, and so on.
    (setq size 1000)
    (while (> size 0)
      (setq success t)
      (while success
	(setq size (min size (abs (- maxp1 p1)) (abs (- maxp2 p2))))
	(setq size-bar (if backp (- size) size))
	(save-excursion
	 (set-buffer b2)
	 (setq s2 (buffer-substring p2 (+ size-bar p2))))
	(setq s1 (buffer-substring p1 (+ size-bar p1)))
	(setq success (and (> size 0) (equal s1 s2)))
	(if success
	    (setq p1 (+ p1 size-bar) p2 (+ p2 size-bar))))
      (setq size (/ size 2)))

    (goto-char p1)
    (set-window-point w2 p2)
    (if (= (point) opoint)
	(ding))))
Technical Details
Message-ID: <9005251134.AA18450@.dupuis.>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!fernwood!apple!mips!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ri.osf.fr!macrakis

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,ceb150c574465020,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-05-25 07:29:02 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!fernwood!apple!mips!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ri.osf.fr!macrakis
From: macrakis@ri.osf.fr
Newsgroups: gnu.emacs.bug
Subject: two-way compare-windows
Message-ID: <9005251134.AA18450@.dupuis.>
Date: 25 May 90 10:39:03 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 65
Posted: Fri May 25 11:39:03 1990