OCamlPro / ocp-indent

Indentation tool for OCaml, to be used from editors like Emacs and Vim.
http://www.typerex.org/ocp-indent.html
Other
200 stars 63 forks source link

Not working for vim #259

Closed bobbypriam closed 6 years ago

bobbypriam commented 6 years ago

Hi, thank you for this awesome tool.

I haven't used vim for a while for OCaml (around two months), and when I come back somehow ocp-indent is not working properly, while I can remember previously it worked just fine. I'm using ocp-indent v1.6.1, tried downgrading to v1.5.3 to no avail.

Here is the original code:

let todos_list =
  get "/todos" (fun _req ->
      let%lwt todos = Todos.get_all () in
      let result = List.map Todos.string_of_todo todos in
      let result_json = Ezjsonm.list Ezjsonm.string result in
      `Json result_json |> respond'
    )

But when I block them and press =, I've got this:

let todos_list =
get "/todos" (fun _req ->
let%lwt todos = Todos.get_all () in
let result = List.map Todos.string_of_todo todos in
let result_json = Ezjsonm.list Ezjsonm.string result in
`Json result_json |> respond'
)

The indentations disappears. I've tried removing my .vimrc, and let user-setup (v0.6) handles it:

$ mv ~/.vimrc ~/.vimrc.bak
$ opam user-setup install --editors=vim
vim > /Users/bobbypriambodo/.vimrc: installing new config file template
vim > base > .vimrc: adding configuration
vim > ocp-indent > .vimrc: adding configuration

But it still behaves the same. I've tried this on Neovim v0.2.2 and Vim 8.0. I've made sure that I'm using the correct ocp-indent on my switch. The ocp-indent command itself works fine from terminal:

$ ocp-indent src/server.ml
...
let todos_list =
  get "/todos" (fun _req ->
      let%lwt todos = Todos.get_all () in
      let result = List.map Todos.string_of_todo todos in
      let result_json = Ezjsonm.list Ezjsonm.string result in
      `Json result_json |> respond'
    )
...

It's like somehow vim couldn't find the binary, even when I :echo $PATH the path is correct. Merlin works fine though. Do you have any idea how to troubleshoot this?

bobbypriam commented 6 years ago

Oh, nevermind. It turns out that I was using ZSH as my shell and the opam config environment setting (in .zshrc, .zshenv) was a mess. I ended up removing the automatically-added reference to ~/.opam/opam-init/init.zsh from my zshrc and just put eval $(opam env) on zshenv, which will be sourced on every shell invocation and not just on interactive (-i) shells, therefore setting the correct path on vim, and made ocp-indent work as intended. Computers do funny things sometimes.

Closing this, sorry for the trouble.