From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: How to create new buffer with t-m-m active region? Date: Sat, 4 Sep 2010 17:25:52 -0700 Message-ID: <076A3A212B3F4180869BBBCA325A60F7@us.oracle.com> References: <87k4n11hhj.fsf@stats.ox.ac.uk> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1283646544 20228 80.91.229.12 (5 Sep 2010 00:29:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 5 Sep 2010 00:29:04 +0000 (UTC) To: "'Dan Davison'" , "'help-gnu-emacs mailing list'" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Sep 05 02:29:03 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 1Os35b-0003uG-OZ for geh-help-gnu-emacs@m.gmane.org; Sun, 05 Sep 2010 02:29:03 +0200 Original-Received: from localhost ([127.0.0.1]:54656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Os35O-0004IF-Ju for geh-help-gnu-emacs@m.gmane.org; Sat, 04 Sep 2010 20:27:54 -0400 Original-Received: from [140.186.70.92] (port=36359 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Os350-0004Hw-Fp for help-gnu-emacs@gnu.org; Sat, 04 Sep 2010 20:27:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Os34S-0003wE-AD for help-gnu-emacs@gnu.org; Sat, 04 Sep 2010 20:26:57 -0400 Original-Received: from rcsinet10.oracle.com ([148.87.113.121]:58729) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Os34S-0003w2-5R for help-gnu-emacs@gnu.org; Sat, 04 Sep 2010 20:26:56 -0400 Original-Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id o850QqGt029099 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 5 Sep 2010 00:26:53 GMT Original-Received: from acsmt353.oracle.com (acsmt353.oracle.com [141.146.40.153]) by acsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o84FffZs009581; Sun, 5 Sep 2010 00:26:51 GMT Original-Received: from abhmt005.oracle.com by acsmt355.oracle.com with ESMTP id 577577601283646356; Sat, 04 Sep 2010 17:25:56 -0700 Original-Received: from dradamslap1 (/10.159.217.95) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 04 Sep 2010 17:25:56 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <87k4n11hhj.fsf@stats.ox.ac.uk> Thread-Index: ActMYHL9jMzySDINSxqoZYLSa4ZvFAAMAPpA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:74885 Archived-At: > 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)