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: Fri, 30 Mar 2018 11:05:24 -0400 Message-ID: References: <20180327165816.GB4105@ACM> <20180327194507.GD4105@ACM> <20180328204254.GC6592@ACM> <20180329151033.GA5213@ACM> <20180329171101.GB5213@ACM> <20180330114636.GA5432@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1522422257 17063 195.159.176.226 (30 Mar 2018 15:04:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 30 Mar 2018 15:04:17 +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 Fri Mar 30 17:04:13 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 1f1vZc-0004JY-Gg for ged-emacs-devel@m.gmane.org; Fri, 30 Mar 2018 17:04:12 +0200 Original-Received: from localhost ([::1]:44712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1vbg-0000yD-3f for ged-emacs-devel@m.gmane.org; Fri, 30 Mar 2018 11:06:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1vat-0000wm-VS for emacs-devel@gnu.org; Fri, 30 Mar 2018 11:05:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1vap-0000Gc-Qv for emacs-devel@gnu.org; Fri, 30 Mar 2018 11:05:31 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:52547) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1vap-0000GE-Jl for emacs-devel@gnu.org; Fri, 30 Mar 2018 11:05:27 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id w2UF5PXd017341; Fri, 30 Mar 2018 11:05:25 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 03274607C9; Fri, 30 Mar 2018 11:05:24 -0400 (EDT) In-Reply-To: <20180330114636.GA5432@ACM> (Alan Mackenzie's message of "Fri, 30 Mar 2018 11:46:36 +0000") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6254=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6254> : inlines <6531> : streams <1782706> : uri <2617478> 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:224179 Archived-At: > (defun wrap-and-run-primitive-undo (beg end list) > (let ((old-bul buffer-undo-list) > (end-marker (copy-marker end))) I'd have expected it to start with: (defun wrap-and-run-primitive-undo (beg end list) (combine-change-calls also this is an internal function that will only be useful for combine-change-calls, so it needs to have a "--" in its name. > (let ((inhibit-modification-hooks t)) > (funcall #'primitive-undo 1 list)) I think you want something like (while list (setq list (primitive-undo 1 list)) in case there are some undo-boundaries in `list`. > (defmacro combine-change-calls (beg end &rest forms) > `(let ((-beg- ,beg) It now occurs to me that it's probable preferable to do: (defmacro combine-change-calls (beg end &rest forms) `(combine-change-calls-function ,beg ,end (lambda () ,@forms))) and then (defun combine-change-calls-function (beg rest body) ... do the heavy lifting here ...) > (while (not (eq (cdr ptr) old-bul)) > (setq ptr (cdr ptr))) This can inf-loop if the new buffer-undo-list happens not to be an extension of the old list any more. >> I could imagine a macro `with-inhibit-read-only` which would bind >> inhibit-read-only to t and then tweak the buffer-undo-list similarly to >> what you're doing such that the undo is also performed with >> inhibit-read-only bound to t. > OK, thanks. The above code hasn't taken this into account That was for the case that you decided not to use (apply ...) but some new undo-element. Stefan