Indent snippet after expansion

19 views
Skip to first unread message

hs

unread,
Jun 26, 2008, 1:18:16 PM6/26/08
to smart-snippet and YASnippet
Hi all.

I want to make a snippet called 'eif' that will help me adding elseif
clauses inside an "if ... end"
The problem is that the snippet is not properly indented.

Expanding this snippet:

elseif ${1:cond} then
$0

in this case:

if ... then
eif<TAB>
end

will get me

if ... then
elseif $2 then
$0
end

but i needed

if ... then
elseif $2 then
$0
end

What I'm missing is a notation to say that the region/line should be
reindented (after expansion). I believe we had this in the old smart-
snippet with '$'.

Thanks in advance,
Hugo

Chiyuan Zhang

unread,
Jun 26, 2008, 10:03:24 PM6/26/08
to smart-...@googlegroups.com
On Fri, Jun 27, 2008 at 1:18 AM, hs <hug...@gmail.com> wrote:
>
> Hi all.
>
> I want to make a snippet called 'eif' that will help me adding elseif
> clauses inside an "if ... end"
> The problem is that the snippet is not properly indented.
>
[...snip...]

> What I'm missing is a notation to say that the region/line should be
> reindented (after expansion). I believe we had this in the old smart-
> snippet with '$'.

If you mean $> in smart-snippet. It is not perfect. In some mode (e.g.
python-mode), the way to do indenting seems strange and indenting on a
snippet with overlays may totally confuse it. So this is not supported
in YASnippet.

However, there's a yas/after-exit-snippet-hook that maybe helpful. Say,

(add-hook 'yas/after-exit-snippet-hook
'(lambda ()
(indent-region yas/snippet-beg yas/snippet-end)))

may indent your snippet region after you finish your snippet. That is,
the indent is not done after you expand the snippet, but after you filled
$1 and jumped to $0. At that time, all overlays are removed, so there's
no chance to get Emacs confused.

I wish this is helpful.

>
> Thanks in advance,
> Hugo
> >
>

--
pluskid

vagn.j...@gmail.com

unread,
Jun 30, 2008, 4:33:53 AM6/30/08
to smart-snippet and YASnippet
>   (add-hook 'yas/after-exit-snippet-hook
>             '(lambda ()
>                (indent-region yas/snippet-beg yas/snippet-end)))
>
> may indent your snippet region after you finish your snippet.

Maybe it could be specified on the snippet that indent-region
should be called afterwards?

For example "#indent: region"


Reply all
Reply to author
Forward
0 new messages