diff options
author | Rui Abreu Ferreira <raf-ep@gmx.com> | 2017-06-21 16:59:52 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-09-12 15:52:54 -0700 |
commit | e9cf515888705640ebd754483349f2bf84c32255 (patch) | |
tree | a8709dfdb9e5e6090b47fc601e6bc21350f78fac /src | |
parent | 426399c2c4dd325bf00ffe1f410c1b9fd5053692 (diff) | |
download | rneovim-e9cf515888705640ebd754483349f2bf84c32255.tar.gz rneovim-e9cf515888705640ebd754483349f2bf84c32255.tar.bz2 rneovim-e9cf515888705640ebd754483349f2bf84c32255.zip |
UIAttach, UIDetach
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/ui.c | 14 | ||||
-rw-r--r-- | src/nvim/auevents.lua | 4 | ||||
-rw-r--r-- | src/nvim/channel.c | 2 | ||||
-rw-r--r-- | src/nvim/ui_bridge.c | 16 |
4 files changed, 36 insertions, 0 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index ada26a2a07..acf0404c31 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -19,6 +19,8 @@ #include "nvim/highlight.h" #include "nvim/screen.h" #include "nvim/window.h" +#include "nvim/fileio.h" +#include "nvim/eval.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/ui.c.generated.h" @@ -169,6 +171,12 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, pmap_put(uint64_t)(connected_uis, channel_id, ui); ui_attach_impl(ui); + + dict_T *dict = get_vim_var_dict(VV_EVENT); + tv_dict_add_nr(dict, S_LEN("chan"), (long)channel_id); + tv_dict_set_keys_readonly(dict); + apply_autocmds(EVENT_UIATTACH, NULL, NULL, false, curbuf); + tv_dict_clear(dict); } /// @deprecated @@ -196,6 +204,12 @@ void nvim_ui_detach(uint64_t channel_id, Error *err) return; } remote_ui_disconnect(channel_id); + + dict_T *dict = get_vim_var_dict(VV_EVENT); + tv_dict_add_nr(dict, S_LEN("chan"), (long)channel_id); + tv_dict_set_keys_readonly(dict); + apply_autocmds(EVENT_UIDETACH, NULL, NULL, false, curbuf); + tv_dict_clear(dict); } diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 12fc8fd02a..1505b984ad 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -96,6 +96,8 @@ return { 'TextChangedI', -- text was modified in Insert mode(no popup) 'TextChangedP', -- text was modified in Insert mode(popup) 'TextYankPost', -- after a yank or delete was done (y, d, c) + 'UIAttach', -- after a UI attached + 'UIDetach', -- after a UI detaches 'User', -- user defined autocommand 'VimEnter', -- after starting Vim 'VimLeave', -- before exiting Vim @@ -123,5 +125,7 @@ return { TabNewEntered=true, TermClose=true, TermOpen=true, + UIAttach=true, + UIDetach=true, }, } diff --git a/src/nvim/channel.c b/src/nvim/channel.c index 104c79efd9..f9102fa0e2 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -172,6 +172,7 @@ static Channel *channel_alloc(ChannelStreamType type) chan->refcount = 1; chan->exit_status = -1; chan->streamtype = type; + assert(chan->id <= VARNUMBER_MAX); pmap_put(uint64_t)(channels, chan->id, chan); return chan; } @@ -190,6 +191,7 @@ void channel_create_event(Channel *chan, const char *ext_source) source = (const char *)IObuff; } + assert(chan->id <= VARNUMBER_MAX); Dictionary info = channel_info(chan->id); typval_T tv = TV_INITIAL_VALUE; // TODO(bfredl): do the conversion in one step. Also would be nice diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c index 91cd458702..be76a8b047 100644 --- a/src/nvim/ui_bridge.c +++ b/src/nvim/ui_bridge.c @@ -17,6 +17,8 @@ #include "nvim/ui_bridge.h" #include "nvim/ugrid.h" #include "nvim/api/private/helpers.h" +#include "nvim/fileio.h" +#include "nvim/eval.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui_bridge.c.generated.h" @@ -86,6 +88,13 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler) uv_mutex_unlock(&rv->mutex); ui_attach_impl(&rv->bridge); + + dict_T *dict = get_vim_var_dict(VV_EVENT); + tv_dict_add_nr(dict, S_LEN("chan"), 0); + tv_dict_set_keys_readonly(dict); + apply_autocmds(EVENT_UIATTACH, NULL, NULL, false, curbuf); + tv_dict_clear(dict); + return &rv->bridge; } @@ -107,6 +116,13 @@ static void ui_bridge_stop(UI *b) // Detach bridge first, so that "stop" is the last event the TUI loop // receives from the main thread. #8041 ui_detach_impl(b); + + dict_T *dict = get_vim_var_dict(VV_EVENT); + tv_dict_add_nr(dict, S_LEN("chan"), 0); + tv_dict_set_keys_readonly(dict); + apply_autocmds(EVENT_UIDETACH, NULL, NULL, false, curbuf); + tv_dict_clear(dict); + UIBridgeData *bridge = (UIBridgeData *)b; bool stopped = bridge->stopped = false; UI_BRIDGE_CALL(b, stop, 1, b); |