diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-09-12 17:45:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-12 17:45:33 -0700 |
commit | 3855204f5860ff2a66133541ff7593f0c2606a75 (patch) | |
tree | c028665f67fc7b9f9d8b576fa8c46157245016d3 /src | |
parent | 426399c2c4dd325bf00ffe1f410c1b9fd5053692 (diff) | |
parent | 492ac04f7e0ffcc5011d3604b234d149f8b0bb91 (diff) | |
download | rneovim-3855204f5860ff2a66133541ff7593f0c2606a75.tar.gz rneovim-3855204f5860ff2a66133541ff7593f0c2606a75.tar.bz2 rneovim-3855204f5860ff2a66133541ff7593f0c2606a75.zip |
Merge #6917 'UIEnter, UILeave'
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/ui.c | 4 | ||||
-rw-r--r-- | src/nvim/aucmd.c | 22 | ||||
-rw-r--r-- | src/nvim/aucmd.h | 2 | ||||
-rw-r--r-- | src/nvim/auevents.lua | 4 | ||||
-rw-r--r-- | src/nvim/channel.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.h | 21 | ||||
-rw-r--r-- | src/nvim/main.c | 7 | ||||
-rw-r--r-- | src/nvim/ui.c | 16 | ||||
-rw-r--r-- | src/nvim/ui_bridge.c | 12 | ||||
-rw-r--r-- | src/nvim/ui_compositor.c | 2 |
11 files changed, 69 insertions, 25 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index ada26a2a07..75ee05761b 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -57,7 +57,7 @@ void remote_ui_disconnect(uint64_t channel_id) pmap_del(uint64_t)(connected_uis, channel_id); xfree(ui->data); ui->data = NULL; // Flag UI as "stopped". - ui_detach_impl(ui); + ui_detach_impl(ui, channel_id); xfree(ui); } @@ -168,7 +168,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, ui->data = data; pmap_put(uint64_t)(connected_uis, channel_id, ui); - ui_attach_impl(ui); + ui_attach_impl(ui, channel_id); } /// @deprecated diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c index 3bb0fcec3b..a9a7d834a4 100644 --- a/src/nvim/aucmd.c +++ b/src/nvim/aucmd.c @@ -7,11 +7,32 @@ #include "nvim/main.h" #include "nvim/ui.h" #include "nvim/aucmd.h" +#include "nvim/eval.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "aucmd.c.generated.h" #endif +void do_autocmd_uienter(uint64_t chanid, bool attached) +{ + static bool recursive = false; + + if (recursive) { + return; // disallow recursion + } + recursive = true; + + dict_T *dict = get_vim_var_dict(VV_EVENT); + assert(chanid < VARNUMBER_MAX); + tv_dict_add_nr(dict, S_LEN("chan"), (varnumber_T)chanid); + tv_dict_set_keys_readonly(dict); + apply_autocmds(attached ? EVENT_UIENTER : EVENT_UILEAVE, + NULL, NULL, false, curbuf); + tv_dict_clear(dict); + + recursive = false; +} + static void focusgained_event(void **argv) { bool *gainedp = argv[0]; @@ -38,4 +59,3 @@ static void do_autocmd_focusgained(bool gained) NULL, NULL, false, curbuf); recursive = false; } - diff --git a/src/nvim/aucmd.h b/src/nvim/aucmd.h index 6570ba7a92..9a4dd79a78 100644 --- a/src/nvim/aucmd.h +++ b/src/nvim/aucmd.h @@ -1,6 +1,8 @@ #ifndef NVIM_AUCMD_H #define NVIM_AUCMD_H +#include <stdint.h> + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "aucmd.h.generated.h" #endif diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 12fc8fd02a..c808af37b1 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) + 'UIEnter', -- after UI attaches + 'UILeave', -- after 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, + UIEnter=true, + UILeave=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/ex_cmds2.c b/src/nvim/ex_cmds2.c index affdda0386..25528e667f 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -3111,8 +3111,6 @@ int do_source(char_u *fname, int check_other, int is_vimrc) } if (is_vimrc == DOSO_VIMRC) { vimrc_found(fname_exp, (char_u *)"MYVIMRC"); - } else if (is_vimrc == DOSO_GVIMRC) { - vimrc_found(fname_exp, (char_u *)"MYGVIMRC"); } #ifdef USE_CRNL diff --git a/src/nvim/ex_cmds2.h b/src/nvim/ex_cmds2.h index 0a164cdeb8..f85ea94ed6 100644 --- a/src/nvim/ex_cmds2.h +++ b/src/nvim/ex_cmds2.h @@ -7,19 +7,18 @@ typedef void (*DoInRuntimepathCB)(char_u *, void *); -/* - * flags for check_changed() - */ -#define CCGD_AW 1 /* do autowrite if buffer was changed */ -#define CCGD_MULTWIN 2 /* check also when several wins for the buf */ -#define CCGD_FORCEIT 4 /* ! used */ -#define CCGD_ALLBUF 8 /* may write all buffers */ -#define CCGD_EXCMD 16 /* may suggest using ! */ +// +// flags for check_changed() +// +#define CCGD_AW 1 // do autowrite if buffer was changed +#define CCGD_MULTWIN 2 // check also when several wins for the buf +#define CCGD_FORCEIT 4 // ! used +#define CCGD_ALLBUF 8 // may write all buffers +#define CCGD_EXCMD 16 // may suggest using ! -/* last argument for do_source() */ +// last argument for do_source() #define DOSO_NONE 0 -#define DOSO_VIMRC 1 /* loading vimrc file */ -#define DOSO_GVIMRC 2 /* loading gvimrc file */ +#define DOSO_VIMRC 1 // loading vimrc file #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ex_cmds2.h.generated.h" diff --git a/src/nvim/main.c b/src/nvim/main.c index bca8991b0f..e7835ccbf1 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -12,6 +12,7 @@ #include "nvim/ascii.h" #include "nvim/vim.h" #include "nvim/main.h" +#include "nvim/aucmd.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/diff.h" @@ -351,7 +352,7 @@ int main(int argc, char **argv) bool use_remote_ui = (embedded_mode && !headless_mode); bool use_builtin_ui = (!headless_mode && !embedded_mode && !silent_mode); if (use_remote_ui || use_builtin_ui) { - TIME_MSG("waiting for UI to make request"); + TIME_MSG("waiting for UI"); if (use_remote_ui) { remote_ui_wait_for_attach(); } else { @@ -537,6 +538,10 @@ int main(int argc, char **argv) set_vim_var_nr(VV_VIM_DID_ENTER, 1L); apply_autocmds(EVENT_VIMENTER, NULL, NULL, false, curbuf); TIME_MSG("VimEnter autocommands"); + if (use_remote_ui || use_builtin_ui) { + do_autocmd_uienter(use_remote_ui ? CHAN_STDIO : 0, true); + TIME_MSG("UIEnter autocommands"); + } // Adjust default register name for "unnamed" in 'clipboard'. Can only be // done after the clipboard is available and all initial commands that may diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 25077675bf..79fa8b8223 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -9,6 +9,7 @@ #include "nvim/vim.h" #include "nvim/log.h" +#include "nvim/aucmd.h" #include "nvim/ui.h" #include "nvim/charset.h" #include "nvim/cursor.h" @@ -268,7 +269,7 @@ void ui_busy_stop(void) } } -void ui_attach_impl(UI *ui) +void ui_attach_impl(UI *ui, uint64_t chanid) { if (ui_count == MAX_UI_COUNT) { abort(); @@ -292,9 +293,14 @@ void ui_attach_impl(UI *ui) ui_send_all_hls(ui); } ui_refresh(); + + bool is_compositor = (ui == uis[0]); + if (!is_compositor) { + do_autocmd_uienter(chanid, true); + } } -void ui_detach_impl(UI *ui) +void ui_detach_impl(UI *ui, uint64_t chanid) { size_t shift_index = MAX_UI_COUNT; @@ -326,6 +332,8 @@ void ui_detach_impl(UI *ui) if (!ui->ui_ext[kUIMultigrid] && !ui->ui_ext[kUIFloatDebug]) { ui_comp_detach(ui); } + + do_autocmd_uienter(chanid, false); } void ui_set_ext_option(UI *ui, UIExtension ext, bool active) @@ -476,9 +484,7 @@ Array ui_array(void) PUT(info, ui_ext_names[j], BOOLEAN_OBJ(ui->ui_ext[j])); } } - if (ui->inspect) { - ui->inspect(ui, &info); - } + ui->inspect(ui, &info); ADD(all_uis, DICTIONARY_OBJ(info)); } return all_uis; diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c index 91cd458702..9a1988739c 100644 --- a/src/nvim/ui_bridge.c +++ b/src/nvim/ui_bridge.c @@ -63,6 +63,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler) rv->bridge.set_icon = ui_bridge_set_icon; rv->bridge.option_set = ui_bridge_option_set; rv->bridge.raw_line = ui_bridge_raw_line; + rv->bridge.inspect = ui_bridge_inspect; rv->scheduler = scheduler; for (UIExtension i = 0; (int)i < kUIExtCount; i++) { @@ -85,7 +86,8 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler) } uv_mutex_unlock(&rv->mutex); - ui_attach_impl(&rv->bridge); + ui_attach_impl(&rv->bridge, 0); + return &rv->bridge; } @@ -106,7 +108,8 @@ 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); + ui_detach_impl(b, 0); + UIBridgeData *bridge = (UIBridgeData *)b; bool stopped = bridge->stopped = false; UI_BRIDGE_CALL(b, stop, 1, b); @@ -213,3 +216,8 @@ static void ui_bridge_option_set_event(void **argv) api_free_object(value); xfree(argv[3]); } + +static void ui_bridge_inspect(UI *ui, Dictionary *info) +{ + PUT(*info, "chan", INTEGER_OBJ(0)); +} diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index f91442642d..1af027d415 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -83,7 +83,7 @@ void ui_comp_init(void) kv_push(layers, &default_grid); curgrid = &default_grid; - ui_attach_impl(compositor); + ui_attach_impl(compositor, 0); } void ui_comp_syn_init(void) |