0

Here is a part of my ftplugin/fortran_state.vim

" Check python modules and install{{{1
if !executable('fprettify') || !executable('fortls') || !executable('unidecode')
  :let choice =confirm("Some python dependencies doesn't exists! Install them?", "&Yes\n&No(use fallback)")
  if !executable('fprettify')
    :call install_deps#install_fprettify() 
  endif
  if !executable('fortls')
    :call install_deps#install_fortls() 
  endif
  if !executable('unidecode')
    :call install_deps#install_unidecode() 
  endif
endif
"}}}

The intention is these block will be executed and install the dependencies only when they are not installed (obviously!) Problem is, even they are installed and in path, this block is executed every time I open a fortran file.

pip3 install --user fortran-language-server fprettify unidecode
Requirement already satisfied: fortran-language-server in ~/.local/lib/python3.9/site-packages (1.12.0)
Requirement already satisfied: fprettify in ~.local/lib/python3.9/site-packages (0.3.7)
Requirement already satisfied: unidecode in ~/.local/lib/python3.9/site-packages (1.1.2)
Requirement already satisfied: configargparse in ~/.local/lib/python3.9/site-packages (from fprettify) (1.2.3)


which fprettify 
~/.local/bin/fprettify
which fortls
~/.local/bin/fortls
which unidecode 
~/.local/bin/unidecode

One odd thing is installation is going on even if I select No(Use fallback).

The install_deps is from autoload, with:

function! install_deps#install_fprettify()
  echom "Installing fprettify"
  :execute ':!pip3 install fprettify --user -q'
endfunction
function! install_deps#install_unidecode()
  echom "Installing unidecode"
  :execute ':!pip3 install unidecode --user -q'
endfunction
function! install_deps#install_fortls()
  echom "Installing fortls"
  :execute ':!pip3 install fortran-language-server --user -q'
endfunction

So,it looks like if block and choice does not work as I think.

What I am doing wrong here?

Update

  1. Reply to Mat:

  2. Reply to Ben: I have used:

     let choice =confirm("Some python dependencies doesn't exists! Install them?", "&Yes\n&No(use fallback)")
     echo choice
    

If I chose Yes, confirm is 1, with No, its 2. But, code should not go to choice at all when all of them are already installed. Why the code is reading that choice line?

3
  • 1
    :echo $PATH while inside Vim.
    – Matt
    Jan 30, 2021 at 12:21
  • 1
    You haven't checked the return value of confirm, have you?
    – D. Ben Knoble
    Jan 30, 2021 at 13:54
  • Note that in ftplugin/*.vim you don't need to type the colon before commands (i.e. just call install_deps#install_fprettify(), not :call install_deps#install_fprettify()) Mar 4, 2021 at 14:15

1 Answer 1

0

oh, I have found the solution. This is for others reference. vim probably can not expand ~/ to $HOME. In my .bashrc, I had

PATH="${PATH}:~/bin"
PATH="$PATH:~/.local/bin"

changing that to

PATH="${PATH}:${HOME}/bin"
PATH="$PATH:${HOME}/.local/bin"

solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.