diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/CMakeLists.txt | 10 | ||||
-rw-r--r-- | src/nvim/api/private/dispatch.c | 45 | ||||
-rw-r--r-- | src/nvim/api/private/dispatch.h | 1 | ||||
-rw-r--r-- | src/nvim/api/private/helpers.c | 21 | ||||
-rw-r--r-- | src/nvim/api/tabpage.c | 17 | ||||
-rw-r--r-- | src/nvim/api/window.c | 20 | ||||
-rw-r--r-- | src/nvim/edit.c | 3 | ||||
-rw-r--r-- | src/nvim/eval.c | 33 | ||||
-rw-r--r-- | src/nvim/event/rstream.c | 4 | ||||
-rw-r--r-- | src/nvim/ex_eval.h | 22 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 1 | ||||
-rw-r--r-- | src/nvim/fold.c | 13 | ||||
-rw-r--r-- | src/nvim/if_cscope.c | 43 | ||||
-rw-r--r-- | src/nvim/normal.c | 3 | ||||
-rw-r--r-- | src/nvim/option.c | 9 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 10 | ||||
-rw-r--r-- | src/nvim/testdir/Makefile | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_history.vim | 65 | ||||
-rw-r--r-- | src/nvim/version.c | 17 | ||||
-rw-r--r-- | src/nvim/window.c | 51 |
20 files changed, 301 insertions, 88 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index cbea6a05c9..49edfda838 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -18,7 +18,8 @@ set(API_METADATA ${PROJECT_BINARY_DIR}/api_metadata.mpack) set(FUNCS_DATA ${PROJECT_BINARY_DIR}/funcs_data.mpack) set(HEADER_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendeclarations.lua) set(GENERATED_INCLUDES_DIR ${PROJECT_BINARY_DIR}/include) -set(GENERATED_API_DISPATCH ${GENERATED_DIR}/api/private/dispatch.c) +set(GENERATED_API_DISPATCH ${GENERATED_DIR}/api/private/dispatch_wrappers.generated.h) +set(GENERATED_FUNCS_METADATA ${GENERATED_DIR}/api/private/funcs_metadata.generated.h) set(GENERATED_EX_CMDS_ENUM ${GENERATED_INCLUDES_DIR}/ex_cmds_enum.generated.h) set(GENERATED_EX_CMDS_DEFS ${GENERATED_DIR}/ex_cmds_defs.generated.h) set(GENERATED_FUNCS_HASH_INPUT ${GENERATED_DIR}/funcs.generated.h.gperf) @@ -197,8 +198,11 @@ add_custom_command(OUTPUT ${GENERATED_UNICODE_TABLES} ${UNICODE_FILES} ) -add_custom_command(OUTPUT ${GENERATED_API_DISPATCH} ${API_METADATA} - COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${CMAKE_CURRENT_LIST_DIR} ${API_HEADERS} ${GENERATED_API_DISPATCH} ${API_METADATA} +add_custom_command(OUTPUT ${GENERATED_API_DISPATCH} ${GENERATED_FUNCS_METADATA} + ${API_METADATA} + COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${CMAKE_CURRENT_LIST_DIR} + ${API_HEADERS} ${GENERATED_API_DISPATCH} + ${GENERATED_FUNCS_METADATA} ${API_METADATA} DEPENDS ${API_HEADERS} ${MSGPACK_RPC_HEADERS} diff --git a/src/nvim/api/private/dispatch.c b/src/nvim/api/private/dispatch.c new file mode 100644 index 0000000000..9b3bcc380a --- /dev/null +++ b/src/nvim/api/private/dispatch.c @@ -0,0 +1,45 @@ +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <assert.h> +#include <msgpack.h> + +#include "nvim/map.h" +#include "nvim/log.h" +#include "nvim/vim.h" +#include "nvim/msgpack_rpc/helpers.h" +#include "nvim/api/private/dispatch.h" +#include "nvim/api/private/helpers.h" +#include "nvim/api/private/defs.h" + +#include "nvim/api/buffer.h" +#include "nvim/api/tabpage.h" +#include "nvim/api/ui.h" +#include "nvim/api/vim.h" +#include "nvim/api/window.h" + +static Map(String, MsgpackRpcRequestHandler) *methods = NULL; + +static void msgpack_rpc_add_method_handler(String method, + MsgpackRpcRequestHandler handler) +{ + map_put(String, MsgpackRpcRequestHandler)(methods, method, handler); +} + +MsgpackRpcRequestHandler msgpack_rpc_get_handler_for(const char *name, + size_t name_len) +{ + String m = { .data = (char *)name, .size = name_len }; + MsgpackRpcRequestHandler rv = + map_get(String, MsgpackRpcRequestHandler)(methods, m); + + if (!rv.fn) { + rv.fn = msgpack_rpc_handle_missing_method; + } + + return rv; +} + +#ifdef INCLUDE_GENERATED_DECLARATIONS +#include "api/private/dispatch_wrappers.generated.h" +#endif diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h index d91456c306..c12cf9e698 100644 --- a/src/nvim/api/private/dispatch.h +++ b/src/nvim/api/private/dispatch.h @@ -18,6 +18,7 @@ typedef struct { #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/private/dispatch.h.generated.h" +# include "api/private/dispatch_wrappers.h.generated.h" #endif #endif // NVIM_API_PRIVATE_DISPATCH_H diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index d80ee7dc67..c0ee735d1a 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -7,6 +7,7 @@ #include "nvim/api/private/helpers.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/handle.h" +#include "nvim/msgpack_rpc/helpers.h" #include "nvim/ascii.h" #include "nvim/vim.h" #include "nvim/buffer.h" @@ -27,6 +28,7 @@ typedef struct { #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/private/helpers.c.generated.h" +# include "api/private/funcs_metadata.generated.h" #endif /// Start block that may cause vimscript exceptions @@ -761,7 +763,7 @@ Dictionary api_metadata(void) static Dictionary metadata = ARRAY_DICT_INIT; if (!metadata.size) { - msgpack_rpc_init_function_metadata(&metadata); + init_function_metadata(&metadata); init_error_type_metadata(&metadata); init_type_metadata(&metadata); } @@ -769,6 +771,22 @@ Dictionary api_metadata(void) return copy_object(DICTIONARY_OBJ(metadata)).data.dictionary; } +static void init_function_metadata(Dictionary *metadata) +{ + msgpack_unpacked unpacked; + msgpack_unpacked_init(&unpacked); + if (msgpack_unpack_next(&unpacked, + (const char *)funcs_metadata, + sizeof(funcs_metadata), + NULL) != MSGPACK_UNPACK_SUCCESS) { + abort(); + } + Object functions; + msgpack_rpc_to_object(&unpacked.data, &functions); + msgpack_unpacked_destroy(&unpacked); + PUT(*metadata, "functions", functions); +} + static void init_error_type_metadata(Dictionary *metadata) { Dictionary types = ARRAY_DICT_INIT; @@ -784,6 +802,7 @@ static void init_error_type_metadata(Dictionary *metadata) PUT(*metadata, "error_types", DICTIONARY_OBJ(types)); } + static void init_type_metadata(Dictionary *metadata) { Dictionary types = ARRAY_DICT_INIT; diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c index 8b1fb041e2..fa00988ae3 100644 --- a/src/nvim/api/tabpage.c +++ b/src/nvim/api/tabpage.c @@ -159,6 +159,23 @@ Window nvim_tabpage_get_win(Tabpage tabpage, Error *err) } } +/// Gets the tab page number +/// +/// @param tabpage The tabpage handle +/// @param[out] err Details of an error that may have occurred +/// @return The tabpage number +Integer nvim_tabpage_get_number(Tabpage tabpage, Error *err) +{ + Integer rv = 0; + tabpage_T *tab = find_tab_by_handle(tabpage, err); + + if (!tab) { + return rv; + } + + return tabpage_index(tab); +} + /// Checks if a tab page is valid /// /// @param tabpage The tab page handle diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 166e43f698..382f65e7d9 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -341,6 +341,26 @@ Tabpage nvim_win_get_tabpage(Window window, Error *err) return rv; } +/// Gets the window number +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return The window number +Integer nvim_win_get_number(Window window, Error *err) +{ + Integer rv = 0; + win_T *win = find_window_by_handle(window, err); + + if (!win) { + return rv; + } + + int tabnr; + win_get_tabwin(window, &tabnr, (int *)&rv); + + return rv; +} + /// Checks if a window is valid /// /// @param window The window handle diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 51c9fb1556..a0ae1a3e6b 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -462,8 +462,7 @@ static void insert_enter(InsertState *s) o_lnum = curwin->w_cursor.lnum; } - foldUpdateAll(curwin); - foldOpenCursor(); + foldUpdateAfterInsert(); if (s->cmdchar != 'r' && s->cmdchar != 'v') { apply_autocmds(EVENT_INSERTLEAVE, NULL, NULL, false, curbuf); } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index cae032f437..dce2f32707 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9527,24 +9527,35 @@ static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) varnumber_T n; int error = FALSE; - /* Position the cursor. Needed after a message that ends in a space. */ - ui_cursor_goto(msg_row, msg_col); - ++no_mapping; ++allow_keys; for (;; ) { - if (argvars[0].v_type == VAR_UNKNOWN) - /* getchar(): blocking wait. */ + // Position the cursor. Needed after a message that ends in a space, + // or if event processing caused a redraw. + ui_cursor_goto(msg_row, msg_col); + + if (argvars[0].v_type == VAR_UNKNOWN) { + // getchar(): blocking wait. + if (!(char_avail() || using_script() || input_available())) { + input_enable_events(); + (void)os_inchar(NULL, 0, -1, 0); + input_disable_events(); + if (!multiqueue_empty(main_loop.events)) { + multiqueue_process_events(main_loop.events); + continue; + } + } n = safe_vgetc(); - else if (get_tv_number_chk(&argvars[0], &error) == 1) - /* getchar(1): only check if char avail */ + } else if (get_tv_number_chk(&argvars[0], &error) == 1) { + // getchar(1): only check if char avail n = vpeekc_any(); - else if (error || vpeekc_any() == NUL) - /* illegal argument or getchar(0) and no char avail: return zero */ + } else if (error || vpeekc_any() == NUL) { + // illegal argument or getchar(0) and no char avail: return zero n = 0; - else - /* getchar(0) and char avail: return char */ + } else { + // getchar(0) and char avail: return char n = safe_vgetc(); + } if (n == K_IGNORE) continue; diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c index 5126dfd84e..92efc9fa2e 100644 --- a/src/nvim/event/rstream.c +++ b/src/nvim/event/rstream.c @@ -112,8 +112,8 @@ static void read_cb(uv_stream_t *uvstream, ssize_t cnt, const uv_buf_t *buf) // to `alloc_cb` will return the same unused pointer(`rbuffer_produced` // won't be called) && cnt != 0) { - DLOG("Closing Stream(%p) because of %s(%zd)", stream, - uv_strerror((int)cnt), cnt); + DLOG("Closing Stream (%p): %s (%s)", stream, + uv_err_name((int)cnt), os_strerror((int)cnt)); // Read error or EOF, either way stop the stream and invoke the callback // with eof == true uv_read_stop(uvstream); diff --git a/src/nvim/ex_eval.h b/src/nvim/ex_eval.h index 30871c7711..f61e01d25b 100644 --- a/src/nvim/ex_eval.h +++ b/src/nvim/ex_eval.h @@ -23,19 +23,19 @@ struct eslist_elem { #define CSTACK_LEN 50 struct condstack { - short cs_flags[CSTACK_LEN]; /* CSF_ flags */ - char cs_pending[CSTACK_LEN]; /* CSTP_: what's pending in ":finally"*/ + int cs_flags[CSTACK_LEN]; // CSF_ flags + char cs_pending[CSTACK_LEN]; // CSTP_: what's pending in ":finally" union { - void *csp_rv[CSTACK_LEN]; /* return typeval for pending return */ - void *csp_ex[CSTACK_LEN]; /* exception for pending throw */ + void *csp_rv[CSTACK_LEN]; // return typeval for pending return + void *csp_ex[CSTACK_LEN]; // exception for pending throw } cs_pend; - void *cs_forinfo[CSTACK_LEN]; /* info used by ":for" */ - int cs_line[CSTACK_LEN]; /* line nr of ":while"/":for" line */ - int cs_idx; /* current entry, or -1 if none */ - int cs_looplevel; /* nr of nested ":while"s and ":for"s */ - int cs_trylevel; /* nr of nested ":try"s */ - eslist_T *cs_emsg_silent_list; /* saved values of "emsg_silent" */ - char cs_lflags; /* loop flags: CSL_ flags */ + void *cs_forinfo[CSTACK_LEN]; // info used by ":for" + int cs_line[CSTACK_LEN]; // line nr of ":while"/":for" line + int cs_idx; // current entry, or -1 if none + int cs_looplevel; // nr of nested ":while"s and ":for"s + int cs_trylevel; // nr of nested ":try"s + eslist_T *cs_emsg_silent_list; // saved values of "emsg_silent" + int cs_lflags; // loop flags: CSL_ flags }; # define cs_rettv cs_pend.csp_rv # define cs_exception cs_pend.csp_ex diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 4254697241..7444eb8a38 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4396,6 +4396,7 @@ static HistoryType hist_char2type(const int c) case '>': { return HIST_DEBUG; } + case NUL: case '/': case '?': { return HIST_SEARCH; diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 70030b8525..c84d738cb4 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -788,6 +788,19 @@ void foldUpdate(win_T *wp, linenr_T top, linenr_T bot) } } +/// Updates folds when leaving insert-mode. +void foldUpdateAfterInsert(void) +{ + if (foldmethodIsManual(curwin) // foldmethod=manual: No need to update. + // These foldmethods are too slow, do not auto-update on insert-leave. + || foldmethodIsSyntax(curwin) || foldmethodIsExpr(curwin)) { + return; + } + + foldUpdateAll(curwin); + foldOpenCursor(); +} + /* foldUpdateAll() {{{2 */ /* * Update all lines in a window for folding. diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 3ed85677fc..0b20647771 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -1761,8 +1761,8 @@ static void cs_print_tags_priv(char **matches, char **cntxts, */ static int cs_read_prompt(size_t i) { - char ch; - char *buf = NULL; /* buffer for possible error message from cscope */ + int ch; + char *buf = NULL; // buffer for possible error message from cscope size_t bufpos = 0; char *cs_emsg = _("E609: Cscope error: %s"); size_t cs_emsg_len = strlen(cs_emsg); @@ -1774,35 +1774,34 @@ static int cs_read_prompt(size_t i) size_t maxlen = IOSIZE - cs_emsg_len; for (;; ) { - while ((ch = (char)getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0]) - /* if there is room and char is printable */ + while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0]) { + // if there is room and char is printable if (bufpos < maxlen - 1 && vim_isprintc(ch)) { // lazy buffer allocation if (buf == NULL) { buf = xmalloc(maxlen); } - { - /* append character to the message */ - buf[bufpos++] = ch; - buf[bufpos] = NUL; - if (bufpos >= epromptlen - && strcmp(&buf[bufpos - epromptlen], eprompt) == 0) { - /* remove eprompt from buf */ - buf[bufpos - epromptlen] = NUL; - - /* print message to user */ - (void)EMSG2(cs_emsg, buf); + // append character to the message + buf[bufpos++] = (char)ch; + buf[bufpos] = NUL; + if (bufpos >= epromptlen + && strcmp(&buf[bufpos - epromptlen], eprompt) == 0) { + // remove eprompt from buf + buf[bufpos - epromptlen] = NUL; + + // print message to user + (void)EMSG2(cs_emsg, buf); - /* send RETURN to cscope */ - (void)putc('\n', csinfo[i].to_fp); - (void)fflush(csinfo[i].to_fp); + // send RETURN to cscope + (void)putc('\n', csinfo[i].to_fp); + (void)fflush(csinfo[i].to_fp); - /* clear buf */ - bufpos = 0; - buf[bufpos] = NUL; - } + // clear buf + bufpos = 0; + buf[bufpos] = NUL; } } + } for (size_t n = 0; n < strlen(CSCOPE_PROMPT); ++n) { if (n > 0) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 6dcbf50750..76e3829bee 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5925,8 +5925,7 @@ static void nv_replace(cmdarg_T *cap) set_last_insert(cap->nchar); } - foldUpdateAll(curwin); - foldOpenCursor(); + foldUpdateAfterInsert(); } /* diff --git a/src/nvim/option.c b/src/nvim/option.c index e2a5d38bee..81919c00d2 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1032,6 +1032,15 @@ void set_init_3(void) xfree(p); } + if (bufempty()) { + int idx_ffs = findoption((char_u *)"ffs"); + + // Apply the first entry of 'fileformats' to the initial buffer. + if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET)) { + set_fileformat(default_fileformat(), OPT_LOCAL); + } + } + set_title_defaults(); } diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index e9a3dcbff8..18ee008d66 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -545,6 +545,16 @@ static size_t write_output(char *output, size_t remaining, bool to_buffer, static void shell_write_cb(Stream *stream, void *data, int status) { + if (status) { + // Can happen if system() tries to send input to a shell command that was + // backgrounded (:call system("cat - &", "foo")). #3529 #5241 + EMSG2(_("E5677: Error writing input to shell-command: %s"), + uv_err_name(status)); + } + if (stream->closed) { // Process may have exited before this write. + ELOG("stream was already closed"); + return; + } stream_close(stream, NULL, NULL); } diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 4d21887240..67e7c97905 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -34,6 +34,7 @@ NEW_TESTS = \ test_cscope.res \ test_hardcopy.res \ test_help_tagjump.res \ + test_history.res \ test_langmap.res \ test_syntax.res \ test_usercommands.res \ diff --git a/src/nvim/testdir/test_history.vim b/src/nvim/testdir/test_history.vim new file mode 100644 index 0000000000..ee6acfffc3 --- /dev/null +++ b/src/nvim/testdir/test_history.vim @@ -0,0 +1,65 @@ +" Tests for the history functions + +if !has('cmdline_hist') + finish +endif + +set history=7 + +function History_Tests(hist) + " First clear the history + call histadd(a:hist, 'dummy') + call assert_true(histdel(a:hist)) + call assert_equal(-1, histnr(a:hist)) + call assert_equal('', histget(a:hist)) + + call assert_true(histadd(a:hist, 'ls')) + call assert_true(histadd(a:hist, 'buffers')) + call assert_equal('buffers', histget(a:hist)) + call assert_equal('ls', histget(a:hist, -2)) + call assert_equal('ls', histget(a:hist, 1)) + call assert_equal('', histget(a:hist, 5)) + call assert_equal('', histget(a:hist, -5)) + call assert_equal(2, histnr(a:hist)) + call assert_true(histdel(a:hist, 2)) + call assert_false(histdel(a:hist, 7)) + call assert_equal(1, histnr(a:hist)) + call assert_equal('ls', histget(a:hist, -1)) + + call assert_true(histadd(a:hist, 'buffers')) + call assert_true(histadd(a:hist, 'ls')) + call assert_equal('ls', histget(a:hist, -1)) + call assert_equal(4, histnr(a:hist)) + + " Test for removing entries matching a pattern + for i in range(1, 3) + call histadd(a:hist, 'text_' . i) + endfor + call assert_true(histdel(a:hist, 'text_\d\+')) + call assert_equal('ls', histget(a:hist, -1)) + + " Test for freeing the entire history list + for i in range(1, 7) + call histadd(a:hist, 'text_' . i) + endfor + call histdel(a:hist) + for i in range(1, 7) + call assert_equal('', histget(a:hist, i)) + call assert_equal('', histget(a:hist, i - 7 - 1)) + endfor +endfunction + +function Test_History() + for h in ['cmd', ':', '', 'search', '/', '?', 'expr', '=', 'input', '@', 'debug', '>'] + call History_Tests(h) + endfor + + " Negative tests + call assert_false(histdel('abc')) + call assert_equal('', histget('abc')) + call assert_fails('call histdel([])', 'E730:') + call assert_equal('', histget(10)) + call assert_fails('call histget([])', 'E730:') + call assert_equal(-1, histnr('abc')) + call assert_fails('call histnr([])', 'E730:') +endfunction diff --git a/src/nvim/version.c b/src/nvim/version.c index 399d19ae45..e24836306c 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -608,7 +608,7 @@ static int included_patches[] = { // 1836, // 1835, // 1834, - // 1833, + 1833, 1832, 1831, // 1830 NA @@ -824,7 +824,7 @@ static int included_patches[] = { // 1622 NA // 1621 NA 1620, - // 1619, + 1619, // 1618 NA // 1617 NA // 1616 NA @@ -949,7 +949,7 @@ static int included_patches[] = { // 1497 NA // 1496 NA // 1495 NA - // 1494, + 1494, // 1493 NA 1492, 1491, @@ -2652,14 +2652,13 @@ void intro_message(int colon) N_(NVIM_VERSION_LONG), "", N_("by Bram Moolenaar et al."), - N_("Vim is open source and freely distributable"), - "", - N_("Type \":Tutor\" or \":help nvim\" to get started!"), - "", - N_("Still have questions? https://neovim.io/community"), + N_("Nvim is open source and freely distributable"), + N_("https://neovim.io/community"), "", + N_("type :help nvim<Enter> if you are new! "), + N_("type :CheckHealth<Enter> to optimize Nvim"), N_("type :q<Enter> to exit "), - N_("type :help<Enter> or <F1> for on-line help"), + N_("type :help<Enter> for help "), "", N_("Help poor children in Uganda!"), N_("type :help iccf<Enter> for information "), diff --git a/src/nvim/window.c b/src/nvim/window.c index a259654d52..29c670322a 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5716,45 +5716,46 @@ int win_getid(typval_T *argvars) int win_gotoid(typval_T *argvars) { - win_T *wp; - tabpage_T *tp; int id = get_tv_number(&argvars[0]); - for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { - for (wp = tp == curtab ? firstwin : tp->tp_firstwin; - wp != NULL; wp = wp->w_next) { - if (wp->handle == id) { - goto_tabpage_win(tp, wp); - return 1; - } + FOR_ALL_TAB_WINDOWS(tp, wp) { + if (wp->handle == id) { + goto_tabpage_win(tp, wp); + return 1; } } return 0; } -void win_id2tabwin(typval_T *argvars, list_T *list) +void win_get_tabwin(handle_T id, int *tabnr, int *winnr) { - win_T *wp; - tabpage_T *tp; - int winnr = 1; - int tabnr = 1; - int id = get_tv_number(&argvars[0]); + *tabnr = 0; + *winnr = 0; - for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { - for (wp = tp == curtab ? firstwin : tp->tp_firstwin; - wp != NULL; wp = wp->w_next) { + int tnum = 1, wnum = 1; + FOR_ALL_TABS(tp) { + FOR_ALL_WINDOWS_IN_TAB(wp, tp) { if (wp->handle == id) { - list_append_number(list, tabnr); - list_append_number(list, winnr); + *winnr = wnum; + *tabnr = tnum; return; } - winnr++; + wnum++; } - tabnr++; - winnr = 1; + tnum++; + wnum = 1; } - list_append_number(list, 0); - list_append_number(list, 0); +} + +void win_id2tabwin(typval_T *argvars, list_T *list) +{ + int winnr = 1; + int tabnr = 1; + int id = get_tv_number(&argvars[0]); + + win_get_tabwin(id, &tabnr, &winnr); + list_append_number(list, tabnr); + list_append_number(list, winnr); } int win_id2win(typval_T *argvars) |