help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to create new buffer with t-m-m active region?


From: Dan Davison
Subject: Re: How to create new buffer with t-m-m active region?
Date: Sat, 04 Sep 2010 23:47:33 -0400
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux)

"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



reply via email to

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