Patch 9.0.1092
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)
Files:      src/ex_cmds.c, src/search.c, src/proto/search.pro,
            src/testdir/test_global.vim


*** ../vim-9.0.1091/src/ex_cmds.c       2022-11-12 16:36:31.235201639 +0000
--- src/ex_cmds.c       2022-12-23 18:55:56.663392153 +0000
***************
*** 1902,1913 ****
  #endif
  
  /*
!  * write current buffer to file 'eap->arg'
!  * if 'eap->append' is TRUE, append to the file
   *
!  * if *eap->arg == NUL write to current file
   *
!  * return FAIL for failure, OK otherwise
   */
      int
  do_write(exarg_T *eap)
--- 1902,1913 ----
  #endif
  
  /*
!  * 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.
   *
!  * Return FAIL for failure, OK otherwise.
   */
      int
  do_write(exarg_T *eap)
***************
*** 4011,4017 ****
        return;
      }
  
!     if (search_regcomp(pat, RE_SUBST, which_pat, SEARCH_HIS, &regmatch) == 
FAIL)
      {
        if (subflags.do_error)
            emsg(_(e_invalid_command));
--- 4011,4017 ----
        return;
      }
  
!     if (search_regcomp(pat, NULL, RE_SUBST, which_pat, SEARCH_HIS, &regmatch) 
== FAIL)
      {
        if (subflags.do_error)
            emsg(_(e_invalid_command));
***************
*** 5039,5044 ****
--- 5039,5045 ----
  
      char_u    delim;          // delimiter, normally '/'
      char_u    *pat;
+     char_u    *used_pat;
      regmmatch_T       regmatch;
      int               match;
      int               which_pat;
***************
*** 5104,5110 ****
            *cmd++ = NUL;                   // replace it with a NUL
      }
  
!     if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, &regmatch) == 
FAIL)
      {
        emsg(_(e_invalid_command));
        return;
--- 5105,5111 ----
            *cmd++ = NUL;                   // replace it with a NUL
      }
  
!     if (search_regcomp(pat, &used_pat, RE_BOTH, which_pat, SEARCH_HIS, 
&regmatch) == FAIL)
      {
        emsg(_(e_invalid_command));
        return;
***************
*** 5148,5163 ****
            if (type == 'v')
            {
                if (in_vim9script())
!                   semsg(_(e_pattern_found_in_every_line_str), pat);
                else
!                   smsg(_("Pattern found in every line: %s"), pat);
            }
            else
            {
                if (in_vim9script())
!                   semsg(_(e_pattern_not_found_str), pat);
                else
!                   smsg(_("Pattern not found: %s"), pat);
            }
        }
        else
--- 5149,5164 ----
            if (type == 'v')
            {
                if (in_vim9script())
!                   semsg(_(e_pattern_found_in_every_line_str), used_pat);
                else
!                   smsg(_("Pattern found in every line: %s"), used_pat);
            }
            else
            {
                if (in_vim9script())
!                   semsg(_(e_pattern_not_found_str), used_pat);
                else
!                   smsg(_("Pattern not found: %s"), used_pat);
            }
        }
        else
*** ../vim-9.0.1091/src/search.c        2022-11-26 18:59:15.555251083 +0000
--- src/search.c        2022-12-23 18:55:56.663392153 +0000
***************
*** 123,128 ****
--- 123,129 ----
      int
  search_regcomp(
      char_u    *pat,
+     char_u    **used_pat,
      int               pat_save,
      int               pat_use,
      int               options,
***************
*** 159,164 ****
--- 160,168 ----
      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,603 ****
        return;
      }
      ++emsg_off;               // So it doesn't beep if bad expr
!     (void)search_regcomp((char_u *)"", 0, last_idx, SEARCH_KEEP, regmatch);
      --emsg_off;
  }
  #endif
--- 601,607 ----
        return;
      }
      ++emsg_off;               // So it doesn't beep if bad expr
!     (void)search_regcomp((char_u *)"", NULL, 0, last_idx, SEARCH_KEEP, 
regmatch);
      --emsg_off;
  }
  #endif
***************
*** 661,667 ****
      int               unused_timeout_flag = FALSE;
      int               *timed_out = &unused_timeout_flag;  // set when timed 
out.
  
!     if (search_regcomp(pat, RE_SEARCH, pat_use,
                   (options & (SEARCH_HIS + SEARCH_KEEP)), &regmatch) == FAIL)
      {
        if ((options & SEARCH_MSG) && !rc_did_emsg)
--- 665,671 ----
      int               unused_timeout_flag = FALSE;
      int               *timed_out = &unused_timeout_flag;  // set when timed 
out.
  
!     if (search_regcomp(pat, NULL, RE_SEARCH, pat_use,
                   (options & (SEARCH_HIS + SEARCH_KEEP)), &regmatch) == FAIL)
      {
        if ((options & SEARCH_MSG) && !rc_did_emsg)
***************
*** 2864,2870 ****
      if (pattern == NULL)
        pattern = spats[last_idx].pat;
  
!     if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH,
                                              SEARCH_KEEP, &regmatch) == FAIL)
        return -1;
  
--- 2868,2874 ----
      if (pattern == NULL)
        pattern = spats[last_idx].pat;
  
!     if (search_regcomp(pattern, NULL, RE_SEARCH, RE_SEARCH,
                                              SEARCH_KEEP, &regmatch) == FAIL)
        return -1;
  
*** ../vim-9.0.1091/src/proto/search.pro        2022-06-27 23:15:21.000000000 
+0100
--- src/proto/search.pro        2022-12-23 19:02:32.058858151 +0000
***************
*** 1,5 ****
  /* search.c */
! int search_regcomp(char_u *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);
--- 1,5 ----
  /* search.c */
! 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);
*** ../vim-9.0.1091/src/testdir/test_global.vim 2022-09-28 21:06:30.634345977 
+0100
--- src/testdir/test_global.vim 2022-12-23 18:55:56.663392153 +0000
***************
*** 92,97 ****
--- 92,109 ----
    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
*** ../vim-9.0.1091/src/version.c       2022-12-23 17:56:21.409511531 +0000
--- src/version.c       2022-12-23 19:01:58.998900959 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1092,
  /**/

-- 
FATHER:    You killed eight wedding guests in all!
LAUNCELOT: Er, Well ... the thing is ... I thought your son was a lady.
FATHER:    I can understand that.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221223190718.DF02E1C0AA3%40moolenaar.net.

Raspunde prin e-mail lui