From edcc73e766438facc88db19000f054aa52ab8b13 Mon Sep 17 00:00:00 2001 From: Peter Hodge Date: Fri, 26 Jan 2018 20:36:11 +0100 Subject: API: Implement buffer updates Originally written by @phodge in https://github.com/neovim/neovim/pull/5269. --- src/nvim/api/buffer.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') 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); -- cgit From bafae1c427cb1eeb52e4caa641ad134c1e062e8e Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 26 Jan 2018 15:49:35 +0100 Subject: Add argument to not send a buffers content when updates are enabled Add a test. --- src/nvim/api/buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 159683db9e..e594e4975c 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -87,6 +87,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) Boolean nvim_buf_live_updates(uint64_t channel_id, Buffer buffer, Boolean enabled, + Boolean send_buffer, Error *err) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY { @@ -97,7 +98,7 @@ Boolean nvim_buf_live_updates(uint64_t channel_id, } if (enabled) { - return liveupdate_register(buf, channel_id); + return liveupdate_register(buf, channel_id, send_buffer); } liveupdate_unregister(buf, channel_id); -- cgit From 71816e584cef01c195797e738e1d6dba1de39102 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 26 Jan 2018 16:52:51 +0100 Subject: Adjust FUNC_API_SINCE for nvim_buf_live_updates --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index e594e4975c..44e274484a 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -89,7 +89,7 @@ Boolean nvim_buf_live_updates(uint64_t channel_id, Boolean enabled, Boolean send_buffer, Error *err) - FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY + FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { buf_T *buf = find_buffer_by_handle(buffer, err); -- cgit From 8bcc01195968b84d1a74ecb82598bdf538004404 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 26 Jan 2018 17:42:51 +0100 Subject: Make separate functions to start/stop live updates --- src/nvim/api/buffer.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 44e274484a..2c7480a16b 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -78,15 +78,14 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// 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 send_buffer Set to true if the initial notification should contain +/// the whole buffer /// @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, +Boolean nvim_buf_live_updates_start(uint64_t channel_id, Buffer buffer, - Boolean enabled, Boolean send_buffer, Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY @@ -97,8 +96,25 @@ Boolean nvim_buf_live_updates(uint64_t channel_id, return false; } - if (enabled) { - return liveupdate_register(buf, channel_id, send_buffer); + return liveupdate_register(buf, channel_id, send_buffer); + +} +// +/// Deactivate live updates from this buffer to the current channel. +/// +/// @param buffer The buffer handle +/// @param[out] err Details of an error that may have occurred +/// @return False when live updates couldn't be disabled because the buffer +/// isn't loaded; otherwise True. +Boolean nvim_buf_live_updates_stop(uint64_t channel_id, + Buffer buffer, + Error *err) + FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + + if (!buf) { + return false; } liveupdate_unregister(buf, channel_id); -- cgit From 37b8e95fd69ba4991454f79802bfe1bccf7c827a Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 26 Jan 2018 20:25:53 +0100 Subject: Lint --- src/nvim/api/buffer.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 2c7480a16b..6778227a27 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -85,9 +85,9 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// @return False when live updates couldn't be enabled because the buffer isn't /// loaded; otherwise True. Boolean nvim_buf_live_updates_start(uint64_t channel_id, - Buffer buffer, - Boolean send_buffer, - Error *err) + Buffer buffer, + Boolean send_buffer, + Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -97,7 +97,6 @@ Boolean nvim_buf_live_updates_start(uint64_t channel_id, } return liveupdate_register(buf, channel_id, send_buffer); - } // /// Deactivate live updates from this buffer to the current channel. @@ -107,8 +106,8 @@ Boolean nvim_buf_live_updates_start(uint64_t channel_id, /// @return False when live updates couldn't be disabled because the buffer /// isn't loaded; otherwise True. Boolean nvim_buf_live_updates_stop(uint64_t channel_id, - Buffer buffer, - Error *err) + Buffer buffer, + Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { buf_T *buf = find_buffer_by_handle(buffer, err); -- cgit From 6bdcbef2f5acfd9815599c751bd8dcbe3204281f Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sun, 11 Feb 2018 22:51:29 +0100 Subject: The grand renaming --- src/nvim/api/buffer.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 6778227a27..d59ce1ce3d 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -25,7 +25,7 @@ #include "nvim/window.h" #include "nvim/undo.h" #include "nvim/ex_docmd.h" -#include "nvim/liveupdate.h" +#include "nvim/buffer_updates.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/buffer.c.generated.h" @@ -76,18 +76,18 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) return rv; } -/// Activate live updates from this buffer to the current channel. +/// Activate updates from this buffer to the current channel. /// /// @param buffer The buffer handle /// @param send_buffer Set to true if the initial notification should contain /// the whole buffer /// @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 +/// @return False when updates couldn't be enabled because the buffer isn't /// loaded; otherwise True. -Boolean nvim_buf_live_updates_start(uint64_t channel_id, - Buffer buffer, - Boolean send_buffer, - Error *err) +Boolean nvim_buf_attach(uint64_t channel_id, + Buffer buffer, + Boolean send_buffer, + Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -96,18 +96,18 @@ Boolean nvim_buf_live_updates_start(uint64_t channel_id, return false; } - return liveupdate_register(buf, channel_id, send_buffer); + return buffer_updates_register(buf, channel_id, send_buffer); } // -/// Deactivate live updates from this buffer to the current channel. +/// Deactivate updates from this buffer to the current channel. /// /// @param buffer The buffer handle /// @param[out] err Details of an error that may have occurred -/// @return False when live updates couldn't be disabled because the buffer +/// @return False when updates couldn't be disabled because the buffer /// isn't loaded; otherwise True. -Boolean nvim_buf_live_updates_stop(uint64_t channel_id, - Buffer buffer, - Error *err) +Boolean nvim_buf_detach(uint64_t channel_id, + Buffer buffer, + Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -116,7 +116,7 @@ Boolean nvim_buf_live_updates_stop(uint64_t channel_id, return false; } - liveupdate_unregister(buf, channel_id); + buffer_updates_unregister(buf, channel_id); return true; } -- cgit From 2106bada5bbd6de4729a8714d011e0eca61cee35 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Sun, 11 Feb 2018 23:02:53 +0100 Subject: Enable -Wconversion --- src/nvim/api/buffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index d59ce1ce3d..f6a6534560 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -85,9 +85,9 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// @return False when updates couldn't be enabled because the buffer isn't /// loaded; otherwise True. Boolean nvim_buf_attach(uint64_t channel_id, - Buffer buffer, - Boolean send_buffer, - Error *err) + Buffer buffer, + Boolean send_buffer, + Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -106,8 +106,8 @@ Boolean nvim_buf_attach(uint64_t channel_id, /// @return False when updates couldn't be disabled because the buffer /// isn't loaded; otherwise True. Boolean nvim_buf_detach(uint64_t channel_id, - Buffer buffer, - Error *err) + Buffer buffer, + Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { buf_T *buf = find_buffer_by_handle(buffer, err); -- cgit From e7451f8a91e0a9452fc3c3627ac60dc80288252c Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Tue, 24 Apr 2018 20:38:00 +0200 Subject: Some renamings and doc changes --- src/nvim/api/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index f6a6534560..756367f801 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -96,7 +96,7 @@ Boolean nvim_buf_attach(uint64_t channel_id, return false; } - return buffer_updates_register(buf, channel_id, send_buffer); + return buf_updates_register(buf, channel_id, send_buffer); } // /// Deactivate updates from this buffer to the current channel. @@ -116,7 +116,7 @@ Boolean nvim_buf_detach(uint64_t channel_id, return false; } - buffer_updates_unregister(buf, channel_id); + buf_updates_unregister(buf, channel_id); return true; } -- cgit From 0bee3925ab5186211f10c823d4f149d4d16eb7a5 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Thu, 10 May 2018 23:13:58 +0200 Subject: Send changedtick as first event if buffer contents weren't requested --- src/nvim/api/buffer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 756367f801..12d1feb370 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -80,7 +80,9 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// /// @param buffer The buffer handle /// @param send_buffer Set to true if the initial notification should contain -/// the whole buffer +/// the whole buffer. If so, the first notification will be a +/// `nvim_buf_lines_event`. Otherwise, the first notification will be +/// a `nvim_buf_changedtick_event` /// @param[out] err Details of an error that may have occurred /// @return False when updates couldn't be enabled because the buffer isn't /// loaded; otherwise True. -- cgit From 333679ad0ea6cb387debeae37645ecc0a830de25 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Mon, 21 May 2018 20:42:59 +0200 Subject: Add empty options dict to buf_attach --- src/nvim/api/buffer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 12d1feb370..215859a499 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -83,15 +83,22 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// the whole buffer. If so, the first notification will be a /// `nvim_buf_lines_event`. Otherwise, the first notification will be /// a `nvim_buf_changedtick_event` +/// @param opts Optional parameters. Currently not used. /// @param[out] err Details of an error that may have occurred /// @return False when updates couldn't be enabled because the buffer isn't -/// loaded; otherwise True. +/// loaded or `opts` contained an invalid key; otherwise True. Boolean nvim_buf_attach(uint64_t channel_id, Buffer buffer, Boolean send_buffer, + Dictionary opts, Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { + if (opts.size > 0) { + api_set_error(err, kErrorTypeValidation, "dict isn't empty"); + return false; + } + buf_T *buf = find_buffer_by_handle(buffer, err); if (!buf) { -- cgit