Raydel Miranda
Raydel Miranda

Reputation: 14360

How to make Sublime Text select a custom Build System automatically?

There are some documentation out there that explains how to write a custom build system for compiling using C++11. Rigth now I'm able to compile C++11 code, but I have to select the build system from the Tools->Build System menu.

Before that (when I was workin only with Python and C++98) I use to have just selected Tools->Build System->Automatic and I was able to compile(run in case of Python) both just pressing Ctrl + B.

I want that Sublime Text to use automatically my C++11 custom Build System instead the default C++. There are some way to achive this?

Upvotes: 1

Views: 1235

Answers (2)

Jeremy
Jeremy

Reputation: 332

Sorry I would make this a comment, but I don't have enough reputation. But is this something like what you want?

How to create a shortcut for user's build system in Sublime Text?

EDIT: (thank you Roger Fan)

which says (in case the link dies):

AFAIK, there is no such a way to pass current file name through key binding, and it's not possible to use key binding to specify a certain build system. Thus, writing a Python script is of necessity.

There are only three steps.

1. Save the following content to /Data/Package/User/compile_with_xelatex.py:

    import sublime, sublime_plugin

    class CompileWithXelatexCommand(sublime_plugin.TextCommand):
      def run(self, edit):
        self.view.window().run_command('exec', {'cmd': ["xelatex.exe","-synctex=1","-interaction=nonstopmode", self.view.file_name()[:-4]]})

2. Add a line to /Data/Packages/User/Default(<your-plat>).sublime-keymap

{"keys": ["f1"], "command": "compile_with_xelatex"},

3. Open your LaTeX source file with Sublime Text, and then press F1 to compile it with XeLaTeX.

Indeed, it's a little tricky, but it works like a charm for me.

Upvotes: 1

Raydel Miranda
Raydel Miranda

Reputation: 14360

I found a way:

Just take the C++11 build system file and name it as: ~/.config/sublime-text-3/Packages/C++/C++.sublime-build

That way it will compile with that Build System automatically (if Tools->Build System->Automatic is selected) each time C++ syntax is detected.

For those that want to have the option to select either C++11 or C++98, or any other you can follow the link posted by JeremyCraig: How to create a shortcut for user's build system in Sublime Text?.

Upvotes: 1

Related Questions