Add BufWritePre and BufWritePost hooks

This commit is contained in:
Maxime Coste 2013-12-11 13:58:38 +00:00
parent 1b1031627c
commit 39512914ad
2 changed files with 8 additions and 0 deletions

View File

@ -580,6 +580,10 @@ existing hooks are:
* +BufOpen+: A buffer for an existing file has been created, filename is * +BufOpen+: A buffer for an existing file has been created, filename is
used for filtering used for filtering
* +BufCreate+: A buffer 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 * +RuntimeError+: an error was encountered while executing an user command
the error message is used for filtering the error message is used for filtering
* +KakBegin+: Kakoune started, this is called just after reading the user * +KakBegin+: Kakoune started, this is called just after reading the user

View File

@ -205,6 +205,8 @@ static void write(int fd, memoryview<char> data, const String& filename)
void write_buffer_to_file(Buffer& buffer, 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<String>(); String eolformat = buffer.options()["eolformat"].get<String>();
if (eolformat == "crlf") if (eolformat == "crlf")
eolformat = "\r\n"; 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()) if ((buffer.flags() & Buffer::Flags::File) and filename == buffer.name())
buffer.notify_saved(); buffer.notify_saved();
buffer.run_hook_in_own_context("BufWritePost", buffer.name());
} }
String find_file(const String& filename, memoryview<String> paths) String find_file(const String& filename, memoryview<String> paths)