Run C++ macros from Sublime Text on Windows 10

Hello!
Just wanted to share my Sublime Text build system for ROOT C++ macros on Windows 10.
I searched the forum for something similar, but to no avail.

For quite a long time I used to switch via Alt-Tab into Developer Command Prompt for VS, then type root C:\path\to\my\script and .q + Enter after getting things done.
It’s a bit cumbersome, so recently I dived in and made a workaround, and now I’m posting it here.

First, make new build system with Tools -> Build System -> New Build System and paste

{
	"env" : {
		"INCLUDE": "%INCLUDE%;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.35.32215\\include;",
	},
	"file_regex": "^(...*?):([0-9]*):([0-9]*): ([^\\n]+)",
	"cmd": ["root", "-l", "$file"],
	"working_dir": "$file_path",
	"selector": "source.c++",
	"variants": [{
	    "name": "Run Interactive",
	    "cmd": ["cmd", "/c", "start", "root", "-l", "$file"]
  	}]
}

and save it as cern-root.sublime-build, for example.
You should probably change the INCLUDE line to the actual path to your VS installation.

Now you can run ROOT macros directly via Ctrl-B after selecting new build system.
Cancel run with Ctrl-Alt-B or just close ROOT session window.
If there is an error in macro, you can jump straight to it from build output, thanks to regex.
Also, if you select Run Interactive with Ctrl-Shift-B, the macro will run in an external interactive terminal, this is added because Sublime Text’s built-in terminal does not support input.

This build system can be adapted to any other OS if needed, I think.
I hope this will be useful to someone!

1 Like

Thanks for sharing this here, @Ako_b - that’s nice!

1 Like