Something like this would be possible by creating a plugin that includes an event listener that listens for the event that indicates that a file is (or is about to be) saved. When the event triggers, you can check to see if it’s a file that you care about for your purposes and then take some action.
For example:
import sublime, sublime_plugin
class OnSaveListener(sublime_plugin.EventListener):
def on_post_save (self, view):
# Check here to see if view.file_name() is interesting to you based on
# it's type, location, path, etc.
print ("saved" + view.file_name ())
# Execute some external command; you may want to specify "path",
# "working_dir", etc.
view.window ().run_command ("exec", {"cmd": "ls"})
This one prints out the name of the file that was just saved and then uses the internal exec
command to execute ls
for no obvious reason.
Probably you would want to allow for some filtering here; such an event handler will always trigger for every file saved, which would make your external program always trigger. So you may want to do something like examine the file name, it’s location or some project specific setting to see if you actually care about running your external command or not.
on_post_save
as it’s name suggests, gets triggered after the file is finished saving. There is also an on_pre_save
which triggers before the save happens. This would allow you to e.g. modify the contents of the file being saved before it was written. Depending on what you’re trying to do (and in particular if you really need to run this ‘within the ST save command’) that might be what you want to use instead.