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: Christopher J. White
Subject: Re: A little lisp help
Date: Wed, 22 Jan 2003 17:55:02 -0500
User-agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2 (powerpc-apple-darwin)

>>>>> "peter" == Peter Lee <spam@nospam.org> writes:

peter> (defun curly-brace-region (m p)
peter>   "Inserts curly braces around region and indents"
peter>   (interactive "r")
peter>   (if mark-active
peter>       (let ((transient-mark-mode nil))
peter>         (kill-region m p)
peter>         (insert-string "{")
peter>         (newline-and-indent)
peter>         (insert-string "}")
peter>         (newline-and-indent)
peter>         (forward-line -1)
peter>         (yank 1)
peter>         (forward-line 1)
peter>         (indent-region (- m 1) (point) nil))))

peter> Thanks for the help.

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.  

...cj

-- 
------------------------------------------------------------------------------
 Christopher J. White                                    chris@grierwhite.com
------------------------------------------------------------------------------ 


reply via email to

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