diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-11-14 17:52:57 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-11-14 17:52:57 +1100 |
| commit | 9a68a2d3afa5d44961e04d7c4e1e0a0b568f4dee (patch) | |
| tree | 37b8528dbe3e9d3be90e380e9cda25bac2115e2e /src/buffer_utils.cc | |
| parent | 021ba55b3811f7f12743e1dfe7c11c4aa523d3a6 (diff) | |
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.
Diffstat (limited to 'src/buffer_utils.cc')
| -rw-r--r-- | src/buffer_utils.cc | 12 |
1 files changed, 9 insertions, 3 deletions
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 <unistd.h> @@ -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)); |
