aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Abreu Ferreira <raf-ep@gmx.com>2017-06-21 16:59:52 +0100
committerJustin M. Keyes <justinkz@gmail.com>2019-09-12 15:52:54 -0700
commite9cf515888705640ebd754483349f2bf84c32255 (patch)
treea8709dfdb9e5e6090b47fc601e6bc21350f78fac
parent426399c2c4dd325bf00ffe1f410c1b9fd5053692 (diff)
downloadrneovim-e9cf515888705640ebd754483349f2bf84c32255.tar.gz
rneovim-e9cf515888705640ebd754483349f2bf84c32255.tar.bz2
rneovim-e9cf515888705640ebd754483349f2bf84c32255.zip
UIAttach, UIDetach
-rw-r--r--runtime/doc/autocmd.txt25
-rw-r--r--runtime/doc/deprecated.txt2
-rw-r--r--runtime/doc/vim_diff.txt2
-rw-r--r--src/nvim/api/ui.c14
-rw-r--r--src/nvim/auevents.lua4
-rw-r--r--src/nvim/channel.c2
-rw-r--r--src/nvim/ui_bridge.c16
-rw-r--r--test/functional/api/ui_spec.lua10
8 files changed, 60 insertions, 15 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 6b39f1a103..0fab2bd24f 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -280,8 +280,8 @@ Name triggered by ~
Startup and exit
|VimEnter| after doing all the startup stuff
-|GUIEnter| after starting the GUI successfully
-|GUIFailed| after starting the GUI failed
+|UIAttach| after a new UI attaches
+|UIDetach| after a UI detaches
|TermResponse| after the terminal response to t_RV is received
|QuitPre| when using `:quit`, before deciding whether to exit
|ExitPre| when using a command that may make Vim exit
@@ -805,19 +805,14 @@ FuncUndefined When a user function is used but it isn't
NOTE: When writing Vim scripts a better
alternative is to use an autoloaded function.
See |autoload-functions|.
- *GUIEnter*
-GUIEnter After starting the GUI successfully, and after
- opening the window. It is triggered before
- VimEnter when using gvim. Can be used to
- position the window from a gvimrc file: >
- :autocmd GUIEnter * winpos 100 50
-< *GUIFailed*
-GUIFailed After starting the GUI failed. Vim may
- continue to run in the terminal, if possible
- (only on Unix and alikes, when connecting the
- X server fails). You may want to quit Vim: >
- :autocmd GUIFailed * qall
-< *InsertChange*
+ {Nvim} *UIAttach*
+UIAttach After a new UI connects to nvim and successfully
+ calls |nvim_ui_attach|. Sets chan in |v:event| with
+ the channel id or 0 if using the internal UI.
+ {Nvim} *UIDetach*
+UIDetach After a UI detaches from nvim. Sets chan in |v:event|
+ with the channel id or 0 if using the internal UI.
+ *InsertChange*
InsertChange When typing <Insert> while in Insert or
Replace mode. The |v:insertmode| variable
indicates the new mode.
diff --git a/runtime/doc/deprecated.txt b/runtime/doc/deprecated.txt
index 27e60be368..c26ddf8fe8 100644
--- a/runtime/doc/deprecated.txt
+++ b/runtime/doc/deprecated.txt
@@ -28,6 +28,8 @@ Environment Variables ~
Events ~
*EncodingChanged* Never fired; 'encoding' is always "utf-8".
*FileEncoding* Never fired; equivalent to |EncodingChanged|.
+*GUIEnter* Never fired; Use |UIAttach| instead.
+*GUIFailed* Never fired.
Keycodes ~
*<MouseDown>* Use <ScrollWheelUp> instead.
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 7381ae4e2b..b96e9892a2 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -154,6 +154,8 @@ Events:
|TermClose|
|TermOpen|
|TextYankPost|
+ |UIAttach|
+ |UIDetach|
|VimResume|
|VimSuspend|
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);
diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua
index 2758da6a1f..bedc381b70 100644
--- a/test/functional/api/ui_spec.lua
+++ b/test/functional/api/ui_spec.lua
@@ -6,6 +6,7 @@ local eval = helpers.eval
local meths = helpers.meths
local request = helpers.request
local pcall_err = helpers.pcall_err
+local command = helpers.command
describe('nvim_ui_attach()', function()
before_each(function()
@@ -34,4 +35,13 @@ describe('nvim_ui_attach()', function()
eq('UI already attached to channel: 1',
pcall_err(request, 'nvim_ui_attach', 40, 10, { rgb=false }))
end)
+ it('autocmds UIAttach/Detach set v:event', function()
+ local screen = Screen.new()
+ command('autocmd UIAttach * :let g:ui_attach_v_event = deepcopy(v:event)')
+ command('autocmd UIDetach * :let g:ui_detach_v_event = deepcopy(v:event)')
+ screen:attach()
+ assert.same({chan=1}, eval('g:ui_attach_v_event'))
+ screen:detach()
+ assert.same({chan=1}, eval('g:ui_detach_v_event'))
+ end)
end)