Sublime Forum

How to make snippets a bit smarter?

#1

Hey guys. I have a couple of questions about how I could make snippets a bit smarter. So:

How to make indentation inheritable?

Right now, if I have a snippet that’s indented with spaces inserted in a tab-indented document, it will insert spaces. There is a way of making this a bit context aware that I miss?

Context aware

Which take us to the next question: on some projects i have the K&R style:

[code]
protected function foo()
{

}[/code]

On other projects, i have… non K&R style (i’m not sure how is called):

[code]
protected function foo(){

}[/code]

There is a way to automagically detect this kind of stuff (with a project settings, of course)?

That’s all, thanks!

0 Likes

#2

With regards to the first point, indent your snippets with tabs and it’ll all work out

0 Likes

#3

Oh, I didn’t knew that! Thanks.

0 Likes

#4

So yeah, ST will expand literal tabs according to the indent setting of your view. This applies for snippets, completions, the insert_snippets command an the insert command. Not sure if the undocs cover this already, but it’s on the list.

Regarding the indentation style, snippets have this advanced feature in where they have access to and can expand shellVaribles. You know, the ones that define the comment sequences for the toggle_comment command.

You can find some documentation on that here and see an example here (along with the rest of the repo).

Since you can not change this with a project setting or a setting in general you’ll need to either use some hook for automation or use a toggle command whenever you are switching projects.

PS: I can’t be the only one who always attempts to use markdown-style links and then realizes he needs BBcode.

0 Likes

#5

Probably Jon will invest 30 mins one day to install an instance of Discourse… 30 mins for everything (from registering for Digital Ocean account and Mandrill to actually install the whole thing).

Thanks, this sounds like what i had in mind :wink:

0 Likes

#6

Actually that example works like a charm. Thanks!

0 Likes