Add BufCloseFifo hook and use that to remove fifo directories

This commit is contained in:
Maxime Coste 2014-06-16 19:49:58 +01:00
parent e78fd2d235
commit 3ef5bf53d5
5 changed files with 11 additions and 5 deletions

View File

@ -677,10 +677,14 @@ 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 * +BufWritePre+: Executed just before a buffer is written, filename is
used for filtering. used for filtering.
* +BufWritePost+: Executre just after a buffer is written, filename is * +BufWritePost+: Executed just after a buffer is written, filename is
used for filtering. used for filtering.
* +BufClose+: Executed when a buffer is deleted, while it is still valid.
* +BufCloseFifo+: Executed when a fifo buffer closes its fifo file descriptor
either because the buffer is being deleted, or because the writing
end has been closed.
* +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

@ -39,7 +39,7 @@ def -shell-params \
echo "eval -try-client '$kak_opt_docsclient' %{ echo "eval -try-client '$kak_opt_docsclient' %{
edit! -fifo ${output} *git* edit! -fifo ${output} *git*
set buffer filetype '${filetype}' set buffer filetype '${filetype}'
hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } } hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
}" }"
} }

View File

@ -14,7 +14,7 @@ def -shell-params -file-completion \
echo "eval -try-client '$kak_opt_toolsclient' %{ echo "eval -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${output} -scroll *grep* edit! -fifo ${output} -scroll *grep*
set buffer filetype grep set buffer filetype grep
hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } } hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
}" }"
}} }}

View File

@ -9,7 +9,7 @@ def -shell-params make %{ %sh{
echo "eval -try-client '$kak_opt_toolsclient' %{ echo "eval -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${output} -scroll *make* edit! -fifo ${output} -scroll *make*
set buffer filetype make set buffer filetype make
hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } } hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
}" }"
}} }}

View File

@ -64,6 +64,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
buffer->flags() &= ~Buffer::Flags::Fifo; buffer->flags() &= ~Buffer::Flags::Fifo;
buffer->flags() &= ~Buffer::Flags::NoUndo; buffer->flags() &= ~Buffer::Flags::NoUndo;
close(fifo); close(fifo);
buffer->run_hook_in_own_context("BufCloseFifo", "");
delete &watcher; delete &watcher;
} }
}); });
@ -74,6 +75,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
if (buffer->flags() & Buffer::Flags::Fifo) if (buffer->flags() & Buffer::Flags::Fifo)
{ {
close(watcher->fd()); close(watcher->fd());
buffer->run_hook_in_own_context("BufCloseFifo", "");
delete watcher; delete watcher;
} }
}); });