From 2455886f7fde605f081bc5fa95c5735ca89afd2d Mon Sep 17 00:00:00 2001 From: Vadim Misbakh-Soloviov Date: Thu, 9 Dec 2021 16:12:18 +0700 Subject: gentoo-common: try to load pythons from python-exec.conf Signed-off-by: Vadim Misbakh-Soloviov --- plugin/gentoo-common.vim | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'plugin') diff --git a/plugin/gentoo-common.vim b/plugin/gentoo-common.vim index 42b2451..50478ba 100644 --- a/plugin/gentoo-common.vim +++ b/plugin/gentoo-common.vim @@ -56,8 +56,32 @@ fun! GentooGetPythonTargets() if exists("g:gentoopythontargets") && g:gentoopythontargets != "" return g:gentoopythontargets else - let l:py3 = system("python -c 'import epython; print(epython.EPYTHON)'") - let l:py3 = substitute(l:py3, "\n", "", "g") + let l:pyexec_path = "/etc/python-exec/python-exec.conf" + + if filereadable(l:pyexec_path) + let l:pys = readfile(l:pyexec_path)->filter("v:val =~ '^[^#-]'")->sort() + let l:py3s = [] + let l:others = [] + for l:py in l:pys + let l:m = l:py->matchstr("^python3.*")->matchstr("\\d*$") + if !empty(l:m) + eval l:py3s->add(l:m) + continue + else + eval l:others->add(l:py) + endif + endfor + let l:impls = [] + if len(l:py3s) ==# 1 + let l:impls = l:impls->add("python3.".l:py3s->join()) + elseif len(l:py3s) > 1 + let l:impls = l:impls->add("python3.{".l:py3s->sort('N')->join(",")."}") + endif + let l:py3 = flatten(l:impls->add(l:others))->join() + endif + if empty(l:py3) + let l:py3 = system("python -c 'import epython; print(epython.EPYTHON)'")->substitute("\n","","g") + endif let l:pythons = substitute(l:py3, "[.]", "_", "g") -- cgit v1.2.3-65-gdbad