Mercurial > vim
diff src/userfunc.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 | e3f1086429d8 |
children | 9a4cb96c9550 |
line wrap: on
line diff
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -903,12 +903,25 @@ get_function_body( --end; if (end > p && *end == '{') { + int is_block; + + // check for trailing "=> {": start of an inline function --end; while (end > p && VIM_ISWHITE(*end)) --end; - if (end > p + 2 && end[-1] == '=' && end[0] == '>') + is_block = end > p + 2 && end[-1] == '=' && end[0] == '>'; + if (!is_block) { - // found trailing "=> {", start of an inline function + char_u *s = p; + + // check for line starting with "au" for :autocmd or + // "com" for :command, these can use a {} block + is_block = checkforcmd_noparen(&s, "autocmd", 2) + || checkforcmd_noparen(&s, "command", 3); + } + + if (is_block) + { if (nesting == MAX_FUNC_NESTING - 1) emsg(_(e_function_nesting_too_deep)); else