Sublime Forum

Makefiles, RECIPEPREFIX, and syntax highlighting

#1

Hello everyone. I like to replace tabs with spaces, so make doesn’t like my files unless I post-process them to put tabs back in, or I set the .RECIPIEPREFIX .RECIPEPREFIX variable. However, setting the prefix breaks syntax highlighting in a recipe. Any ideas on how to change this with user preferences? I’d love it if I could use > as a recipe prefix, but still get syntax highlighting in the recipe.

Thanks!

0 Likes

#2

There is no easy way to do that as the official Makefile syntax simply assumes .RECIPIEPREFIX is a Tab/Space char.

User preferences have nothing to do with syntax highlighting.

0 Likes

#3

Thanks for replying @jfcherng. I think the reason you couldn’t find anything on Google is that I spelled recipe wrong in the body of my comment! It is in use, although not frequently.

https://github.com/search?q=RECIPEPREFIX+filename%3Amake&type=Code&ref=advsearch&l=&l=

My question wasn’t “should I use RECIPEPREFIX or not,” it is “can I override syntax highlighting rules within user preferences?” I see you say that is not possible, but given you also misspelled recipe, I wonder if your answer is correct.

–Adam

P.S. I wrote my reply before you removed this from yours:

The most simple solution is just use Tab as it’s the nature. I can’t even find anyone use “RECIPIEPREFIX” by googling RECIPIEPREFIX … But sure, there are always people who go the hard way.

0 Likes

#4

He was correct; you can control what syntax is used via a setting, but settings can’t alter what a syntax definition does; it’s just a list of predefined rules.

For something like this you would need one or more customized versions of the syntax that you could swap between, and in such a case a plugin could be used in combination with settings to know what syntax to use based on what the file contains.

0 Likes

#5

Thanks, @OdatNurd. So, it sounds like the way to do it is create my own syntax which is a slight tweak of the built-in syntax. I’ll take a look at that. Thanks!

0 Likes

#6

In ST4 there is new functionality to have one syntax extend another one, and in doing so you can replace contexts and variables from the base syntax. I’m not familiar with the Makefile syntax at all, but that might be a way for you to leverage the existing syntax and replace just the prefix rules or similar, if the current syntax is amenable.

More info can be found here: https://www.sublimetext.com/docs/syntax.html#inheritance

0 Likes