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)
#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)
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));
char_u delim; // delimiter, normally '/'
char_u *pat;
+ char_u *used_pat;
regmmatch_T regmatch;
int match;
int which_pat;
*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;
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
/* 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);
int
search_regcomp(
char_u *pat,
+ char_u **used_pat,
int pat_save,
int pat_use,
int options,
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')
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
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)
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;
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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1092,
/**/
1091,
/**/