Sublime Forum

Build on save

#1

Hi,

Is it possible to build on save?

Many thanks

0 Likes

#2

any ideas?

0 Likes

Dev Build 2096
#3

I don’t know how build works (even if i know is there, in menus :smiley: ), 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?

0 Likes

#4

you mean make a key mapping like:

{ "keys": "super+s"], "command": {"command": "save"}, {"command": "build"} ]}

0 Likes

#5

No, i mean macro. Check out the Packages/Default folder and you will see there few macro examples.

0 Likes

#6

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

0 Likes

#7

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]

0 Likes

#8

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…

0 Likes

#9

Hmm, seems like you’re doing everything right. Where is your macro saved? Have you tried a different keybind?

0 Likes

#10

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

0 Likes

#11

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.

0 Likes

#12

If you were using yesterday’s dev version, it was ignoring user keybindings. Download the newest and it should work.

0 Likes

#13

@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 :confused:

0 Likes

#14

2097 should be good. Did you try charlesroper’s suggestion with saving a macro and running it from the menu?

0 Likes

#15

Ye I tried it manually and nothing screencast.com/t/EnApxeGnK

0 Likes

#16

Even tried this screencast.com/t/znViKZ2Pg nothing happens

0 Likes

#17

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 :smile:

0 Likes