mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-27 02:23:26 +03:00
rework fifo handling, use real fifos in {make,grep}.kak, update README
This commit is contained in:
parent
a467d73115
commit
f6d2533cae
@ -343,11 +343,16 @@ the +edit+ command can take a -fifo parameter:
|
||||
:edit -fifo <filename> <buffername>
|
||||
-----------------------------------
|
||||
in this case, a buffer named +<buffername>+ is created which reads its content
|
||||
from +<filename>+. When filename is appended to, the buffer is automatically
|
||||
from fifo +<filename>+. When the fifo is written to, the buffer is automatically
|
||||
updated.
|
||||
|
||||
This is very useful for running some commands asynchronously while displaying
|
||||
their result in a buffer. See rc/make.kak and rc/grep.kak for examples.
|
||||
|
||||
When the buffer is deleted, the fifo will be closed, so any program writing
|
||||
to it will receive SIGPIPE. This is usefull as it permits to stop the writing
|
||||
program when the buffer is deleted.
|
||||
|
||||
Kakrc
|
||||
-----
|
||||
|
||||
|
@ -247,11 +247,15 @@ Buffer* open_fifo(const String& name , const String& filename, Context& context)
|
||||
EventManager::instance().watch(fd, [buffer, &context](int fd) {
|
||||
char data[512];
|
||||
ssize_t count = read(fd, data, 512);
|
||||
if (count > 0)
|
||||
buffer->insert(buffer->end()-1,
|
||||
count > 0 ? String(data, data+count)
|
||||
: "*** kak: fifo closed ***\n");
|
||||
buffer->reset_undo_data();
|
||||
context.draw_ifn();
|
||||
if (count <= 0)
|
||||
{
|
||||
buffer->insert(buffer->end()-1, String(data, data + count));
|
||||
buffer->reset_undo_data();
|
||||
context.draw_ifn();
|
||||
close(fd);
|
||||
EventManager::instance().unwatch(fd);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -36,7 +36,7 @@ void EventManager::handle_next_events()
|
||||
{
|
||||
for (size_t i = 0; i < m_events.size(); ++i)
|
||||
{
|
||||
if (m_events[i].revents & POLLIN)
|
||||
if (m_events[i].revents)
|
||||
m_handlers[i](m_events[i].fd);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
def -shell-params -file-completion \
|
||||
grep %{ echo grep in progress, please wait...; %sh{
|
||||
output=$(mktemp -t kak-grep.XXXXXXXX)
|
||||
grep -PHn $@ >& ${output} < /dev/null &
|
||||
output=$(mktemp -t -d kak-grep.XXXXXXXX)/fifo
|
||||
mkfifo ${output}
|
||||
( grep -PHn "$@" >& ${output} ) >& /dev/null < /dev/null &
|
||||
echo "echo
|
||||
try %{ db *grep* } catch %{ }
|
||||
edit -fifo ${output} *grep*
|
||||
setb filetype grep
|
||||
hook buffer BufClose .* %{ %sh{ rm ${output} } }"
|
||||
hook buffer BufClose .* %{ %sh{ rm -r $(dirname ${output}) } }"
|
||||
}}
|
||||
|
||||
hook global WinSetOption filetype=grep %{
|
||||
|
@ -1,11 +1,12 @@
|
||||
def -shell-params make %{ echo make in progress, please wait...; %sh{
|
||||
output=$(mktemp -t kak-make.XXXXXXXX)
|
||||
make $@ >& ${output} < /dev/null &
|
||||
output=$(mktemp -t -d kak-make.XXXXXXXX)/fifo
|
||||
mkfifo ${output}
|
||||
( make $@ >& ${output} ) >& /dev/null < /dev/null &
|
||||
echo "echo
|
||||
try %{ db *make* } catch %{ }
|
||||
edit -fifo ${output} *make*
|
||||
setb filetype make
|
||||
hook buffer BufClose .* %{ %sh{ rm ${output} } }"
|
||||
hook buffer BufClose .* %{ %sh{ rm -r $(dirname ${output}) } }"
|
||||
}}
|
||||
|
||||
hook global WinSetOption filetype=make %{
|
||||
|
Loading…
Reference in New Issue
Block a user