Steps to reproduce
Run this shell command:
vim -Nu NONE -S <(tee <<'EOF'
vim9script
var lines =<< trim END
# first
aaa
aaa
aaa
# second
bbb
bbb
bbb
# third
ccc
ccc
ccc
END
var file = '/tmp/file'
lines->writefile(file)
execute 'noswapfile edit ' .. file
var dir = '/tmp/.vim'
&runtimepath = dir
dir ..= '/autoload'
dir->mkdir('p')
lines =<< trim END
vim9script
export def Expr(): string
return getline(v:lnum) =~ '^#' ? '>1' : '1'
enddef
END
lines->writefile(dir .. '/fold.vim')
import autoload 'fold.vim'
&foldexpr = 'fold.Expr()'
&foldmethod = 'expr'
&debug = 'throw'
EOF
)
E121
is given 17 times (i.e. once for each line in the buffer):
E121: Undefined variable: fold
The lines are not folded.
Expected behavior
No error is given. The lines are folded.
Version of Vim
8.2 Included patches: 1-4171
Environment
Operating system: Ubuntu 20.04.3 LTS
Terminal: xterm
Value of $TERM: xterm-256color
Shell: zsh 5.8
Additional context
If we replace this line:
&foldexpr = 'fold.Expr()'
With this line:
&foldexpr = 'fold#Expr()'
The issue disappears:
vim9script var lines =<< trim END # first aaa aaa aaa # second bbb bbb bbb # third ccc ccc ccc END var file = '/tmp/file' lines->writefile(file) execute 'noswapfile edit ' .. file var dir = '/tmp/.vim' &runtimepath = dir dir ..= '/autoload' dir->mkdir('p') lines =<< trim END vim9script export def Expr(): string return getline(v:lnum) =~ '^#' ? '>1' : '1' enddef END lines->writefile(dir .. '/fold.vim') import autoload 'fold.vim' &foldexpr = 'fold#Expr()' &foldmethod = 'expr' &debug = 'throw'
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.
More generally, the expression cannot access anything in the script file.
A good solution appears to be that the expression is evaluated in the context of the script where the option was set.
I don't think this will have backwards compatibility problems, previously the expression could be evaluated anywhere.
This probably also applies to other "expr" options, but let's do 'foldexpr' first.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.