Patch 8.2.2182
Problem:    Vim9: value of 'magic' is still relevant.
Solution:   Always behave like 'magic' is on in Vim9 script (closes #7509)
Files:      src/option.c, src/proto/option.pro, src/arglist.c, src/buffer.c,
            src/cmdexpand.c, src/ex_cmds.c, src/ex_docmd.c, src/ex_getln.c,
            src/insexpand.c, src/normal.c, src/search.c, src/tag.c,
            src/structs.h, src/globals.h, src/ex_cmds.h,
            src/testdir/test_vim9_cmd.vim


*** ../vim-8.2.2181/src/option.c        2020-10-24 20:49:37.498683038 +0200
--- src/option.c        2020-12-21 19:11:25.553333603 +0100
***************
*** 6996,6998 ****
--- 6996,7017 ----
      return OK;
  }
  #endif
+ 
+ /*
+  * Get the value of 'magic' adjusted for Vim9 script.
+  */
+     int
+ magic_isset(void)
+ {
+     switch (magic_overruled)
+     {
+       case MAGIC_ON:      return TRUE;
+       case MAGIC_OFF:     return FALSE;
+       case MAGIC_NOT_SET: break;
+     }
+ #ifdef FEAT_EVAL
+     if (in_vim9script())
+       return TRUE;
+ #endif
+     return p_magic;
+ }
*** ../vim-8.2.2181/src/proto/option.pro        2020-05-01 14:26:17.132949262 
+0200
--- src/proto/option.pro        2020-12-21 18:58:18.012051532 +0100
***************
*** 75,78 ****
--- 75,79 ----
  char_u *get_showbreak_value(win_T *win);
  dict_T *get_winbuf_options(int bufopt);
  int fill_culopt_flags(char_u *val, win_T *wp);
+ int magic_isset(void);
  /* vim: set ft=c : */
*** ../vim-8.2.2181/src/arglist.c       2020-10-24 20:49:37.490683063 +0200
--- src/arglist.c       2020-12-21 18:57:53.296137618 +0100
***************
*** 409,415 ****
            p = file_pat_to_reg_pat(p, NULL, NULL, FALSE);
            if (p == NULL)
                break;
!           regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0);
            if (regmatch.regprog == NULL)
            {
                vim_free(p);
--- 409,415 ----
            p = file_pat_to_reg_pat(p, NULL, NULL, FALSE);
            if (p == NULL)
                break;
!           regmatch.regprog = vim_regcomp(p, magic_isset() ? RE_MAGIC : 0);
            if (regmatch.regprog == NULL)
            {
                vim_free(p);
*** ../vim-8.2.2181/src/buffer.c        2020-11-24 19:36:12.718255326 +0100
--- src/buffer.c        2020-12-21 18:58:37.739982886 +0100
***************
*** 2605,2611 ****
                p = pat;
                if (*p == '^' && !(attempt & 1))         // add/remove '^'
                    ++p;
!               regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0);
                if (regmatch.regprog == NULL)
                {
                    vim_free(pat);
--- 2605,2611 ----
                p = pat;
                if (*p == '^' && !(attempt & 1))         // add/remove '^'
                    ++p;
!               regmatch.regprog = vim_regcomp(p, magic_isset() ? RE_MAGIC : 0);
                if (regmatch.regprog == NULL)
                {
                    vim_free(pat);
*** ../vim-8.2.2181/src/cmdexpand.c     2020-12-18 19:49:52.337571884 +0100
--- src/cmdexpand.c     2020-12-21 18:59:26.911811948 +0100
***************
*** 1391,1397 ****
                if (*arg != NUL)
                {
                    xp->xp_context = EXPAND_NOTHING;
!                   arg = skip_regexp(arg + 1, *arg, p_magic);
                }
            }
            return find_nextcmd(arg);
--- 1391,1397 ----
                if (*arg != NUL)
                {
                    xp->xp_context = EXPAND_NOTHING;
!                   arg = skip_regexp(arg + 1, *arg, magic_isset());
                }
            }
            return find_nextcmd(arg);
***************
*** 1429,1435 ****
            {
                // skip "from" part
                ++arg;
!               arg = skip_regexp(arg, delim, p_magic);
            }
            // skip "to" part
            while (arg[0] != NUL && arg[0] != delim)
--- 1429,1435 ----
            {
                // skip "from" part
                ++arg;
!               arg = skip_regexp(arg, delim, magic_isset());
            }
            // skip "to" part
            while (arg[0] != NUL && arg[0] != delim)
***************
*** 2077,2083 ****
        pat = tofree;
      }
  
