* How to create new buffer with t-m-m active region?
@ 2010-09-04 18:38 Dan Davison
2010-09-05 0:25 ` Drew Adams
0 siblings, 1 reply; 4+ messages in thread
From: Dan Davison @ 2010-09-04 18:38 UTC (permalink / raw)
To: help-gnu-emacs mailing list
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-;
Thanks,
Dan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to create new buffer with t-m-m active region?
[not found] <mailman.7.1283625538.1782.help-gnu-emacs@gnu.org>
@ 2010-09-04 23:01 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2010-09-04 23:01 UTC (permalink / raw)
To: help-gnu-emacs
> (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)))
You need to wrap the delete-region and the inserts with (let
((deactivate-mark)) ...) so that they don't cause the mark to be
deactivated as soon as the command ends.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: How to create new buffer with t-m-m active region?
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
2010-09-05 3:47 ` Dan Davison
0 siblings, 1 reply; 4+ messages in thread
From: Drew Adams @ 2010-09-05 0:25 UTC (permalink / raw)
To: 'Dan Davison', 'help-gnu-emacs mailing list'
> 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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to create new buffer with t-m-m active region?
2010-09-05 0:25 ` Drew Adams
@ 2010-09-05 3:47 ` Dan Davison
0 siblings, 0 replies; 4+ messages in thread
From: Dan Davison @ 2010-09-05 3:47 UTC (permalink / raw)
To: Drew Adams; +Cc: 'help-gnu-emacs mailing list'
"Drew Adams" <drew.adams@oracle.com> writes:
>> 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)
Thanks for that Drew.
Dan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-09-05 3:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).