From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Bingham, Jay" Newsgroups: gmane.emacs.help Subject: RE: A little lisp help Date: Fri, 24 Jan 2003 10:51:03 -0600 Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <72A87F7160C0994D8C5A36E2FDC227F5045D1BF4@txnexc01.americas.cpqcorp.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: main.gmane.org 1043427191 2872 80.91.224.249 (24 Jan 2003 16:53:11 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 24 Jan 2003 16:53:11 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18c74g-0000jM-00 for ; Fri, 24 Jan 2003 17:53:02 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18c756-0004Qr-01 for gnu-help-gnu-emacs@m.gmane.org; Fri, 24 Jan 2003 11:53:28 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18c74Z-0004I5-00 for help-gnu-emacs@gnu.org; Fri, 24 Jan 2003 11:52:55 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18c74W-0004Fn-00 for help-gnu-emacs@gnu.org; Fri, 24 Jan 2003 11:52:54 -0500 Original-Received: from zcamail04.zca.compaq.com ([161.114.32.104]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18c72s-0003bs-00 for help-gnu-emacs@gnu.org; Fri, 24 Jan 2003 11:51:10 -0500 Original-Received: from cacexg11.americas.cpqcorp.net (cacexg11.americas.cpqcorp.net [16.105.250.94]) by zcamail04.zca.compaq.com (Postfix) with ESMTP id AEB26AA8 for ; Fri, 24 Jan 2003 08:51:04 -0800 (PST) Original-Received: from txnexc01.americas.cpqcorp.net ([16.74.7.244]) by cacexg11.americas.cpqcorp.net with Microsoft SMTPSVC(5.0.2195.2966); Fri, 24 Jan 2003 08:51:04 -0800 X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 content-class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: A little lisp help Thread-Index: AcLDfECa+dY83gCeQreKfD4eDD5B0QAR0fQA Original-To: X-OriginalArrivalTime: 24 Jan 2003 16:51:04.0546 (UTC) FILETIME=[C88E9C20:01C2C3C8] X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:5935 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5935 On Friday, January 24, 2003 1:39 AM Jim Janney wrote: >Christopher J. White wrote: > >> You have to be careful when using region end-points >> and inserting text. m and p above are numerical values >> that reference offsets from the beginning of the file and >> do not "move" when text is inserted before them. >>=20 >> Use markers if you really want to be able to move around >> and insert text, but the best method was the previous >> suggestion to narrow-to-region. =20 > >Markers are the most general solution, but you can sometimes get by >without them by making changes in reverse buffer order. For example, in >this case > > (goto-char p) > (insert "}\n") > (save-excursion (goto-char m) (insert "{\n")) > (indent-region m (point) nil)) > >Note that (interactive "r") always passes the arguments smallest first, >but for a function that might also be called from lisp code you'd want >to check that m really comes before p. I prefer to call the values >"start" and "end" since they may not be the actual point and mark. Markers are indeed a general solution, however, there are some circumstances where they do not work as advertized. In Emacs 20.4 I found that the replace-match function does not update markers. (I have not tried it in Emacs 21). If the modifications will occur entirely before the location that needs to be preserved, a simple method for doing this is to calculate the distance of the location from the end of the buffer before doing the modifications, then when the modifications are complete the new value of the location can be calculated by subtracting offset from the new end of the buffer. For example: (setq offset-from-eob (- point-max point-I-want-to-remember)) ... the modifications happen here ... (setq point-I-want-to-remember (- point-max offset-from-eob)) -_ J_) C_)ingham . HP - NonStop Austin Software & Services - Software Quality Assurance . Austin, TX . "Language is the apparel in which your thoughts parade in public. . Never clothe them in vulgar and shoddy attire." -Dr. George W. Crane-