comparison src/vim9compile.c @ 25469:dcd45fe7fe2e v8.2.3271

patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function Commit: https://github.com/vim/vim/commit/e4db17fb6e2d029aa2dddfca703ace9bcf0d85fd Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 1 21:19:43 2021 +0200 patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function Problem: Vim9: cannot use :command or :au with a block in a :def function. Solution: Recognize the start of the block.
author Bram Moolenaar <Bram@vim.org>
date Sun, 01 Aug 2021 21:30:03 +0200
parents 9adaa0c056c7
children a8f526c9b172
comparison
equal deleted inserted replaced
25468:0290badbbf7b 25469:dcd45fe7fe2e
8859 8859
8860 /* 8860 /*
8861 * A command that is not compiled, execute with legacy code. 8861 * A command that is not compiled, execute with legacy code.
8862 */ 8862 */
8863 static char_u * 8863 static char_u *
8864 compile_exec(char_u *line, exarg_T *eap, cctx_T *cctx) 8864 compile_exec(char_u *line_arg, exarg_T *eap, cctx_T *cctx)
8865 { 8865 {
8866 char_u *line = line_arg;
8866 char_u *p; 8867 char_u *p;
8867 int has_expr = FALSE; 8868 int has_expr = FALSE;
8868 char_u *nextcmd = (char_u *)""; 8869 char_u *nextcmd = (char_u *)"";
8870 char_u *tofree = NULL;
8869 8871
8870 if (cctx->ctx_skip == SKIP_YES) 8872 if (cctx->ctx_skip == SKIP_YES)
8871 goto theend; 8873 goto theend;
8872 8874
8873 // If there was a prececing command modifier, drop it and include it in the 8875 // If there was a prececing command modifier, drop it and include it in the
8920 { 8922 {
8921 *p = NUL; 8923 *p = NUL;
8922 nextcmd = p + 1; 8924 nextcmd = p + 1;
8923 } 8925 }
8924 } 8926 }
8927 else if (eap->cmdidx == CMD_command || eap->cmdidx == CMD_autocmd)
8928 {
8929 // If there is a trailing '{' read lines until the '}'
8930 p = eap->arg + STRLEN(eap->arg) - 1;
8931 while (p > eap->arg && VIM_ISWHITE(*p))
8932 --p;
8933 if (*p == '{')
8934 {
8935 exarg_T ea;
8936 int flags; // unused
8937 int start_lnum = SOURCING_LNUM;
8938
8939 CLEAR_FIELD(ea);
8940 ea.arg = eap->arg;
8941 fill_exarg_from_cctx(&ea, cctx);
8942 (void)may_get_cmd_block(&ea, p, &tofree, &flags);
8943 if (tofree != NULL)
8944 {
8945 *p = NUL;
8946 line = concat_str(line, tofree);
8947 if (line == NULL)
8948 goto theend;
8949 vim_free(tofree);
8950 tofree = line;
8951 SOURCING_LNUM = start_lnum;
8952 }
8953 }
8954 }
8925 } 8955 }
8926 8956
8927 if (eap->cmdidx == CMD_syntax && STRNCMP(eap->arg, "include ", 8) == 0) 8957 if (eap->cmdidx == CMD_syntax && STRNCMP(eap->arg, "include ", 8) == 0)
8928 { 8958 {
8929 // expand filename in "syntax include [@group] filename" 8959 // expand filename in "syntax include [@group] filename"
9006 { 9036 {
9007 // the parser expects a pointer to the bar, put it back 9037 // the parser expects a pointer to the bar, put it back
9008 --nextcmd; 9038 --nextcmd;
9009 *nextcmd = '|'; 9039 *nextcmd = '|';
9010 } 9040 }
9041 vim_free(tofree);
9011 9042
9012 return nextcmd; 9043 return nextcmd;
9013 } 9044 }
9014 9045
9015 /* 9046 /*