rename: UIAttach/UIDetach => UIEnter/UILeave

"enter"/"leave" is more conventional for Vim events, and
"attach"/"detach" distinction does not gain much.
This commit is contained in:
Justin M. Keyes
2019-09-12 16:08:22 -07:00
parent 44d45e29ea
commit 589f612adf
8 changed files with 26 additions and 26 deletions

View File

@@ -280,8 +280,8 @@ Name triggered by ~
Startup and exit Startup and exit
|VimEnter| after doing all the startup stuff |VimEnter| after doing all the startup stuff
|UIAttach| after a UI attaches |UIEnter| after a UI attaches
|UIDetach| after a UI detaches |UILeave| after a UI detaches
|TermResponse| after the terminal response to t_RV is received |TermResponse| after the terminal response to t_RV is received
|QuitPre| when using `:quit`, before deciding whether to exit |QuitPre| when using `:quit`, before deciding whether to exit
|ExitPre| when using a command that may make Vim exit |ExitPre| when using a command that may make Vim exit
@@ -805,14 +805,14 @@ FuncUndefined When a user function is used but it isn't
NOTE: When writing Vim scripts a better NOTE: When writing Vim scripts a better
alternative is to use an autoloaded function. alternative is to use an autoloaded function.
See |autoload-functions|. See |autoload-functions|.
*UIAttach* *UIEnter*
UIAttach After a UI connects via |nvim_ui_attach()|, UIEnter After a UI connects via |nvim_ui_attach()|,
after VimEnter. Can be used for GUI-specific after VimEnter. Can be used for GUI-specific
configuration. configuration.
Sets these |v:event| keys: Sets these |v:event| keys:
chan chan
*UIDetach* *UILeave*
UIDetach After a UI detaches from Nvim. UILeave After a UI disconnects from Nvim.
Sets these |v:event| keys: Sets these |v:event| keys:
chan chan
*InsertChange* *InsertChange*

View File

@@ -28,7 +28,7 @@ Environment Variables ~
Events ~ Events ~
*EncodingChanged* Never fired; 'encoding' is always "utf-8". *EncodingChanged* Never fired; 'encoding' is always "utf-8".
*FileEncoding* Never fired; equivalent to |EncodingChanged|. *FileEncoding* Never fired; equivalent to |EncodingChanged|.
*GUIEnter* Never fired; use |UIAttach| instead. *GUIEnter* Never fired; use |UIEnter| instead.
*GUIFailed* Never fired. *GUIFailed* Never fired.
Keycodes ~ Keycodes ~

View File

@@ -12,11 +12,11 @@ Nvim Graphical User Interface *gui* *GUI*
Starting the GUI *gui-start* *E229* *E233* Starting the GUI *gui-start* *E229* *E233*
*ginit.vim* *gui-init* *gvimrc* *$MYGVIMRC* *ginit.vim* *gui-init* *gvimrc* *$MYGVIMRC*
For GUI-specific configuration Nvim provides the |UIAttach| event. This For GUI-specific configuration Nvim provides the |UIEnter| event. This
happens after other |initialization|s, like reading your vimrc file. happens after other |initialization|s, like reading your vimrc file.
Example: this sets "g:gui" to the value of the UI's "rgb" field: > Example: this sets "g:gui" to the value of the UI's "rgb" field: >
:autocmd UIAttach * let g:gui = filter(nvim_list_uis(),{k,v-> v.chan==v:event.chan})[0].rgb :autocmd UIEnter * let g:gui = filter(nvim_list_uis(),{k,v-> v.chan==v:event.chan})[0].rgb
< <
*:winp* *:winpos* *E188* *:winp* *:winpos* *E188*

View File

@@ -154,8 +154,8 @@ Events:
|TermClose| |TermClose|
|TermOpen| |TermOpen|
|TextYankPost| |TextYankPost|
|UIAttach| |UIEnter|
|UIDetach| |UILeave|
|VimResume| |VimResume|
|VimSuspend| |VimSuspend|

View File

