I am writing a minor mode in which I want to remap
`undo' to ALWAYS act as if a specific region was active
and transient-mark-mode was on.
Your mention of a "specific" region and your code attempt suggest that it is
always the same region, or at least that the region start is always the same
(the end is always eob, apparently).
So how would I go about "faking" this active region in Emacs
Lisp?
Eli> See region-active-p and push-mark.
I doubt that will help much.
This is I think something like what Deniz requested:
(defun reg-undo ()
"..."
(interactive)
(save-excursion
(save-restriction
(narrow-to-region nima-prompt-end (point-max))
(setq this-command 'undo)
(condition-case nil (undo) (error nil)))))
You must set `this-command' to `undo'.
To work on a region, which might not be active, just use `narrow-to-region' (and
`save-restriction'). A `save-excursion' seems to be needed at least for the
case where changes (which won't be undone) were made outside the region.
Likewise, the `condition-case' (or `ignore-errors', if you prefer).
You might need to tweak this a bit - test with various scenarios (redo etc.).