Reputation: 31
First, please know that I am a beginner with Dune and project management in Ocaml. Nevertheless, I have installed Dune and created a new Dune-project which deals with camlimages library, graphics, etc. Project compilation and execution works well when i do the usual:
However, I can't use Tuareg Mode in emacs because the latter doesn't seem to find/understand well the dune-project configuration file standing for the former ".merlin" before dune v2.8 (according to the doc: https://dune.readthedocs.io/en/latest/usage.html?highlight=merlin). That implies lot of "unbound modules" errors when I try to launch the current .ml into the Tuareg repl.
I've tried to add packages manually with
but Merlin does not seem to care about this, even though it appears in the merlin configuration file.
Some hypothesis:
Every time I want to access external "opam-installed" library/packages from dune, I need to launch Dune from Opam in order to access them instead of launching a simple "Dune" command into the shell. I feel the "Opam environment" is not accessible from the "shell environment". Does that play a role in my problem?
You could find some relevant information below, which might be useful to understand my problem:
Loaded .merlin files: /home/erwan/Bureau/Nextcloud/GIT/Projet_integrateur_L3OPTIM/dev/importimg/dune-project Custom buffer settings: -packages: none -flags: "" -extensions: none Custom merlin setup: ((env "PATH=/home/erwan/.opam/default/bin") (command . "/home/erwan/.opam/default/bin/ocamlmerlin"))
(executable (name importimg) (libraries camlimages.core camlimages.png graphics camlimages.graphics))
.
├── _build
│ ├── default
│ │ ├── dune
│ │ ├── dune-project
│ │ ├── image.png
│ │ ├── importimg.exe
│ │ └── importimg.ml
│ └── log
├── dune
├── dune-project
├── image.png
├── #importimg.ml#
└── importimg.ml
;; Basic .emacs with a good set of defaults, to be used as template for usage
;; with OCaml and OPAM
;;
;; Author: Louis Gesbert <[email protected]>
;; Released under CC0
;; Generic, recommended configuration options
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ac-use-fuzzy nil)
'(backup-directory-alist (quote (("." . "~/.local/share/emacs/backups"))))
'(compilation-context-lines 2)
'(compilation-error-screen-columns nil)
'(compilation-scroll-output t)
'(compilation-search-path (quote (nil "src")))
'(custom-enabled-themes (quote (tango-dark)))
'(electric-indent-mode nil)
'(indent-tabs-mode nil)
'(line-move-visual t)
'(next-error-highlight t)
'(next-error-highlight-no-select t)
'(next-line-add-newlines nil)
'(require-final-newline t)
'(sentence-end-double-space nil)
'(show-paren-mode t)
'(show-trailing-whitespace t)
'(visible-bell t))
;; ANSI color in compilation buffer
(require 'ansi-color)
(defun colorize-compilation-buffer ()
(toggle-read-only)
(ansi-color-apply-on-region (point-min) (point-max))
(toggle-read-only))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
;; Some key bindings
(global-set-key [f3] 'next-match)
(defun prev-match () (interactive nil) (next-match -1))
(global-set-key [(shift f3)] 'prev-match)
(global-set-key [backtab] 'auto-complete)
;; OCaml configuration
;; - better error and backtrace matching
(defun set-ocaml-error-regexp ()
(set
'compilation-error-regexp-alist
(list '("[Ff]ile \\(\"\\(.*?\\)\", line \\(-?[0-9]+\\)\\(, characters \\(-?[0-9]+\\)-\\([0-9]+\\)\\)?\\)\\(:\n\\(\\(Warning .*?\\)\\|\\(Error\\)\\):\\)?"
2 3 (5 . 6) (9 . 11) 1 (8 compilation-message-face)))))
(add-hook 'tuareg-mode-hook 'set-ocaml-error-regexp)
(add-hook 'caml-mode-hook 'set-ocaml-error-regexp)
;; ## added by OPAM user-setup for emacs / base ## 56ab50dc8996d2bb95e7856a6eddb17b ## you can edit, but keep this line
(require 'opam-user-setup "~/.emacs.d/opam-user-setup.el")
;; ## end of OPAM user-setup addition for emacs / base ## keep this line
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
Merlin: 3.7.0
Dune: 2.1.3
Emacs: GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian
Opam: 2.0.5
Ocaml: 4.08.1
Thanks in advance
Upvotes: 3
Views: 515
Reputation: 31
I have finally solved my problem in setting-up an "opam switch" into my working directory (WD). Once you are into your WD you have to launch the following command:
opam switch create . ocaml-base-compiler
Then, I reinstalled all the needed packages. Utop surprisingly replaced ocaml REPL in emacs ^^' (but i don't mind too much...). Now, dune and merlin "see" the packages.
Nevertheless, this tutorial helped me providing you this answer; https://ocamlverse.github.io/content/quickstart_ocaml_project_dune.html
(Please note that opam, emacs and utop were already installed on my working environment).
Upvotes: 0