diff --git a/README.asciidoc b/README.asciidoc index 066beab7..cdc2abf5 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -580,6 +580,10 @@ existing hooks are: * +BufOpen+: A buffer for an existing file has been created, filename is used for filtering * +BufCreate+: A buffer has been created, filename is used for filtering + * +BufWritePre+: Executre just before a buffer is written, filename is + used for filtering. + * +BufWritePost+: Executre just after a buffer is written, filename is + used for filtering. * +RuntimeError+: an error was encountered while executing an user command the error message is used for filtering * +KakBegin+: Kakoune started, this is called just after reading the user diff --git a/src/file.cc b/src/file.cc index c28833f8..a003c68c 100644 --- a/src/file.cc +++ b/src/file.cc @@ -205,6 +205,8 @@ static void write(int fd, memoryview data, const String& filename) void write_buffer_to_file(Buffer& buffer, const String& filename) { + buffer.run_hook_in_own_context("BufWritePre", buffer.name()); + String eolformat = buffer.options()["eolformat"].get(); if (eolformat == "crlf") eolformat = "\r\n"; @@ -231,6 +233,8 @@ void write_buffer_to_file(Buffer& buffer, const String& filename) } if ((buffer.flags() & Buffer::Flags::File) and filename == buffer.name()) buffer.notify_saved(); + + buffer.run_hook_in_own_context("BufWritePost", buffer.name()); } String find_file(const String& filename, memoryview paths)