all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Atomic Macro Calls
@ 2010-05-03 13:07 Nordlöw
  2010-05-03 19:48 ` Andreas Politz
  0 siblings, 1 reply; 2+ messages in thread
From: Nordlöw @ 2010-05-03 13:07 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Atomic Macro Calls
  2010-05-03 13:07 Atomic Macro Calls Nordlöw
@ 2010-05-03 19:48 ` Andreas Politz
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Politz @ 2010-05-03 19:48 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-03 19:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-03 13:07 Atomic Macro Calls Nordlöw
2010-05-03 19:48 ` Andreas Politz

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.