diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-04-08 20:01:47 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-04-08 20:01:47 +0200 |
commit | 46ad288b9b2a6eb0430cf802ff5ce68a58629897 (patch) | |
tree | c4122a4f891cd211e2604b690cefef88b2d7c8ff /src/evalfunc.c | |
parent | 9845f36aa6ba28e0aa388bb635d4bb8ab56f1a47 (diff) |
patch 8.1.1140: not easy to find out what neighbors a window hasv8.1.1140
Problem: Not easy to find out what neighbors a window has.
Solution: Add more arguments to winnr(). (Yegappan Lakshmanan, closes #3993)
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r-- | src/evalfunc.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index 7f8330f999..76f1125a1d 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -13982,6 +13982,8 @@ get_winnr(tabpage_T *tp, typval_T *argvar) twin = (tp == curtab) ? curwin : tp->tp_curwin; if (argvar->v_type != VAR_UNKNOWN) { + int invalid_arg = FALSE; + arg = tv_get_string_chk(argvar); if (arg == NULL) nr = 0; /* type error; errmsg already given */ @@ -13995,6 +13997,32 @@ get_winnr(tabpage_T *tp, typval_T *argvar) } else { + long count; + char_u *endp; + + // Extract the window count (if specified). e.g. winnr('3j') + count = strtol((char *)arg, (char **)&endp, 10); + if (count <= 0) + count = 1; // if count is not specified, default to 1 + if (endp != NULL && *endp != '\0') + { + if (STRCMP(endp, "j") == 0) + twin = win_vert_neighbor(tp, twin, FALSE, count); + else if (STRCMP(endp, "k") == 0) + twin = win_vert_neighbor(tp, twin, TRUE, count); + else if (STRCMP(endp, "h") == 0) + twin = win_horz_neighbor(tp, twin, TRUE, count); + else if (STRCMP(endp, "l") == 0) + twin = win_horz_neighbor(tp, twin, FALSE, count); + else + invalid_arg = TRUE; + } + else + invalid_arg = TRUE; + } + + if (invalid_arg) + { semsg(_(e_invexpr2), arg); nr = 0; } |