diff options
author | Peter Hodge <peter.hodge84@gmail.com> | 2018-01-26 20:36:11 +0100 |
---|---|---|
committer | KillTheMule <KillTheMule@users.noreply.github.com> | 2018-05-23 22:07:27 +0200 |
commit | edcc73e766438facc88db19000f054aa52ab8b13 (patch) | |
tree | 17a62cbbb7785e6f88aaa99728cfa0d8cd5e076c /src/nvim/api/buffer.c | |
parent | 418abfc9d06923e96f1317419fe83ed4e6d67c1d (diff) | |
download | rneovim-edcc73e766438facc88db19000f054aa52ab8b13.tar.gz rneovim-edcc73e766438facc88db19000f054aa52ab8b13.tar.bz2 rneovim-edcc73e766438facc88db19000f054aa52ab8b13.zip |
API: Implement buffer updates
Originally written by @phodge in
https://github.com/neovim/neovim/pull/5269.
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r-- | src/nvim/api/buffer.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index fa4ad27e60..159683db9e 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -25,6 +25,7 @@ #include "nvim/window.h" #include "nvim/undo.h" #include "nvim/ex_docmd.h" +#include "nvim/liveupdate.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/buffer.c.generated.h" @@ -75,6 +76,34 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) return rv; } +/// Activate live updates from this buffer to the current channel. +/// +/// +/// @param buffer The buffer handle +/// @param enabled True turns on live updates, False turns them off. +/// @param[out] err Details of an error that may have occurred +/// @return False when live updates couldn't be enabled because the buffer isn't +/// loaded; otherwise True. +Boolean nvim_buf_live_updates(uint64_t channel_id, + Buffer buffer, + Boolean enabled, + Error *err) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + + if (!buf) { + return false; + } + + if (enabled) { + return liveupdate_register(buf, channel_id); + } + + liveupdate_unregister(buf, channel_id); + return true; +} + /// Sets a buffer line /// /// @deprecated use nvim_buf_set_lines instead. @@ -407,7 +436,7 @@ void nvim_buf_set_lines(uint64_t channel_id, false); } - changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra); + changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra, true); if (save_curbuf.br_buf == NULL) { fix_cursor((linenr_T)start, (linenr_T)end, (linenr_T)extra); |