help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Atomic Macro Calls


From: Andreas Politz
Subject: Re: Atomic Macro Calls
Date: Mon, 03 May 2010 21:48:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Nordlöw <per.nordlow@gmail.com> writes:

> Hey!
>
> I think "the security" of macro calls in Emacs would be improved if
> we, upon error during execution, queried the user for complete revert/
> undo of all the effects that were made in buffers affected by this
> last macro call. For the case when only a single buffer is changed the
> following function could serve as a first mockup for a suitable
> wrapper function that solves this problem.
>
> (defun kmacro-call-macro-atomic (arg)
>   "Call last keyboard macro.
> If an error during execution ask user to revert any changes that
> occurred."
>   (interactive "P")
>   (atomic-change-group
>    (kmacro-call-macro arg)))
>
> Unfortunately atomic-change-group does not seem to work as expected
> here.
> It does not revert the buffer contents but instead the function cancel-
> change-group errors with the message:
>
>     Undoing to some unrelated state
>
> To compare with the following code changes the buffer contents only if
> the search succeeds:
>
>     (atomic-change-group (insert "x") (search-forward ";; "))
>
> Does anybody have a better implementation of the function kmacro-call-
> macro-atomic that undoes the changes made during the macro-call?
>
> Thanks in advance for all kinds of feedback,
> Per Nordlöw



I believe this is a bug, at least I reported one.  You can try the
function below.

As for making atomic changes to many buffers, this is documented by the
`prepare-change-group' function.  I suppose you would need to `prepare'
all buffers, because a macro can do about anything to any buffer.

(defun kmacro-call-macro-atomic (arg)
  "Call last keyboard macro.
If an error during execution ask user to revert any changes that
occurred."
  (interactive "P")
  (when (and (consp buffer-undo-list)
             (null (car buffer-undo-list)))
    (pop buffer-undo-list))
  (atomic-change-group
    (kmacro-call-macro arg)))

-ap



reply via email to

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