From 9a68a2d3afa5d44961e04d7c4e1e0a0b568f4dee Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 14 Nov 2018 17:52:57 +1100 Subject: Change BufReadFifo hook param to contain the inserted range the buffer name was not a very interesting information, whereas the buffer range allows a hook to run only on the appended text instead of all the buffer. --- src/buffer_utils.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/buffer_utils.cc') diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index c2c75da0..bb0669ff 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -3,6 +3,7 @@ #include "buffer_manager.hh" #include "event_manager.hh" #include "file.hh" +#include "selection.hh" #include @@ -127,8 +128,10 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll // if we read data slower than it arrives in the fifo, limiting the // iteration number allows us to go back go back to the event loop and // handle other events sources (such as input) - size_t loops = 16; + constexpr size_t max_loop = 16; + size_t loop = 0; char data[buffer_size]; + BufferCoord insert_coord; const int fifo = watcher.fd(); do { @@ -144,6 +147,8 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll if (prevent_scrolling) pos = buffer->next(pos); + if (loop == 0) + insert_coord = pos; buffer->insert(pos, StringView(data, data+count)); if (prevent_scrolling) @@ -155,9 +160,10 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll buffer->insert(buffer->end_coord(), "\n"); } } - while (--loops and fd_readable(fifo)); + while (++loop < max_loop and fd_readable(fifo)); - buffer->run_hook_in_own_context(Hook::BufReadFifo, buffer->name()); + buffer->run_hook_in_own_context(Hook::BufReadFifo, + selection_to_string({insert_coord, buffer->back_coord()})); }), std::move(watcher_deleter)); buffer->values()[fifo_watcher_id] = Value(std::move(watcher)); -- cgit v1.2.3