From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Madden Newsgroups: gmane.emacs.help Subject: Re: restore region after replace-string Date: Sun, 16 Jan 2011 10:08:30 -0700 Message-ID: <4D33260E.5080901@noaa.gov> References: <0dfdb0af-c0b4-446b-8d3d-d194b128d85f@u32g2000yqe.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7BIT X-Trace: dough.gmane.org 1295209098 6582 80.91.229.12 (16 Jan 2011 20:18:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 16 Jan 2011 20:18:18 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jan 16 21:18:14 2011 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 1PeZ3C-0008MK-Uv for geh-help-gnu-emacs@m.gmane.org; Sun, 16 Jan 2011 21:18:11 +0100 Original-Received: from localhost ([127.0.0.1]:43565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PeZ3C-0002MT-CF for geh-help-gnu-emacs@m.gmane.org; Sun, 16 Jan 2011 15:18:10 -0500 Original-Received: from [140.186.70.92] (port=42924 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PeW5j-0006Su-D2 for help-gnu-emacs@gnu.org; Sun, 16 Jan 2011 12:08:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PeW5i-0005zf-2i for help-gnu-emacs@gnu.org; Sun, 16 Jan 2011 12:08:35 -0500 Original-Received: from rome.boulder.noaa.gov ([140.172.10.146]:54167) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PeW5h-0005zO-UD for help-gnu-emacs@gnu.org; Sun, 16 Jan 2011 12:08:34 -0500 Original-Received: from [192.168.0.5] (c-98-245-119-87.hsd1.co.comcast.net [98.245.119.87]) by email.boulder.noaa.gov (iPlanet Messaging Server 5.2 HotFix 2.01 (built Aug 26 2004)) with ESMTPSA id <0LF400FW6KY7SO@email.boulder.noaa.gov> for help-gnu-emacs@gnu.org; Sun, 16 Jan 2011 17:08:31 +0000 (GMT) In-reply-to: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7 X-Enigmail-Version: 1.1.1 X-detected-operating-system: by eggs.gnu.org: Solaris 9 X-Mailman-Approved-At: Sun, 16 Jan 2011 15:17:33 -0500 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:78484 Archived-At: Le, Thank you! That was the key. Here's the working function, in case it helps someone someday: (defun rs () (interactive) (let (deactivate-mark) (save-excursion (call interactively 'replace-string))) (exchange-point-and-mark) (exchange-point-and-mark)) paul On 01/16/2011 03:28 AM, Le Wang wrote: > I had to solve this recently -- keeping the region active after a command > modifies the buffer. The relevant documentation is > here: http://www.gnu.org/s/emacs/manual/html_node/elisp/The-Mark.html > > > Variable: *deactivate-mark* > > If an editor command sets this variable non-|nil|, then the editor > command loop deactivates the mark after the command returns (if > Transient Mark mode is enabled). _All the primitives that change the > buffer set |deactivate-mark|_, to deactivate the mark when the command > is finished. > > To write Lisp code that modifies the buffer without causing deactivation > of the mark at the end of the command, > bind |deactivate-mark| to |nil| around the code that does the > modification. For example: > > (let (deactivate-mark) > > (insert " ")) > > > > -- > Le