Hi,
Is it possible to build on save?
Many thanks
I don’t know how build works (even if i know is there, in menus ), but i guess you can set a macro to save & build. Then you set up the ctrl(cmd) + s to run that macro. Like so:
{"command": "save"},
{"command": "build"}
]
Doesn’t work?
you mean make a key mapping like:
{ "keys": "super+s"], "command":
{"command": "save"},
{"command": "build"}
]}
No, i mean macro. Check out the Packages/Default folder and you will see there few macro examples.
I see the macros in that folder… so I’d bind the key press to call that macro? If you could give me a full example that would be amazing.
Many thanks
Yes, you’d bind a key press (e.g., Ctrl-s or Super-s or whatever) to your macro. So if you wanted to run the Delete to Hard EOL macro found in Packages/Default, you’d add this to your user keybindings (Preferences > Key Bindings - User)
{ "keys": "super+s"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete to Hard EOL.sublime-macro"} }
To put that in context, here’s the complete content of my user keybindings with that macro binding added to the end:
[code]
{ “keys”: “alt+shift+v”], “command”: “validate” },
{ “keys”: “alt+ctrl+2”], “command”: “toggle_quotes” },
{ “keys”: “super+j”], “command”: “code_intel_auto_complete” },
{ “keys”: “super+f3”], “command”: “goto_python_definition” },
{ “keys”: “alt+c”], “command”: “web_colors” },
{ “keys”: “alt+enter”], “command”: “move_to”, “args”: {“to”: “hardeol”}},
{ “keys”: “super+s”], “command”: “run_macro_file”, “args”: {“file”: “Packages/Default/Delete to Hard EOL.sublime-macro”} }
][/code]
Thank you for your reply.
so I did exactly that making a new macro file and then adding
{"command": "save"},
{"command": "build"}
]
to the file and now when I press super+s (apple+s) nothing happens… it doesn’t save, build or anything…
Hmm, seems like you’re doing everything right. Where is your macro saved? Have you tried a different keybind?
it’s saved in Packages/Default/Save and Build.sublime-macro, ye tried another key binding like ctrl + s and nothing… I’m using the latest dev version
Have you tried recording a macro and running the commands manually? That is, Tools > Record macro, then run File > Save and Tools > Build, then Tools > Stop Recording Macro. You can now save the macro (Tools > Save Macro). Try running the macro from the Tools menu to see if it works. If it does, bind that to a shortcut.
If you were using yesterday’s dev version, it was ignoring user keybindings. Download the newest and it should work.
@adzenith I’m using 2097 screencast.com/t/1RobrPf7L is that the one from yesterday?
@charlesroper I’ll give it a try, but I really need to bind save
2097 should be good. Did you try charlesroper’s suggestion with saving a macro and running it from the menu?
I ended just overriding the binding for save to { “keys”: “super+s”], “command”: “build” } and have always save on build checked… not ideal and not sure why macros aren’t working (would be nice to know what the issue is) but at least this is a working solution for now