@@ -13,7 +13,7 @@
# include "aucmd.c.generated.h" # include "aucmd.c.generated.h"
#endif #endif
void do_autocmd_uiattach(uint64_t chanid, bool attached) void do_autocmd_uienter(uint64_t chanid, bool attached)
{ {
static bool recursive = false; static bool recursive = false;
@@ -26,7 +26,7 @@ void do_autocmd_uiattach(uint64_t chanid, bool attached)
assert(chanid < VARNUMBER_MAX); assert(chanid < VARNUMBER_MAX);
tv_dict_add_nr(dict, S_LEN("chan"), (varnumber_T)chanid); tv_dict_add_nr(dict, S_LEN("chan"), (varnumber_T)chanid);
tv_dict_set_keys_readonly(dict); tv_dict_set_keys_readonly(dict);
apply_autocmds(attached ? EVENT_UIATTACH : EVENT_UIDETACH, apply_autocmds(attached ? EVENT_UIENTER : EVENT_UILEAVE,
NULL, NULL, false, curbuf); NULL, NULL, false, curbuf);
tv_dict_clear(dict); tv_dict_clear(dict);

View File

@@ -96,8 +96,8 @@ return {
'TextChangedI', -- text was modified in Insert mode(no popup) 'TextChangedI', -- text was modified in Insert mode(no popup)
'TextChangedP', -- text was modified in Insert mode(popup) 'TextChangedP', -- text was modified in Insert mode(popup)
'TextYankPost', -- after a yank or delete was done (y, d, c) 'TextYankPost', -- after a yank or delete was done (y, d, c)
'UIAttach', -- after a UI attached 'UIEnter', -- after UI attaches
'UIDetach', -- after a UI detaches 'UILeave', -- after UI detaches
'User', -- user defined autocommand 'User', -- user defined autocommand
'VimEnter', -- after starting Vim 'VimEnter', -- after starting Vim
'VimLeave', -- before exiting Vim 'VimLeave', -- before exiting Vim
@@ -125,7 +125,7 @@ return {
TabNewEntered=true, TabNewEntered=true,
TermClose=true, TermClose=true,
TermOpen=true, TermOpen=true,
UIAttach=true, UIEnter=true,
UIDetach=true, UILeave=true,
}, },
} }

View File

@@ -296,7 +296,7 @@ void ui_attach_impl(UI *ui, uint64_t chanid)
bool is_compositor = (ui == uis[0]); bool is_compositor = (ui == uis[0]);
if (!is_compositor) { if (!is_compositor) {
do_autocmd_uiattach(chanid, true); do_autocmd_uienter(chanid, true);
} }
} }
@@ -333,7 +333,7 @@ void ui_detach_impl(UI *ui, uint64_t chanid)
ui_comp_detach(ui); ui_comp_detach(ui);
} }
do_autocmd_uiattach(chanid, false); do_autocmd_uienter(chanid, false);
} }
void ui_set_ext_option(UI *ui, UIExtension ext, bool active) void ui_set_ext_option(UI *ui, UIExtension ext, bool active)

View File

@@ -36,21 +36,21 @@ describe('nvim_ui_attach()', function()
end) end)
end) end)
it('autocmds UIAttach/UIDetach', function() it('autocmds UIEnter/UILeave', function()
clear{args={ clear{args={
'--cmd', 'let g:evs = []', '--cmd', 'let g:evs = []',
'--cmd', 'autocmd UIAttach * :call add(g:evs, "UIAttach") | let g:ui_attach_ev = deepcopy(v:event)', '--cmd', 'autocmd UIEnter * :call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event)',
'--cmd', 'autocmd UIDetach * :call add(g:evs, "UIDetach") | let g:ui_detach_ev = deepcopy(v:event)', '--cmd', 'autocmd UILeave * :call add(g:evs, "UILeave") | let g:uileave_ev = deepcopy(v:event)',
'--cmd', 'autocmd VimEnter * :call add(g:evs, "VimEnter")', '--cmd', 'autocmd VimEnter * :call add(g:evs, "VimEnter")',
}} }}
local screen = Screen.new() local screen = Screen.new()
screen:attach() screen:attach()
eq({chan=1}, eval('g:ui_attach_ev')) eq({chan=1}, eval('g:uienter_ev'))
screen:detach() screen:detach()
eq({chan=1}, eval('g:ui_detach_ev')) eq({chan=1}, eval('g:uileave_ev'))
eq({ eq({
'VimEnter', 'VimEnter',
'UIAttach', 'UIEnter',
'UIDetach', 'UILeave',
}, eval('g:evs')) }, eval('g:evs'))
end) end)