From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: An idea: combine-change-calls Date: Sat, 24 Mar 2018 13:50:24 +0000 Message-ID: <20180324135024.GA6319@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1521902179 1905 195.159.176.226 (24 Mar 2018 14:36:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 24 Mar 2018 14:36:19 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 24 15:36:15 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 1ezkHH-0000PO-I1 for ged-emacs-devel@m.gmane.org; Sat, 24 Mar 2018 15:36:15 +0100 Original-Received: from localhost ([::1]:43381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezkJK-0006BG-F7 for ged-emacs-devel@m.gmane.org; Sat, 24 Mar 2018 10:38:22 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezkHS-0005hW-Qg for emacs-devel@gnu.org; Sat, 24 Mar 2018 10:37:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezjrI-0005XB-PR for emacs-devel@gnu.org; Sat, 24 Mar 2018 10:14:09 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:40452 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1ezjrI-0005W5-I9 for emacs-devel@gnu.org; Sat, 24 Mar 2018 10:09:24 -0400 Original-Received: (qmail 66816 invoked by uid 3782); 24 Mar 2018 14:09:21 -0000 Original-Received: from acm.muc.de (p5B147FE1.dip0.t-ipconnect.de [91.20.127.225]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 24 Mar 2018 15:09:20 +0100 Original-Received: (qmail 6424 invoked by uid 1000); 24 Mar 2018 13:50:24 -0000 Content-Disposition: inline X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 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:223983 Archived-At: Hello, Emacs. We have the macro combine-after-change-calls, which does more or less what it says - the executions of after-change-functions is postponed to the end of the macro, and then they are all executed at once. This is all very well, but suffers from the severe restriction that it doesn't work with before-change-functions at all. How about combine-change-calls, which combine the b-c-f calls and a-c-f calls of some function which makes many primitive changes into just one b-c-f call and one a-c-f call. It might look something like 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-))))) . The motivation is bug #30735, where executing comment-region on a large region is slow. It is slow because of the high number of calls to before/after-change-functions caused by the many individual changes made by comment-region. The final part of comment-region could be amended from: (save-excursion ;; FIXME: maybe we should call uncomment depending on ARG. (funcall comment-region-function beg end arg))) to (save-excursion ;; FIXME: maybe we should call uncomment depending on ARG. (if comment-region-combine-change-calls (combine-change-calls beg end (funcall comment-region-function beg end arg)) (funcall comment-region-function beg end arg)))) , where comment-region-combine-change-calls would be a new buffer local variable. What do people think? -- Alan Mackenzie (Nuremberg, Germany).