]> granicus.if.org Git - vim/commitdiff
patch 9.0.1092: search error message doesn't show used pattern v9.0.1092
authorRob Pilling <robpilling@gmail.com>
Fri, 23 Dec 2022 19:06:04 +0000 (19:06 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 23 Dec 2022 19:06:04 +0000 (19:06 +0000)
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)

src/ex_cmds.c
src/proto/search.pro
src/search.c
src/testdir/test_global.vim
src/version.c

index 5b398089fd5762162feeaa4c5b376c32d8bda7cf..693b0acace968434a21e87c29490250fbbe599c3 100644 (file)
@@ -1902,12 +1902,12 @@ check_writable(char_u *fname)
 #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 @@ ex_substitute(exarg_T *eap)
        return;
     }
 
-    if (search_regcomp(pat, RE_SUBST, which_pat, SEARCH_HIS, &regmatch) == FAIL)
+    if (search_regcomp(pat, NULL, RE_SUBST, which_pat, SEARCH_HIS, &regmatch) == FAIL)
     {
        if (subflags.do_error)
            emsg(_(e_invalid_command));
@@ -5039,6 +5039,7 @@ ex_global(exarg_T *eap)
 
     char_u     delim;          // delimiter, normally '/'
     char_u     *pat;
+    char_u     *used_pat;
     regmmatch_T        regmatch;
     int                match;
     int                which_pat;
@@ -5104,7 +5105,7 @@ ex_global(exarg_T *eap)
            *cmd++ = NUL;                   // replace it with a NUL
     }
 
-    if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, &regmatch) == FAIL)
+    if (search_regcomp(pat, &used_pat, RE_BOTH, which_pat, SEARCH_HIS, &regmatch) == FAIL)
     {
        emsg(_(e_invalid_command));
        return;
@@ -5148,16 +5149,16 @@ ex_global(exarg_T *eap)
            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
index 8fa01da9b94928cda69fd15c00bb1c2d5f673b4c..7a29ff3a03cec1c353fc94f025cf2ec70dee6685 100644 (file)
@@ -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);
index ff4f419da3b8b030570454934b3ac275dcdfb4a8..219afd5755c075df7afac94e4a9a0f007a846acf 100644 (file)
@@ -123,6 +123,7 @@ typedef struct SearchedFile
     int
 search_regcomp(
     char_u     *pat,
+    char_u     **used_pat,
     int                pat_save,
     int                pat_use,
     int                options,
@@ -159,6 +160,9 @@ search_regcomp(
     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 @@ 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;
 }
 #endif
@@ -661,7 +665,7 @@ searchit(
     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)), &regmatch) == FAIL)
     {
        if ((options & SEARCH_MSG) && !rc_did_emsg)
@@ -2864,7 +2868,7 @@ is_zero_width(char_u *pattern, int move, pos_T *cur, int direction)
     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, &regmatch) == FAIL)
        return -1;
 
index 1c76642a18f70401c4bd6479ed401ce0d7dc73eb..34857b25554131cac21309bde1e3a8f70728581d 100644 (file)
@@ -92,6 +92,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
index 5679588336857f9ea5b11296f301abd167528a93..53f00014bb737c820d8d167714b6fccf81a6d37c 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1092,
 /**/
     1091,
 /**/