Catch 'before save' event for buffer


#1

I’d like to issue a command before a file is saved. I use an awkward version control system which requires a command before editing. In order to do so, I would like to find out when a users issues a save for a buffer to take care of issuing the command before the actual save happens. Any ideas or pointers as to how that can be accomplished would be highly appreciated!


#2

You can hook to the will-be-saved event of the buffer (see here) but since it is a synchronous dispatch (unless I missed something) you may have trouble if the command you need to trigger do async stuff (as spawning a child process).


#3

Yeah that will leave me with lots of nasty timing issues. In theory, I could issue the command when the buffer is changed for the first time. Any pointers on how to do that? Thanks!


#4

There’s a content-modified event on the Editor object that gets called.


#5

You can always monkey patch the save handler :slight_smile: