unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Deniz Dogan'" <deniz@dogan.se>, <help-gnu-emacs@gnu.org>
Subject: RE: Faking an active region
Date: Sat, 3 Sep 2011 09:40:23 -0700	[thread overview]
Message-ID: <A5FF7120B1464801891D3015A1CE5AA1@us.oracle.com> (raw)
In-Reply-To: <4E62514A.7040905@dogan.se>

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




  parent reply	other threads:[~2011-09-03 16:40 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 [this message]
2011-09-03 17:30   ` Deniz Dogan

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=A5FF7120B1464801891D3015A1CE5AA1@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=deniz@dogan.se \
    --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).