[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A little lisp help
From: |
Henrik Enberg |
Subject: |
Re: A little lisp help |
Date: |
Tue, 21 Jan 2003 20:24:22 +0100 |
User-agent: |
Gnus/5.090013 (Oort Gnus v0.13) Emacs/21.3.50 (i686-pc-linux-gnu) |
Peter Lee <spam@nospam.org> writes:
> I'm learning lisp atm, and decided to write a macro to insert curly
> braces around a region and re-indent.
>
> So for this,
>
> if (x)
> y=0;
>
> z=0;
> w=0;
> *
>
> setting mark at begining of line y=0 and setting point at * would
> produce the following.
>
> if (x)
> {
> y=0;
>
> z=0;
> w=0;
> }
Something like this perhaps. The `narrow-to-region' function is very
powerful. It lets you work on a region as if it is the whole buffer.
(defun curly-brace-region (beg end)
"Inserts curly braces around region and indents."
(interactive "r")
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
(insert "{\n")
(goto-char (point-max))
(insert "}\n")
(c-indent-region beg end)))