Sublime Forum

HTML snippets

#1

I read that they have to be implemented yet in ST2.

What makeshift solutions are available now for those who want to use HTML? Can these regex snippets be copied from 1.4? Or downloaded from anywhere?

0 Likes

#2

I may be confusing something. Thought that’s how they worked in 1.4 (not a separate snippet for each tag but all packed in HTML.tmLanguage file). Anyway no matter how you call them I would like to be able to use them :smile:

0 Likes

#3

Scope is surely the problem here.

I can easily enter tags in .html file but not in .php. I edited HTML.tmLanguage file adding:

<key>fileTypes</key> <array> (...) <string>php</string> </array>

but to no avail. Maybe I should edit HTML.sublime-completions as well? My only aim is to get it to work in .php files.

0 Likes

#4

I would be glad to have the option available wherever I happen to be in .php file.

As for HTML.sublime-completions its entire contents are:

[code]{
“scope”: “text.html - source - meta.tag, punctuation.definition.tag.begin”,

"completions":

	{ "trigger": "a", "contents": "<a href=\"$1\">$2</a>" },
	{ "trigger": "abbr", "contents": "<abbr>$1</abbr>" },
  (...)
	{ "trigger": "PARAM", "contents": "<PARAM>" }
]

}[/code]I’ve tried several modifications but nothing came of it.

0 Likes

#5

There should be no difference between PHP files and HTML files. Try opening an empty php file, and:

  1. Check that the tab_completion setting is on, via running “view.settings().get(‘tab_completion’)” in the console
  2. Check the scope name, via Ctrl+Alt+P (Windows/Linux). It should be “text.html.basic”.

Once you’ve checked both the above, then you should be able to complete HTML tags.

0 Likes

#6

I changed tab_complitions to true, it works but still not the way I would like it to.

HTML tag completions work only outside <?php ?> block. I use a lot of heredoc which is always inside <?php ?> block.

When I’m inside php block php completions ovveride that of html. Typing “td” and hitting TAB results for example in: “cairo_matrix_transform_distance(matrix, dx, dy)”, typing “span” and hitting TAB in “gupnp_service_proxy_add_notify(proxy, value, type, callback)”. It is amazing how any tag I can think of triggers some mysterious php function :smile:

0 Likes

#7

If you change the scope in the completions file to:

"scope": "text.html - source - meta.tag, punctuation.definition.tag.begin, source.php",

Then you should be good to go.

0 Likes

#8

Thanks, that helped.

I’ve one more question though. If I type say “table” and it completes after TAB and then inside of

<table></table>

I type “tr” and press TAB again no completion is made only caret goes beyond table tag. Is this default behaviour?

0 Likes

#9

It is, because you’re still within the snippet fields. There are two options:

  • Press escape, to cancel the snippet fields
  • OR use Ctrl+Space, rather than tab, to insert the tr snippet
0 Likes

#10

Ok.

I’m not exaclty happy with the fact that input->TAB gives simply:

<input>

instead of:

<input type="text" name="test" value="value" />

I can easily correct this in HTML.sublime-completions.

The question is what would be the best action if I want to protect my changes in this file from being overwritten? Should I copy it to the “User” folder (this works only if I add a new completion, if completion with the same trigger exists in the original file though it has higher priority)? Copying the whole “HTML” folder to “User” is basically doing the same thing so I don’t expect it to work either.

0 Likes

#11

Will this always be the case.

The idea of triggering a snippet within snippet field seems like a good one to me.

0 Likes

#12

[quote=“atomi”]
The idea of triggering a snippet within snippet field seems like a good one to me.[/quote]

And the idea isn’t new because that is how it worked (should say works) in ST 1.4.

0 Likes

#13

I’m still geting some problems here.

  1. I’ve set tab completions to true,
  2. the scope is text.html.basic,
  3. changed the scope of HTML.sublime-completions file to:
text.html - source - meta.tag, punctuation.definition.tag.begin, source.php, source.js

Now some triggers work fine and some don’t. For example when I press a->tab HTML trigger for loses with PHP one for abs() though the latter should be triggered by abs->tab not by a->tab.

And this had already worked fine, it got bad on the last build or the one before.

Is it possible to change priority of these completions? So that those defined in HTML.sublime-copletions will always prevail over PHP ones, or at least when I’m in heredoc, string etc. Why would I want to type a php function there? And especially one like “cairo_ps_surface_dsc_begin_page_setup()”?

Edit:

As a makeshift solution I deleted the file PHP.sublime-completions. It was pretty useless anyway and with over 4000 (!) hardly-ever used functions getting in the way of whatever you type.

0 Likes

#14

good posts!

0 Likes