all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Bingham, Jay" <Jay.Bingham@hp.com>
Subject: RE: A little lisp help
Date: Fri, 24 Jan 2003 10:51:03 -0600	[thread overview]
Message-ID: <72A87F7160C0994D8C5A36E2FDC227F5045D1BF4@txnexc01.americas.cpqcorp.net> (raw)

On Friday, January 24, 2003 1:39 AM Jim Janney wrote:

>Christopher J. White <chris@grierwhite.com> 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.
>> 
>> 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.  
>
>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-

             reply	other threads:[~2003-01-24 16:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-24 16:51 Bingham, Jay [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-01-21 19:06 A little lisp help Peter Lee
2003-01-21 19:24 ` Henrik Enberg
2003-01-21 20:13 ` Stefan Monnier <foo@acm.com>
2003-01-21 20:32   ` Peter Lee
2003-01-21 20:41     ` Barry Margolin
2003-01-21 21:52 ` Peter Lee
2003-01-21 22:34   ` Peter Lee
2003-01-22 22:55     ` Christopher J. White
2003-01-22 23:02       ` Stefan Monnier <foo@acm.com>
2003-01-24  7:39       ` Jim Janney
2003-01-27 14:48         ` Stefan Monnier <foo@acm.com>
2003-01-22  8:24   ` Kai Großjohann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=72A87F7160C0994D8C5A36E2FDC227F5045D1BF4@txnexc01.americas.cpqcorp.net \
    --to=jay.bingham@hp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.