Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Create .merlin file for a project with all your ocamlfind packages and .opam sources in there
#!/bin/sh
if test -f .merlin; then
echo ".merlin already exists, bailing out ..." >&2
exit 1
else
# You could add your default EXT's and such to this list:
cat >.merlin <<EOF
S .
B _build
EOF
# Add PKG's:
ocamlfind list \
| awk '{ print "PKG "$1 }' >>.merlin
# See https://github.com/the-lambda-church/merlin/wiki/Letting-merlin-locate-go-to-stuff-in-.opam
find ~/.opam -name '*.cmt' -print0 \
| xargs -0 -I{} dirname '{}' \
| sort -u \
| awk '{ print "S "$0"\nB "$0 }' >> .merlin
fi

copy commented Apr 3, 2016

Very useful – thanks!

Loading all packages is a bit of an overkill and makes my editor take very long to load. I'm using it as follows:

merlin-init.sh | grep endian >> .merlin

And changed the script to print to stdout:

#!/bin/sh

# Add PKG's:
ocamlfind list \
    | awk '{ print "PKG "$1 }'

# See https://github.com/the-lambda-church/merlin/wiki/Letting-merlin-locate-go-to-stuff-in-.opam
find ~/.opam -name '*.cmt' -print0 \
    | xargs -0 -I{} dirname '{}' \
    | sort -u \
    | awk '{ print "S "$0"\nB "$0 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment