From 3ef5bf53d5747c2369ff5124e9bdba95d7a72dee Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 16 Jun 2014 19:49:58 +0100 Subject: [PATCH] Add BufCloseFifo hook and use that to remove fifo directories --- README.asciidoc | 8 ++++++-- rc/git-tools.kak | 2 +- rc/grep.kak | 2 +- rc/make.kak | 2 +- src/buffer_utils.cc | 2 ++ 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index add67f68..c88d5d52 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -677,10 +677,14 @@ 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 + * +BufWritePre+: Executed just before a buffer is written, filename is 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. + * +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 the error message is used for filtering * +KakBegin+: Kakoune started, this is called just after reading the user diff --git a/rc/git-tools.kak b/rc/git-tools.kak index b53238ed..a34022c7 100644 --- a/rc/git-tools.kak +++ b/rc/git-tools.kak @@ -39,7 +39,7 @@ def -shell-params \ echo "eval -try-client '$kak_opt_docsclient' %{ edit! -fifo ${output} *git* set buffer filetype '${filetype}' - hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } } + hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } }" } diff --git a/rc/grep.kak b/rc/grep.kak index 728dce76..8029e956 100644 --- a/rc/grep.kak +++ b/rc/grep.kak @@ -14,7 +14,7 @@ def -shell-params -file-completion \ echo "eval -try-client '$kak_opt_toolsclient' %{ edit! -fifo ${output} -scroll *grep* set buffer filetype grep - hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } } + hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } }" }} diff --git a/rc/make.kak b/rc/make.kak index c020a4e0..213328cf 100644 --- a/rc/make.kak +++ b/rc/make.kak @@ -9,7 +9,7 @@ def -shell-params make %{ %sh{ echo "eval -try-client '$kak_opt_toolsclient' %{ edit! -fifo ${output} -scroll *make* set buffer filetype make - hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } } + hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } }" }} diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index f05db777..5f8cb9fd 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -64,6 +64,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll) buffer->flags() &= ~Buffer::Flags::Fifo; buffer->flags() &= ~Buffer::Flags::NoUndo; close(fifo); + buffer->run_hook_in_own_context("BufCloseFifo", ""); delete &watcher; } }); @@ -74,6 +75,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll) if (buffer->flags() & Buffer::Flags::Fifo) { close(watcher->fd()); + buffer->run_hook_in_own_context("BufCloseFifo", ""); delete watcher; } });