diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/command.c | 25 | ||||
-rw-r--r-- | src/nvim/api/options.c | 7 | ||||
-rw-r--r-- | src/nvim/api/ui_events.in.h | 2 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 2 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/diff.c | 2 | ||||
-rw-r--r-- | src/nvim/drawscreen.c | 32 | ||||
-rw-r--r-- | src/nvim/edit.c | 13 | ||||
-rw-r--r-- | src/nvim/eval.c | 14 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 5 | ||||
-rw-r--r-- | src/nvim/ex_session.c | 2 | ||||
-rw-r--r-- | src/nvim/getchar.c | 52 | ||||
-rw-r--r-- | src/nvim/grid.c | 4 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 15 | ||||
-rw-r--r-- | src/nvim/main.c | 12 | ||||
-rw-r--r-- | src/nvim/move.c | 3 | ||||
-rw-r--r-- | src/nvim/normal.c | 17 | ||||
-rw-r--r-- | src/nvim/option.c | 24 | ||||
-rw-r--r-- | src/nvim/option_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/options.lua | 3 | ||||
-rw-r--r-- | src/nvim/optionstr.c | 19 | ||||
-rw-r--r-- | src/nvim/runtime.c | 76 | ||||
-rw-r--r-- | src/nvim/screen.c | 17 | ||||
-rw-r--r-- | src/nvim/search.c | 4 | ||||
-rw-r--r-- | src/nvim/syntax.c | 2 | ||||
-rw-r--r-- | src/nvim/window.c | 15 |
27 files changed, 147 insertions, 224 deletions
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index 32378ed244..de766c14b9 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -938,10 +938,11 @@ static void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdin /// - force: (boolean, default true) Override any previous definition. /// - preview: (function) Preview callback for 'inccommand' |:command-preview| /// @param[out] err Error details, if any. -void nvim_create_user_command(String name, Object command, Dict(user_command) *opts, Error *err) +void nvim_create_user_command(uint64_t channel_id, String name, Object command, + Dict(user_command) *opts, Error *err) FUNC_API_SINCE(9) { - create_user_command(name, command, opts, 0, err); + create_user_command(channel_id, name, command, opts, 0, err); } /// Delete a user-defined command. @@ -959,7 +960,7 @@ void nvim_del_user_command(String name, Error *err) /// @param buffer Buffer handle, or 0 for current buffer. /// @param[out] err Error details, if any. /// @see nvim_create_user_command -void nvim_buf_create_user_command(Buffer buffer, String name, Object command, +void nvim_buf_create_user_command(uint64_t channel_id, Buffer buffer, String name, Object command, Dict(user_command) *opts, Error *err) FUNC_API_SINCE(9) { @@ -970,7 +971,7 @@ void nvim_buf_create_user_command(Buffer buffer, String name, Object command, buf_T *save_curbuf = curbuf; curbuf = target_buf; - create_user_command(name, command, opts, UC_BUFFER, err); + create_user_command(channel_id, name, command, opts, UC_BUFFER, err); curbuf = save_curbuf; } @@ -1011,8 +1012,8 @@ void nvim_buf_del_user_command(Buffer buffer, String name, Error *err) api_set_error(err, kErrorTypeException, "Invalid command (not found): %s", name.data); } -void create_user_command(String name, Object command, Dict(user_command) *opts, int flags, - Error *err) +void create_user_command(uint64_t channel_id, String name, Object command, Dict(user_command) *opts, + int flags, Error *err) { uint32_t argt = 0; int64_t def = -1; @@ -1205,11 +1206,13 @@ void create_user_command(String name, Object command, Dict(user_command) *opts, }); } - if (uc_add_command(name.data, name.size, rep, argt, def, flags, compl, compl_arg, compl_luaref, - preview_luaref, addr_type_arg, luaref, force) != OK) { - api_set_error(err, kErrorTypeException, "Failed to create user command"); - // Do not goto err, since uc_add_command now owns luaref, compl_luaref, and compl_arg - } + WITH_SCRIPT_CONTEXT(channel_id, { + if (uc_add_command(name.data, name.size, rep, argt, def, flags, compl, compl_arg, compl_luaref, + preview_luaref, addr_type_arg, luaref, force) != OK) { + api_set_error(err, kErrorTypeException, "Failed to create user command"); + // Do not goto err, since uc_add_command now owns luaref, compl_luaref, and compl_arg + } + }); return; diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c index ddaed3a254..2d9ffcba06 100644 --- a/src/nvim/api/options.c +++ b/src/nvim/api/options.c @@ -157,7 +157,8 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err) /// - win: |window-ID|. Used for setting window local option. /// - buf: Buffer number. Used for setting buffer local option. /// @param[out] err Error details, if any -void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error *err) +void nvim_set_option_value(uint64_t channel_id, String name, Object value, Dict(option) *opts, + Error *err) FUNC_API_SINCE(9) { int scope = 0; @@ -202,7 +203,9 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error }); } - access_option_value_for(name.data, &numval, &stringval, scope, opt_type, to, false, err); + WITH_SCRIPT_CONTEXT(channel_id, { + access_option_value_for(name.data, &numval, &stringval, scope, opt_type, to, false, err); + }); } /// Gets the option information for all options. diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index a08e8dbfeb..b93f521ca3 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -114,7 +114,7 @@ void msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep_char) FUNC_API_SINCE(6) FUNC_API_COMPOSITOR_IMPL FUNC_API_CLIENT_IGNORE; void win_viewport(Integer grid, Window win, Integer topline, Integer botline, Integer curline, - Integer curcol, Integer line_count) + Integer curcol, Integer line_count, Integer scroll_delta) FUNC_API_SINCE(7) FUNC_API_CLIENT_IGNORE; void win_extmark(Integer grid, Window win, Integer ns_id, Integer mark_id, Integer row, Integer col) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 0f27040fd3..315ccd13e6 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -579,7 +579,7 @@ ArrayOf(String) nvim__get_runtime(Array pat, Boolean all, Dict(runtime) *opts, E if (source) { for (size_t i = 0; i < res.size; i++) { String name = res.items[i].data.string; - (void)do_source(name.data, false, DOSO_NONE); + (void)do_source(name.data, false, DOSO_NONE, NULL); } } diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 6122136a75..4bdf5aac64 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -1222,6 +1222,7 @@ struct window_S { colnr_T w_valid_leftcol; // last known w_leftcol bool w_viewport_invalid; + linenr_T w_viewport_last_topline; // topline when the viewport was last updated // w_cline_height is the number of physical lines taken by the buffer line // that the cursor is on. We use this to avoid extra calls to plines_win(). diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 289939b2ca..52c5732f23 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -3136,7 +3136,7 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr if (added != 0) { // Adjust marks. This will change the following entries! - mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, added, kExtmarkUndo); + mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, added, kExtmarkNOOP); if (curwin->w_cursor.lnum >= lnum) { // Adjust the cursor position if it's in/after the changed // lines. diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 384dbf82f9..d8c9da870a 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -728,19 +728,15 @@ static void win_redr_border(win_T *wp) /// Show current cursor info in ruler and various other places /// /// @param always if false, only show ruler if position has changed. -void show_cursor_info(bool always) +void show_cursor_info_later(bool force) { - if (!always && !redrawing()) { - return; - } - int state = get_real_state(); int empty_line = (State & MODE_INSERT) == 0 && *ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false) == NUL; // Only draw when something changed. validate_virtcol_win(curwin); - if (always + if (force || curwin->w_cursor.lnum != curwin->w_stl_cursor.lnum || curwin->w_cursor.col != curwin->w_stl_cursor.col || curwin->w_virtcol != curwin->w_stl_virtcol @@ -750,27 +746,19 @@ void show_cursor_info(bool always) || curwin->w_topfill != curwin->w_stl_topfill || empty_line != curwin->w_stl_empty || state != curwin->w_stl_state) { - win_check_ns_hl(curwin); - if ((*p_stl != NUL || *curwin->w_p_stl != NUL) - && (curwin->w_status_height || global_stl_height())) { - redraw_custom_statusline(curwin); + if ((curwin->w_status_height || global_stl_height())) { + curwin->w_redr_status = true; } else { - win_redr_ruler(curwin); + redraw_cmdline = true; } + if (*p_wbr != NUL || *curwin->w_p_wbr != NUL) { - win_redr_winbar(curwin); + curwin->w_redr_status = true; } - if (need_maketitle - || (p_icon && (stl_syntax & STL_IN_ICON)) + if ((p_icon && (stl_syntax & STL_IN_ICON)) || (p_title && (stl_syntax & STL_IN_TITLE))) { - maketitle(); - } - - win_check_ns_hl(NULL); - // Redraw the tab pages line if needed. - if (redraw_tabline) { - draw_tabline(); + need_maketitle = true; } } @@ -2136,7 +2124,7 @@ void status_redraw_all(void) bool is_stl_global = global_stl_height() != 0; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - if ((!is_stl_global && wp->w_status_height) || (is_stl_global && wp == curwin) + if ((!is_stl_global && wp->w_status_height) || wp == curwin || wp->w_winbar_height) { wp->w_redr_status = true; redraw_later(wp, UPD_VALID); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 9eb4802d97..48ba93e666 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1350,12 +1350,15 @@ void ins_redraw(bool ready) } pum_check_clear(); + show_cursor_info_later(false); if (must_redraw) { update_screen(); - } else if (clear_cmdline || redraw_cmdline) { - showmode(); // clear cmdline and show mode + } else { + redraw_statuslines(); + if (clear_cmdline || redraw_cmdline || redraw_mode) { + showmode(); // clear cmdline and show mode + } } - show_cursor_info(false); setcursor(); emsg_on_display = false; // may remove error message now } @@ -1510,14 +1513,14 @@ bool prompt_curpos_editable(void) // Undo the previous edit_putchar(). void edit_unputchar(void) { - if (pc_status != PC_STATUS_UNSET && pc_row >= msg_scrolled) { + if (pc_status != PC_STATUS_UNSET) { if (pc_status == PC_STATUS_RIGHT) { curwin->w_wcol++; } if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT) { redrawWinline(curwin, curwin->w_cursor.lnum); } else { - grid_puts(&curwin->w_grid, pc_bytes, pc_row - msg_scrolled, pc_col, pc_attr); + grid_puts(&curwin->w_grid, pc_bytes, pc_row, pc_col, pc_attr); } } } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 384e088bcf..14f2379504 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6951,14 +6951,12 @@ int handle_subscript(const char **const arg, typval_T *rettv, int evaluate, int tv_dict_unref(selfdict); selfdict = NULL; } else if (**arg == '-') { - if (ret == OK) { - if ((*arg)[2] == '{') { - // expr->{lambda}() - ret = eval_lambda((char **)arg, rettv, evaluate, verbose); - } else { - // expr->name() - ret = eval_method((char **)arg, rettv, evaluate, verbose); - } + if ((*arg)[2] == '{') { + // expr->{lambda}() + ret = eval_lambda((char **)arg, rettv, evaluate, verbose); + } else { + // expr->name() + ret = eval_method((char **)arg, rettv, evaluate, verbose); } } else { // **arg == '[' || **arg == '.' tv_dict_unref(selfdict); diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a12c2a15b4..d398d3e06e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3747,6 +3747,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T update_topline(curwin); validate_cursor(); redraw_later(curwin, UPD_SOME_VALID); + show_cursor_info_later(true); update_screen(); highlight_match = false; redraw_later(curwin, UPD_SOME_VALID); @@ -3765,7 +3766,6 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T _("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); msg_no_more = false; msg_scroll = (int)i; - show_cursor_info(true); if (!ui_has(kUIMessages)) { ui_cursor_goto(msg_row, msg_col); } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index f460b4b93f..49f6d24c89 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5666,10 +5666,7 @@ static void ex_equal(exarg_T *eap) static void ex_sleep(exarg_T *eap) { if (cursor_valid()) { - int n = curwin->w_winrow + curwin->w_wrow - msg_scrolled; - if (n >= 0) { - ui_cursor_goto(n, curwin->w_wincol + curwin->w_wcol); - } + setcursor_mayforce(true); } long len = eap->line2; diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 8e3e68d9b7..855a5f7538 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -909,7 +909,7 @@ void ex_loadview(exarg_T *eap) return; } - if (do_source(fname, false, DOSO_NONE) == FAIL) { + if (do_source(fname, false, DOSO_NONE, NULL) == FAIL) { semsg(_(e_notopen), fname); } xfree(fname); diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index ea541dbca4..605705e0e3 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2073,39 +2073,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) } } - // Check for match with 'pastetoggle' - if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL))) { - bool match = typebuf_match_len((uint8_t *)p_pt, &mlen); - if (match) { - // write chars to script file(s) - if (mlen > typebuf.tb_maplen) { - gotchars(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_maplen, - (size_t)(mlen - typebuf.tb_maplen)); - } - - del_typebuf(mlen, 0); // remove the chars - set_option_value_give_err("paste", !p_paste, NULL, 0); - if (!(State & MODE_INSERT)) { - msg_col = 0; - msg_row = Rows - 1; - msg_clr_eos(); // clear ruler - } - status_redraw_all(); - redraw_statuslines(); - showmode(); - setcursor(); - *keylenp = keylen; - return map_result_retry; - } - // Need more chars for partly match. - if (mlen == typebuf.tb_len) { - keylen = KEYLEN_PART_KEY; - } else if (max_mlen < mlen) { - // no match, may have to check for termcode at next character - max_mlen = mlen + 1; - } - } - if ((mp == NULL || max_mlen > mp_match_len) && keylen != KEYLEN_PART_MAP) { // When no matching mapping found or found a non-matching mapping that // matches at least what the matching mapping matched: @@ -2116,13 +2083,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) || (typebuf.tb_buf[typebuf.tb_off + 1] == KS_MODIFIER && typebuf.tb_len < 4))) { // Incomplete modifier sequence: cannot decide whether to simplify yet. keylen = KEYLEN_PART_KEY; - } else if (keylen == KEYLEN_PART_KEY && !*timedout) { - // If 'pastetoggle' matched partially, don't simplify. - // When the last characters were not typed, don't wait for a typed character to - // complete 'pastetoggle'. - if (typebuf.tb_len == typebuf.tb_maplen) { - keylen = 0; - } } else { // Try to include the modifier into the key. keylen = check_simplify_modifier(max_mlen + 1); @@ -2923,18 +2883,6 @@ int fix_input_buffer(uint8_t *buf, int len) return len; } -static bool typebuf_match_len(const uint8_t *str, int *mlen) -{ - int i; - for (i = 0; i < typebuf.tb_len && str[i]; i++) { - if (str[i] != typebuf.tb_buf[typebuf.tb_off + i]) { - break; - } - } - *mlen = i; - return str[i] == NUL; // matched the whole string -} - /// Get command argument for <Cmd> key char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) { diff --git a/src/nvim/grid.c b/src/nvim/grid.c index efbeac4f3f..cd70e98047 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -549,9 +549,9 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle } if (bg_attr) { + assert(off_from == (size_t)col); for (int c = col; c < endcol; c++) { - linebuf_attr[off_from + (size_t)c] = - hl_combine_attr(bg_attr, linebuf_attr[off_from + (size_t)c]); + linebuf_attr[c] = hl_combine_attr(bg_attr, linebuf_attr[c]); } } diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 078bc4fea9..819e3cccff 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1623,12 +1623,12 @@ void ex_lua(exarg_T *const eap) } // When =expr is used transform it to print(vim.inspect(expr)) if (code[0] == '=') { - len += sizeof("vim.pretty_print()") - sizeof("="); + len += sizeof("vim.print()") - sizeof("="); // code_buf needs to be 1 char larger then len for null byte in the end. // lua nlua_typval_exec doesn't expect null terminated string so len // needs to end before null byte. char *code_buf = xmallocz(len); - vim_snprintf(code_buf, len + 1, "vim.pretty_print(%s)", code + 1); + vim_snprintf(code_buf, len + 1, "vim.print(%s)", code + 1); xfree(code); code = code_buf; } @@ -2061,10 +2061,15 @@ void nlua_set_sctx(sctx_T *current) break; } char *source_path = fix_fname(info->source + 1); - get_current_script_id(&source_path, current); - xfree(source_path); - current->sc_lnum = info->currentline; + int sid = find_script_by_name(source_path); + if (sid > 0) { + xfree(source_path); + } else { + new_script_item(source_path, &sid); + } + current->sc_sid = sid; current->sc_seq = -1; + current->sc_lnum = info->currentline; cleanup: xfree(info); diff --git a/src/nvim/main.c b/src/nvim/main.c index be1714b207..ea5f511fc6 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1937,7 +1937,7 @@ static void do_system_initialization(void) dir_len += 1; } memcpy(vimrc + dir_len, path_tail, sizeof(path_tail)); - if (do_source(vimrc, false, DOSO_NONE) != FAIL) { + if (do_source(vimrc, false, DOSO_NONE, NULL) != FAIL) { xfree(vimrc); xfree(config_dirs); return; @@ -1949,7 +1949,7 @@ static void do_system_initialization(void) #ifdef SYS_VIMRC_FILE // Get system wide defaults, if the file name is defined. - (void)do_source(SYS_VIMRC_FILE, false, DOSO_NONE); + (void)do_source(SYS_VIMRC_FILE, false, DOSO_NONE, NULL); #endif } @@ -1978,7 +1978,7 @@ static bool do_user_initialization(void) // init.lua if (os_path_exists(init_lua_path) - && do_source(init_lua_path, true, DOSO_VIMRC)) { + && do_source(init_lua_path, true, DOSO_VIMRC, NULL)) { if (os_path_exists(user_vimrc)) { semsg(_("E5422: Conflicting configs: \"%s\" \"%s\""), init_lua_path, user_vimrc); @@ -1992,7 +1992,7 @@ static bool do_user_initialization(void) xfree(init_lua_path); // init.vim - if (do_source(user_vimrc, true, DOSO_VIMRC) != FAIL) { + if (do_source(user_vimrc, true, DOSO_VIMRC, NULL) != FAIL) { do_exrc = p_exrc; if (do_exrc) { do_exrc = (path_full_compare(VIMRC_FILE, user_vimrc, false, true) != kEqualFiles); @@ -2018,7 +2018,7 @@ static bool do_user_initialization(void) memmove(vimrc, dir, dir_len); vimrc[dir_len] = PATHSEP; memmove(vimrc + dir_len + 1, path_tail, sizeof(path_tail)); - if (do_source(vimrc, true, DOSO_VIMRC) != FAIL) { + if (do_source(vimrc, true, DOSO_VIMRC, NULL) != FAIL) { do_exrc = p_exrc; if (do_exrc) { do_exrc = (path_full_compare(VIMRC_FILE, vimrc, false, true) != kEqualFiles); @@ -2084,7 +2084,7 @@ static void source_startup_scripts(const mparm_T *const parmp) || strequal(parmp->use_vimrc, "NORC")) { // Do nothing. } else { - if (do_source(parmp->use_vimrc, false, DOSO_NONE) != OK) { + if (do_source(parmp->use_vimrc, false, DOSO_NONE, NULL) != OK) { semsg(_("E282: Cannot read from \"%s\""), parmp->use_vimrc); } } diff --git a/src/nvim/move.c b/src/nvim/move.c index 8fda73cbec..6d55955927 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -512,8 +512,7 @@ void approximate_botline_win(win_T *wp) int cursor_valid(void) { check_cursor_moved(curwin); - return (curwin->w_valid & (VALID_WROW|VALID_WCOL)) == - (VALID_WROW|VALID_WCOL); + return (curwin->w_valid & (VALID_WROW|VALID_WCOL)) == (VALID_WROW|VALID_WCOL); } // Validate cursor position. Makes sure w_wrow and w_wcol are valid. diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 890215e754..2a8fbbb962 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1306,16 +1306,20 @@ static void normal_redraw(NormalState *s) update_topline(curwin); validate_cursor(); + show_cursor_info_later(false); + if (VIsual_active) { redraw_curbuf_later(UPD_INVERTED); // update inverted part - update_screen(); - } else if (must_redraw) { - update_screen(); - } else if (redraw_cmdline || clear_cmdline || redraw_mode) { - showmode(); } - redraw_statuslines(); + if (must_redraw) { + update_screen(); + } else { + redraw_statuslines(); + if (redraw_cmdline || clear_cmdline || redraw_mode) { + showmode(); + } + } if (need_maketitle) { maketitle(); @@ -1348,7 +1352,6 @@ static void normal_redraw(NormalState *s) did_emsg = false; msg_didany = false; // reset lines_left in msg_start() may_clear_sb_text(); // clear scroll-back text on next msg - show_cursor_info(false); setcursor(); } diff --git a/src/nvim/option.c b/src/nvim/option.c index 4e0fbc20f8..f9b7aa9f99 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2255,9 +2255,6 @@ static char *set_bool_option(const int opt_idx, char *const varp, const int valu if ((int *)varp == &p_ru || (int *)varp == &p_sc) { // in case 'ruler' or 'showcmd' changed comp_col(); - if ((int *)varp == &p_ru) { - win_redr_ruler(curwin); - } } if (curwin->w_curswant != MAXCOL && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) { @@ -2921,11 +2918,7 @@ getoption_T get_option_value(const char *name, long *numval, char **stringval, u return gov_hidden_string; } if (stringval != NULL) { - if ((char **)varp == &p_pt) { // 'pastetoggle' - *stringval = str2special_save(*(char **)(varp), false, false); - } else { - *stringval = xstrdup(*(char **)(varp)); - } + *stringval = xstrdup(*(char **)(varp)); } return gov_string; } @@ -3535,17 +3528,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ char_u *part = NULL; if (*valuep != NULL) { - // Output 'pastetoggle' as key names. For other - // options some characters have to be escaped with - // CTRL-V or backslash - if (valuep == &p_pt) { - char_u *s = (char_u *)(*valuep); - while (*s != NUL) { - if (put_escstr(fd, (char *)str2special((const char **)&s, false, false), 2) == FAIL) { - return FAIL; - } - } - } else if ((flags & P_EXPAND) != 0) { + if ((flags & P_EXPAND) != 0) { size_t size = (size_t)strlen(*valuep) + 1; // replace home directory in the whole option value into "buf" @@ -4993,9 +4976,6 @@ static void option_value2string(vimoption_T *opp, int scope) NameBuff[0] = NUL; } else if (opp->flags & P_EXPAND) { home_replace(NULL, varp, NameBuff, MAXPATHL, false); - // Translate 'pastetoggle' into special key names. - } else if ((char **)opp->var == &p_pt) { - str2specialbuf((const char *)p_pt, NameBuff, MAXPATHL); } else { xstrlcpy(NameBuff, varp, MAXPATHL); } diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 470eae2090..de289fe54e 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -613,7 +613,6 @@ EXTERN char *p_nf; ///< 'nrformats' EXTERN char *p_opfunc; // 'operatorfunc' EXTERN char *p_para; // 'paragraphs' EXTERN int p_paste; // 'paste' -EXTERN char *p_pt; // 'pastetoggle' EXTERN char *p_pex; // 'patchexpr' EXTERN char *p_pm; // 'patchmode' EXTERN char *p_path; // 'path' diff --git a/src/nvim/options.lua b/src/nvim/options.lua index a4ee114f39..bb673a2c58 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1685,9 +1685,8 @@ return { }, { full_name='pastetoggle', abbreviation='pt', - short_desc=N_("key code that causes 'paste' to toggle"), + short_desc=N_("No description"), type='string', scope={'global'}, - varname='p_pt', defaults={if_true=""} }, { diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 0774baf2d8..cba95377a2 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -1221,7 +1221,6 @@ static void did_set_statusline(win_T *win, char **varp, char **gvarp, char **err } if (varp == &p_ruf && *errmsg == NULL) { comp_col(); - win_redr_ruler(curwin); } // add / remove window bars for 'winbar' if (gvarp == &p_wbr) { @@ -1307,22 +1306,6 @@ static void did_set_foldcolumn(char **varp, char **errmsg) } } -static void did_set_pastetoggle(void) -{ - // 'pastetoggle': translate key codes like in a mapping - if (*p_pt) { - char *p = NULL; - (void)replace_termcodes(p_pt, - strlen(p_pt), - &p, REPTERM_FROM_PART | REPTERM_DO_LT, NULL, - CPO_TO_CPO_FLAGS); - if (p != NULL) { - free_string_option(p_pt); - p_pt = p; - } - } -} - static void did_set_backspace(char **errmsg) { if (ascii_isdigit(*p_bs)) { @@ -1779,8 +1762,6 @@ static char *did_set_string_option_for(buf_T *buf, win_T *win, int opt_idx, char did_set_opt_strings(*varp, p_sloc_values, false, &errmsg); } else if (gvarp == &win->w_allbuf_opt.wo_fdc) { // 'foldcolumn' did_set_foldcolumn(varp, &errmsg); - } else if (varp == &p_pt) { // 'pastetoggle' - did_set_pastetoggle(); } else if (varp == &p_bs) { // 'backspace' did_set_backspace(&errmsg); } else if (varp == &p_bo) { diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index c316b61082..c9667d58ed 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -78,6 +78,8 @@ garray_T script_items = { 0, 0, sizeof(scriptitem_T *), 20, NULL }; /// The names of packages that once were loaded are remembered. static garray_T ga_loaded = { 0, 0, sizeof(char *), 4, NULL }; +static int last_current_SID_seq = 0; + /// Initialize the execution stack. void estack_init(void) { @@ -266,7 +268,7 @@ void set_context_in_runtime_cmd(expand_T *xp, const char *arg) static void source_callback(char *fname, void *cookie) { - (void)do_source(fname, false, DOSO_NONE); + (void)do_source(fname, false, DOSO_NONE, cookie); } /// Find the file "name" in all directories in "path" and invoke @@ -855,7 +857,7 @@ static void source_all_matches(char *pat) } for (int i = 0; i < num_files; i++) { - (void)do_source(files[i], false, DOSO_NONE); + (void)do_source(files[i], false, DOSO_NONE, NULL); } FreeWild(num_files, files); } @@ -1701,7 +1703,7 @@ static void cmd_source(char *fname, exarg_T *eap) || eap->cstack->cs_idx >= 0); // ":source" read ex commands - } else if (do_source(fname, false, DOSO_NONE) == FAIL) { + } else if (do_source(fname, false, DOSO_NONE, NULL) == FAIL) { semsg(_(e_notopen), fname); } } @@ -1954,9 +1956,12 @@ int do_source_str(const char *cmd, const char *traceback_name) /// @param fname /// @param check_other check for .vimrc and _vimrc /// @param is_vimrc DOSO_ value +/// @param ret_sid if not NULL and we loaded the script before, don't load it again /// /// @return FAIL if file could not be opened, OK otherwise -int do_source(char *fname, int check_other, int is_vimrc) +/// +/// If a scriptitem_T was found or created "*ret_sid" is set to the SID. +int do_source(char *fname, int check_other, int is_vimrc, int *ret_sid) { struct source_cookie cookie; char *p; @@ -1982,6 +1987,15 @@ int do_source(char *fname, int check_other, int is_vimrc) goto theend; } + // See if we loaded this script before. + int sid = find_script_by_name(fname_exp); + if (sid > 0 && ret_sid != NULL) { + // Already loaded and no need to load again, return here. + *ret_sid = sid; + retval = OK; + goto theend; + } + // Apply SourceCmd autocommands, they should get the file and source it. if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL) && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp, @@ -2080,7 +2094,24 @@ int do_source(char *fname, int check_other, int is_vimrc) save_funccal(&funccalp_entry); const sctx_T save_current_sctx = current_sctx; - si = get_current_script_id(&fname_exp, ¤t_sctx); + + current_sctx.sc_lnum = 0; + + // Always use a new sequence number. + current_sctx.sc_seq = ++last_current_SID_seq; + + if (sid > 0) { + // loading the same script again + si = SCRIPT_ITEM(sid); + } else { + // It's new, generate a new SID. + si = new_script_item(fname_exp, &sid); + fname_exp = xstrdup(si->sn_name); // used for autocmd + if (ret_sid != NULL) { + *ret_sid = sid; + } + } + current_sctx.sc_sid = sid; // Keep the sourcing name/lnum, for recursive calls. estack_push(ETYPE_SCRIPT, si->sn_name, 0); @@ -2192,7 +2223,7 @@ theend: /// Find an already loaded script "name". /// If found returns its script ID. If not found returns -1. -static int find_script_by_name(char *name) +int find_script_by_name(char *name) { assert(script_items.ga_len >= 0); for (int sid = script_items.ga_len; sid > 0; sid--) { @@ -2209,35 +2240,6 @@ static int find_script_by_name(char *name) return -1; } -/// Check if fname was sourced before to finds its SID. -/// If it's new, generate a new SID. -/// -/// @param[in,out] fnamep pointer to file path of script -/// @param[out] ret_sctx sctx of this script -scriptitem_T *get_current_script_id(char **fnamep, sctx_T *ret_sctx) -{ - static int last_current_SID_seq = 0; - - scriptitem_T *si; - int sid = find_script_by_name(*fnamep); - if (sid > 0) { - si = SCRIPT_ITEM(sid); - } else { - si = new_script_item(*fnamep, &sid); - *fnamep = xstrdup(si->sn_name); - } - - sctx_T script_sctx = { .sc_seq = ++last_current_SID_seq, - .sc_lnum = 0, - .sc_sid = sid }; - - if (ret_sctx != NULL) { - *ret_sctx = script_sctx; - } - - return si; -} - /// ":scriptnames" void ex_scriptnames(exarg_T *eap) { @@ -2704,7 +2706,9 @@ bool script_autoload(const char *const name, const size_t name_len, const bool r } // Try loading the package from $VIMRUNTIME/autoload/<name>.vim - if (source_runtime(scriptname, 0) == OK) { + // Use "ret_sid" to avoid loading the same script again. + int ret_sid; + if (do_in_runtimepath(scriptname, 0, source_callback, &ret_sid) == OK) { ret = true; } } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 43c7866180..8b0f8b58a7 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -111,14 +111,14 @@ static int win_fill_end(win_T *wp, int c1, int c2, int off, int width, int row, int attr) { int nn = off + width; + const int endcol = wp->w_grid.cols; - if (nn > wp->w_grid.cols) { - nn = wp->w_grid.cols; + if (nn > endcol) { + nn = endcol; } if (wp->w_p_rl) { - grid_fill(&wp->w_grid, row, endrow, W_ENDCOL(wp) - nn, W_ENDCOL(wp) - off, - c1, c2, attr); + grid_fill(&wp->w_grid, row, endrow, endcol - nn, endcol - off, c1, c2, attr); } else { grid_fill(&wp->w_grid, row, endrow, off, nn, c1, c2, attr); } @@ -156,13 +156,12 @@ void win_draw_end(win_T *wp, int c1, int c2, bool draw_margin, int row, int endr int attr = hl_combine_attr(win_bg_attr(wp), win_hl_attr(wp, (int)hl)); + const int endcol = wp->w_grid.cols; if (wp->w_p_rl) { - grid_fill(&wp->w_grid, row, endrow, wp->w_wincol, W_ENDCOL(wp) - 1 - n, - c2, c2, attr); - grid_fill(&wp->w_grid, row, endrow, W_ENDCOL(wp) - 1 - n, W_ENDCOL(wp) - n, - c1, c2, attr); + grid_fill(&wp->w_grid, row, endrow, 0, endcol - 1 - n, c2, c2, attr); + grid_fill(&wp->w_grid, row, endrow, endcol - 1 - n, endcol - n, c1, c2, attr); } else { - grid_fill(&wp->w_grid, row, endrow, n, wp->w_grid.cols, c1, c2, attr); + grid_fill(&wp->w_grid, row, endrow, n, endcol, c1, c2, attr); } } diff --git a/src/nvim/search.c b/src/nvim/search.c index e5a456161f..782f60f11f 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -2340,7 +2340,6 @@ void showmatch(int c) dollar_vcol = -1; } curwin->w_virtcol++; // do display ')' just before "$" - update_screen(); // show the new char first colnr_T save_dollar_vcol = dollar_vcol; int save_state = State; @@ -2349,7 +2348,8 @@ void showmatch(int c) curwin->w_cursor = mpos; // move to matching char *so = 0; // don't use 'scrolloff' here *siso = 0; // don't use 'sidescrolloff' here - show_cursor_info(false); + show_cursor_info_later(false); + update_screen(); // show the new char setcursor(); ui_flush(); // Restore dollar_vcol(), because setcursor() may call curs_rows() diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index d4161b9ca2..14fef19399 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4026,7 +4026,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing) prev_toplvl_grp = curwin->w_s->b_syn_topgrp; curwin->w_s->b_syn_topgrp = sgl_id; if (source - ? do_source(eap->arg, false, DOSO_NONE) == FAIL + ? do_source(eap->arg, false, DOSO_NONE, NULL) == FAIL : source_runtime(eap->arg, DIP_ALL) == FAIL) { semsg(_(e_notopen), eap->arg); } diff --git a/src/nvim/window.c b/src/nvim/window.c index 38b7326363..39e9efbabb 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -993,10 +993,22 @@ void ui_ext_win_viewport(win_T *wp) // interact with incomplete final line? Diff filler lines? botline = wp->w_buffer->b_ml.ml_line_count; } + int scroll_delta = 0; + if (wp->w_viewport_last_topline > line_count) { + scroll_delta -= wp->w_viewport_last_topline - line_count; + wp->w_viewport_last_topline = line_count; + } + if (wp->w_topline < wp->w_viewport_last_topline) { + scroll_delta -= plines_m_win(wp, wp->w_topline, wp->w_viewport_last_topline - 1); + } else if (wp->w_topline > wp->w_viewport_last_topline + && wp->w_topline <= line_count) { + scroll_delta += plines_m_win(wp, wp->w_viewport_last_topline, wp->w_topline - 1); + } ui_call_win_viewport(wp->w_grid_alloc.handle, wp->handle, wp->w_topline - 1, botline, wp->w_cursor.lnum - 1, wp->w_cursor.col, - line_count); + line_count, scroll_delta); wp->w_viewport_invalid = false; + wp->w_viewport_last_topline = wp->w_topline; } } @@ -5038,6 +5050,7 @@ static win_T *win_alloc(win_T *after, bool hidden) new_wp->w_floating = 0; new_wp->w_float_config = FLOAT_CONFIG_INIT; new_wp->w_viewport_invalid = true; + new_wp->w_viewport_last_topline = 1; new_wp->w_ns_hl = -1; |