Sublime Forum

Interpret backslash as delimiter Windows makefile


Hi, I have Windows command line (nmake) makefiles. When using the Makefile syntax under View-Syntax, backslashes are interpreted as escapes instead of directory paths.

At present, I’d just like to change the colorization of the escaped character, as it is distracting visually. I’ve attached a screen grab to show what I’m talking about.

Also, it’s possible this would affect builds if run from Sublime (but I’m not there yet).

Makefile Plus and Makefile Improved do not indicate they address this issue. Suggestions? Thank you!



Until one replies with the 100% correct solution, could you switch to forward slash’s ? Windows does accept those as well. Or else a double backslash \



You can color the escaped char scope constant.character.escape.makefile to the same with string. The side effect is that nothing is visually escaped then.

\tools is {TAB}ools or \\tools :man_shrugging:



This sounds promising. Is it possible for me to create a separate “Makefile-Win” syntax because all other makefiles (Unix/Mac/Linux) would interpret backslashes as escapes? I’m thinking copy/paste some section of some Sublime control file… ?



I am not sure. Maybe they are just run in the shell as-is so it’s shell magic.



Sorry, I mean that if I’m reading a Linux makefile on my Windows machine, I’d like the visual cues for escaped symbols to show up. The only way I could see doing this is to have two different syntax choices, the current “Makefile” and the proposed “Makefile-Win”. So to be specific, in what file would I make the change to constant.character.escape.makefile, and could that section be copied, changed as per your suggestion, then renamed “Makefile-Win”?



If you only work with Windows makefile, then

is the simplest workaround, which only requires to change to color scheme, but you are not the case now.

You are lucky that in your new makefile-win syntax, I think you just have to change

  - match: \\.
    scope: constant.character.escape.makefile


escape-literals: []


name: Makefile


name: Makefile (Windows)

Unfortunately, you have to manually select which makefile syntax to be used unless there is something that differentiates it from Linux’s. may help since it has contains rule.



Worked like a champ - thanks! RE: choosing syntax manually - that’s OK because a lot of times it’s just named Makefile without extension, so there’s no way to add a rule based on extension. Maybe Sublime can automatically determine based on file content, but that’s for a future day…



ApplySyntax allows you to do that iirc.



OK, I installed ApplySyntax and added this to the user settings:
“syntaxes”: [
“syntax”: “Makefile (Windows)/Makefile (Windows)”,
“rules”: [
{“contains”: “^CC\\s*\\=\\s*cl”}

But it is not working. I’m trying to key off the line “CC = cl” for which the regular expression is ^CC\s*=\s*cl. I note the Python syntax requires escaping the backslash, hence the “\\” in the code.

I can’t find any documentation on the pieces of ApplySyntax, so I’m guessing based on the default settings in there already.

  1. Why is the syntax name repeated twice in most default settings?
  2. Do you see any issues with the Python-escaped regex?
  3. Could you offer pointers as to why it’s not working?

(PS Sorry if the code snippet is not indented. I selected “Preformatted Text” before pasting, but in the preview it’s not showing up correctly.)




The documentation for ApplySyntax is found under Preferences->Package Settings->ApplySyntax->Documentation->User Guide.
Sorry if you have already found this.



I poked around and found the user guide, thanks. In my version there is no “-> User Guide” at the end of the Preferences path you supplied - it just ends in Documentation. Selecting it takes you to a website where the user guide is not intuitively obvious - Table of Contents ends with Installation, and you have to manually click through the right arrows at the bottom of the page until you get to the User Guide.

Anyway, for some reason, neither the caret (“starts with”) nor the $ (“ends with”) symbols are being accepted! This does NOT work:
{“contains”: “^CC\\s*\\=\\s*cl$”}

Instead, I had to put,
{“contains”: “(\n|^)CC\\s*\\=\\s*cl($|\n)”}

So I understand this for future situations, can anyone explain why this is the case? Something to do with Windows line endings?



maybe ^$ matches per file being/end. not per line begin/end.



Ah, that must be it - the underlying engine sucks in an entire file as a single string. I had assumed it was “chomping” into lines. Thanks!



It seems that there are two versions of the ApplySyntax documentation: the Windows version is as I described, and the Ubuntu version is as you described. It seems truncated in Linux.
Sorry for the inconvenience.