I try to install merlin by typing "opam install merlin" in the terminal. After the installation is done, I am asked to do this, but it doesn't seem to work. The github instruction seems to be different

enter image description here

(load "/Users/yxchng/.opam/system/share/emacs/site-lisp/tuareg-site-file")

(add-to-list 'load-path
(require 'ocp-indent)

;; Add opam emacs directory to the load-path
(setq opam-share (substring (shell-command-to-string "opam config var
share 2> /dev/null") 0 -1))
(add-to-list 'load-path (concat opam-share "/emacs/site-lisp"))
;; Load merlin-mode
(require 'merlin)
;; Start merlin on ocaml files
(add-hook 'tuareg-mode-hook 'merlin-mode t)
(add-hook 'caml-mode-hook 'merlin-mode t)
;; Enable auto-complete
(setq merlin-use-auto-complete-mode 'easy)
;; Use opam switch to lookup ocamlmerlin binary
(setq merlin-command 'opam)

I added this code to .emacs but it doesn't seem to work

it gives me spurious error and says

/usr/local/Cellar/emacs/24.5/Emacs.app/Contents/MacOS/Emacs: \
/bin/bash: opam: command not found/ocamlmerlin: No such file or directory

(linebreak added to prevent scrolling)

The error is like this

enter image description here How should I solve this problem?

  • 1
    Can you make sure the argument to shell-command-to-string is spelled correctly? I don't know what it should look like, but right now it looks like some bits are missing. Does it have to have a linebreak there? – wvxvw May 3 '15 at 7:57
  • @wvxvw i am not sure too, i just copy and paste from the instruction given. Thats why I need some help – user10024395 May 3 '15 at 8:12
  • 1
    "i just copy and paste from the instruction given" -- It might help to see the instructions you are trying to follow in context. Please add an appropriate link to your question. – itsjeyd May 3 '15 at 8:36
  • @itsjeyd edited – user10024395 May 3 '15 at 8:55
  • Can you actually run "opam config var share" on the command line? Is "opam" in your PATH? – rekado May 3 '15 at 9:17

OS X does not evaluate your shell configuration for GUI applications. Hence, your Emacs runs with a different $PATH than your shell, and thus can't find the opam executable.

The exec-path-from-shell package helps you to work around this issue. Simply install the package with M-x package-install and then add the following to your init file:

(when (memq window-system '(mac ns))

Likewise, I'd recommend you to install Merlin via M-x package-install RET merlin, because that makes all the load-path management in your init file redundant, and reduces your OPAM configuration to:

(add-hook 'tuareg-mode-hook #'merlin-mode)
(add-hook 'caml-mode-hook #'merlin-mode) ; If you really like to use Caml Mode

(with-eval-after-load 'merlin
  (setq merlin-command 'opam))

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.