Sublime Forum

How to force a build on save?

#1

I started using Sublime Text 2 very recently, awesome feedback so far. I have a project created in ST2 with a make file, which I’m able to build using a CMD+B combination. The build is blazingly fast, so I’m trying to figure ways to avoid that extra CMD+B combination and tie it to a save operation. Is there a way to trigger a build on each save operation in a project?

Thanks for the support.

0 Likes

#2

Is ‘Save All on Build’ option an option for you ?

0 Likes

#3

Thanks for replying. Save on build wouldn’t work for my requirement. What I’m looking for is exactly the opposite, a ‘Build on Save’ option.

0 Likes

#4

Actually if you have not other requirement, I don’t see why replacing ‘Save’ step by ‘Build’ step in your workflow doesn’t resolve your issue :question:
Anyway, you could probably write a plugin that trigger a ‘build’ command on the ‘on_post_save’ event, something like that (not tested):

class AutoBuildOnSave(sublime_plugin.EventListener): def on_post_save(self, view): view.run_command('build')

0 Likes

#5

Thanks bizoo. I actually ended up writing the same yesterday. I would’ve saved a lot of trouble if I had seen your recent post before I sat down to learn the syntax of Sublime plugins and a bit of Python.

I’ve hosted the same on my GitHub in case anyone is looking for the same functionality.
github.com/alexnj/SublimeOnSaveBuild

I would want to add a menu item with a checkbox so that it can be easily enabled or disabled for projects that need or don’t need the functionality, instead of removing the plugin from the file system to do the same. I couldn’t figure out from the API docs how to add a checkbox to a menu item though, pretty much everything else is ready for the same :smile:

Thanks for the support, once again.

0 Likes

#6

Hi, I extended your Plugin with a setting “saveOnBuild”, so you can disable it by default and only activate it in specific projects within the project settings. Works for me very well: github.com/lunow/SublimeOnSaveBuild

:smile:

0 Likes