Mercurial > vim
comparison src/testdir/test_vim9_func.vim @ 26594:b12d8a5af20e v8.2.3826
patch 8.2.3826: Vim9: using "g:Func" as funcref doesn't work in :def function
Commit: https://github.com/vim/vim/commit/b15cf44c1d9c92a2ac07cff415071e31a9ad88fa
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 16 15:49:43 2021 +0000
patch 8.2.3826: Vim9: using "g:Func" as funcref doesn't work in :def function
Problem: Vim9: using "g:Func" as a funcref does not work in a :def
function.
Solution: Include "g:" in the function name. (closes #9336)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 16 Dec 2021 17:00:05 +0100 |
parents | 7f90bde42bcc |
children | d54a39ec6d43 |
comparison
equal
deleted
inserted
replaced
26593:a0fcea60c6f5 | 26594:b12d8a5af20e |
---|---|
1230 def g:CountSpaces(type = ''): string | 1230 def g:CountSpaces(type = ''): string |
1231 normal! '[V']y | 1231 normal! '[V']y |
1232 g:result = getreg('"')->count(' ') | 1232 g:result = getreg('"')->count(' ') |
1233 return '' | 1233 return '' |
1234 enddef | 1234 enddef |
1235 # global function works at script level | |
1235 &operatorfunc = g:CountSpaces | 1236 &operatorfunc = g:CountSpaces |
1236 new | 1237 new |
1237 'a b c d e'->setline(1) | 1238 'a b c d e'->setline(1) |
1238 feedkeys("g@_", 'x') | 1239 feedkeys("g@_", 'x') |
1239 assert_equal(4, g:result) | 1240 assert_equal(4, g:result) |
1241 | |
1242 &operatorfunc = '' | |
1243 g:result = 0 | |
1244 # global function works in :def function | |
1245 def Func() | |
1246 &operatorfunc = g:CountSpaces | |
1247 enddef | |
1248 Func() | |
1249 feedkeys("g@_", 'x') | |
1250 assert_equal(4, g:result) | |
1251 | |
1240 bwipe! | 1252 bwipe! |
1241 END | 1253 END |
1242 CheckScriptSuccess(lines) | 1254 CheckScriptSuccess(lines) |
1243 &operatorfunc = '' | 1255 &operatorfunc = '' |
1244 enddef | 1256 enddef |