mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(dirchanged): tab -> tabpage
Match Vim's behavior.
This commit is contained in:
parent
36290a2ebd
commit
6004f9137a
@ -520,10 +520,10 @@ DiffUpdated After diffs have been updated. Depending on
|
|||||||
*DirChanged*
|
*DirChanged*
|
||||||
DirChanged After the |current-directory| was changed.
|
DirChanged After the |current-directory| was changed.
|
||||||
The pattern can be:
|
The pattern can be:
|
||||||
"window" to trigger on `:lcd`
|
"window" to trigger on `:lcd`
|
||||||
"tab" to trigger on `:tcd`
|
"tabpage" to trigger on `:tcd`
|
||||||
"global" to trigger on `:cd`
|
"global" to trigger on `:cd`
|
||||||
"auto" to trigger on 'autochdir'.
|
"auto" to trigger on 'autochdir'.
|
||||||
Sets these |v:event| keys:
|
Sets these |v:event| keys:
|
||||||
cwd: current working directory
|
cwd: current working directory
|
||||||
scope: "global", "tab", "window"
|
scope: "global", "tab", "window"
|
||||||
|
@ -1093,7 +1093,7 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
if (curwin->w_localdir != NULL) {
|
if (curwin->w_localdir != NULL) {
|
||||||
scope = kCdScopeWindow;
|
scope = kCdScopeWindow;
|
||||||
} else if (curtab->tp_localdir != NULL) {
|
} else if (curtab->tp_localdir != NULL) {
|
||||||
scope = kCdScopeTab;
|
scope = kCdScopeTabpage;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!changedir_func(argvars[0].vval.v_string, scope)) {
|
if (!changedir_func(argvars[0].vval.v_string, scope)) {
|
||||||
@ -3445,8 +3445,8 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
// Numbers of the scope objects (window, tab) we want the working directory
|
// Numbers of the scope objects (window, tab) we want the working directory
|
||||||
// of. A `-1` means to skip this scope, a `0` means the current object.
|
// of. A `-1` means to skip this scope, a `0` means the current object.
|
||||||
int scope_number[] = {
|
int scope_number[] = {
|
||||||
[kCdScopeWindow] = 0, // Number of window to look at.
|
[kCdScopeWindow ] = 0, // Number of window to look at.
|
||||||
[kCdScopeTab ] = 0, // Number of tab to look at.
|
[kCdScopeTabpage] = 0, // Number of tab to look at.
|
||||||
};
|
};
|
||||||
|
|
||||||
char_u *cwd = NULL; // Current working directory to print
|
char_u *cwd = NULL; // Current working directory to print
|
||||||
@ -3489,8 +3489,8 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the tabpage by number
|
// Find the tabpage by number
|
||||||
if (scope_number[kCdScopeTab] > 0) {
|
if (scope_number[kCdScopeTabpage] > 0) {
|
||||||
tp = find_tabpage(scope_number[kCdScopeTab]);
|
tp = find_tabpage(scope_number[kCdScopeTabpage]);
|
||||||
if (!tp) {
|
if (!tp) {
|
||||||
EMSG(_("E5000: Cannot find tab number."));
|
EMSG(_("E5000: Cannot find tab number."));
|
||||||
return;
|
return;
|
||||||
@ -3499,7 +3499,7 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
|
|
||||||
// Find the window in `tp` by number, `NULL` if none.
|
// Find the window in `tp` by number, `NULL` if none.
|
||||||
if (scope_number[kCdScopeWindow] >= 0) {
|
if (scope_number[kCdScopeWindow] >= 0) {
|
||||||
if (scope_number[kCdScopeTab] < 0) {
|
if (scope_number[kCdScopeTabpage] < 0) {
|
||||||
EMSG(_("E5001: Higher scope cannot be -1 if lower scope is >= 0."));
|
EMSG(_("E5001: Higher scope cannot be -1 if lower scope is >= 0."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3523,7 +3523,7 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case kCdScopeTab:
|
case kCdScopeTabpage:
|
||||||
assert(tp);
|
assert(tp);
|
||||||
from = tp->tp_localdir;
|
from = tp->tp_localdir;
|
||||||
if (from) {
|
if (from) {
|
||||||
@ -4652,8 +4652,8 @@ static void f_haslocaldir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
// Numbers of the scope objects (window, tab) we want the working directory
|
// Numbers of the scope objects (window, tab) we want the working directory
|
||||||
// of. A `-1` means to skip this scope, a `0` means the current object.
|
// of. A `-1` means to skip this scope, a `0` means the current object.
|
||||||
int scope_number[] = {
|
int scope_number[] = {
|
||||||
[kCdScopeWindow] = 0, // Number of window to look at.
|
[kCdScopeWindow ] = 0, // Number of window to look at.
|
||||||
[kCdScopeTab ] = 0, // Number of tab to look at.
|
[kCdScopeTabpage] = 0, // Number of tab to look at.
|
||||||
};
|
};
|
||||||
|
|
||||||
tabpage_T *tp = curtab; // The tabpage to look at.
|
tabpage_T *tp = curtab; // The tabpage to look at.
|
||||||
@ -4691,8 +4691,8 @@ static void f_haslocaldir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the tabpage by number
|
// Find the tabpage by number
|
||||||
if (scope_number[kCdScopeTab] > 0) {
|
if (scope_number[kCdScopeTabpage] > 0) {
|
||||||
tp = find_tabpage(scope_number[kCdScopeTab]);
|
tp = find_tabpage(scope_number[kCdScopeTabpage]);
|
||||||
if (!tp) {
|
if (!tp) {
|
||||||
EMSG(_("E5000: Cannot find tab number."));
|
EMSG(_("E5000: Cannot find tab number."));
|
||||||
return;
|
return;
|
||||||
@ -4701,7 +4701,7 @@ static void f_haslocaldir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
|
|
||||||
// Find the window in `tp` by number, `NULL` if none.
|
// Find the window in `tp` by number, `NULL` if none.
|
||||||
if (scope_number[kCdScopeWindow] >= 0) {
|
if (scope_number[kCdScopeWindow] >= 0) {
|
||||||
if (scope_number[kCdScopeTab] < 0) {
|
if (scope_number[kCdScopeTabpage] < 0) {
|
||||||
EMSG(_("E5001: Higher scope cannot be -1 if lower scope is >= 0."));
|
EMSG(_("E5001: Higher scope cannot be -1 if lower scope is >= 0."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -4720,7 +4720,7 @@ static void f_haslocaldir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
assert(win);
|
assert(win);
|
||||||
rettv->vval.v_number = win->w_localdir ? 1 : 0;
|
rettv->vval.v_number = win->w_localdir ? 1 : 0;
|
||||||
break;
|
break;
|
||||||
case kCdScopeTab:
|
case kCdScopeTabpage:
|
||||||
assert(tp);
|
assert(tp);
|
||||||
rettv->vval.v_number = tp->tp_localdir ? 1 : 0;
|
rettv->vval.v_number = tp->tp_localdir ? 1 : 0;
|
||||||
break;
|
break;
|
||||||
|
@ -7711,7 +7711,7 @@ void free_cd_dir(void)
|
|||||||
static char_u *get_prevdir(CdScope scope)
|
static char_u *get_prevdir(CdScope scope)
|
||||||
{
|
{
|
||||||
switch (scope) {
|
switch (scope) {
|
||||||
case kCdScopeTab:
|
case kCdScopeTabpage:
|
||||||
return curtab->tp_prevdir;
|
return curtab->tp_prevdir;
|
||||||
break;
|
break;
|
||||||
case kCdScopeWindow:
|
case kCdScopeWindow:
|
||||||
@ -7731,7 +7731,7 @@ void post_chdir(CdScope scope, bool trigger_dirchanged)
|
|||||||
XFREE_CLEAR(curwin->w_localdir);
|
XFREE_CLEAR(curwin->w_localdir);
|
||||||
|
|
||||||
// Overwrite the tab-local CWD for :cd, :tcd.
|
// Overwrite the tab-local CWD for :cd, :tcd.
|
||||||
if (scope >= kCdScopeTab) {
|
if (scope >= kCdScopeTabpage) {
|
||||||
XFREE_CLEAR(curtab->tp_localdir);
|
XFREE_CLEAR(curtab->tp_localdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7752,7 +7752,7 @@ void post_chdir(CdScope scope, bool trigger_dirchanged)
|
|||||||
// We are now in the global directory, no need to remember its name.
|
// We are now in the global directory, no need to remember its name.
|
||||||
XFREE_CLEAR(globaldir);
|
XFREE_CLEAR(globaldir);
|
||||||
break;
|
break;
|
||||||
case kCdScopeTab:
|
case kCdScopeTabpage:
|
||||||
curtab->tp_localdir = (char_u *)xstrdup(cwd);
|
curtab->tp_localdir = (char_u *)xstrdup(cwd);
|
||||||
break;
|
break;
|
||||||
case kCdScopeWindow:
|
case kCdScopeWindow:
|
||||||
@ -7803,7 +7803,7 @@ bool changedir_func(char_u *new_dir, CdScope scope)
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (scope) {
|
switch (scope) {
|
||||||
case kCdScopeTab:
|
case kCdScopeTabpage:
|
||||||
curtab->tp_prevdir = pdir;
|
curtab->tp_prevdir = pdir;
|
||||||
break;
|
break;
|
||||||
case kCdScopeWindow:
|
case kCdScopeWindow:
|
||||||
@ -7850,7 +7850,7 @@ void ex_cd(exarg_T *eap)
|
|||||||
switch (eap->cmdidx) {
|
switch (eap->cmdidx) {
|
||||||
case CMD_tcd:
|
case CMD_tcd:
|
||||||
case CMD_tchdir:
|
case CMD_tchdir:
|
||||||
scope = kCdScopeTab;
|
scope = kCdScopeTabpage;
|
||||||
break;
|
break;
|
||||||
case CMD_lcd:
|
case CMD_lcd:
|
||||||
case CMD_lchdir:
|
case CMD_lchdir:
|
||||||
|
@ -1610,8 +1610,8 @@ void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause)
|
|||||||
case kCdScopeGlobal:
|
case kCdScopeGlobal:
|
||||||
snprintf(buf, sizeof(buf), "global");
|
snprintf(buf, sizeof(buf), "global");
|
||||||
break;
|
break;
|
||||||
case kCdScopeTab:
|
case kCdScopeTabpage:
|
||||||
snprintf(buf, sizeof(buf), "tab");
|
snprintf(buf, sizeof(buf), "tabpage");
|
||||||
break;
|
break;
|
||||||
case kCdScopeWindow:
|
case kCdScopeWindow:
|
||||||
snprintf(buf, sizeof(buf), "window");
|
snprintf(buf, sizeof(buf), "window");
|
||||||
|
@ -1034,9 +1034,9 @@ typedef enum {
|
|||||||
/// directly, use `MIN_CD_SCOPE` and `MAX_CD_SCOPE` instead.
|
/// directly, use `MIN_CD_SCOPE` and `MAX_CD_SCOPE` instead.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
kCdScopeInvalid = -1,
|
kCdScopeInvalid = -1,
|
||||||
kCdScopeWindow, ///< Affects one window.
|
kCdScopeWindow, ///< Affects one window.
|
||||||
kCdScopeTab, ///< Affects one tab page.
|
kCdScopeTabpage, ///< Affects one tab page.
|
||||||
kCdScopeGlobal, ///< Affects the entire Nvim instance.
|
kCdScopeGlobal, ///< Affects the entire Nvim instance.
|
||||||
} CdScope;
|
} CdScope;
|
||||||
|
|
||||||
#define MIN_CD_SCOPE kCdScopeWindow
|
#define MIN_CD_SCOPE kCdScopeWindow
|
||||||
|
@ -4546,7 +4546,7 @@ static void win_enter_ext(win_T *const wp, const int flags)
|
|||||||
if (os_chdir(new_dir) == 0) {
|
if (os_chdir(new_dir) == 0) {
|
||||||
if (!p_acd && pathcmp(new_dir, cwd, -1) != 0) {
|
if (!p_acd && pathcmp(new_dir, cwd, -1) != 0) {
|
||||||
do_autocmd_dirchanged(new_dir, curwin->w_localdir
|
do_autocmd_dirchanged(new_dir, curwin->w_localdir
|
||||||
? kCdScopeWindow : kCdScopeTab, kCdCauseWindow);
|
? kCdScopeWindow : kCdScopeTabpage, kCdCauseWindow);
|
||||||
}
|
}
|
||||||
shorten_fnames(true);
|
shorten_fnames(true);
|
||||||
}
|
}
|
||||||
|
@ -33,17 +33,20 @@ describe('autocmd DirChanged', function()
|
|||||||
command([[autocmd DirChanged * let g:getcwd = substitute(g:getcwd, '\\', '/', 'g')]])
|
command([[autocmd DirChanged * let g:getcwd = substitute(g:getcwd, '\\', '/', 'g')]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('sets v:event', function()
|
it('sets v:event and <amatch>', function()
|
||||||
command('lcd '..dirs[1])
|
command('lcd '..dirs[1])
|
||||||
eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev'))
|
eq({cwd=dirs[1], scope='window', changed_window=false}, eval('g:ev'))
|
||||||
|
eq('window', eval('g:amatch'))
|
||||||
eq(1, eval('g:cdcount'))
|
eq(1, eval('g:cdcount'))
|
||||||
|
|
||||||
command('tcd '..dirs[2])
|
command('tcd '..dirs[2])
|
||||||
eq({cwd=dirs[2], scope='tab', changed_window=false}, eval('g:ev'))
|
eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev'))
|
||||||
|
eq('tabpage', eval('g:amatch'))
|
||||||
eq(2, eval('g:cdcount'))
|
eq(2, eval('g:cdcount'))
|
||||||
|
|
||||||
command('cd '..dirs[3])
|
command('cd '..dirs[3])
|
||||||
eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev'))
|
eq({cwd=dirs[3], scope='global', changed_window=false}, eval('g:ev'))
|
||||||
|
eq('global', eval('g:amatch'))
|
||||||
eq(3, eval('g:cdcount'))
|
eq(3, eval('g:cdcount'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -69,17 +72,6 @@ describe('autocmd DirChanged', function()
|
|||||||
eq(dirs[3], eval('getcwd()'))
|
eq(dirs[3], eval('getcwd()'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('sets <amatch> to CWD "scope"', function()
|
|
||||||
command('lcd '..dirs[1])
|
|
||||||
eq('window', eval('g:amatch'))
|
|
||||||
|
|
||||||
command('tcd '..dirs[2])
|
|
||||||
eq('tab', eval('g:amatch'))
|
|
||||||
|
|
||||||
command('cd '..dirs[3])
|
|
||||||
eq('global', eval('g:amatch'))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('does not trigger if :cd fails', function()
|
it('does not trigger if :cd fails', function()
|
||||||
command('let g:ev = {}')
|
command('let g:ev = {}')
|
||||||
|
|
||||||
@ -135,7 +127,8 @@ describe('autocmd DirChanged', function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
command('tcd '..dirs[2])
|
command('tcd '..dirs[2])
|
||||||
eq({cwd=dirs[2], scope='tab', changed_window=false}, eval('g:ev'))
|
eq({cwd=dirs[2], scope='tabpage', changed_window=false}, eval('g:ev'))
|
||||||
|
eq('tabpage', eval('g:amatch'))
|
||||||
eq(2, eval('g:cdcount'))
|
eq(2, eval('g:cdcount'))
|
||||||
command('let g:ev = {}')
|
command('let g:ev = {}')
|
||||||
command('tcd '..dirs[2])
|
command('tcd '..dirs[2])
|
||||||
@ -195,8 +188,10 @@ describe('autocmd DirChanged', function()
|
|||||||
command('tcd '..dirs[3])
|
command('tcd '..dirs[3])
|
||||||
command('tabnext') -- tab 1 (no tab-local CWD)
|
command('tabnext') -- tab 1 (no tab-local CWD)
|
||||||
eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev'))
|
eq({cwd=dirs[2], scope='window', changed_window=true}, eval('g:ev'))
|
||||||
|
eq('window', eval('g:amatch'))
|
||||||
command('tabnext') -- tab 2
|
command('tabnext') -- tab 2
|
||||||
eq({cwd=dirs[3], scope='tab', changed_window=true}, eval('g:ev'))
|
eq({cwd=dirs[3], scope='tabpage', changed_window=true}, eval('g:ev'))
|
||||||
|
eq('tabpage', eval('g:amatch'))
|
||||||
eq(7, eval('g:cdcount'))
|
eq(7, eval('g:cdcount'))
|
||||||
|
|
||||||
command('tabnext') -- tab 1
|
command('tabnext') -- tab 1
|
||||||
|
Loading…
Reference in New Issue
Block a user