Screencast: yasnippet for emacs Now Supports Snippet in a Snippet

| Comments

I am pretty excited that yasnippet can now expand a snippet from inside another snippet. I've slowly been tweaking my own snippets to be able to better take advantage of this new feature. I've already gotten most of my Moose snippets working well. I am very happy that I was able to get them to indent pretty well without any manual intervention.

I’ve worked pretty hard to overload my tab key. I am using it for hippie-expand, yas/expand, and indenting. It probably does what I want to over 95% of the time. I do run into two problems with this, though.

I can't call hippie expand from a snippet. I suppose I could have an extra hippie-expand binding, but I don't really like that idea. I may break down and set one up, though, because I haven't thought of a better solution.

Sometimes my tab key calls hippie-expand when I want to indent. This is the one that drives me nuts because I can't predict when it is going to happen. I tried adding an extra indent bind, but I just can't train myself to use it. I've used the tab key for indenting for so many years that the habit has just become too hard to break.

I have my enter key bound to newline-and-indent but I still have to manually hit my indent key sometimes. I've thought about having the enter key also run an indent on the current line. I haven't done it because I don't like the idea of accidentally changing the indentation of existing lines. I don't need to pull indentation changes into version control for no good reason.

How I Configured My Tab Key

I cheated. I tried every trick I could find to bind yas/expand, hippie-expand, and indenting to the same key and none of them were working. I ended up putting yas/hippie-try-expand at the front of my hippie-expand-try-functions-list and indent-for-tab-command at the end.

The only side effect this seems to have is that I get a No expansion found message on a successful indent. That doesn't bother me at all, though.