From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: track-changes and undo Date: Mon, 22 Apr 2024 19:04:10 -0400 Message-ID: References: <864jbvdszb.fsf@p200300d6272f17de4b8317bb694a7515.dip0.t-ipconnect.de> <86il09g8bo.fsf@p200300d6272f1758742b590e6df1ee48.dip0.t-ipconnect.de> <86a5lloz2q.fsf@p200300d6272f172e0e35ca5d92eef483.dip0.t-ipconnect.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24181"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: "'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'" To: Joost Kremers Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 23 01:04:59 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 1rz2iZ-00060l-AO for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 23 Apr 2024 01:04:59 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rz2hw-00036n-82; Mon, 22 Apr 2024 19:04:20 -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 1rz2hs-00036Y-C9 for help-gnu-emacs@gnu.org; Mon, 22 Apr 2024 19:04:16 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rz2hq-0000C7-8b for help-gnu-emacs@gnu.org; Mon, 22 Apr 2024 19:04:16 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 862A5100170; Mon, 22 Apr 2024 19:04:12 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1713827051; bh=udZs4HQVTRJisw1InQlh68lgSdJI1tXW4b5HHZGRr94=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Td68qKSEz6Q2nIyUHRZNGU8bERRYplFNy7gFGvmFZy4tbsZY0/yBd8d/I0xp/mQIg GEXI2xkQZI4FhsmreXxNd80KJqVT2HfSgDPaklp3nFN+Ddtz14iTjvJ3Q0ocaPzciv HehqfRdhABdjISXbi4Zu2DIjJjIK89HJMsT9UFmxshjNdhDx0liKDe1GKsa2UTdfwd MZObIags8N9s2425ulrSHsF+KMdqjO4n8Z20kJxQmi033QG2Vbw3XpHwdHLE4RHNrF qhLAcZSbdBN2Wue6MJ48BFbIl5yh06WM09LdeApDXNuoPRFJh1zW0MvR6r27D7W8F4 Uh9MwTmZ8aAkw== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7548210005D; Mon, 22 Apr 2024 19:04:11 -0400 (EDT) Original-Received: from pastel (unknown [45.72.201.215]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5506D12064B; Mon, 22 Apr 2024 19:04:11 -0400 (EDT) In-Reply-To: <86a5lloz2q.fsf@p200300d6272f172e0e35ca5d92eef483.dip0.t-ipconnect.de> (Joost Kremers's message of "Mon, 22 Apr 2024 23:41:01 +0200") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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:146435 Archived-At: >> 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, It wouldn't be worse than what you have now since you also modify the buffer from `before/after-change-functions`. > but it looks like that's the only way. In the general case it's tricky to postpone the buffer change to a safer time, indeed. In practice, tho, you should be able to distinguish "undo commands" from all other commands (basically depending on whether they do all their modifications with `undo-in-progress` or not) and then ignore only the changes of undo commands: the result should be good enough. IOW something like: (track-changes-register #'cm-change-signal :immediate t) (defvar-local cm-change-pending nil) (defun cm-change-signal (id) (cond (cm-change-pending nil) ;; Nothing to do, we're already waiting. (undo-in-progress ;; Just ignore this undo change. (track-changes-fetch id #'ignore)) (t (setq cm-change-pending (run-with-timer 0 nil #'cm-change-do id))))) (defun cm-change-do (id) (track-changes-fetch (lambda (beg end before) ..DO THE CriticalMarkup THING.. ;; Ignore the changes we just made. (track-changes-fetch id #'ignore) (setq cm-change-pending nil)))) >> One other thing that you might have trouble to reproduce with >> `track-changes` is the following test: >> >> (and (= beg (point-min)) (= 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 even > fired up a Vagrant box with an old Ubuntu release with Emacs 24, which would be > the most recent version when I wrote that code). Have you tried `M-x revert-buffer RET` (assuming the file and the buffer aren't equal)? > Making it a minor mode makes sense, of course. It was already a minor mode, IMO, just one defined by hand instead of using the dedicated macro. Stefan