From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: An idea: combine-change-calls Date: Tue, 27 Mar 2018 14:30:53 -0400 Message-ID: References: <20180324135024.GA6319@ACM> <20180325191424.GE6292@ACM> <20180326201728.GA28620@ACM> <20180327165816.GB4105@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1522175377 14813 195.159.176.226 (27 Mar 2018 18:29:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 27 Mar 2018 18:29:37 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 27 20:29:33 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f0tLh-0003m7-HI for ged-emacs-devel@m.gmane.org; Tue, 27 Mar 2018 20:29:33 +0200 Original-Received: from localhost ([::1]:35609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0tNl-0003Fs-3R for ged-emacs-devel@m.gmane.org; Tue, 27 Mar 2018 14:31:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0tN5-0003ET-6P for emacs-devel@gnu.org; Tue, 27 Mar 2018 14:31:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0tN2-0004ny-3I for emacs-devel@gnu.org; Tue, 27 Mar 2018 14:30:59 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:35150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0tN1-0004nS-RI for emacs-devel@gnu.org; Tue, 27 Mar 2018 14:30:56 -0400 Original-Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id w2RIUrBf021544; Tue, 27 Mar 2018 14:30:53 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 32F5C663C5; Tue, 27 Mar 2018 14:30:53 -0400 (EDT) In-Reply-To: <20180327165816.GB4105@ACM> (Alan Mackenzie's message of "Tue, 27 Mar 2018 16:58:16 +0000") X-NAI-Spam-Flag: NO X-NAI-Spam-Level: X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0.2 X-NAI-Spam-Rules: 4 Rules triggered TRK_NCM1=0.1, URI_SUCPCD_WRDS_HTML=0.1, EDT_SA_DN_PASS=0, RV6251=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6251> : inlines <6522> : streams <1782434> : uri <2615849> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.20 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:224103 Archived-At: > happens to undo-entries which aren't in the region. Maybe they are > just discarded, maybe they are somehow kept in the undo list. They're just discarded (when building the list to pass to primitive-undo only: they stay in buffer-undo-list, of course). > By the way, what's undo-tree? I've not been able to find that symbol at > all in the source code. See http://elpa.gnu.org/packages/undo-tree.html >> Better use the (apply DELTA BEG END FUN-NAME . ARGS) form, which was >> introduced specifically for use of such extensions. > This won't work, at least not without some seriously twisted coding: The > essential thing about (combine-change-end/begin ..) is that they bind > inhibit-modification-hooks to non-nil for other entries in the > undo-list. Maybe FUN-NAME could call primitive-undo, but this doesn't > seem wise. Actually the way I was thinking of using it was something like: (let ((elem-apply `(apply 0 ,beg ,end ,#'my-undo-combining nil))) (push elem-apply buffer-undo-list) (funcall body) (let ((new-bul (memq elem-apply buffer-undo-list))) (when new-bul (let ((undo-elems buffer-undo-list)) (setf (nthcdr (- (length undo-elems) (length new-bul)) undo-elems) nil) (setf (nth 1 elem-apply) (- end-marker end)) (setf (nth 3 elem-apply) (marker-position end-marker)) (setf (nth 5 elem-apply) undo-elems) (setq buffer-undo-list new-bul))))) and then (defun my-undo-combining (undo-elems) (let ((inhibit-modification-hooks t)) (while t (primitive-undo 1 undo-elems)))) But you might prefer just replacing the whole thing with a pair of insert+delete, which is simpler and vastly more efficient (but with the disadvantage that it doesn't preserve markers quite as well). Stefan