From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: track-changes and undo Date: Mon, 22 Apr 2024 23:41:01 +0200 Message-ID: <86a5lloz2q.fsf@p200300d6272f172e0e35ca5d92eef483.dip0.t-ipconnect.de> References: <864jbvdszb.fsf@p200300d6272f17de4b8317bb694a7515.dip0.t-ipconnect.de> <86il09g8bo.fsf@p200300d6272f1758742b590e6df1ee48.dip0.t-ipconnect.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10329"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.12.2; emacs 29.3 Cc: "'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'" To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Apr 22 23:41:41 2024 Return-path: Envelope-to: geh-help-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 1rz1Pw-0002Zx-FQ for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 22 Apr 2024 23:41:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rz1PY-0006nx-Hc; Mon, 22 Apr 2024 17:41:16 -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 1rz1PV-0006nQ-Np for help-gnu-emacs@gnu.org; Mon, 22 Apr 2024 17:41:13 -0400 Original-Received: from wfout1-smtp.messagingengine.com ([64.147.123.144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rz1PT-0003Cw-M9 for help-gnu-emacs@gnu.org; Mon, 22 Apr 2024 17:41:13 -0400 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.west.internal (Postfix) with ESMTP id B9D2A1C00154; Mon, 22 Apr 2024 17:41:06 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 22 Apr 2024 17:41:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1713822066; x=1713908466; bh=+rv14MIbYvbdy4A7LWGTAI35nDR0tVSGXG5JbcIO3HQ=; b= vCdZEeY8QV3+8xBWo7JihEB4rwmbZJOgiGW1LJUBkRjdhPxA6pEd0PqNAKH9bgPo 5C0bSZ9oq77N3lgjZOmd1ts3Aqwfsr/K/imr5e5qdPBAIDoXfil2KsHKtiifjrOr jIMyK+HTjmwmEQRFh2UMgO5xzTZ79nILNDW5mXxRIor0z8hwqSvyFUJduHE3grmS BGUjunFUbW79Qi4rcTp3HjytyqhiwXx78le4LTNvO54TuIuCGjItue1NKdGpe7eL zIgl74kqUuo27m2dEQfuu69s2s7ro/fiFIiVztogOzRZT5AOsid0Mc6BKjLgqWtZ +Tq3vKlmLhVq7hClmDsIZQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1713822066; x= 1713908466; bh=+rv14MIbYvbdy4A7LWGTAI35nDR0tVSGXG5JbcIO3HQ=; b=X aiNR7dKoKP2cd+8Q79pO45RiwDlRBYmU0CoRrUVbzd2UhQYGseYCbM9rXZJygcEv 1oTH8L7uvousY/y1+hnzofXItWOagu61KZYVNd+ebRJLLs8r8c+4MwwK01vOYfE3 MTROaYXb/klB5cXCxHGHyzB1VLf5vIJzVI1XSGXymG+1NKuRQlnqsq4ziyPuzTyy yvpKAo7igc3mvFhRMNKmNp694e2/T4F6CAie40EoDd/ssBJfZs13mCR0nA7gdUO8 38hrVcx7RR+iXDWpo2JAPwzcs59hSabMmOn5l/Omf6iKOF1tW44OLI2h+N8j2uir DdZNpVT2g0+S/iJUxzWDQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeltddgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefujghffgffkfggtgfgsehtqhertddtreejnecuhfhrohhmpeflohho shhtucfmrhgvmhgvrhhsuceojhhoohhsthhkrhgvmhgvrhhssehfrghsthhmrghilhdrfh hmqeenucggtffrrghtthgvrhhnpeelgeeiheduueelgeevudefgedtffejudetvedutdfh keejteegheevkeeutdfgvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehjohhoshhtkhhrvghmvghrshesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Feedback-ID: ie15541ac:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 22 Apr 2024 17:41:05 -0400 (EDT) In-Reply-To: (Stefan Monnier's message of "Mon, 22 Apr 2024 08:38:14 -0400") Received-SPF: pass client-ip=64.147.123.144; envelope-from=joostkremers@fastmail.fm; helo=wfout1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:146434 Archived-At: On Mon, Apr 22 2024, Stefan Monnier wrote: > The gain from `track-changes` is just to provide you with the "before" > string for deletions so it takes care of reading it in > `before-change-functions` and then providing it to you in the > `after-change-functions` (with the advantage that it detects/handles the > various corner cases where that pairing fails). I think I'll try and see if I can make it work with the `:immediate` option. It would of course mean that the buffer is modified inside `after-change-functions`, which you warn against, but it looks like that's = the only way. > One other thing that you might have trouble to reproduce with > `track-changes` is the following test: > > (and (=3D beg (point-min)) (=3D end (point-max))) > > that you have in `cm-before-change`. I'm not completely sure what this > is for, tho. Is it for `revert-buffer`? I honestly don't remember... Based on the comment, it looks like `switch-to-buffer` triggers `before-change-functions`, but a) that doesn't = make much sense; and b) the code seems to work just fine without that line. (I e= ven fired up a Vagrant box with an old Ubuntu release with Emacs 24, which woul= d be the most recent version when I wrote that code). > [ I tend to do "destructive reads", so the patch below is the result of > reading that part of your code. ] Thanks. > +(define-minor-mode cm-follow-changes ;FIXME: Shouldn't it end in `mode'? > + "Minor mode to follow changes." > + :global nil > + (if cm-follow-changes > + (progn > + (add-hook 'before-change-functions #'cm-before-change t t) > + (add-hook 'after-change-functions #'cm-after-change nil t)) > + (remove-hook 'before-change-functions #'cm-before-change t) > + (remove-hook after-change-functions #'cm-after-change t))) Making it a minor mode makes sense, of course. And don't ask me why I used `add-to-list` instead of `add-hook`. =F0=9F=A4=94 =20=20 --=20 Joost Kremers Life has its moments