From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: How to create new buffer with t-m-m active region? Date: Sun, 05 Sep 2010 01:01:07 +0200 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1291862082 18308 80.91.229.12 (9 Dec 2010 02:34:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 02:34:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 03:34:35 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQWL5-0005TE-G0 for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 03:34:35 +0100 Original-Received: from localhost ([127.0.0.1]:37433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQWL4-0004WF-Oo for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 21:34:34 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 17 Injection-Date: Sat, 4 Sep 2010 23:01:07 +0000 (UTC) Injection-Info: mx03.eternal-september.org; posting-host="hMELHbimAdWTIcCSDv1zlg"; logging-data="1808"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181LlmnhYMy8yPLBBcDxmci" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:7tpxWaKZn54Jv1YxCUOl1p0cNEM= sha1:ozULzQpcOp5u99QDzMBye+4XCl4= Original-Xref: usenet.stanford.edu gnu.emacs.help:181143 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:76488 Archived-At: > (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