Running merlin from MacVim

I’m using MacVim on macOS and it has trouble executing merlin despite being set up as suggested. The same setup works on Linux where I’m using GVim. I suspect that MacVim, which is a macOS application bundle, does not pass the expected environment to merlin. Has anybody experience with this combination? It used to work but I suspect macOS sandboxing became stronger over time. Below are the lines in my .vimrc to set up merlin integration.

let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
execute "set rtp+=" . g:opamshare . "/merlin/vim"
execute "set rtp+=" . g:opamshare . "/ocp-indent/vim"

Do you have an error log?
My guess the opam binary is not in the path of the MacOs applications.
On my system, opam, installed with homebrew, is in /opt/homebrew/bin/opam which is not part of the default $PATH (or whatever MacOs app use to find executables…) but it’s added by my fish configuration when I launch a terminal.
I think on my previous system, homebrew was more than happy to populate something in /usr/local and that was making it more compatible with non-terminal based app.

:e ~/src/fit/bin/   main.mli
merlin: unknown flag /Users/lindig/src/fit/bin/, flag -filename: error, Unix.Unix_error(Unix
.ENOENT, "create_process", "dune")

This suggests to me that Merlin is executed but something else goes wrong. You can find on Google other people reporting the problem but it’s murky.

Doesn’t Unix.Unix_error(Unix .ENOENT, "create_process", "dune") means the create_process function couldn’t find dune?

So I’m guessing the vim config can find merlin, but merlin expect dune to be in the path, which doesn’t happen unless opam is allowed to dynamically add the current switch bin to $PATH.

As a test, if you have admin access, you could add your current switch bin folder to /etc/paths and see if that works? (Not a solution of course, but at least it would clarify the issue)

1 Like

Indeed, the bin/ directory containing dune must be mentioned in /etc/paths or via /etc/paths.d. MacVim does not inherit my shell environment and this creates the problem. To solve the problem within Vim, I’ve added to my .vimrc:

let g:opambin = substitute(system('opam config var bin'),'\n$','','''')
let $PATH .= ":" . g:opambin
1 Like