I'm trying to integrate opam-user-setup's output with vim-plug. I've produced the following:
let s:opam_share_dir = system("opam config var share")
let s:opam_share_dir = substitute(s:opam_share_dir, '[\r\n]*$', '', '')
let s:opam_configuration = {}
function! OpamConfOcpIndent()
Plug s:opam_share_dir . "/ocp-indent/vim"
endfunction
let s:opam_configuration['ocp-indent'] = function('OpamConfOcpIndent')
function! OpamConfOcpIndex()
Plug s:opam_share_dir . "/ocp-index/vim"
endfunction
let s:opam_configuration['ocp-index'] = function('OpamConfOcpIndex')
function! OpamConfMerlin()
Plug s:opam_share_dir . "/merlin/vim"
endfunction
let s:opam_configuration['merlin'] = function('OpamConfMerlin')
let s:opam_packages = ["ocp-indent", "ocp-index", "merlin"]
let s:opam_check_cmdline = ["opam list --installed --short --safe --color=never"] + s:opam_packages
let s:opam_available_tools = split(system(join(s:opam_check_cmdline)))
for tool in s:opam_packages
" Respect package order (merlin should be after ocp-index)
if count(s:opam_available_tools, tool) > 0
call s:opam_configuration[tool]()
endif
endfor
However, the Plug s:opam_share_dir . "/ocp-indent/vim"
-style lines explode with this error:
Error detected while processing function OpamConfOcpIndent:
line 1:
E121: Undefined variable: s:opam_share_dir
E116: Invalid arguments for function plug#
However, if I add echo s:opam_share_dir
immediately before the Plug s:opam_share_dir ...
line, it works just fine — the variable is definitely defined. What am I doing wrong?
tl;dr I can't figure out how to pass a variable to a custom command, in a vim-script.