diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/window.c | 46 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 5 | ||||
-rw-r--r-- | src/nvim/file_search.c | 2 | ||||
-rw-r--r-- | src/nvim/option.c | 109 | ||||
-rw-r--r-- | src/nvim/optionstr.c | 2 | ||||
-rw-r--r-- | src/nvim/path.c | 2 | ||||
-rw-r--r-- | src/nvim/plines.c | 38 | ||||
-rw-r--r-- | src/nvim/terminal.c | 2 | ||||
-rw-r--r-- | src/nvim/window.c | 8 |
9 files changed, 78 insertions, 136 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 07aad2cd88..5480584aa5 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -488,15 +488,20 @@ void nvim_win_set_hl_ns(Window window, Integer ns_id, Error *err) /// - end_vcol: Ending virtual column index on "end_row", /// 0-based exclusive, rounded up to full screen lines. /// When omitted include the whole line. -/// @return The number of screen lines that the range of text occupy. +/// @return Dictionary containing text height information, with these keys: +/// - all: The total number of screen lines occupied by the range. +/// - fill: The number of diff filler or virtual lines among them. /// /// @see |virtcol()| for text width. -Object nvim_win_text_height(Window window, Dict(win_text_height) *opts, Error *err) +Dictionary nvim_win_text_height(Window window, Dict(win_text_height) *opts, Arena *arena, + Error *err) FUNC_API_SINCE(12) { + Dictionary rv = arena_dict(arena, 2); + win_T *const win = find_window_by_handle(window, err); if (!win) { - return NIL; + return rv; } buf_T *const buf = win->w_buffer; const linenr_T line_count = buf->b_ml.ml_line_count; @@ -510,58 +515,65 @@ Object nvim_win_text_height(Window window, Dict(win_text_height) *opts, Error *e if (HAS_KEY(opts->start_row)) { VALIDATE_T("start_row", kObjectTypeInteger, opts->start_row.type, { - return NIL; + return rv; }); start_lnum = (linenr_T)normalize_index(buf, opts->start_row.data.integer, false, &oob); } if (HAS_KEY(opts->end_row)) { VALIDATE_T("end_row", kObjectTypeInteger, opts->end_row.type, { - return NIL; + return rv; }); end_lnum = (linenr_T)normalize_index(buf, opts->end_row.data.integer, false, &oob); } VALIDATE(!oob, "%s", "Line index out of bounds", { - return NIL; + return rv; }); VALIDATE((start_lnum <= end_lnum), "%s", "'start_row' is higher than 'end_row'", { - return NIL; + return rv; }); if (HAS_KEY(opts->start_vcol)) { VALIDATE(HAS_KEY(opts->start_row), "%s", "'start_vcol' specified without 'start_row'", { - return NIL; + return rv; }); VALIDATE_T("start_vcol", kObjectTypeInteger, opts->start_vcol.type, { - return NIL; + return rv; }); start_vcol = opts->start_vcol.data.integer; VALIDATE_RANGE((start_vcol >= 0 && start_vcol <= MAXCOL), "start_vcol", { - return NIL; + return rv; }); } if (HAS_KEY(opts->end_vcol)) { VALIDATE(HAS_KEY(opts->end_row), "%s", "'end_vcol' specified without 'end_row'", { - return NIL; + return rv; }); VALIDATE_T("end_vcol", kObjectTypeInteger, opts->end_vcol.type, { - return NIL; + return rv; }); end_vcol = opts->end_vcol.data.integer; VALIDATE_RANGE((end_vcol >= 0 && end_vcol <= MAXCOL), "end_vcol", { - return NIL; + return rv; }); } if (start_lnum == end_lnum && start_vcol >= 0 && end_vcol >= 0) { VALIDATE((start_vcol <= end_vcol), "%s", "'start_vcol' is higher than 'end_vcol'", { - return NIL; + return rv; }); } - const int64_t res = win_text_height(win, start_lnum, start_vcol, end_lnum, end_vcol) - + (HAS_KEY(opts->end_row) ? 0 : win_get_fill(win, line_count + 1)); - return INTEGER_OBJ(res); + int64_t fill = 0; + int64_t all = win_text_height(win, start_lnum, start_vcol, end_lnum, end_vcol, &fill); + if (!HAS_KEY(opts->end_row)) { + const int64_t end_fill = win_get_fill(win, line_count + 1); + fill += end_fill; + all += end_fill; + } + PUT_C(rv, "all", INTEGER_OBJ(all)); + PUT_C(rv, "fill", INTEGER_OBJ(fill)); + return rv; } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 6bb980d501..927877dc74 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -261,6 +261,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s return false; } + emsg_off++; exarg_T ea = { .line1 = 1, .line2 = 1, @@ -368,6 +369,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s curwin->w_cursor = save_cursor; retval = true; theend: + emsg_off--; return retval; } @@ -2427,9 +2429,12 @@ static bool cmdpreview_may_show(CommandLineState *s) int cmdpreview_type = 0; char *cmdline = xstrdup(ccline.cmdbuff); const char *errormsg = NULL; + emsg_off++; // Block errors when parsing the command line, and don't update v:errmsg if (!parse_cmdline(cmdline, &ea, &cmdinfo, &errormsg)) { + emsg_off--; goto end; } + emsg_off--; // Check if command is previewable, if not, don't attempt to show preview if (!(ea.argt & EX_PREVIEW)) { diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 1bfbe2e634..b5cdeff21c 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1469,7 +1469,7 @@ char *find_file_in_path_option(char *ptr, size_t len, int options, int first, ch // copy next path buf[0] = 0; - copy_option_part(&dir, buf, MAXPATHL, " ,"); + copy_option_part(&dir, buf, MAXPATHL, ","); // get the stopdir string r_ptr = vim_findfile_stopdir(buf); diff --git a/src/nvim/option.c b/src/nvim/option.c index 598ae8e490..bece6f3605 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -842,77 +842,6 @@ static void do_set_num(int opt_idx, int opt_flags, char **argp, int nextchar, co errbuf, errbuflen, opt_flags); } -// Handle some special cases with string option values -static void munge_string_opt_val(char **varp, char **oldval, char **const origval, - char **const origval_l, char **const origval_g, char **const argp, - char *const whichwrap, size_t whichwraplen, char **const save_argp) -{ - // Set 'keywordprg' to ":help" if an empty - // value was passed to :set by the user. - if (varp == &p_kp && (**argp == NUL || **argp == ' ')) { - *save_argp = *argp; - *argp = ":help"; - } else if (varp == &p_bs && ascii_isdigit((uint8_t)(**varp))) { - // Convert 'backspace' number to string, for - // adding, prepending and removing string. - const int i = getdigits_int(varp, true, 0); - switch (i) { - case 0: - *varp = empty_option; - break; - case 1: - *varp = xstrdup("indent,eol"); - break; - case 2: - *varp = xstrdup("indent,eol,start"); - break; - case 3: - *varp = xstrdup("indent,eol,nostop"); - break; - } - xfree(*oldval); - if (*origval == *oldval) { - *origval = *varp; - } - if (*origval_l == *oldval) { - *origval_l = *varp; - } - if (*origval_g == *oldval) { - *origval_g = *varp; - } - *oldval = *varp; - } else if (varp == &p_ww && ascii_isdigit(**argp)) { - // Convert 'whichwrap' number to string, for backwards compatibility - // with Vim 3.0. - *whichwrap = NUL; - int i = getdigits_int(argp, true, 0); - if (i & 1) { - xstrlcat(whichwrap, "b,", whichwraplen); - } - if (i & 2) { - xstrlcat(whichwrap, "s,", whichwraplen); - } - if (i & 4) { - xstrlcat(whichwrap, "h,l,", whichwraplen); - } - if (i & 8) { - xstrlcat(whichwrap, "<,>,", whichwraplen); - } - if (i & 16) { - xstrlcat(whichwrap, "[,],", whichwraplen); - } - if (*whichwrap != NUL) { // remove trailing , - whichwrap[strlen(whichwrap) - 1] = NUL; - } - *save_argp = *argp; - *argp = whichwrap; - } else if (**argp == '>' && (varp == &p_dir || varp == &p_bdir)) { - // Remove '>' before 'dir' and 'bdir', for backwards compatibility with - // version 3.0 - (*argp)++; - } -} - /// Get the default value for a string option. static char *stropt_get_default_val(int opt_idx, uint64_t flags) { @@ -1084,20 +1013,14 @@ static void stropt_remove_dupflags(char *newval, uint32_t flags) /// set {opt}< /// set {opt}={val} /// set {opt}:{val} -static char *stropt_get_newval(int nextchar, int opt_idx, char **argp, void *varp, - char **origval_arg, char **origval_l_arg, char **origval_g_arg, - char **oldval_arg, set_op_T *op_arg, uint32_t flags) +static char *stropt_get_newval(int nextchar, int opt_idx, char **argp, void *varp, char *origval, + set_op_T *op_arg, uint32_t flags) { char *arg = *argp; - char *origval = *origval_arg; - char *origval_l = *origval_l_arg; - char *origval_g = *origval_g_arg; - char *oldval = *oldval_arg; set_op_T op = *op_arg; char *save_arg = NULL; char *newval; char *s = NULL; - char whichwrap[80]; if (nextchar == '&') { // set to default val newval = stropt_get_default_val(opt_idx, flags); } else if (nextchar == '<') { // set to global val @@ -1105,8 +1028,12 @@ static char *stropt_get_newval(int nextchar, int opt_idx, char **argp, void *var } else { arg++; // jump to after the '=' or ':' - munge_string_opt_val((char **)varp, &oldval, &origval, &origval_l, &origval_g, &arg, - whichwrap, sizeof(whichwrap), &save_arg); + // Set 'keywordprg' to ":help" if an empty + // value was passed to :set by the user. + if (varp == &p_kp && (*arg == NUL || *arg == ' ')) { + save_arg = arg; + arg = ":help"; + } // Copy the new string into allocated memory. newval = stropt_copy_value(origval, &arg, op, flags); @@ -1155,10 +1082,6 @@ static char *stropt_get_newval(int nextchar, int opt_idx, char **argp, void *var arg = save_arg; // arg was temporarily changed, restore it } *argp = arg; - *origval_arg = origval; - *origval_l_arg = origval_l; - *origval_g_arg = origval_g; - *oldval_arg = oldval; *op_arg = op; return newval; @@ -1207,8 +1130,7 @@ static void do_set_option_string(int opt_idx, int opt_flags, char **argp, int ne } // Get the new value for the option - char *newval = stropt_get_newval(nextchar, opt_idx, &arg, varp, &origval, - &origval_l, &origval_g, &oldval, &op, flags); + char *newval = stropt_get_newval(nextchar, opt_idx, &arg, varp, origval, &op, flags); // Set the new value. *(char **)(varp) = newval; @@ -5903,16 +5825,13 @@ bool can_bs(int what) if (what == BS_START && bt_prompt(curbuf)) { return false; } - switch (*p_bs) { - case '3': - return true; - case '2': + + // support for number values was removed but we keep '2' since it is used in + // legacy tests + if (*p_bs == '2') { return what != BS_NOSTOP; - case '1': - return what != BS_START; - case '0': - return false; } + return vim_strchr(p_bs, what) != NULL; } diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 3750574613..f07c05c113 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -1664,7 +1664,7 @@ const char *did_set_foldcolumn(optset_T *args) const char *did_set_backspace(optset_T *args FUNC_ATTR_UNUSED) { if (ascii_isdigit(*p_bs)) { - if (*p_bs > '3' || p_bs[1] != NUL) { + if (*p_bs != '2') { return e_invarg; } } else if (check_opt_strings(p_bs, p_bs_values, true) != OK) { diff --git a/src/nvim/path.c b/src/nvim/path.c index d1e0947038..3b36c2a550 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -847,7 +847,7 @@ static void expand_path_option(char *curdir, garray_T *gap) char *buf = xmalloc(MAXPATHL); while (*path_option != NUL) { - copy_option_part(&path_option, buf, MAXPATHL, " ,"); + copy_option_part(&path_option, buf, MAXPATHL, ","); if (buf[0] == '.' && (buf[1] == NUL || vim_ispathsep(buf[1]))) { // Relative to current buffer: diff --git a/src/nvim/plines.c b/src/nvim/plines.c index 73b15edb27..236a992bf9 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -600,16 +600,17 @@ static int win_nolbr_chartabsize(chartabsize_T *cts, int *headp) /// Get the number of screen lines a range of text will take in window "wp". /// -/// @param start_lnum Starting line number, 1-based inclusive. -/// @param start_vcol >= 0: Starting virtual column index on "start_lnum", -/// 0-based inclusive, rounded down to full screen lines. -/// < 0: Count a full "start_lnum", including filler lines above. -/// @param end_lnum Ending line number, 1-based inclusive. -/// @param end_vcol >= 0: Ending virtual column index on "end_lnum", -/// 0-based exclusive, rounded up to full screen lines. -/// < 0: Count a full "end_lnum", not including fillers lines below. +/// @param[in] start_lnum Starting line number, 1-based inclusive. +/// @param[in] start_vcol >= 0: Starting virtual column index on "start_lnum", +/// 0-based inclusive, rounded down to full screen lines. +/// < 0: Count a full "start_lnum", including filler lines above. +/// @param[in] end_lnum Ending line number, 1-based inclusive. +/// @param[in] end_vcol >= 0: Ending virtual column index on "end_lnum", +/// 0-based exclusive, rounded up to full screen lines. +/// < 0: Count a full "end_lnum", not including filler lines below. +/// @param[out] fill If not NULL, set to the number of filler lines in the range. int64_t win_text_height(win_T *const wp, const linenr_T start_lnum, const int64_t start_vcol, - const linenr_T end_lnum, const int64_t end_vcol) + const linenr_T end_lnum, const int64_t end_vcol, int64_t *const fill) { int width1 = 0; int width2 = 0; @@ -620,39 +621,44 @@ int64_t win_text_height(win_T *const wp, const linenr_T start_lnum, const int64_ width2 = MAX(width2, 0); } - int64_t height_sum = 0; + int64_t height_sum_fill = 0; int64_t height_cur_nofill = 0; + int64_t height_sum_nofill = 0; linenr_T lnum = start_lnum; if (start_vcol >= 0) { linenr_T lnum_next = lnum; const bool folded = hasFoldingWin(wp, lnum, &lnum, &lnum_next, true, NULL); height_cur_nofill = folded ? 1 : plines_win_nofill(wp, lnum, false); - height_sum += height_cur_nofill; + height_sum_nofill += height_cur_nofill; const int64_t row_off = (start_vcol < width1 || width2 <= 0) ? 0 : 1 + (start_vcol - width1) / width2; - height_sum -= MIN(row_off, height_cur_nofill); + height_sum_nofill -= MIN(row_off, height_cur_nofill); lnum = lnum_next + 1; } while (lnum <= end_lnum) { linenr_T lnum_next = lnum; const bool folded = hasFoldingWin(wp, lnum, &lnum, &lnum_next, true, NULL); + height_sum_fill += win_get_fill(wp, lnum); height_cur_nofill = folded ? 1 : plines_win_nofill(wp, lnum, false); - height_sum += win_get_fill(wp, lnum) + height_cur_nofill; + height_sum_nofill += height_cur_nofill; lnum = lnum_next + 1; } if (end_vcol >= 0) { - height_sum -= height_cur_nofill; + height_sum_nofill -= height_cur_nofill; const int64_t row_off = end_vcol == 0 ? 0 : (end_vcol <= width1 || width2 <= 0) ? 1 : 1 + (end_vcol - width1 + width2 - 1) / width2; - height_sum += MIN(row_off, height_cur_nofill); + height_sum_nofill += MIN(row_off, height_cur_nofill); } - return height_sum; + if (fill != NULL) { + *fill = height_sum_fill; + } + return height_sum_fill + height_sum_nofill; } diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 1479656bca..caa4674cef 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -766,7 +766,7 @@ void terminal_send_key(Terminal *term, int c) if (key) { vterm_keyboard_key(term->vt, key, mod); - } else { + } else if (!IS_SPECIAL(c)) { vterm_keyboard_unichar(term->vt, (uint32_t)c, mod); } } diff --git a/src/nvim/window.c b/src/nvim/window.c index 1a78918b09..e230bde95c 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1052,19 +1052,19 @@ void ui_ext_win_viewport(win_T *wp) || (cur_topline == last_topline && wp->w_skipcol < last_skipcol)) { if (last_topline > 0 && cur_botline < last_topline) { // Scrolling too many lines: only give an approximate "scroll_delta". - delta -= win_text_height(wp, cur_topline, wp->w_skipcol, cur_botline, 0); + delta -= win_text_height(wp, cur_topline, wp->w_skipcol, cur_botline, 0, NULL); delta -= last_topline - cur_botline; } else { - delta -= win_text_height(wp, cur_topline, wp->w_skipcol, last_topline, last_skipcol); + delta -= win_text_height(wp, cur_topline, wp->w_skipcol, last_topline, last_skipcol, NULL); } } else if (cur_topline > last_topline || (cur_topline == last_topline && wp->w_skipcol > last_skipcol)) { if (last_botline > 0 && cur_topline > last_botline) { // Scrolling too many lines: only give an approximate "scroll_delta". - delta += win_text_height(wp, last_topline, last_skipcol, last_botline, 0); + delta += win_text_height(wp, last_topline, last_skipcol, last_botline, 0, NULL); delta += cur_topline - last_botline; } else { - delta += win_text_height(wp, last_topline, last_skipcol, cur_topline, wp->w_skipcol); + delta += win_text_height(wp, last_topline, last_skipcol, cur_topline, wp->w_skipcol, NULL); } } delta += last_topfill; |