help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A little lisp help


From: Jim Janney
Subject: Re: A little lisp help
Date: Fri, 24 Jan 2003 00:39:29 -0700
User-agent: MacSOUP/2.5b2 (Mac OS 9.2.2)

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.

-- 
Jim Janney  


reply via email to

[Prev in Thread] Current Thread [Next in Thread]