all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Dan Davison'" <davison@stats.ox.ac.uk>,
	"'help-gnu-emacs mailing list'" <help-gnu-emacs@gnu.org>
Subject: RE: How to create new buffer with t-m-m active region?
Date: Sat, 4 Sep 2010 17:25:52 -0700	[thread overview]
Message-ID: <076A3A212B3F4180869BBBCA325A60F7@us.oracle.com> (raw)
In-Reply-To: <87k4n11hhj.fsf@stats.ox.ac.uk>

> How would I generate a new buffer containing an active region 
> such that the next command issued in the new buffer will act
> on the region? (And so that the region is highlighted)
> 
> For example, this function doesn't do what it wants to do:
> 
> (defun new-buffer-w-active-region ()
>   (interactive)
>   (let ((transient-mark-mode t))
>     (switch-to-buffer (get-buffer-create "region-test"))
>     (delete-region (point-min) (point-max))
>     (insert "I want these lines\n")
>     (insert "to be in an active region with t-m-m on\n")
>     (insert "such that comment-region comments them out\n")
>     (emacs-lisp-mode)
>     (push-mark (point-min) nil 'activate)))
> 
> 
> With that function, the following doesn't do what is intended:
> 
> M-x new-buffer-w-active-region
> M-;

Yes, this is a common gotcha that you just have to learn once if you do this
kind of thing: Add this sexp at the end of your command:

(setq deactivate-mark  nil)




  reply	other threads:[~2010-09-05  0:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-04 18:38 How to create new buffer with t-m-m active region? Dan Davison
2010-09-05  0:25 ` Drew Adams [this message]
2010-09-05  3:47   ` Dan Davison
     [not found] <mailman.7.1283625538.1782.help-gnu-emacs@gnu.org>
2010-09-04 23:01 ` Stefan Monnier

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=076A3A212B3F4180869BBBCA325A60F7@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=davison@stats.ox.ac.uk \
    --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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.