aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/buffer.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-06-25 21:07:49 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-07-04 10:05:34 -0400
commitedaff441de1015068d7cee64c222f3c65fcd7dc6 (patch)
treef086b4aba319e5b225efeeccd4f73185b34fab7b /src/nvim/buffer.c
parent43a2e5fe4b4e107a53ccd5edbf2f3c0a97d79f6e (diff)
downloadrneovim-edaff441de1015068d7cee64c222f3c65fcd7dc6.tar.gz
rneovim-edaff441de1015068d7cee64c222f3c65fcd7dc6.tar.bz2
rneovim-edaff441de1015068d7cee64c222f3c65fcd7dc6.zip
vim-patch:8.1.1372: when evaluating 'statusline' the current window is unknown
Problem: When evaluating 'statusline' the current window is unknown. (Daniel Hahler) Solution: Set "g:actual_curwin" for %{} items. Set "g:statusline_winid" when evaluationg %!. (closes vim/vim#4406, closes vim/vim#3299) https://github.com/vim/vim/commit/1c6fd1e100fd0457375642ec50d483bcc0f61bb2
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r--src/nvim/buffer.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 29712e9f52..86067aceac 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -3464,7 +3464,8 @@ int build_stl_str_hl(
} type;
} items[STL_MAX_ITEM];
#define TMPLEN 70
- char_u tmp[TMPLEN];
+ char_u buf_tmp[TMPLEN];
+ char_u win_tmp[TMPLEN];
char_u *usefmt = fmt;
const int save_must_redraw = must_redraw;
const int save_redr_type = curwin->w_redr_type;
@@ -3472,10 +3473,18 @@ int build_stl_str_hl(
// When the format starts with "%!" then evaluate it as an expression and
// use the result as the actual format string.
if (fmt[0] == '%' && fmt[1] == '!') {
+ typval_T tv = {
+ .v_type = VAR_NUMBER,
+ .vval.v_number = wp->handle,
+ };
+ set_var(S_LEN("g:statusline_winid"), &tv, false);
+
usefmt = eval_to_string_safe(fmt + 2, NULL, use_sandbox);
if (usefmt == NULL) {
usefmt = fmt;
}
+
+ do_unlet(S_LEN("g:statusline_winid"), true);
}
if (fillchar == 0) {
@@ -3904,8 +3913,10 @@ int build_stl_str_hl(
// { Evaluate the expression
// Store the current buffer number as a string variable
- vim_snprintf((char *)tmp, sizeof(tmp), "%d", curbuf->b_fnum);
- set_internal_string_var((char_u *)"g:actual_curbuf", tmp);
+ vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), "%d", curbuf->b_fnum);
+ set_internal_string_var((char_u *)"g:actual_curbuf", buf_tmp);
+ vim_snprintf((char *)win_tmp, sizeof(win_tmp), "%d", curwin->handle);
+ set_internal_string_var((char_u *)"g:actual_curwin", win_tmp);
buf_T *const save_curbuf = curbuf;
win_T *const save_curwin = curwin;
@@ -3926,6 +3937,7 @@ int build_stl_str_hl(
// Remove the variable we just stored
do_unlet(S_LEN("g:actual_curbuf"), true);
+ do_unlet(S_LEN("g:actual_curwin"), true);
// }
@@ -3984,8 +3996,8 @@ int build_stl_str_hl(
// Store the position percentage in our temporary buffer.
// Note: We cannot store the value in `num` because
// `get_rel_pos` can return a named position. Ex: "Top"
- get_rel_pos(wp, tmp, TMPLEN);
- str = tmp;
+ get_rel_pos(wp, buf_tmp, TMPLEN);
+ str = buf_tmp;
break;
case STL_ARGLISTSTAT:
@@ -3995,19 +4007,19 @@ int build_stl_str_hl(
// at the end of the null-terminated string.
// Setting the first byte to null means it will place the argument
// number string at the beginning of the buffer.
- tmp[0] = 0;
+ buf_tmp[0] = 0;
// Note: The call will only return true if it actually
- // appended data to the `tmp` buffer.
- if (append_arg_number(wp, tmp, (int)sizeof(tmp), false)) {
- str = tmp;
+ // appended data to the `buf_tmp` buffer.
+ if (append_arg_number(wp, buf_tmp, (int)sizeof(buf_tmp), false)) {
+ str = buf_tmp;
}
break;
case STL_KEYMAP:
fillable = false;
- if (get_keymap_str(wp, (char_u *)"<%s>", tmp, TMPLEN)) {
- str = tmp;
+ if (get_keymap_str(wp, (char_u *)"<%s>", buf_tmp, TMPLEN)) {
+ str = buf_tmp;
}
break;
case STL_PAGENUM:
@@ -4064,9 +4076,9 @@ int build_stl_str_hl(
// (including the brackets and null terminating character)
if (*wp->w_buffer->b_p_ft != NUL
&& STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 3) {
- vim_snprintf((char *)tmp, sizeof(tmp), "[%s]",
- wp->w_buffer->b_p_ft);
- str = tmp;
+ vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), "[%s]",
+ wp->w_buffer->b_p_ft);
+ str = buf_tmp;
}
break;
@@ -4078,13 +4090,13 @@ int build_stl_str_hl(
// (including the comma and null terminating character)
if (*wp->w_buffer->b_p_ft != NUL
&& STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 2) {
- vim_snprintf((char *)tmp, sizeof(tmp), ",%s",
- wp->w_buffer->b_p_ft);
+ vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), ",%s",
+ wp->w_buffer->b_p_ft);
// Uppercase the file extension
- for (char_u *t = tmp; *t != 0; t++) {
+ for (char_u *t = buf_tmp; *t != 0; t++) {
*t = (char_u)TOUPPER_LOC(*t);
}
- str = tmp;
+ str = buf_tmp;
}
break;
}