[Top][All Lists]

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

Re: Faking an active region

From: Deniz Dogan
Subject: Re: Faking an active region
Date: Sat, 03 Sep 2011 19:30:36 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1

On 2011-09-03 18:40, Drew Adams wrote:
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

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 ()
       (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.).

Thanks a lot, that does _almost_ what I had in mind. It seems to get stuck in some sort of infinite undo/redo loop though -- it never says "No further undo information".

Here is the real scenario:

I'm writing an IRC client where nima-prompt-end is the marker at the end of the input prompt. When the user wants to "undo", I don't want any changes in the chat buffer to be undone (as they only represent a visual "history" that cannot be undone).

rcirc accomplishes this by disabling and then immediately enabling undo information for the buffer (if I understand it correctly). However, I believe if only I could "fake" an active region appropriately, this wouldn't be necessary.

reply via email to

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