From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: compare-windows - synchronize points Date: 14 Aug 2003 08:33:10 +0300 Organization: JURTA Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <87ptj8ajmx.fsf@mail.jurta.org> References: <87adagx8x8.fsf@mail.jurta.org> <87oeyuuuvz.fsf@mail.jurta.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1060839914 30353 80.91.224.253 (14 Aug 2003 05:45:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 14 Aug 2003 05:45:14 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Thu Aug 14 07:45:13 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19nAvB-00072d-00 for ; Thu, 14 Aug 2003 07:45:13 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 19nAva-0005FZ-00 for ; Thu, 14 Aug 2003 07:45:39 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19nArT-0003TL-7a for emacs-devel@quimby.gnus.org; Thu, 14 Aug 2003 01:41:23 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19nAr9-00038s-CK for emacs-devel@gnu.org; Thu, 14 Aug 2003 01:41:03 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19nAqb-0001iY-Ij for emacs-devel@gnu.org; Thu, 14 Aug 2003 01:41:00 -0400 Original-Received: from [64.246.52.22] (helo=ns5.tangramltd.com) by monty-python.gnu.org with esmtp (Exim 4.20) id 19nAqb-0001hx-97; Thu, 14 Aug 2003 01:40:29 -0400 Original-Received: from 80-235-34-223-dsl.mus.estpak.ee ([80.235.34.223] helo=mail.jurta.org) by ns5.tangramltd.com with esmtp (Exim 4.20) id 19nAqW-0001ZE-VB; Thu, 14 Aug 2003 08:40:25 +0300 Original-To: rms@gnu.org In-Reply-To: User-Agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) Original-Lines: 79 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - ns5.tangramltd.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - jurta.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:15939 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:15939 Richard Stallman writes: > I think that end-of-defun would move too far--the end of the defun can > easily be 100 lines down. This would be quite likely to overlook > further interesting differences. I agree. The end-of-defun is useless on large functions. > Currently the variable compare-windows-sync has no -function suffix, > because it can hold whether a function or a regexp. > > Have you found the regexp case to be useful in any real situation? Yes, the regexp is useful. For example, if different files contain changes separated by some fixed string (as e.g. field separators in comma-separated value lists, etc.) > > Another idea I have for syncing up is that a program could use a > > simple quadratic algorithm to find the first matching 4-character > > string in the two buffers, and move there. This might get painfully > > slow when there are substantial insertions, though. > > If it tried syncing up by comparing entire lines, it could handle > even quite large changes fairly fast. Would you like to give that a try? OK, here is quick implementation of simple quadratic algorithm. Seems, it works well on small differences, but fails on big ones. Increasing the default numbers improves the situation, but function starts to get more slow. (defvar compare-windows-sync-string-size 4) (defvar compare-windows-sync-region-size 200) (defvar compare-windows-sync-point nil) (defvar compare-windows-sync 'compare-windows-sync-default-function) ;; Function works in two passes: one call on each window. ;; On first call both matching points are computed, ;; and one of them is stored in compare-windows-sync-point ;; to be used when this function is called on second window. (defun compare-windows-sync-default-function () (if compare-windows-sync-point (progn (if (numberp compare-windows-sync-point) (goto-char compare-windows-sync-point)) (setq compare-windows-sync-point nil)) (let* ((case-fold-search compare-ignore-case) (w2 (next-window (selected-window))) (b2 (window-buffer w2)) (op2 (1+ (window-point w2))) (op1 (point)) (p1 (1+ op1)) (bound1 (- (min (+ p1 compare-windows-sync-region-size) (point-max)) compare-windows-sync-string-size)) (bound2 (- (min (+ op2 compare-windows-sync-region-size) (with-current-buffer b2 (point-max))) compare-windows-sync-string-size)) s1 p2 p2s pp) (while (< p1 bound1) (setq s1 (buffer-substring-no-properties p1 (+ p1 compare-windows-sync-string-size))) (setq p2 (with-current-buffer b2 (goto-char op2) (search-forward s1 bound2 t))) (when p2 (setq p2 (- p2 compare-windows-sync-string-size)) ;; calculate the distance between two matching points (setq p2s (cons (list (sqrt (+ (expt (- p1 op1) 2) (expt (- p2 op2) 2))) p1 p2) p2s))) (setq p1 (1+ p1))) ;; use matching points with minimal distance (when p2s (setq pp (cdr (assoc (apply 'min (mapcar 'car p2s)) p2s))) (goto-char (car pp))) (setq compare-windows-sync-point (or (cadr pp) t))))) -- http://www.jurta.org/emacs/