!     regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
      if (regmatch.regprog == NULL)
        return FAIL;
  
--- 2077,2083 ----
        pat = tofree;
      }
  
!     regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0);
      if (regmatch.regprog == NULL)
        return FAIL;
  
*** ../vim-8.2.2181/src/ex_cmds.c       2020-12-18 19:49:52.337571884 +0100
--- src/ex_cmds.c       2020-12-21 19:00:30.907589908 +0100
***************
*** 3671,3677 ****
            which_pat = RE_LAST;            // use last used regexp
            delimiter = *cmd++;             // remember delimiter character
            pat = cmd;                      // remember start of search pat
!           cmd = skip_regexp_ex(cmd, delimiter, p_magic, &eap->arg, NULL);
            if (cmd[0] == delimiter)        // end delimiter found
                *cmd++ = NUL;               // replace it with a NUL
        }
--- 3671,3678 ----
            which_pat = RE_LAST;            // use last used regexp
            delimiter = *cmd++;             // remember delimiter character
            pat = cmd;                      // remember start of search pat
!           cmd = skip_regexp_ex(cmd, delimiter, magic_isset(),
!                                                             &eap->arg, NULL);
            if (cmd[0] == delimiter)        // end delimiter found
                *cmd++ = NUL;               // replace it with a NUL
        }
***************
*** 3763,3769 ****
        }
  
        if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0)
!           save_re_pat(RE_SUBST, pat, p_magic);
        // put pattern in history
        add_to_history(HIST_SEARCH, pat, TRUE, NUL);
  
--- 3764,3770 ----
        }
  
        if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0)
!           save_re_pat(RE_SUBST, pat, magic_isset());
        // put pattern in history
        add_to_history(HIST_SEARCH, pat, TRUE, NUL);
  
***************
*** 3897,3903 ****
       * But don't do it when it starts with "\=", then it's an expression.
       */
      if (!(sub[0] == '\\' && sub[1] == '='))
!       sub = regtilde(sub, p_magic);
  
      /*
       * Check for a match on each line.
--- 3898,3904 ----
       * But don't do it when it starts with "\=", then it's an expression.
       */
      if (!(sub[0] == '\\' && sub[1] == '='))
