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: Sun, 25 Mar 2018 16:05:40 -0400 Message-ID: References: <20180324135024.GA6319@ACM> <20180325191424.GE6292@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1522008236 7269 195.159.176.226 (25 Mar 2018 20:03:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 25 Mar 2018 20:03:56 +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 Sun Mar 25 22:03:52 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 1f0Brn-0001k8-Fb for ged-emacs-devel@m.gmane.org; Sun, 25 Mar 2018 22:03:47 +0200 Original-Received: from localhost ([::1]:52418 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0Btq-0007ci-Gh for ged-emacs-devel@m.gmane.org; Sun, 25 Mar 2018 16:05:54 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0Btk-0007cS-RD for emacs-devel@gnu.org; Sun, 25 Mar 2018 16:05:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0Btf-0007S6-SO for emacs-devel@gnu.org; Sun, 25 Mar 2018 16:05:48 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:55631) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0Btf-0007Rl-L0 for emacs-devel@gnu.org; Sun, 25 Mar 2018 16:05:43 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id w2PK5eBs010013; Sun, 25 Mar 2018 16:05:40 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 72BB8603C1; Sun, 25 Mar 2018 16:05:40 -0400 (EDT) In-Reply-To: <20180325191424.GE6292@ACM> (Alan Mackenzie's message of "Sun, 25 Mar 2018 19:14:24 +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, RV6249=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6249> : inlines <6517> : streams <1782249> : uri <2614726> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.22 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:224016 Archived-At: > I've actually got a working implementation going. It is this: > > (defmacro combine-change-calls (beg end &rest form) > `(if (not inhibit-modification-hooks) > (let* ((-beg- ,beg) (-end- ,end) > (end-marker (copy-marker -end-))) > (run-hook-with-args 'before-change-functions beg end) > (let ((inhibit-modification-hooks t)) > ,@form) > (run-hook-with-args 'after-change-functions > beg (marker-position end-marker) > (- -end- -beg-))) > ,@form)) You need to evaluate `beg` and `end` even if inhibit-modification-hooks is set, otherwise someone will get bitten. I recommend you move the `form` to a lambda so you don't have to duplicate it: `(let ((body (lambda () ,@form)) (-beg- ,beg) (-end- ,end)) ...) Another benefit is that by moving `form` outside of the `let*`, you won't need to use gensym/make-symbol nor obfuscated names. I'd also recommend you check that `beg` hasn't changed position and that the distance between end-marker and point-max remained the same. >> Maybe combine-change-calls should also combine all those changes on the >> undo-list into a big "delete+insert" (of course, it could also try and >> keep the undo granularity but mark those undo entries so that they're >> undone within their own combine-change-calls). > :-) Either of those would be quite a project, but possibly worth doing. Replacing the entries with a pair of delete+insert should be pretty easy. Something like (let ((old-buffer-undo-list buffer-undo-list) (orig-text (buffer-substring beg end))) ... (setq buffer-undo-list `((,(marker-position end-marker) ,beg) (,orig-text . ,beg) . ,old-buffer-undo-list))) modulo sanity checks (i.e. don't do it if undo is disabled and don't do it if old-buffer-undo-list is not within buffer-undo-list any more). Stefan