Sublime Forum

Auto build when saving a particular file type or buffer?

#1

**Question 1
**I’d like to auto build .less files or have the option to build just a single buffer on save but no other file types or buffers. I know you can assign the crtl+s key to building but this builds other files i’m working on.

**Question 2
**I can’t get the Build system “Automatic” selection to work for less files. This is what i have in LESS.sublime-bulid…

{ "cmd": "dotless.Compiler.exe", "$file"], "selector": "source.less" }

It output this error…

[Error 2] The system cannot find the file specified [Finished]

It works perfectly if I select “LESS” as the build system but just doesn’t work for “Automatic”.

0 Likes

#2

What does the status bar say if you press Ctrl+Alt+P with a less file open?

0 Likes

#3

Ah it said source.css.less. I’ve fixed it and it works now. Thanks :smile:

Any idea with the second question?

0 Likes

#4

I’m not sure I understand question 1. Are you asking for a single key that will save the current file (only), and run the build command?

0 Likes

#5

Ok, I’ve rethought and what i’d actually like is to assign the building of a particular file in my project to a keybinding. Can I also set project specific keybindings?

0 Likes

#6

So I’d like something like this to work but it doesn’t seem to; it just builds the current file.

{ "keys": "ctrl+s"], "command": "build", "args": {"file": "/Users/ME/Dropbox/Projects/mysite/wp-content/themes/mytheme/base.css.less"} }
0 Likes

#7

Build systems are just a fancy way of calling the exec command, to do that, just use exec directly, for example: sublime2 key binding command exec

0 Likes

#8

Ok. I’ve got it to work using that example (see below) but sadly ctrl+s no longer saves the current buffer.

{ "keys": "ctrl+s"], "command": "exec", "args": { "cmd": "dotless.Compiler.exe", "/Users/mypath/base.css.less", "/Users/mypath/base.css" ]} }

I’d like it to save the current buffer and then run the build. Is it possible to combine commands?

0 Likes

#9

You’d have to write a plugin to do that

0 Likes

#10

I don’t generally resurrect an old thread like this, but after recently moving across to Sublime from Eclipse I was trying to do exactly this.

I ended up writing a plugin to automatically run an Ant script on file save and was amazed at how simple Sublime makes this.

If anyone else is looking for it the script is here:

http://www.purplebeanie.com/Development/automatically-run-build-on-save-in-sublime-text-2.html

0 Likes