mirror of
https://github.com/neovim/neovim.git
synced 2025-10-10 11:56:30 +00:00
@@ -2377,6 +2377,7 @@ win_screenpos({nr}) List get screen position of window {nr}
|
|||||||
winbufnr({nr}) Number buffer number of window {nr}
|
winbufnr({nr}) Number buffer number of window {nr}
|
||||||
wincol() Number window column of the cursor
|
wincol() Number window column of the cursor
|
||||||
winheight({nr}) Number height of window {nr}
|
winheight({nr}) Number height of window {nr}
|
||||||
|
winlayout([{tabnr}]) List layout of windows in tab {tabnr}
|
||||||
winline() Number window line of the cursor
|
winline() Number window line of the cursor
|
||||||
winnr([{expr}]) Number number of current window
|
winnr([{expr}]) Number number of current window
|
||||||
winrestcmd() String returns command to restore window sizes
|
winrestcmd() String returns command to restore window sizes
|
||||||
@@ -8537,6 +8538,35 @@ winheight({nr}) *winheight()*
|
|||||||
This excludes any window toolbar line.
|
This excludes any window toolbar line.
|
||||||
Examples: >
|
Examples: >
|
||||||
:echo "The current window has " . winheight(0) . " lines."
|
:echo "The current window has " . winheight(0) . " lines."
|
||||||
|
<
|
||||||
|
winlayout([{tabnr}]) *winlayout()*
|
||||||
|
The result is a nested List containing the layout of windows
|
||||||
|
in a tabpage.
|
||||||
|
|
||||||
|
Without {tabnr} use the current tabpage, otherwise the tabpage
|
||||||
|
with number {tabnr}. If the tabpage {tabnr} is not found,
|
||||||
|
returns an empty list.
|
||||||
|
|
||||||
|
For a leaf window, it returns:
|
||||||
|
['leaf', {winid}]
|
||||||
|
For horizontally split windows, which form a column, it
|
||||||
|
returns:
|
||||||
|
['col', [{nested list of windows}]]
|
||||||
|
For vertically split windows, which form a row, it returns:
|
||||||
|
['row', [{nested list of windows}]]
|
||||||
|
|
||||||
|
Example: >
|
||||||
|
" Only one window in the tab page
|
||||||
|
:echo winlayout()
|
||||||
|
['leaf', 1000]
|
||||||
|
" Two horizontally split windows
|
||||||
|
:echo winlayout()
|
||||||
|
['col', [['leaf', 1000], ['leaf', 1001]]]
|
||||||
|
" Three horizontally split windows, with two
|
||||||
|
" vertically split windows in the middle window
|
||||||
|
:echo winlayout(2)
|
||||||
|
['col', [['leaf', 1002], ['row', ['leaf', 1003],
|
||||||
|
['leaf', 1001]]], ['leaf', 1000]]
|
||||||
<
|
<
|
||||||
*winline()*
|
*winline()*
|
||||||
winline() The result is a Number, which is the screen line of the cursor
|
winline() The result is a Number, which is the screen line of the cursor
|
||||||
|
@@ -8868,8 +8868,8 @@ static void f_fnamemodify(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
} else {
|
} else {
|
||||||
len = strlen(fname);
|
len = strlen(fname);
|
||||||
size_t usedlen = 0;
|
size_t usedlen = 0;
|
||||||
(void)modify_fname((char_u *)mods, &usedlen, (char_u **)&fname, &fbuf,
|
(void)modify_fname((char_u *)mods, false, &usedlen,
|
||||||
&len);
|
(char_u **)&fname, &fbuf, &len);
|
||||||
}
|
}
|
||||||
|
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
@@ -17872,6 +17872,25 @@ static void f_winheight(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "winlayout()" function
|
||||||
|
static void f_winlayout(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||||
|
{
|
||||||
|
tabpage_T *tp;
|
||||||
|
|
||||||
|
tv_list_alloc_ret(rettv, 2);
|
||||||
|
|
||||||
|
if (argvars[0].v_type == VAR_UNKNOWN) {
|
||||||
|
tp = curtab;
|
||||||
|
} else {
|
||||||
|
tp = find_tabpage((int)tv_get_number(&argvars[0]));
|
||||||
|
if (tp == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get_framelayout(tp->tp_topframe, rettv->vval.v_list, true);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "winline()" function
|
* "winline()" function
|
||||||
*/
|
*/
|
||||||
@@ -22623,6 +22642,7 @@ void reset_v_option_vars(void)
|
|||||||
int
|
int
|
||||||
modify_fname(
|
modify_fname(
|
||||||
char_u *src, // string with modifiers
|
char_u *src, // string with modifiers
|
||||||
|
bool tilde_file, // "~" is a file name, not $HOME
|
||||||
size_t *usedlen, // characters after src that are used
|
size_t *usedlen, // characters after src that are used
|
||||||
char_u **fnamep, // file name so far
|
char_u **fnamep, // file name so far
|
||||||
char_u **bufp, // buffer for allocated file name or NULL
|
char_u **bufp, // buffer for allocated file name or NULL
|
||||||
@@ -22652,8 +22672,8 @@ repeat:
|
|||||||
|| (*fnamep)[1] == '\\'
|
|| (*fnamep)[1] == '\\'
|
||||||
# endif
|
# endif
|
||||||
|| (*fnamep)[1] == NUL)
|
|| (*fnamep)[1] == NUL)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
&& !(tilde_file && (*fnamep)[1] == NUL)
|
||||||
) {
|
) {
|
||||||
*fnamep = expand_env_save(*fnamep);
|
*fnamep = expand_env_save(*fnamep);
|
||||||
xfree(*bufp); /* free any allocated file name */
|
xfree(*bufp); /* free any allocated file name */
|
||||||
|
@@ -352,6 +352,7 @@ return {
|
|||||||
winbufnr={args=1},
|
winbufnr={args=1},
|
||||||
wincol={},
|
wincol={},
|
||||||
winheight={args=1},
|
winheight={args=1},
|
||||||
|
winlayout={args={0, 1}},
|
||||||
winline={},
|
winline={},
|
||||||
winnr={args={0, 1}},
|
winnr={args={0, 1}},
|
||||||
winrestcmd={},
|
winrestcmd={},
|
||||||
|
@@ -8552,6 +8552,7 @@ eval_vars (
|
|||||||
size_t resultlen;
|
size_t resultlen;
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
int valid = VALID_HEAD | VALID_PATH; // Assume valid result.
|
int valid = VALID_HEAD | VALID_PATH; // Assume valid result.
|
||||||
|
bool tilde_file = false;
|
||||||
int skip_mod = false;
|
int skip_mod = false;
|
||||||
char strbuf[30];
|
char strbuf[30];
|
||||||
|
|
||||||
@@ -8608,9 +8609,11 @@ eval_vars (
|
|||||||
case SPEC_PERC: /* '%': current file */
|
case SPEC_PERC: /* '%': current file */
|
||||||
if (curbuf->b_fname == NULL) {
|
if (curbuf->b_fname == NULL) {
|
||||||
result = (char_u *)"";
|
result = (char_u *)"";
|
||||||
valid = 0; /* Must have ":p:h" to be valid */
|
valid = 0; // Must have ":p:h" to be valid
|
||||||
} else
|
} else {
|
||||||
result = curbuf->b_fname;
|
result = curbuf->b_fname;
|
||||||
|
tilde_file = STRCMP(result, "~") == 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SPEC_HASH: /* '#' or "#99": alternate file */
|
case SPEC_HASH: /* '#' or "#99": alternate file */
|
||||||
@@ -8659,9 +8662,11 @@ eval_vars (
|
|||||||
*lnump = ECMD_LAST;
|
*lnump = ECMD_LAST;
|
||||||
if (buf->b_fname == NULL) {
|
if (buf->b_fname == NULL) {
|
||||||
result = (char_u *)"";
|
result = (char_u *)"";
|
||||||
valid = 0; /* Must have ":p:h" to be valid */
|
valid = 0; // Must have ":p:h" to be valid
|
||||||
} else
|
} else {
|
||||||
result = buf->b_fname;
|
result = buf->b_fname;
|
||||||
|
tilde_file = STRCMP(result, "~") == 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -8746,7 +8751,8 @@ eval_vars (
|
|||||||
resultlen = (size_t)(s - result);
|
resultlen = (size_t)(s - result);
|
||||||
}
|
}
|
||||||
} else if (!skip_mod) {
|
} else if (!skip_mod) {
|
||||||
valid |= modify_fname(src, usedlen, &result, &resultbuf, &resultlen);
|
valid |= modify_fname(src, tilde_file, usedlen, &result,
|
||||||
|
&resultbuf, &resultlen);
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
*errormsg = (char_u *)"";
|
*errormsg = (char_u *)"";
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@@ -425,9 +425,11 @@ cs_add_common(
|
|||||||
expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
|
expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
|
||||||
size_t len = STRLEN(fname);
|
size_t len = STRLEN(fname);
|
||||||
fbuf = (char_u *)fname;
|
fbuf = (char_u *)fname;
|
||||||
(void)modify_fname((char_u *)":p", &usedlen, (char_u **)&fname, &fbuf, &len);
|
(void)modify_fname((char_u *)":p", false, &usedlen,
|
||||||
if (fname == NULL)
|
(char_u **)&fname, &fbuf, &len);
|
||||||
|
if (fname == NULL) {
|
||||||
goto add_err;
|
goto add_err;
|
||||||
|
}
|
||||||
fname = (char *)vim_strnsave((char_u *)fname, len);
|
fname = (char *)vim_strnsave((char_u *)fname, len);
|
||||||
xfree(fbuf);
|
xfree(fbuf);
|
||||||
FileInfo file_info;
|
FileInfo file_info;
|
||||||
|
@@ -870,8 +870,8 @@ size_t home_replace(const buf_T *const buf, const char_u *src,
|
|||||||
size_t usedlen = 0;
|
size_t usedlen = 0;
|
||||||
size_t flen = strlen(homedir_env_mod);
|
size_t flen = strlen(homedir_env_mod);
|
||||||
char_u *fbuf = NULL;
|
char_u *fbuf = NULL;
|
||||||
(void)modify_fname((char_u *)":p", &usedlen, (char_u **)&homedir_env_mod,
|
(void)modify_fname((char_u *)":p", false, &usedlen,
|
||||||
&fbuf, &flen);
|
(char_u **)&homedir_env_mod, &fbuf, &flen);
|
||||||
flen = strlen(homedir_env_mod);
|
flen = strlen(homedir_env_mod);
|
||||||
assert(homedir_env_mod != homedir_env);
|
assert(homedir_env_mod != homedir_env);
|
||||||
if (vim_ispathsep(homedir_env_mod[flen - 1])) {
|
if (vim_ispathsep(homedir_env_mod[flen - 1])) {
|
||||||
|
@@ -101,3 +101,23 @@ func Test_win_getid_curtab()
|
|||||||
call assert_equal(win_getid(1), win_getid(1, 1))
|
call assert_equal(win_getid(1), win_getid(1, 1))
|
||||||
tabclose!
|
tabclose!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_winlayout()
|
||||||
|
let w1 = win_getid()
|
||||||
|
call assert_equal(['leaf', w1], winlayout())
|
||||||
|
|
||||||
|
split
|
||||||
|
let w2 = win_getid()
|
||||||
|
call assert_equal(['col', [['leaf', w2], ['leaf', w1]]], winlayout())
|
||||||
|
|
||||||
|
split
|
||||||
|
let w3 = win_getid()
|
||||||
|
call assert_equal(['col', [['leaf', w3], ['leaf', w2], ['leaf', w1]]], winlayout())
|
||||||
|
|
||||||
|
2wincmd w
|
||||||
|
vsplit
|
||||||
|
let w4 = win_getid()
|
||||||
|
call assert_equal(['col', [['leaf', w3], ['row', [['leaf', w4], ['leaf', w2]]], ['leaf', w1]]], winlayout())
|
||||||
|
|
||||||
|
only!
|
||||||
|
endfunc
|
||||||
|
@@ -6658,6 +6658,41 @@ void win_findbuf(typval_T *argvars, list_T *list)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the layout of the given tab page for winlayout().
|
||||||
|
void get_framelayout(const frame_T *fr, list_T *l, bool outer)
|
||||||
|
{
|
||||||
|
list_T *fr_list;
|
||||||
|
|
||||||
|
if (fr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outer) {
|
||||||
|
// outermost call from f_winlayout()
|
||||||
|
fr_list = l;
|
||||||
|
} else {
|
||||||
|
fr_list = tv_list_alloc(2);
|
||||||
|
tv_list_append_list(l, fr_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fr->fr_layout == FR_LEAF) {
|
||||||
|
if (fr->fr_win != NULL) {
|
||||||
|
tv_list_append_string(fr_list, "leaf", -1);
|
||||||
|
tv_list_append_number(fr_list, fr->fr_win->handle);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tv_list_append_string(fr_list, fr->fr_layout == FR_ROW ? "row" : "col", -1);
|
||||||
|
|
||||||
|
list_T *const win_list = tv_list_alloc(kListLenUnknown);
|
||||||
|
tv_list_append_list(fr_list, win_list);
|
||||||
|
const frame_T *child = fr->fr_child;
|
||||||
|
while (child != NULL) {
|
||||||
|
get_framelayout(child, win_list, false);
|
||||||
|
child = child->fr_next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void win_ui_flush_positions(void)
|
void win_ui_flush_positions(void)
|
||||||
{
|
{
|
||||||
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
||||||
|
@@ -62,6 +62,14 @@ describe('expand file name', function()
|
|||||||
call delete('Xdir ~ dir', 'd')
|
call delete('Xdir ~ dir', 'd')
|
||||||
call assert_false(isdirectory('Xdir ~ dir'))
|
call assert_false(isdirectory('Xdir ~ dir'))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_expand_tilde_filename()
|
||||||
|
split ~
|
||||||
|
call assert_equal('~', expand('%'))
|
||||||
|
call assert_notequal(expand('%:p'), expand('~/'))
|
||||||
|
call assert_match('\~', expand('%:p'))
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -74,4 +82,9 @@ describe('expand file name', function()
|
|||||||
call('Test_with_tilde')
|
call('Test_with_tilde')
|
||||||
expected_empty()
|
expected_empty()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('does not expand tilde if it is a filename', function()
|
||||||
|
call('Test_expand_tilde_filename')
|
||||||
|
expected_empty()
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user