!       sub = regtilde(sub, magic_isset());
  
      /*
       * Check for a match on each line.
***************
*** 4309,4315 ****
                // get length of substitution part
                sublen = vim_regsub_multi(&regmatch,
                                    sub_firstlnum - regmatch.startpos[0].lnum,
!                                   sub, sub_firstline, FALSE, p_magic, TRUE);
  #ifdef FEAT_EVAL
                // If getting the substitute string caused an error, don't do
                // the replacement.
--- 4310,4316 ----
                // get length of substitution part
                sublen = vim_regsub_multi(&regmatch,
                                    sub_firstlnum - regmatch.startpos[0].lnum,
!                              sub, sub_firstline, FALSE, magic_isset(), TRUE);
  #ifdef FEAT_EVAL
                // If getting the substitute string caused an error, don't do
                // the replacement.
***************
*** 4413,4419 ****
  
                (void)vim_regsub_multi(&regmatch,
                                    sub_firstlnum - regmatch.startpos[0].lnum,
!                                          sub, new_end, TRUE, p_magic, TRUE);
                sub_nsubs++;
                did_sub = TRUE;
  
--- 4414,4420 ----
  
                (void)vim_regsub_multi(&regmatch,
                                    sub_firstlnum - regmatch.startpos[0].lnum,
!                                     sub, new_end, TRUE, magic_isset(), TRUE);
                sub_nsubs++;
                did_sub = TRUE;
  
***************
*** 4846,4852 ****
        if (delim)
            ++cmd;              // skip delimiter if there is one
        pat = cmd;              // remember start of pattern
!       cmd = skip_regexp_ex(cmd, delim, p_magic, &eap->arg, NULL);
        if (cmd[0] == delim)                // end delimiter found
            *cmd++ = NUL;                   // replace it with a NUL
      }
--- 4847,4853 ----
        if (delim)
            ++cmd;              // skip delimiter if there is one
        pat = cmd;              // remember start of pattern
!       cmd = skip_regexp_ex(cmd, delim, magic_isset(), &eap->arg, NULL);
        if (cmd[0] == delim)                // end delimiter found
            *cmd++ = NUL;                   // replace it with a NUL
      }
*** ../vim-8.2.2181/src/ex_docmd.c      2020-12-19 22:10:09.857835454 +0100
--- src/ex_docmd.c      2020-12-21 19:20:56.192372800 +0100
***************
*** 3951,3957 ****
                }
                if (skip)       // skip "/pat/"
                {
!                   cmd = skip_regexp(cmd, c, (int)p_magic);
                    if (*cmd == c)
                        ++cmd;
                }
--- 3951,3957 ----
                }
                if (skip)       // skip "/pat/"
                {
!                   cmd = skip_regexp(cmd, c, magic_isset());
                    if (*cmd == c)
                        ++cmd;
                }
***************
*** 6535,6543 ****
      {
        // ":open /pattern/": put cursor in column found with pattern
        ++eap->arg;
!       p = skip_regexp(eap->arg, '/', p_magic);
        *p = NUL;
!       regmatch.regprog = vim_regcomp(eap->arg, p_magic ? RE_MAGIC : 0);
        if (regmatch.regprog != NULL)
        {
            regmatch.rm_ic = p_ic;
--- 6535,6543 ----
      {
        // ":open /pattern/": put cursor in column found with pattern
        ++eap->arg;
!       p = skip_regexp(eap->arg, '/', magic_isset());
        *p = NUL;
!       regmatch.regprog = vim_regcomp(eap->arg, magic_isset() ? RE_MAGIC : 0);
        if (regmatch.regprog != NULL)
        {
            regmatch.rm_ic = p_ic;
***************
*** 7529,7539 ****
      static void
  ex_submagic(exarg_T *eap)
  {
!     int               magic_save = p_magic;
  
!     p_magic = (eap->cmdidx == CMD_smagic);
      ex_substitute(eap);
!     p_magic = magic_save;
  }
  
  /*
--- 7529,7539 ----
      static void
  ex_submagic(exarg_T *eap)
  {
!     magic_T saved = magic_overruled;
  
!     magic_overruled = eap->cmdidx == CMD_smagic ? MAGIC_ON : MAGIC_OFF;
      ex_substitute(eap);
!     magic_overruled = saved;
  }
  
  /*
***************
*** 8333,8339 ****
      {
        whole = FALSE;
        ++eap->arg;
!       p = skip_regexp(eap->arg, '/', p_magic);
        if (*p)
        {
            *p++ = NUL;
--- 8333,8339 ----
      {
        whole = FALSE;
        ++eap->arg;
!       p = skip_regexp(eap->arg, '/', magic_isset());
        if (*p)
        {
            *p++ = NUL;
*** ../vim-8.2.2181/src/ex_getln.c      2020-12-03 19:54:38.177924280 +0100
--- src/ex_getln.c      2020-12-21 19:23:04.276075101 +0100
***************
*** 149,155 ****
      pos_T     match_end;
      int               did_incsearch;
      int               incsearch_postponed;
!     int               magic_save;
  } incsearch_state_T;
  
      static void
--- 149,155 ----
      pos_T     match_end;
      int               did_incsearch;
      int               incsearch_postponed;
!     magic_T   magic_overruled_save;
  } incsearch_state_T;
  
      static void
***************
*** 159,165 ****
      is_state->match_start = curwin->w_cursor;
      is_state->did_incsearch = FALSE;
      is_state->incsearch_postponed = FALSE;
!     is_state->magic_save = p_magic;
      CLEAR_POS(&is_state->match_end);
      is_state->save_cursor = curwin->w_cursor;  // may be restored later
      is_state->search_start = curwin->w_cursor;
--- 159,165 ----
      is_state->match_start = curwin->w_cursor;
      is_state->did_incsearch = FALSE;
      is_state->incsearch_postponed = FALSE;
!     is_state->magic_overruled_save = magic_overruled;
      CLEAR_POS(&is_state->match_end);
      is_state->save_cursor = curwin->w_cursor;  // may be restored later
      is_state->search_start = curwin->w_cursor;
***************
*** 252,260 ****
            || STRNCMP(cmd, "vglobal", p - cmd) == 0)
      {
        if (*cmd == 's' && cmd[1] == 'm')
!           p_magic = TRUE;
        else if (*cmd == 's' && cmd[1] == 'n')
!           p_magic = FALSE;
      }
      else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0)
      {
--- 252,260 ----
            || STRNCMP(cmd, "vglobal", p - cmd) == 0)
      {
        if (*cmd == 's' && cmd[1] == 'm')
!           magic_overruled = MAGIC_ON;
        else if (*cmd == 's' && cmd[1] == 'n')
!           magic_overruled = MAGIC_OFF;
      }
      else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0)
      {
***************
*** 288,294 ****
      p = skipwhite(p);
      delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++;
      *search_delim = delim;
!     end = skip_regexp(p, delim, p_magic);
  
      use_last_pat = end == p && *end == delim;
  
--- 288,294 ----
      p = skipwhite(p);
      delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++;
      *search_delim = delim;
!     end = skip_regexp(p, delim, magic_isset());
  
      use_last_pat = end == p && *end == delim;
  
***************
*** 372,378 ****
        search_first_line = 0;
        search_last_line = MAXLNUM;
  
!       p_magic = is_state->magic_save;
  
        validate_cursor();      // needed for TAB
        redraw_all_later(SOME_VALID);
--- 372,378 ----
        search_first_line = 0;
        search_last_line = MAXLNUM;
  
!       magic_overruled = is_state->magic_overruled_save;
  
        validate_cursor();      // needed for TAB
        redraw_all_later(SOME_VALID);
***************
*** 713,719 ****
            if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen))
                *c = MB_TOLOWER(*c);
            if (*c == search_delim || vim_strchr((char_u *)(
!                              p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL)
            {
                // put a backslash before special characters
                stuffcharReadbuff(*c);
--- 713,719 ----
            if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen))
                *c = MB_TOLOWER(*c);
            if (*c == search_delim || vim_strchr((char_u *)(
!                            magic_isset() ? "\\~^$.*[" : "\\^$"), *c) != NULL)
            {
                // put a backslash before special characters
                stuffcharReadbuff(*c);
*** ../vim-8.2.2181/src/insexpand.c     2020-12-18 19:49:52.341571870 +0100
--- src/insexpand.c     2020-12-21 19:14:01.737094305 +0100
***************
*** 1216,1222 ****
      }
      else
      {
!       regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
        if (regmatch.regprog == NULL)
            goto theend;
      }
--- 1216,1222 ----
      }
      else
      {
!       regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0);
        if (regmatch.regprog == NULL)
            goto theend;
      }
***************
*** 4175,4181 ****
                    break;
                // FALLTHROUGH
            case '~':
!               if (!p_magic)   // quote these only if magic is set
                    break;
                // FALLTHROUGH
            case '\\':
--- 4175,4181 ----
                    break;
                // FALLTHROUGH
            case '~':
!               if (!magic_isset())     // quote these only if magic is set
                    break;
                // FALLTHROUGH
            case '\\':
*** ../vim-8.2.2181/src/normal.c        2020-12-18 19:49:52.345571854 +0100
--- src/normal.c        2020-12-21 19:14:22.729070081 +0100
***************
*** 3738,3746 ****
      else
      {
        if (cmdchar == '*')
!           aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\");
        else if (cmdchar == '#')
!           aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\");
        else if (tag_cmd)
        {
            if (curbuf->b_help)
--- 3738,3746 ----
      else
      {
        if (cmdchar == '*')
!           aux_ptr = (char_u *)(magic_isset() ? "/.*~[^$\\" : "/^$\\");
        else if (cmdchar == '#')
!           aux_ptr = (char_u *)(magic_isset() ? "/?.*~[^$\\" : "/?^$\\");
        else if (tag_cmd)
        {
            if (curbuf->b_help)
*** ../vim-8.2.2181/src/search.c        2020-12-18 19:49:52.345571854 +0100
--- src/search.c        2020-12-21 19:15:50.300951968 +0100
***************
*** 134,140 ****
      int               i;
  
      rc_did_emsg = FALSE;
!     magic = p_magic;
  
      /*
       * If no pattern given, use a previously defined pattern.
--- 134,140 ----
      int               i;
  
      rc_did_emsg = FALSE;
!     magic = magic_isset();
  
      /*
       * If no pattern given, use a previously defined pattern.
***************
*** 1341,1347 ****
             * If there is a matching '/' or '?', toss it.
             */
            ps = strcopy;
