facelessuser/ApplySyntax — pull request #16 by gabrielecirulli (2013-06-24 22:03:24+00:00)
Title: Implement 'content' rule to match anywhere inside file

Hey, I had the need to set a certain syntax on a file only when it contained a certain string. I found your very nice plugin but it looked like it lacked the ability to build rules by matching anywhere in the file.

I blew the dust off my Python knowledge and tried to write a simple implementation for this rule. The code might not be the best because I haven't touched Python in a long time and I had no prior experience with the ST2 API (I didn't check if this works on ST3 because I currently haven't made the switch yet, but it should considering I've only used one function from the actual API).

I've included one example in the settings file for the `contains` rule. It's the practical case I needed it for: switching an HTML file to the Handlebars syntax highlighting if a handlebars script is detected within the page. I've tried it with my own file by first switching it to normal HTML and then saving and I can see it effectively get changed to Handlebars syntax highlighting as soon as I save. The only problem with the `contains` rule I can see right now is that if you include it in the settings file and you don't also include a rule to match the file name, the `contains` rule will also match the settings file and change its syntax highlighting, which is an undesirable side effect. I included that as a note in the comment, but maybe it requires more than a workaround.

Again thanks for the great plugin and let me know if you find this feature useful! :+1: