From b935a12dab17c3887db9c5fd7c90b34b2c51170f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 29 Oct 2017 16:32:13 +0300 Subject: ex_getln: Make use of new parser to color expressions Retires g:Nvim_color_expr callback. --- src/nvim/ex_getln.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 7 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 54e5bcb9ff..386e9e81aa 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -66,6 +66,8 @@ #include "nvim/lib/kvec.h" #include "nvim/api/private/helpers.h" #include "nvim/highlight_defs.h" +#include "nvim/viml/parser/parser.h" +#include "nvim/viml/parser/expressions.h" /* * Variables shared between getcmdline(), redrawcmdline() and others. @@ -2341,6 +2343,62 @@ void free_cmdline_buf(void) enum { MAX_CB_ERRORS = 1 }; +/// Color expression cmdline using built-in expressions parser +/// +/// @param[in] colored_ccline Command-line to color. +/// @param[out] ret_ccline_colors What should be colored. +/// +/// Always colors the whole cmdline. +static void color_expr_cmdline(const CmdlineInfo *const colored_ccline, + ColoredCmdline *const ret_ccline_colors) + FUNC_ATTR_NONNULL_ALL +{ + ParserLine plines[] = { + { + .data = (const char *)colored_ccline->cmdbuff, + .size = STRLEN(colored_ccline->cmdbuff), + .allocated = false, + }, + { NULL, 0, false }, + }; + ParserLine *plines_p = plines; + ParserHighlight colors; + kvi_init(colors); + ParserState pstate; + viml_parser_init( + &pstate, parser_simple_get_line, &plines_p, &colors); + ExprAST east = viml_pexpr_parse(&pstate, kExprFlagsDisallowEOC); + viml_pexpr_free_ast(east); + viml_parser_destroy(&pstate); + kv_resize(ret_ccline_colors->colors, kv_size(colors)); + size_t prev_end = 0; + for (size_t i = 0 ; i < kv_size(colors) ; i++) { + const ParserHighlightChunk chunk = kv_A(colors, i); + if (chunk.start.col != prev_end) { + kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) { + .start = prev_end, + .end = chunk.start.col, + .attr = 0, + })); + } + const int id = syn_name2id((const char_u *)chunk.group); + const int attr = (id == 0 ? 0 : syn_id2attr(id)); + kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) { + .start = chunk.start.col, + .end = chunk.end_col, + .attr = attr, + })); + prev_end = chunk.end_col; + } + if (prev_end < (size_t)colored_ccline->cmdlen) { + kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) { + .start = prev_end, + .end = (size_t)colored_ccline->cmdlen, + .attr = 0, + })); + } +} + /// Color command-line /// /// Should use built-in command parser or user-specified one. Currently only the @@ -2422,13 +2480,8 @@ static bool color_cmdline(const CmdlineInfo *const colored_ccline, tl_ret = try_leave(&tstate, &err); can_free_cb = true; } else if (colored_ccline->cmdfirstc == '=') { - try_enter(&tstate); - err_errmsg = N_( - "E5409: Unable to get g:Nvim_color_expr callback: %s"); - dgc_ret = tv_dict_get_callback(&globvardict, S_LEN("Nvim_color_expr"), - &color_cb); - tl_ret = try_leave(&tstate, &err); - can_free_cb = true; + color_expr_cmdline(colored_ccline, ret_ccline_colors); + can_free_cb = false; } if (!tl_ret || !dgc_ret) { goto color_cmdline_error; -- cgit From 0356dbbb36ffa7934c35e9dbfc6667f9118c244f Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 30 Oct 2017 01:38:02 +0300 Subject: ex_getln: Fix variable name which is wrong after the merge --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 785038f5d6..f64efe08a1 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2500,7 +2500,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) tl_ret = try_leave(&tstate, &err); can_free_cb = true; } else if (colored_ccline->cmdfirstc == '=') { - color_expr_cmdline(colored_ccline, ret_ccline_colors); + color_expr_cmdline(colored_ccline, ccline_colors); can_free_cb = false; } if (!tl_ret || !dgc_ret) { -- cgit From f2660bee6aca35be3d0ddb1d225784476c13cd27 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 6 Nov 2017 20:20:31 +0300 Subject: *: Fix some typos found by oni-link --- src/nvim/ex_getln.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index f64efe08a1..3b751530e8 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2501,7 +2501,6 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) can_free_cb = true; } else if (colored_ccline->cmdfirstc == '=') { color_expr_cmdline(colored_ccline, ccline_colors); - can_free_cb = false; } if (!tl_ret || !dgc_ret) { goto color_cmdline_error; -- cgit From 731dc82f8c04e3019ecc3243b6b512535998635b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 19 Nov 2017 21:21:45 +0300 Subject: ex_getln: Fix memory leak in color_expr_cmdline --- src/nvim/ex_getln.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index e6fb2571c4..cabdda28cf 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2419,6 +2419,7 @@ static void color_expr_cmdline(const CmdlineInfo *const colored_ccline, .attr = 0, })); } + kvi_destroy(colors); } /// Color command-line -- cgit From ba7d6a9e6b3c42f1996d05cec471b4842eeb8b66 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 5 Dec 2017 13:27:06 +0100 Subject: ui: fix glitch with both ext_cmdline and cmd_wildmenu --- src/nvim/ex_getln.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c1500e3121..99330c177c 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3455,8 +3455,10 @@ nextwild ( return FAIL; } - MSG_PUTS("..."); /* show that we are busy */ - ui_flush(); + if (!ui_is_external(kUIWildmenu)) { + MSG_PUTS("..."); // show that we are busy + ui_flush(); + } i = (int)(xp->xp_pattern - ccline.cmdbuff); xp->xp_pattern_len = ccline.cmdpos - i; -- cgit From ac4bbf55f6d6b9b252dd90fe800626850022b690 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 22:04:43 +0300 Subject: *: Hide list implementation in other files as well --- src/nvim/ex_getln.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 1adc8325f8..fcd230d535 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2618,20 +2618,20 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) } varnumber_T prev_end = 0; int i = 0; - for (const listitem_T *li = tv.vval.v_list->lv_first; - li != NULL; li = li->li_next, i++) { - if (li->li_tv.v_type != VAR_LIST) { + TV_LIST_ITER_CONST(tv.vval.v_list, li, { + if (TV_LIST_ITEM_TV(li)->v_type != VAR_LIST) { PRINT_ERRMSG(_("E5401: List item %i is not a List"), i); goto color_cmdline_error; } - const list_T *const l = li->li_tv.vval.v_list; + const list_T *const l = TV_LIST_ITEM_TV(li)->vval.v_list; if (tv_list_len(l) != 3) { PRINT_ERRMSG(_("E5402: List item %i has incorrect length: %li /= 3"), i, tv_list_len(l)); goto color_cmdline_error; } bool error = false; - const varnumber_T start = tv_get_number_chk(&l->lv_first->li_tv, &error); + const varnumber_T start = ( + tv_get_number_chk(TV_LIST_ITEM_TV(tv_list_first(l)), &error)); if (error) { goto color_cmdline_error; } else if (!(prev_end <= start && start < colored_ccline->cmdlen)) { @@ -2651,8 +2651,8 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) .attr = 0, })); } - const varnumber_T end = tv_get_number_chk(&l->lv_first->li_next->li_tv, - &error); + const varnumber_T end = tv_get_number_chk( + TV_LIST_ITEM_TV(TV_LIST_ITEM_NEXT(l, tv_list_first(l))), &error); if (error) { goto color_cmdline_error; } else if (!(start < end && end <= colored_ccline->cmdlen)) { @@ -2668,7 +2668,8 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) goto color_cmdline_error; } prev_end = end; - const char *const group = tv_get_string_chk(&l->lv_last->li_tv); + const char *const group = tv_get_string_chk( + TV_LIST_ITEM_TV(tv_list_last(l))); if (group == NULL) { goto color_cmdline_error; } @@ -2679,7 +2680,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) .end = end, .attr = attr, })); - } + }); if (prev_end < colored_ccline->cmdlen) { kv_push(ccline_colors->colors, ((CmdlineColorChunk) { .start = prev_end, @@ -5021,24 +5022,24 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, */ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file) { - list_T *retlist; - listitem_T *li; - garray_T ga; - - retlist = call_user_expand_func((user_expand_func_T)call_func_retlist, xp, - num_file, file); + list_T *const retlist = call_user_expand_func( + (user_expand_func_T)call_func_retlist, xp, num_file, file); if (retlist == NULL) { return FAIL; } + garray_T ga; ga_init(&ga, (int)sizeof(char *), 3); - /* Loop over the items in the list. */ - for (li = retlist->lv_first; li != NULL; li = li->li_next) { - if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) - continue; /* Skip non-string items and empty strings */ + // Loop over the items in the list. + TV_LIST_ITER_CONST(retlist, li, { + if (TV_LIST_ITEM_TV(li)->v_type != VAR_STRING + || TV_LIST_ITEM_TV(li)->vval.v_string == NULL) { + continue; // Skip non-string items and empty strings. + } - GA_APPEND(char_u *, &ga, vim_strsave(li->li_tv.vval.v_string)); - } + GA_APPEND(char *, &ga, xstrdup( + (const char *)TV_LIST_ITEM_TV(li)->vval.v_string)); + }); tv_list_unref(retlist); *file = ga.ga_data; -- cgit From ceb45a08858837319c8ea67b1aaeceaeb24c8510 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 11 Dec 2017 01:43:36 +0300 Subject: *: Fix test failures --- src/nvim/ex_getln.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index fcd230d535..a5a8804e1c 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2680,6 +2680,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) .end = end, .attr = attr, })); + i++; }); if (prev_end < colored_ccline->cmdlen) { kv_push(ccline_colors->colors, ((CmdlineColorChunk) { -- cgit From 26251d6d0681194e7dc57fa2dfb8857576faed21 Mon Sep 17 00:00:00 2001 From: KunMing Xie Date: Tue, 16 Jan 2018 06:54:56 +0800 Subject: vim-patch:8.0.0374: invalid memory access when using :sc in Ex mode (#7849) Problem: Invalid memory access when using :sc in Ex mode. (Dominique Pelle) Solution: Avoid the column being negative. Also fix a hang in Ex mode. https://github.com/vim/vim/commit/ba748c8a847561c043a63827bcb1d98bdebe16e6 --- src/nvim/ex_getln.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index a5a8804e1c..82fac8d78e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2164,7 +2164,13 @@ getexmodeline ( /* Get one character at a time. Don't use inchar(), it can't handle * special characters. */ prev_char = c1; - c1 = vgetc(); + + // Check for a ":normal" command and no more characters left. + if (ex_normal_busy > 0 && typebuf.tb_len == 0) { + c1 = '\n'; + } else { + c1 = vgetc(); + } /* * Handle line editing. -- cgit From 06994e0e21eb5545aef7c2234f5d1a271865366e Mon Sep 17 00:00:00 2001 From: George Zhao Date: Wed, 17 Jan 2018 19:35:57 +0800 Subject: Fix warning about conversion on mingw64 --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 82fac8d78e..ade8b46956 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -738,7 +738,7 @@ static int command_line_execute(VimState *state, int key) } if (vim_ispathsep(ccline.cmdbuff[s->j]) #ifdef BACKSLASH_IN_FILENAME - && vim_strchr(" *?[{`$%#", ccline.cmdbuff[s->j + 1]) + && vim_strchr((const char_u *)" *?[{`$%#", ccline.cmdbuff[s->j + 1]) == NULL #endif ) { -- cgit From 6acbd76b004990701d9f4c29d9974b0a95e96cac Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Thu, 18 Jan 2018 01:49:42 +0100 Subject: Add completion for :checkhealth --- src/nvim/ex_getln.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 82fac8d78e..f0185d6825 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4257,20 +4257,20 @@ addstar ( * use with vim_regcomp(). First work out how long it will be: */ - /* For help tags the translation is done in find_help_tags(). - * For a tag pattern starting with "/" no translation is needed. */ + // For help tags the translation is done in find_help_tags(). + // For a tag pattern starting with "/" no translation is needed. if (context == EXPAND_HELP + || context == EXPAND_CHECKHEALTH || context == EXPAND_COLORS || context == EXPAND_COMPILER || context == EXPAND_OWNSYNTAX || context == EXPAND_FILETYPE || context == EXPAND_PACKADD - || ((context == EXPAND_TAGS_LISTFILES - || context == EXPAND_TAGS) - && fname[0] == '/')) + || ((context == EXPAND_TAGS_LISTFILES || context == EXPAND_TAGS) + && fname[0] == '/')) { retval = vim_strnsave(fname, len); - else { - new_len = len + 2; /* +2 for '^' at start, NUL at end */ + } else { + new_len = len + 2; // +2 for '^' at start, NUL at end for (i = 0; i < len; i++) { if (fname[i] == '*' || fname[i] == '~') new_len++; /* '*' needs to be replaced by ".*" @@ -4667,6 +4667,10 @@ ExpandFromContext ( char *directories[] = { "syntax", "indent", "ftplugin", NULL }; return ExpandRTDir(pat, 0, num_file, file, directories); } + if (xp->xp_context == EXPAND_CHECKHEALTH) { + char *directories[] = { "autoload/health", NULL }; + return ExpandRTDir(pat, 0, num_file, file, directories); + } if (xp->xp_context == EXPAND_USER_LIST) { return ExpandUserList(xp, num_file, file); } -- cgit From 41394d82365b504c89bb4da9ed5adc11c6f619f0 Mon Sep 17 00:00:00 2001 From: Ömer Sinan Ağacan Date: Mon, 30 Oct 2017 11:07:35 +0300 Subject: vim-patch:8.0.1238 Problem: Incremental search only shows one match. Solution: When 'incsearch' and and 'hlsearch' are both set highlight all matches. (haya14busa, closes vim/vim#2198) https://github.com/vim/vim/commit/2e51d9a0972080b087d566608472928d5b7b35d7 --- src/nvim/ex_getln.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 54bbe66620..81c6854459 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1019,13 +1019,18 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match) ui_flush(); pos_T t; - int search_flags = SEARCH_KEEP + SEARCH_NOOF + SEARCH_PEEK; + int search_flags = SEARCH_NOOF; + save_last_search_pattern(); + if (next_match) { t = s->match_end; search_flags += SEARCH_COL; } else { t = s->match_start; } + if (!p_hls) { + search_flags += SEARCH_KEEP; + } emsg_off++; s->i = searchit(curwin, curbuf, &t, next_match ? FORWARD : BACKWARD, @@ -1066,6 +1071,7 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match) s->old_topfill = curwin->w_topfill; s->old_botline = curwin->w_botline; update_screen(NOT_VALID); + restore_last_search_pattern(); redrawcmdline(); } else { vim_beep(BO_ERROR); @@ -1773,20 +1779,26 @@ static int command_line_changed(CommandLineState *s) } s->incsearch_postponed = false; curwin->w_cursor = s->search_start; // start at old position + save_last_search_pattern(); // If there is no command line, don't do anything if (ccline.cmdlen == 0) { s->i = 0; + SET_NO_HLSEARCH(true); // turn off previous highlight } else { + int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK; ui_busy_start(); ui_flush(); ++emsg_off; // So it doesn't beep if bad expr // Set the time limit to half a second. tm = profile_setlimit(500L); + if (!p_hls) { + search_flags += SEARCH_KEEP; + } s->i = do_search(NULL, s->firstc, ccline.cmdbuff, s->count, - SEARCH_KEEP + SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK, - &tm); - --emsg_off; + search_flags, + &tm); + emsg_off--; // if interrupted while searching, behave like it failed if (got_int) { (void)vpeekc(); // remove from input stream @@ -1836,6 +1848,7 @@ static int command_line_changed(CommandLineState *s) save_cmdline(&s->save_ccline); update_screen(SOME_VALID); restore_cmdline(&s->save_ccline); + restore_last_search_pattern(); // Leave it at the end to make CTRL-R CTRL-W work. if (s->i != 0) { -- cgit From cd973be11bfcdee286017f83e04c3d6c3be2f19a Mon Sep 17 00:00:00 2001 From: Ömer Sinan Ağacan Date: Fri, 3 Nov 2017 08:28:36 +0300 Subject: vim-patch:8.0.1250 Problem: 'hlsearch' highlighting not removed after incsearch (lacygoill) Solution: Redraw all windows. Start search at the end of the match. Improve how CTRL-G works with incremental search. Add tests. (Christian Brabandt, Hirohito Higashi, haya14busa, closes vim/vim#2267) https://github.com/vim/vim/commit/f8f8b2eadbaf3090fcfccbab560de5dbd501833d --- src/nvim/ex_getln.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 81c6854459..692a8893ae 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -426,7 +426,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) curwin->w_botline = s->old_botline; highlight_match = false; validate_cursor(); // needed for TAB - redraw_later(SOME_VALID); + redraw_all_later(SOME_VALID); } if (ccline.cmdbuff != NULL) { @@ -1024,6 +1024,11 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match) if (next_match) { t = s->match_end; + if (lt(s->match_start, s->match_end)) { + // start searching at the end of the match + // not at the beginning of the next column + (void)decl(&t); + } search_flags += SEARCH_COL; } else { t = s->match_start; @@ -1662,7 +1667,9 @@ static int command_line_handle_key(CommandLineState *s) if (char_avail()) { return 1; } - command_line_next_incsearch(s, s->c == Ctrl_G); + if (ccline.cmdlen != 0) { + command_line_next_incsearch(s, s->c == Ctrl_G); + } return command_line_not_changed(s); } break; @@ -1785,6 +1792,7 @@ static int command_line_changed(CommandLineState *s) if (ccline.cmdlen == 0) { s->i = 0; SET_NO_HLSEARCH(true); // turn off previous highlight + redraw_all_later(SOME_VALID); } else { int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK; ui_busy_start(); -- cgit From cd59577d576d71aa788a873ce779ce6dc3e7bc21 Mon Sep 17 00:00:00 2001 From: Ömer Sinan Ağacan Date: Sun, 21 Jan 2018 14:46:54 +0300 Subject: vim-patch:8.0.1396: memory leak when CTRL-G in search command line fails Problem: Memory leak when CTRL-G in search command line fails. Solution: Move restore_last_search_pattern to after "if". https://github.com/vim/vim/commit/a1d5c154dbd5fbe317726bbf2ba99632b91878f4 --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 692a8893ae..e396a179a1 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1076,11 +1076,11 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match) s->old_topfill = curwin->w_topfill; s->old_botline = curwin->w_botline; update_screen(NOT_VALID); - restore_last_search_pattern(); redrawcmdline(); } else { vim_beep(BO_ERROR); } + restore_last_search_pattern(); return; } -- cgit From 9bc1410ee1a467a8058a8de585c0e68d64ef8521 Mon Sep 17 00:00:00 2001 From: Ömer Sinan Ağacan Date: Sun, 21 Jan 2018 15:09:17 +0300 Subject: vim-patch:8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern Problem: CTRL-G/CTRL-T don't work with incsearch and empty pattern. Solution: Use the last search pattern. (Christian Brabandt, closes vim/vim#2292) https://github.com/vim/vim/commit/d0480097177369a6ed91d47aba189ae647afcd68 --- src/nvim/ex_getln.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index e396a179a1..2178505874 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1019,7 +1019,16 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match) ui_flush(); pos_T t; + char_u *pat; int search_flags = SEARCH_NOOF; + + + if (s->firstc == ccline.cmdbuff[0]) { + pat = last_search_pattern(); + } else { + pat = ccline.cmdbuff; + } + save_last_search_pattern(); if (next_match) { @@ -1039,7 +1048,7 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match) emsg_off++; s->i = searchit(curwin, curbuf, &t, next_match ? FORWARD : BACKWARD, - ccline.cmdbuff, s->count, search_flags, + pat, s->count, search_flags, RE_SEARCH, 0, NULL); emsg_off--; ui_busy_stop(); -- cgit From 87e03c2b85cef0b31eee5aab5078cd6457dd3c9b Mon Sep 17 00:00:00 2001 From: Ömer Sinan Ağacan Date: Sun, 21 Jan 2018 16:03:35 +0300 Subject: vim-patch:8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set Problem: Too much highlighting with 'hlsearch' and 'incsearch' set. Solution: Do not highlight matches when the pattern matches everything. https://github.com/vim/vim/commit/6621605eb97cf5fbc481282fd4d349a76e168f16 --- src/nvim/ex_getln.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 2178505874..a2f8994403 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1781,6 +1781,20 @@ static int command_line_not_changed(CommandLineState *s) return command_line_changed(s); } +/// Guess that the pattern matches everything. Only finds specific cases, such +/// as a trailing \|, which can happen while typing a pattern. +static int empty_pattern(char_u *p) +{ + int n = STRLEN(p); + + // remove trailing \v and the like + while (n >= 2 && p[n - 2] == '\\' + && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) { + n -= 2; + } + return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); +} + static int command_line_changed(CommandLineState *s) { // 'incsearch' highlighting. @@ -1856,6 +1870,13 @@ static int command_line_changed(CommandLineState *s) end_pos = curwin->w_cursor; // shutup gcc 4 } + + // Disable 'hlsearch' highlighting if the pattern matches8.0.1304 + // everything. Avoids a flash when typing "foo\|". + if (empty_pattern(ccline.cmdbuff)) { + SET_NO_HLSEARCH(true); + } + validate_cursor(); // May redraw the status line to show the cursor position. if (p_ru && curwin->w_status_height > 0) { -- cgit From 9a36337d32481e0324fe85e2b4886e02f8f74a2c Mon Sep 17 00:00:00 2001 From: Jakub Łuczyński Date: Mon, 29 Jan 2018 02:01:16 +0100 Subject: vim-patch:8.0.0528: highlight wrong text when 'wim' includes "longest" (#7927) Problem: When 'wildmenu' is set and 'wildmode' has "longest" then the first file name is highlighted, even though the text shows the longest match. Solution: Do not highlight the first match. (LemonBoy, closes vim/vim#1602) https://github.com/vim/vim/commit/ef8eb0897819099fb00d675afb9bffe1d008c45e --- src/nvim/ex_getln.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 54bbe66620..c4e0827dad 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4058,12 +4058,12 @@ static int showmatches(expand_T *xp, int wildmenu) msg_start(); /* prepare for paging */ } - if (got_int) - got_int = FALSE; /* only int. the completion, not the cmd line */ - else if (wildmenu) - win_redr_status_matches(xp, num_files, files_found, 0, showtail); - else { - /* find the length of the longest file name */ + if (got_int) { + got_int = false; // only int. the completion, not the cmd line + } else if (wildmenu) { + win_redr_status_matches(xp, num_files, files_found, -1, showtail); + } else { + // find the length of the longest file name maxlen = 0; for (i = 0; i < num_files; ++i) { if (!showtail && (xp->xp_context == EXPAND_FILES -- cgit From 5d8da126d0b5ab7f550a74264ba434a2ad04280e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 6 Feb 2018 19:46:45 +0100 Subject: ui/tui: highlighting refactor Make HlAttr contain highlighting state for both color modes (cterm and rgb). This allows us to implement termguicolors completely in the TUI. Simplify some logic duplicated between ui.c and screen.c. Also avoid some superfluous highlighting reset events. --- src/nvim/ex_getln.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ba51f18518..40b4cc6d79 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2929,11 +2929,11 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) Array item = ARRAY_DICT_INIT; if (chunk.attr) { - attrentry_T *aep = syn_cterm_attr2entry(chunk.attr); + HlAttrs *aep = syn_cterm_attr2entry(chunk.attr); // TODO(bfredl): this desicion could be delayed by making attr_code a // recognized type - HlAttrs rgb_attrs = attrentry2hlattrs(aep, true); - ADD(item, DICTIONARY_OBJ(hlattrs2dict(rgb_attrs))); + Dictionary rgb_attrs = hlattrs2dict(aep, true); + ADD(item, DICTIONARY_OBJ(rgb_attrs)); } else { ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); } -- cgit From ca24ad0b95c7f6360b3c4b732911558361bff3fe Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 1 Feb 2018 23:46:04 +0100 Subject: vim-patch:8.0.0689: ~ character not escaped when extending search pattern Problem: The ~ character is not escaped when adding to the search pattern with CTRL-L. (Ramel Eshed) Solution: Escape the character. (Christian Brabandt) https://github.com/vim/vim/commit/a693d0584b9a7ccce98813dda3a6badb209904c7 --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 40b4cc6d79..bbe1d22473 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1549,7 +1549,7 @@ static int command_line_handle_key(CommandLineState *s) } if (s->c != NUL) { if (s->c == s->firstc - || vim_strchr((char_u *)(p_magic ? "\\^$.*[" : "\\^$"), s->c) + || vim_strchr((char_u *)(p_magic ? "\\~^$.*[" : "\\^$"), s->c) != NULL) { // put a backslash before special characters stuffcharReadbuff(s->c); -- cgit From 7d12597d29e60239fd5c586417b48982893c174e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 1 Feb 2018 23:50:12 +0100 Subject: vim-patch:8.0.0692: CTRL-G with 'incsearch' and ? goes in the wrong direction Problem: Using CTRL-G with 'incsearch' and ? goes in the wrong direction. (Ramel Eshed) Solution: Adjust search_start. (Christian Brabandt) https://github.com/vim/vim/commit/da5116da4586fc714434411d2cccb066caa3723e --- src/nvim/ex_getln.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index bbe1d22473..c99ae687bb 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1063,6 +1063,13 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match) s->search_start = t; (void)decl(&s->search_start); } + else if (next_match && s->firstc == '?') { + // move just after the current match, so that + // when nv_search finishes the cursor will be + // put back on the match + s->search_start = t; + (void)incl(&s->search_start); + } if (lt(t, s->search_start) && next_match) { // wrap around s->search_start = t; -- cgit From cebf31cf705e32ed3b3ac2202884ab6b360f6c52 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 2 Feb 2018 23:26:16 +0100 Subject: vim-patch:8.0.1210: CTRL-G and CTRL-T are ignored with typeahead Problem: When typing a search pattern CTRL-G and CTRL-T are ignored when there is typeahead. Solution: Don't pass SEARCH_PEEK and don't call char_avail(). (haya14busa, closes vim/vim#2233) https://github.com/vim/vim/commit/f8e8c0643b1cd97db11912bc4f773e1328a0da02 --- src/nvim/ex_getln.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c99ae687bb..6b13a57980 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -443,14 +443,8 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) } } - if (s->gotesc) { // abandon command line - xfree(ccline.cmdbuff); - ccline.cmdbuff = NULL; - if (msg_scrolled == 0) { - compute_cmdrow(); - } - MSG(""); - redraw_cmdline = true; + if (s->gotesc) { + abandon_cmdline(); } } @@ -1680,9 +1674,6 @@ static int command_line_handle_key(CommandLineState *s) case Ctrl_G: // next match case Ctrl_T: // previous match if (p_is && !cmd_silent && (s->firstc == '/' || s->firstc == '?')) { - if (char_avail()) { - return 1; - } if (ccline.cmdlen != 0) { command_line_next_incsearch(s, s->c == Ctrl_G); } @@ -1948,6 +1939,18 @@ static int command_line_changed(CommandLineState *s) return 1; } +/// Abandon the command line. +static void abandon_cmdline(void) +{ + xfree(ccline.cmdbuff); + ccline.cmdbuff = NULL; + if (msg_scrolled == 0) { + compute_cmdrow(); + } + MSG(""); + redraw_cmdline = true; +} + /* * getcmdline() - accept a command line starting with firstc. * -- cgit From f26a4d484b486019c90fc55af5e74e33de374bc4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 11 Feb 2018 19:02:57 +0100 Subject: lint --- src/nvim/ex_getln.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 6b13a57980..07aab3307a 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1056,8 +1056,7 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match) // put back on the match s->search_start = t; (void)decl(&s->search_start); - } - else if (next_match && s->firstc == '?') { + } else if (next_match && s->firstc == '?') { // move just after the current match, so that // when nv_search finishes the cursor will be // put back on the match -- cgit From d9497053e84aaf3dabecd362da19913811e8c22e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 13 Feb 2018 19:47:27 +0100 Subject: ex_getln: clear cmdline_block after it's freed --- src/nvim/ex_getln.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 07aab3307a..dd7504c05e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -194,7 +194,8 @@ static int cmd_showtail; /* Only show path tail in lists ? */ static int new_cmdpos; /* position set by set_cmdline_pos() */ -static Array cmdline_block; ///< currently displayed block of context +/// currently displayed block of context +static Array cmdline_block = ARRAY_DICT_INIT; /* * Type used by call_user_expand_func @@ -2990,6 +2991,7 @@ void ui_ext_cmdline_block_append(int indent, const char *line) void ui_ext_cmdline_block_leave(void) { api_free_array(cmdline_block); + cmdline_block = (Array)ARRAY_DICT_INIT; ui_call_cmdline_block_hide(); } -- cgit From d407a48665d8f8e1e42eb1060ea245d979419605 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 14 Mar 2016 23:58:47 +0100 Subject: getchar: implement key to invoke command in any mode --- src/nvim/ex_getln.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index dd7504c05e..ccd00f2097 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -512,8 +512,12 @@ static int command_line_execute(VimState *state, int key) CommandLineState *s = (CommandLineState *)state; s->c = key; - if (s->c == K_EVENT) { - multiqueue_process_events(main_loop.events); + if (s->c == K_EVENT || s->c == K_COMMAND) { + if (s->c == K_EVENT) { + multiqueue_process_events(main_loop.events); + } else { + do_cmdline(NULL, getcmdkeycmd, NULL, DOCMD_NOWAIT); + } redrawcmdline(); return 1; } -- cgit From 998a16c926623a667ecb0228f4a6cd8ba1e90201 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 24 Mar 2018 11:21:20 +0100 Subject: refactor/rename: path_is_absolute() --- src/nvim/ex_getln.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index dd7504c05e..9601e0f3b2 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4923,13 +4923,14 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; bool mustfree = false; // Track memory allocation for *path. - /* For an absolute name we don't use $PATH. */ - if (path_is_absolute_path(pat)) + // For an absolute name we don't use $PATH. + if (path_is_absolute(pat)) { path = (char_u *)" "; - else if ((pat[0] == '.' && (vim_ispathsep(pat[1]) - || (pat[1] == '.' && vim_ispathsep(pat[2]))))) + } else if (pat[0] == '.' && (vim_ispathsep(pat[1]) + || (pat[1] == '.' + && vim_ispathsep(pat[2])))) { path = (char_u *)"."; - else { + } else { path = (char_u *)vim_getenv("PATH"); if (path == NULL) { path = (char_u *)""; -- cgit