From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Deniz Dogan Newsgroups: gmane.emacs.help Subject: Re: Faking an active region Date: Sat, 03 Sep 2011 19:30:36 +0200 Message-ID: <4E62643C.4090401@dogan.se> References: <4E62514A.7040905@dogan.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1315071107 17604 80.91.229.12 (3 Sep 2011 17:31:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 3 Sep 2011 17:31:47 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Sep 03 19:31:43 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Qzu4E-0001C4-Na for geh-help-gnu-emacs@m.gmane.org; Sat, 03 Sep 2011 19:31:42 +0200 Original-Received: from localhost ([::1]:40601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qzu4E-0001d6-0K for geh-help-gnu-emacs@m.gmane.org; Sat, 03 Sep 2011 13:31:42 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:37611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qzu49-0001d1-JN for help-gnu-emacs@gnu.org; Sat, 03 Sep 2011 13:31:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qzu48-0006zQ-KK for help-gnu-emacs@gnu.org; Sat, 03 Sep 2011 13:31:37 -0400 Original-Received: from ch-smtp05.sth.basefarm.net ([80.76.153.6]:34448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qzu48-0006zM-AZ for help-gnu-emacs@gnu.org; Sat, 03 Sep 2011 13:31:36 -0400 Original-Received: from c80-216-107-100.bredband.comhem.se ([80.216.107.100]:52940 helo=[192.168.0.11]) by ch-smtp05.sth.basefarm.net with esmtp (Exim 4.76) (envelope-from ) id 1Qzu3v-0000wb-GD; Sat, 03 Sep 2011 19:31:24 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 In-Reply-To: X-Originating-IP: 80.216.107.100 X-Scan-Result: No virus found in message 1Qzu3v-0000wb-GD. X-Scan-Signature: ch-smtp05.sth.basefarm.net 1Qzu3v-0000wb-GD f328c45c0a17fece8084e5afe3921fb7 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.76.153.6 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:82132 Archived-At: On 2011-09-03 18:40, Drew Adams wrote: >> I am writing a minor mode in which I want to remap >> `undo' to ALWAYS act as if a specific region was active >> and transient-mark-mode was on. > > Your mention of a "specific" region and your code attempt suggest that it is > always the same region, or at least that the region start is always the same > (the end is always eob, apparently). > >> So how would I go about "faking" this active region in Emacs >> Lisp? > > Eli> See region-active-p and push-mark. > > I doubt that will help much. > > This is I think something like what Deniz requested: > > (defun reg-undo () > "..." > (interactive) > (save-excursion > (save-restriction > (narrow-to-region nima-prompt-end (point-max)) > (setq this-command 'undo) > (condition-case nil (undo) (error nil))))) > > You must set `this-command' to `undo'. > > To work on a region, which might not be active, just use `narrow-to-region' (and > `save-restriction'). A `save-excursion' seems to be needed at least for the > case where changes (which won't be undone) were made outside the region. > Likewise, the `condition-case' (or `ignore-errors', if you prefer). > > You might need to tweak this a bit - test with various scenarios (redo etc.). > Thanks a lot, that does _almost_ what I had in mind. It seems to get stuck in some sort of infinite undo/redo loop though -- it never says "No further undo information". Here is the real scenario: I'm writing an IRC client where nima-prompt-end is the marker at the end of the input prompt. When the user wants to "undo", I don't want any changes in the chat buffer to be undone (as they only represent a visual "history" that cannot be undone). rcirc accomplishes this by disabling and then immediately enabling undo information for the buffer (if I understand it correctly). However, I believe if only I could "fake" an active region appropriately, this wouldn't be necessary.