From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#70077: An easier way to track buffer changes Date: Fri, 29 Mar 2024 14:53:41 -0400 Message-ID: References: <86frw8ewk9.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23392"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: yantar92@posteo.net, 70077@debbugs.gnu.org, casouri@gmail.com, qhong@alum.mit.edu, frederic.bour@lakaban.net, joaotavora@gmail.com, mail@nicolasgoaziou.fr, acm@muc.de, stephen_leake@stephe-leake.org, alan.zimm@gmail.com, phillip.lord@russet.org.uk To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 29 19:54:28 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rqHMy-0005rB-I2 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 29 Mar 2024 19:54:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rqHMY-0008JH-Tu; Fri, 29 Mar 2024 14:54:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rqHMX-0008J9-2p for bug-gnu-emacs@gnu.org; Fri, 29 Mar 2024 14:54:01 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rqHMW-0001fL-O8 for bug-gnu-emacs@gnu.org; Fri, 29 Mar 2024 14:54:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rqHMX-0001NY-RY for bug-gnu-emacs@gnu.org; Fri, 29 Mar 2024 14:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 29 Mar 2024 18:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70077 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70077-submit@debbugs.gnu.org id=B70077.17117384325216 (code B ref 70077); Fri, 29 Mar 2024 18:54:01 +0000 Original-Received: (at 70077) by debbugs.gnu.org; 29 Mar 2024 18:53:52 +0000 Original-Received: from localhost ([127.0.0.1]:43428 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rqHMO-0001M4-9A for submit@debbugs.gnu.org; Fri, 29 Mar 2024 14:53:52 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39499) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rqHMM-0001LS-G8 for 70077@debbugs.gnu.org; Fri, 29 Mar 2024 14:53:50 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 46E3910005D; Fri, 29 Mar 2024 14:53:43 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1711738421; bh=zOuPkA9+KnkBmDhWM6pkYAbuAuNqNnLQt+Y6IxhMd+Q=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=PenlcIecRM4Ov26Y46ANcWAjIvOGnUaqlOW6MeWF9LD7PFeEywpkfSSzxeyTPAGB/ jCvOvXHIMBT8wJX3li4kYhBlapZbZvMUr0IoUY5jbGkuLIitUdj7FUEDeIxhvuJuXO n0YsgeRUziSdEnjfVl0aR0PMGQRR5+v3K6JlUnE0pn1yzmUV5z1qdQIpJOlU6bwW59 E4jW7NDsLlW81Fdjd8mNNHtPwydFvXmKwU6FPGP/4fwRQXivCwt7iOf9BOHw4Pyw9O clFNSf4LfT6srImj27nHLg+ns0tWRFk8z5/RH0XL4VzDdmWMahZc2qr0b2g0ZiHviz BbR7/BN0/LpTg== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D48A0100046; Fri, 29 Mar 2024 14:53:41 -0400 (EDT) Original-Received: from pastel (104-222-113-60.cpe.teksavvy.com [104.222.113.60]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 78A36120185; Fri, 29 Mar 2024 14:53:41 -0400 (EDT) In-Reply-To: <86frw8ewk9.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 29 Mar 2024 21:12:54 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:282316 Archived-At: > I cannot imagine how applications would use these APIs. I'm probably > missing something, org the above documentation does. Can you show > some real-life examples? Haven't written real code for it yes, no. The best I can offer is the sample code in the file: (defvar my-foo--change-tracker nil) (define-minor-mode my-foo-mode "Fooing like there's no tomorrow." (if (null my-foo-mode) (when my-foo--change-tracker (track-changes-unregister my-foo--change-tracker) (setq my-foo--change-tracker nil)) (unless my-foo--change-tracker (setq my-foo--change-tracker (track-changes-register (lambda () (track-changes-fetch my-foo--change-tracker (lambda (beg end before) ..DO THE THING..)))))))) Where "DO THE THING" is run similarly to what would happen in an `after-change-functions`, except: - BEFORE is a string holding the content of what was in BEG..END instead of being limited to its length. - It's run at most once per command, so there's no performance worries. - It's run "outside" of the modifications themselves, so `inhibit-modification-hooks` is nil and the code can wait, modify the buffer, or do any kind of crazy things. The code can also be changed to: [...] (track-changes-register (lambda () (run-with-idle-timer 2 nil (lambda () (track-changes-fetch my-foo--change-tracker (lambda (beg end before) ..DO THE THING..)))))))) without any extra work. Stefan