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: Faking an active region Date: Sat, 3 Sep 2011 09:40:23 -0700 Message-ID: References: <4E62514A.7040905@dogan.se> 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 1315068059 29417 80.91.229.12 (3 Sep 2011 16:40:59 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 3 Sep 2011 16:40:59 +0000 (UTC) To: "'Deniz Dogan'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Sep 03 18:40:55 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 1QztH4-0000BO-Qd for geh-help-gnu-emacs@m.gmane.org; Sat, 03 Sep 2011 18:40:54 +0200 Original-Received: from localhost ([::1]:59226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QztH4-0003lo-B3 for geh-help-gnu-emacs@m.gmane.org; Sat, 03 Sep 2011 12:40:54 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:50788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QztH0-0003li-Gn for help-gnu-emacs@gnu.org; Sat, 03 Sep 2011 12:40:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QztGz-0007MO-Gf for help-gnu-emacs@gnu.org; Sat, 03 Sep 2011 12:40:50 -0400 Original-Received: from acsinet15.oracle.com ([141.146.126.227]:61800) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QztGz-0007M6-A8 for help-gnu-emacs@gnu.org; Sat, 03 Sep 2011 12:40:49 -0400 Original-Received: from rtcsinet22.oracle.com (rtcsinet22.oracle.com [66.248.204.30]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p83GefvI027193 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 3 Sep 2011 16:40:43 GMT Original-Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by rtcsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p83GeeZj027487 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 3 Sep 2011 16:40:41 GMT Original-Received: from abhmt118.oracle.com (abhmt118.oracle.com [141.146.116.70]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p83GeZVP018513; Sat, 3 Sep 2011 11:40:35 -0500 Original-Received: from dradamslap1 (/10.159.61.224) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 03 Sep 2011 09:40:34 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <4E62514A.7040905@dogan.se> Thread-Index: AcxqVA1PCuslvF4xSyqn1r6iOMq+RQAAuvsg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6109 X-Source-IP: rtcsinet22.oracle.com [66.248.204.30] X-CT-RefId: str=0001.0A090209.4E62588C.0006,ss=1,re=0.000,fgs=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 141.146.126.227 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:82131 Archived-At: > 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.).