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: Stefan Monnier
Subject: Re: How to create new buffer with t-m-m active region?
Date: Wed, 08 Dec 2010 15:27:31 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

> (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


reply via email to

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