emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

An idea: combine-change-calls


From: Alan Mackenzie
Subject: An idea: combine-change-calls
Date: Sat, 24 Mar 2018 13:50:24 +0000
User-agent: Mutt/1.7.2 (2016-11-26)

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).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]