patch 9.0.1092: search error message doesn't show used pattern
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 #11742)
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 5b39808..693b0ac 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -1902,12 +1902,12 @@
#endif
/*
- * write current buffer to file 'eap->arg'
- * if 'eap->append' is TRUE, append to the file
+ * Write the 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)
@@ -4011,7 +4011,7 @@
return;
}
- if (search_regcomp(pat, RE_SUBST, which_pat, SEARCH_HIS, ®match) == FAIL)
+ if (search_regcomp(pat, NULL, RE_SUBST, which_pat, SEARCH_HIS, ®match) == FAIL)
{
if (subflags.do_error)
emsg(_(e_invalid_command));
@@ -5039,6 +5039,7 @@
char_u delim; // delimiter, normally '/'
char_u *pat;
+ char_u *used_pat;
regmmatch_T regmatch;
int match;
int which_pat;
@@ -5104,7 +5105,7 @@
*cmd++ = NUL; // replace it with a NUL
}
- if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL)
+ if (search_regcomp(pat, &used_pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL)
{
emsg(_(e_invalid_command));
return;
@@ -5148,16 +5149,16 @@
if (type == 'v')
{
if (in_vim9script())
- semsg(_(e_pattern_found_in_every_line_str), pat);
+ semsg(_(e_pattern_found_in_every_line_str), used_pat);
else
- smsg(_("Pattern found in every line: %s"), pat);
+ smsg(_("Pattern found in every line: %s"), used_pat);
}
else
{
if (in_vim9script())
- semsg(_(e_pattern_not_found_str), pat);
+ semsg(_(e_pattern_not_found_str), used_pat);
else
- smsg(_("Pattern not found: %s"), pat);
+ smsg(_("Pattern not found: %s"), used_pat);
}
}
else
diff --git a/src/proto/search.pro b/src/proto/search.pro
index 8fa01da..7a29ff3 100644
--- a/src/proto/search.pro
+++ b/src/proto/search.pro
@@ -1,5 +1,5 @@
/* search.c */
-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);
char_u *get_search_pat(void);
char_u *reverse_text(char_u *s);
void save_re_pat(int idx, char_u *pat, int magic);
diff --git a/src/search.c b/src/search.c
index ff4f419..219afd5 100644
--- a/src/search.c
+++ b/src/search.c
@@ -123,6 +123,7 @@
int
search_regcomp(
char_u *pat,
+ char_u **used_pat,
int pat_save,
int pat_use,
int options,
@@ -159,6 +160,9 @@
else if (options & SEARCH_HIS) // put new pattern in history
add_to_history(HIST_SEARCH, pat, TRUE, NUL);
+ if (used_pat)
+ *used_pat = pat;
+
vim_free(mr_pattern);
#ifdef FEAT_RIGHTLEFT
if (curwin->w_p_rl && *curwin->w_p_rlc == 's')
@@ -597,7 +601,7 @@
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;
}
#endif
@@ -661,7 +665,7 @@
int unused_timeout_flag = FALSE;
int *timed_out = &unused_timeout_flag; // set when 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)
@@ -2864,7 +2868,7 @@
if (pattern == NULL)
pattern = 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/testdir/test_global.vim b/src/testdir/test_global.vim
index 1c76642..34857b2 100644
--- a/src/testdir/test_global.vim
+++ b/src/testdir/test_global.vim
@@ -92,6 +92,18 @@
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/src/version.c b/src/version.c
index 5679588..53f0001 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1092,
+/**/
1091,
/**/
1090,