From: Deniz Dogan <deniz@dogan.se>
To: Drew Adams <drew.adams@oracle.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Faking an active region
Date: Sat, 03 Sep 2011 19:30:36 +0200 [thread overview]
Message-ID: <4E62643C.4090401@dogan.se> (raw)
In-Reply-To: <A5FF7120B1464801891D3015A1CE5AA1@us.oracle.com>
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
>> 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.).
>
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.
prev parent reply other threads:[~2011-09-03 17:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-03 16:09 Faking an active region Deniz Dogan
2011-09-03 16:19 ` Eli Zaretskii
2011-09-03 16:40 ` Drew Adams
2011-09-03 17:30 ` Deniz Dogan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E62643C.4090401@dogan.se \
--to=deniz@dogan.se \
--cc=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).