diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-12-24 07:55:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-24 07:55:03 +0800 |
commit | 3b9bd7bd439a31f393746e01e25291dd0543630d (patch) | |
tree | 46627d70f3c517991744caf0cd8def202441b7ed | |
parent | 3ea1524cf8a7d80d1034011462fd9611fdf385f1 (diff) | |
download | rneovim-3b9bd7bd439a31f393746e01e25291dd0543630d.tar.gz rneovim-3b9bd7bd439a31f393746e01e25291dd0543630d.tar.bz2 rneovim-3b9bd7bd439a31f393746e01e25291dd0543630d.zip |
vim-patch:9.0.1092: search error message doesn't show used pattern (#21518)
Problem: Search error message doesn't show used pattern.
Solution: Pass the actually used pattern to where the error message is
given. (Rob Pilling, closes vim/vim#11742)
https://github.com/vim/vim/commit/e86190e7c1297da29d0fc2415fdeca5ecae8d2ba
Co-authored-by: Rob Pilling <robpilling@gmail.com>
-rw-r--r-- | src/nvim/ex_cmds.c | 20 | ||||
-rw-r--r-- | src/nvim/search.c | 13 | ||||
-rw-r--r-- | src/nvim/testdir/test_global.vim | 12 | ||||
-rw-r--r-- | test/unit/search_spec.lua | 2 |
4 files changed, 33 insertions, 14 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 5eb5359e90..4167d1d182 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1618,12 +1618,12 @@ static int check_writable(const char *fname) } #endif -/// write current buffer to file 'eap->arg' -/// if 'eap->append' is true, append to the file +/// Write current buffer to file "eap->arg". +/// If "eap->append" is true, append to the file. /// -/// if *eap->arg == NUL write to current file +/// If "*eap->arg == NUL" write to current file. /// -/// @return FAIL for failure, OK otherwise +/// @return FAIL for failure, OK otherwise. int do_write(exarg_T *eap) { int other; @@ -3443,8 +3443,8 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T return 0; } - if (search_regcomp((char_u *)pat, RE_SUBST, which_pat, (cmdpreview ? 0 : SEARCH_HIS), - ®match) == FAIL) { + if (search_regcomp((char_u *)pat, NULL, RE_SUBST, which_pat, + (cmdpreview ? 0 : SEARCH_HIS), ®match) == FAIL) { if (subflags.do_error) { emsg(_(e_invcmd)); } @@ -4398,7 +4398,9 @@ void ex_global(exarg_T *eap) } } - if (search_regcomp((char_u *)pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) { + char_u *used_pat; + if (search_regcomp((char_u *)pat, &used_pat, RE_BOTH, which_pat, + SEARCH_HIS, ®match) == FAIL) { emsg(_(e_invcmd)); return; } @@ -4429,9 +4431,9 @@ void ex_global(exarg_T *eap) msg(_(e_interr)); } else if (ndone == 0) { if (type == 'v') { - smsg(_("Pattern found in every line: %s"), pat); + smsg(_("Pattern found in every line: %s"), used_pat); } else { - smsg(_("Pattern not found: %s"), pat); + smsg(_("Pattern not found: %s"), used_pat); } } else { global_exe(cmd); diff --git a/src/nvim/search.c b/src/nvim/search.c index 009e8b4e19..e49535f484 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -132,7 +132,8 @@ typedef struct SearchedFile { /// @param regmatch return: pattern and ignore-case flag /// /// @return FAIL if failed, OK otherwise. -int search_regcomp(char_u *pat, int pat_save, int pat_use, int options, regmmatch_T *regmatch) +int search_regcomp(char_u *pat, char_u **used_pat, int pat_save, int pat_use, int options, + regmmatch_T *regmatch) { int magic; int i; @@ -163,6 +164,10 @@ int search_regcomp(char_u *pat, int pat_save, int pat_use, int options, regmmatc add_to_history(HIST_SEARCH, (char *)pat, true, NUL); } + if (used_pat) { + *used_pat = pat; + } + if (mr_pattern_alloced) { xfree(mr_pattern); mr_pattern_alloced = false; @@ -509,7 +514,7 @@ void last_pat_prog(regmmatch_T *regmatch) return; } emsg_off++; // So it doesn't beep if bad expr - (void)search_regcomp((char_u *)"", 0, last_idx, SEARCH_KEEP, regmatch); + (void)search_regcomp((char_u *)"", NULL, 0, last_idx, SEARCH_KEEP, regmatch); emsg_off--; } @@ -567,7 +572,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, timed_out = &extra_arg->sa_timed_out; } - if (search_regcomp(pat, RE_SEARCH, pat_use, + if (search_regcomp(pat, NULL, RE_SEARCH, pat_use, (options & (SEARCH_HIS + SEARCH_KEEP)), ®match) == FAIL) { if ((options & SEARCH_MSG) && !rc_did_emsg) { semsg(_("E383: Invalid search string: %s"), mr_pattern); @@ -2523,7 +2528,7 @@ static int is_zero_width(char_u *pattern, int move, pos_T *cur, Direction direct pattern = (char_u *)spats[last_idx].pat; } - if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH, + if (search_regcomp(pattern, NULL, RE_SEARCH, RE_SEARCH, SEARCH_KEEP, ®match) == FAIL) { return -1; } diff --git a/src/nvim/testdir/test_global.vim b/src/nvim/testdir/test_global.vim index 8fb4ee0cfa..44a8784348 100644 --- a/src/nvim/testdir/test_global.vim +++ b/src/nvim/testdir/test_global.vim @@ -72,6 +72,18 @@ func Test_global_print() close! endfunc +func Test_global_empty_pattern() + " populate history + silent g/hello/ + + redir @a + g// + redir END + + call assert_match('Pattern not found: hello', @a) + " ^~~~~ this was previously empty +endfunc + " Test for global command with newline character func Test_global_newline() new diff --git a/test/unit/search_spec.lua b/test/unit/search_spec.lua index ce37ebfc3a..be905bf5f0 100644 --- a/test/unit/search_spec.lua +++ b/test/unit/search_spec.lua @@ -37,7 +37,7 @@ end) describe('search_regcomp', function() local search_regcomp = function(pat, pat_save, pat_use, options ) local regmatch = ffi.new("regmmatch_T") - local fail = search.search_regcomp(to_cstr(pat), pat_save, pat_use, options, regmatch) + local fail = search.search_regcomp(to_cstr(pat), nil, pat_save, pat_use, options, regmatch) return fail, regmatch end |