Last active
February 12, 2023 05:40
-
-
Save unhammer/c1ac7320141f09ac38e0 to your computer and use it in GitHub Desktop.
Create .merlin file for a project with all your ocamlfind packages and .opam sources in there
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Super useful. Thanks to both of you!
Here is a slightly updated version that works with opam switches.
#!/bin/sh
eval $(opam config env)
# 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_SWITCH_PREFIX" -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
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: