2

首先,请知道我是 Ocaml 的 Dune 和项目管理的初学者。尽管如此,我已经安装了沙丘并创建了一个新的沙丘项目,它处理 camlimages 库、图形等。当我照常进行时,项目编译和执行效果很好:

  • opam exec 沙丘构建
  • opam exec 沙丘 exec ./myexecutable.exe

但是,我不能在 emacs 中使用 Tuareg 模式,因为后者似乎无法很好地找到/理解 dune-project 配置文件代表沙丘 v2.8 之前的前者“.merlin”(根据文档:https: //dune.readthedocs.io/en/latest/usage.html?highlight=merlin )。当我尝试将当前的 .ml 启动到 Tuareg repl 时,这意味着很多“未绑定模块”错误。

我试图手动添加包

  • Merlin > 选择套餐

但是 Merlin 似乎并不关心这个,即使它出现在 merlin 配置文件中。


一些假设

每次我想从 dune 访问外部“安装 opam”的库/包时,我需要从 Opam 启动 Dune 以便访问它们,而不是在 shell 中启动一个简单的“Dune”命令。我觉得“shell环境”无法访问“Opam环境”。这对我的问题有影响吗?


您可以在下面找到一些相关信息,这可能有助于理解我的问题:

  • Merlin > 检查配置而不手动添加包

加载的 .merlin 文件:/home/erwan/Bureau/Nextcloud/GIT/Projet_integrateur_L3OPTIM/dev/importimg/dune-project 自定义缓冲区设置:-packages: none -flags: "" -extensions: none 自定义 merlin 设置:((env " PATH=/home/erwan/.opam/default/bin”)(命令。“/home/erwan/.opam/default/bin/ocamlmerlin”))

  • 沙丘文件

(可执行文件(名称 importimg)(库 camlimages.core camlimages.png 图形 camlimages.graphics))

  • 我的项目的树结构(由沙丘生成)
.
├── _build
│   ├── default
│   │   ├── dune
│   │   ├── dune-project
│   │   ├── image.png
│   │   ├── importimg.exe
│   │   └── importimg.ml
│   └── log
├── dune
├── dune-project
├── image.png
├── #importimg.ml#
└── importimg.ml
  • .emacs 内容
;; Basic .emacs with a good set of defaults, to be used as template for usage
;; with OCaml and OPAM
;;
;; Author: Louis Gesbert <louis.gesbert@ocamlpro.com>
;; 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.
 )
  • 版本

梅林:3.7.0

沙丘:2.1.3

Emacs:2020-03-26 的 GNU Emacs 26.3(build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14),由 Debian 修改

欧帕姆:2.0.5

奥卡姆:4.08.1


提前致谢

4

0 回答 0