Consider this toy example:
(defun foo ()
(interactive)
(replace-string "a" "A" nil (region-beginning) (region-end) nil)
(replace-string "r" "R" nil (region-beginning) (region-end) nil)
)
(global-set-key (kbd "C-c F") 'foo)
The function foo
replaces all a's and r's with A's and R's, respectively. If one wants to undo it, however, a single undo (C-x u
) isn't be enough; two are required.
I'm looking for a way to define foo
such that only one C-x u
is enough to undo everything it does.
Since the code above is only an example, I'm looking for solutions that do not depend on the specifics of replace-string
. IOW, the solution should work for any foo
of the form
(defun foo ()
(interactive)
;;
;; body
;;
)