Sublime Forum

Is there a way to get notified 'before' buffer modification?

#1

I’m writing a integration plugin for a commercial version control system, it works in a ‘lock(checkout)-modify-unlock(checkin)’ paradigm, what the plugin will do:

  1. when user start editing a file, pop a dialog to ask if he/she likes to checkout the file.
  2. if user choose ‘yes’, then the file is checked-out automatically.
  3. if user choose ‘no’, nothing happens and the content of the file should be untouched.

The hard part is NO.3, where Sublime Text API only documented a ‘on_modified’ event callback, when user choose ‘no’ the buffer is already modified and I can’t find a way to revert the content back.

Is there any un-documented API like ‘on_pre_modify’?

Regards!

0 Likes

#2

There is not.
There are two ways you can undo modifications: you can call the revert command, and you can call the undo command. You can also set all files to be read-only until the user runs a specific command that checks it out from your VCS and clears the read-only flag in Sublime Text.

0 Likes

#3

One more idea: override the action of all of the keyboard keys, to intercept them before they insert characters. E.g. SublimeGit does this on its git status screen. sublimegit.net/

0 Likes