emacs-devel
[Top][All Lists]
Advanced

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

Re: An idea: combine-change-calls


From: Stefan Monnier
Subject: Re: An idea: combine-change-calls
Date: Tue, 27 Mar 2018 14:30:53 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> 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



reply via email to

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