ocaml-opam / opam-user-setup

Simplify the configuration of editors for using OCaml tools
Other
81 stars 12 forks source link

ocp-indent doesn't work in vim #22

Open ddosia opened 8 years ago

ddosia commented 8 years ago

Hi there! I am new to ocaml. I have user-setup version 0.4 [4.02.1] installed through opam. Recently I've tried

dchurikov ~ $ opam user-setup install --editors=vim
vim > .vimrc: already exists, not installing base template
vim > base > .vimrc: adding configuration
vim > ocp-indent > .vimrc: adding configuration

After that I fixed #21 vim has lunched fine. I've tried to edit .ml file to see how indentation works, but nothing happens. Looks like ocp-ident doesn't work.

This is what was generated:

" ## added by OPAM user-setup for vim / base ## 9a3a300d80f2faeb258825d3e0c1947c ## you can edit, but keep this line
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()
  execute "set rtp^=" . s:opam_share_dir . "/ocp-indent/vim"
endfunction
let s:opam_configuration['ocp-indent'] = function('OpamConfOcpIndent')

function! OpamConfOcpIndex()
  execute "set rtp+=" . s:opam_share_dir . "/ocp-index/vim"
endfunction
let s:opam_configuration['ocp-index'] = function('OpamConfOcpIndex')

function! OpamConfMerlin()
  let l:dir = s:opam_share_dir . "/merlin/vim"
  execute "set rtp+=" . l:dir
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
" I changed next line because of issue #21
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
" ## end of OPAM user-setup addition for vim / base ## keep this line
" ## added by OPAM user-setup for vim / ocp-indent ## a8e14cc76b17ff3c60c05a8f8875e778 ## you can edit, but keep this line
if count(s:opam_available_tools,"ocp-indent") == 0
  source "/home/dchurikov/.opam/4.02.1/share/vim/syntax/ocp-indent.vim"
endif
" ## end of OPAM user-setup addition for vim / ocp-indent ## keep this line

The last path (source "/home/dchurikov/.opam/4.02.1/share/vim/syntax/ocp-indent.vim") actually points nowhere, right path would be /home/dchurikov/.opam/4.02.1/share/ocp-indent/vim/indent/ocaml.vim. Anyway after I set this path it still doesn't indent.

Thanks in advance.

AltGr commented 8 years ago

How exactly did you try to indent ? The default keybinding for indent-line is ==.

ddosia commented 8 years ago

I was expecting indentation when I hit "return" key. Also I tried ==. No luck.

rohanjr commented 7 years ago

I'm having the same issue. Was this ever resolved @ddosia ?

AltGr commented 7 years ago

The file to load is actually configured twice, for the two cases where:

This is designed to give users ocp-indent support, without requiring them to install it in every opam switch.

It seems indeed that the path at the end failed to be updated correctly when ocp-indent's installation paths changed, but the previous one should be OK, and is the one that should be used in your case.

Can you try the load command by hand and see what happens ?

let s:opam_share_dir = system("opam config var share")
execute "set rtp^=" . s:opam_share_dir . "/ocp-indent/vim"
rohanjr commented 7 years ago

It turned out that ocp-indent wasn't showing up on my path because the OPAM environment was not being set up. The problem was solved for me by adding the line

eval `opam config env`

to my .profile. Thanks for the help.

ScientificX commented 3 years ago

I had this issue recently on spacemacs fixed by adding the results of opam config env to ~/.spacemacs.env