!           p = skip_regexp_ex(pat, search_delim, (int)p_magic, &strcopy, NULL);
            if (strcopy != ps)
            {
                // made a copy of "pat" to change "\?" to "?"
--- 1341,1348 ----
             * If there is a matching '/' or '?', toss it.
             */
            ps = strcopy;
!           p = skip_regexp_ex(pat, search_delim, magic_isset(),
!                                                              &strcopy, NULL);
            if (strcopy != ps)
            {
                // made a copy of "pat" to change "\?" to "?"
***************
*** 3385,3391 ****
        sprintf((char *)pat, whole ? "\\<%.*s\\>" : "%.*s", len, ptr);
        // ignore case according to p_ic, p_scs and pat
        regmatch.rm_ic = ignorecase(pat);
!       regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
        vim_free(pat);
        if (regmatch.regprog == NULL)
            goto fpip_end;
--- 3386,3392 ----
        sprintf((char *)pat, whole ? "\\<%.*s\\>" : "%.*s", len, ptr);
        // ignore case according to p_ic, p_scs and pat
        regmatch.rm_ic = ignorecase(pat);
!       regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0);
        vim_free(pat);
        if (regmatch.regprog == NULL)
            goto fpip_end;
***************
*** 3393,3399 ****
      inc_opt = (*curbuf->b_p_inc == NUL) ? p_inc : curbuf->b_p_inc;
      if (*inc_opt != NUL)
      {
!       incl_regmatch.regprog = vim_regcomp(inc_opt, p_magic ? RE_MAGIC : 0);
        if (incl_regmatch.regprog == NULL)
            goto fpip_end;
        incl_regmatch.rm_ic = FALSE;    // don't ignore case in incl. pat.
--- 3394,3401 ----
      inc_opt = (*curbuf->b_p_inc == NUL) ? p_inc : curbuf->b_p_inc;
      if (*inc_opt != NUL)
      {
!       incl_regmatch.regprog = vim_regcomp(inc_opt,
!                                                magic_isset() ? RE_MAGIC : 0);
        if (incl_regmatch.regprog == NULL)
            goto fpip_end;
        incl_regmatch.rm_ic = FALSE;    // don't ignore case in incl. pat.
***************
*** 3401,3407 ****
      if (type == FIND_DEFINE && (*curbuf->b_p_def != NUL || *p_def != NUL))
      {
        def_regmatch.regprog = vim_regcomp(*curbuf->b_p_def == NUL
!                          ? p_def : curbuf->b_p_def, p_magic ? RE_MAGIC : 0);
        if (def_regmatch.regprog == NULL)
            goto fpip_end;
        def_regmatch.rm_ic = FALSE;     // don't ignore case in define pat.
--- 3403,3410 ----
      if (type == FIND_DEFINE && (*curbuf->b_p_def != NUL || *p_def != NUL))
      {
        def_regmatch.regprog = vim_regcomp(*curbuf->b_p_def == NUL
!                          ? p_def : curbuf->b_p_def,
!                                                magic_isset() ? RE_MAGIC : 0);
        if (def_regmatch.regprog == NULL)
            goto fpip_end;
        def_regmatch.rm_ic = FALSE;     // don't ignore case in define pat.
*** ../vim-8.2.2181/src/tag.c   2020-10-24 20:49:37.502683026 +0200
--- src/tag.c   2020-12-21 19:24:57.219794153 +0100
***************
*** 1271,1277 ****
        else
            for (pats->headlen = 0; pats->head[pats->headlen] != NUL;
                                                              ++pats->headlen)
!               if (vim_strchr((char_u *)(p_magic ? ".[~*\\$" : "\\$"),
                                           pats->head[pats->headlen]) != NULL)
                    break;
        if (p_tl != 0 && pats->headlen > p_tl)  // adjust for 'taglength'
--- 1271,1277 ----
        else
            for (pats->headlen = 0; pats->head[pats->headlen] != NUL;
                                                              ++pats->headlen)
!               if (vim_strchr((char_u *)(magic_isset() ? ".[~*\\$" : "\\$"),
                                           pats->head[pats->headlen]) != NULL)
                    break;
        if (p_tl != 0 && pats->headlen > p_tl)  // adjust for 'taglength'
***************
*** 1279,1285 ****
      }
  
      if (has_re)
!       pats->regmatch.regprog = vim_regcomp(pats->pat, p_magic ? RE_MAGIC : 0);
      else
        pats->regmatch.regprog = NULL;
  }
--- 1279,1286 ----
      }
  
      if (has_re)
!       pats->regmatch.regprog = vim_regcomp(pats->pat,
!                                                magic_isset() ? RE_MAGIC : 0);
      else
        pats->regmatch.regprog = NULL;
  }
***************
*** 3311,3317 ****
      int               keep_help)      // keep help flag (FALSE for cscope)
  {
      int               save_secure;
!     int               save_magic;
      int               save_p_ws, save_p_scs, save_p_ic;
      linenr_T  save_lnum;
      char_u    *str;
--- 3312,3318 ----
      int               keep_help)      // keep help flag (FALSE for cscope)
  {
      int               save_secure;
!     int               save_magic_overruled;
      int               save_p_ws, save_p_scs, save_p_ic;
      linenr_T  save_lnum;
      char_u    *str;
***************
*** 3503,3510 ****
  #ifdef HAVE_SANDBOX
        ++sandbox;
  #endif
!       save_magic = p_magic;
!       p_magic = FALSE;        // always execute with 'nomagic'
  #ifdef FEAT_SEARCH_EXTRA
        // Save value of no_hlsearch, jumping to a tag is not a real search
        save_no_hlsearch = no_hlsearch;
--- 3504,3511 ----
  #ifdef HAVE_SANDBOX
        ++sandbox;
  #endif
!       save_magic_overruled = magic_overruled;
!       magic_overruled = MAGIC_OFF;    // always execute with 'nomagic'
  #ifdef FEAT_SEARCH_EXTRA
        // Save value of no_hlsearch, jumping to a tag is not a real search
        save_no_hlsearch = no_hlsearch;
***************
*** 3626,3632 ****
        if (secure == 2)
            wait_return(TRUE);
        secure = save_secure;
!       p_magic = save_magic;
  #ifdef HAVE_SANDBOX
        --sandbox;
  #endif
--- 3627,3633 ----
        if (secure == 2)
            wait_return(TRUE);
        secure = save_secure;
!       magic_overruled = save_magic_overruled;
  #ifdef HAVE_SANDBOX
        --sandbox;
  #endif
*** ../vim-8.2.2181/src/structs.h       2020-12-20 17:47:49.257182258 +0100
--- src/structs.h       2020-12-21 19:08:04.386024726 +0100
***************
*** 4309,4311 ****
--- 4309,4317 ----
  // We have to guess how much a sequence of bytes may expand when converting
  // with iconv() to be able to allocate a buffer.
  #define ICONV_MULT 8
+ 
+ typedef enum {
+     MAGIC_NOT_SET,    // p_magic not overruled
+     MAGIC_ON,         // magic on inside regexp
+     MAGIC_OFF         // magic off inside regexp
+ } magic_T;
*** ../vim-8.2.2181/src/globals.h       2020-12-05 21:22:03.626811733 +0100
--- src/globals.h       2020-12-21 19:07:12.838202081 +0100
***************
*** 1938,1940 ****
--- 1938,1945 ----
  
  #define FOR_ALL_LIST_ITEMS(l, li) \
      for ((li) = (l)->lv_first; (li) != NULL; (li) = (li)->li_next)
+ 
+ // While executing a regexp and set to MAGIC_ON or MAGIC_OFF this overrules
+ // p_magic.  Otherwise set to MAGIC_NOT_SET.
+ 
+ EXTERN magic_T magic_overruled INIT(= MAGIC_NOT_SET);
*** ../vim-8.2.2181/src/ex_cmds.h       2020-12-13 17:50:16.730956512 +0100
--- src/ex_cmds.h       2020-12-21 19:35:18.078064083 +0100
***************
*** 1371,1377 ****
        EX_EXTRA|EX_BANG|EX_CMDARG|EX_ARGOPT|EX_TRLBAR,
        ADDR_NONE),
  EXCMD(CMD_smagic,     "smagic",       ex_submagic,
!       EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_CMDWIN|EX_LOCK_OK,
        ADDR_LINES),
  EXCMD(CMD_smap,               "smap",         ex_map,
        EX_EXTRA|EX_TRLBAR|EX_NOTRLCOM|EX_CTRLV|EX_CMDWIN|EX_LOCK_OK,
--- 1371,1377 ----
        EX_EXTRA|EX_BANG|EX_CMDARG|EX_ARGOPT|EX_TRLBAR,
        ADDR_NONE),
  EXCMD(CMD_smagic,     "smagic",       ex_submagic,
!       EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_CMDWIN|EX_LOCK_OK|EX_NONWHITE_OK,
        ADDR_LINES),
  EXCMD(CMD_smap,               "smap",         ex_map,
        EX_EXTRA|EX_TRLBAR|EX_NOTRLCOM|EX_CTRLV|EX_CMDWIN|EX_LOCK_OK,
***************
*** 1386,1392 ****
        EX_RANGE|EX_BANG|EX_FILES|EX_CMDARG|EX_ARGOPT|EX_TRLBAR,
        ADDR_OTHER),
  EXCMD(CMD_snomagic,   "snomagic",     ex_submagic,
!       EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_CMDWIN|EX_LOCK_OK,
        ADDR_LINES),
  EXCMD(CMD_snoremap,   "snoremap",     ex_map,
        EX_EXTRA|EX_TRLBAR|EX_NOTRLCOM|EX_CTRLV|EX_CMDWIN|EX_LOCK_OK,
--- 1386,1392 ----
        EX_RANGE|EX_BANG|EX_FILES|EX_CMDARG|EX_ARGOPT|EX_TRLBAR,
        ADDR_OTHER),
  EXCMD(CMD_snomagic,   "snomagic",     ex_submagic,
!       EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_CMDWIN|EX_LOCK_OK|EX_NONWHITE_OK,
        ADDR_LINES),
  EXCMD(CMD_snoremap,   "snoremap",     ex_map,
        EX_EXTRA|EX_TRLBAR|EX_NOTRLCOM|EX_CTRLV|EX_CMDWIN|EX_LOCK_OK,
*** ../vim-8.2.2181/src/testdir/test_vim9_cmd.vim       2020-12-20 
21:43:31.704882194 +0100
--- src/testdir/test_vim9_cmd.vim       2020-12-21 19:57:48.889460371 +0100
***************
*** 722,725 ****
--- 722,743 ----
    CheckDefFailure(lines, 'E1146:', 1)
  enddef
  
+ def Test_magic_not_used()
+   new
+   for cmd in ['set magic', 'set nomagic']
+     exe cmd
+     setline(1, 'aaa')
+     s/.../bbb/
+     assert_equal('bbb', getline(1))
+   endfor
+ 
+   set magic
+   setline(1, 'aaa')
+   assert_fails('s/.\M../bbb/', 'E486:')
+   assert_fails('snomagic/.../bbb/', 'E486:')
+   assert_equal('aaa', getline(1))
+ 
+   bwipe!
+ enddef
+ 
  " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
*** ../vim-8.2.2181/src/version.c       2020-12-21 18:23:56.687287184 +0100
--- src/version.c       2020-12-21 19:58:45.281264409 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2182,
  /**/

-- 
No engineer can take a shower without wondering if some sort of Teflon coating
would make showering unnecessary.
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202012211859.0BLIxZEL2322704%40masaka.moolenaar.net.

Raspunde prin e-mail lui