I've started using Emacs for Ocaml programming, and used opam for installing some Emacs scripts which enable IDE features. To use these, opam added the following line to my .emacs:

(require 'opam-user-setup "~/.emacs.d/opam-user-setup.el")

However, this line makes the Emacs startup super sluggish. I use Emacs for a lot of things, and most of the time do not need this file at all. So I was wondering if there is a way to configure Emacs to require this file just before loading Ocaml files, and not always at startup.

Thank you!


You can use the following (assuming you're using tuareg-mode for your OCaml files):

(add-hook 'tuareg-mode-hook
          (lambda ()
            (require 'opam-user-setup "~/.emacs.d/opam-user-setup.el")))

But I suggest you also report this problem to the maintainers of the Elisp opam package.

  • Thank you for your answer @stefan! I do use tuareg-mode, but unfortunately this does not quite work. Using this code, opening an Ocaml file does not seem to load the opam file at all, and the configurations in that file are never applied. – Kasra Ferdowsi Feb 13 at 20:33
  • @KasraFerdowsi: Hmm... maybe the opam-user-setup needs to be loaded a bit earlier: does the above "work" on the second OCaml file you visit (within the same Emacs session)? – Stefan Feb 14 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.