Search code examples
emacscygwinocamlopam

Opam in Cygwin with Windows emacs


I installed https://github.com/fdopen/opam-repository-mingw, merlin and tuareg successfully in Cygwin. Now I have installed Windows emacs and changed .emacs to enable modes to edit Ocaml files.

Is this how the setup is supposed to be ? Can Windows emacs work with Cygwin OCaml tools like this ?

If not then I request for details to setup emacs in Cygwin.

Update : Now my init.el is this

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)

(setenv "PATH" (concat "c:/OCaml64/bin;" (getenv "PATH")))
(setq exec-path (cons "c:/OCaml64/bin/" exec-path))
(require 'cygwin-mount)
(cygwin-mount-activate)

(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.
'(package-selected-packages (quote (company))))
(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.
)


;; OCaml code
(add-hook
 'tuareg-mode-hook
 (lambda ()
  ;; 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)
 (company-mode)
 (require 'ocp-indent)
 (autoload 'utop-minor-mode "utop" "Minor mode for utop" t)
 (autoload 'utop-setup-ocaml-buffer "utop" "Toplevel for OCaml" t)
 (autoload 'merlin-mode "merlin" "Merlin mode" t)
 (utop-minor-mode)
 (company-quickhelp-mode)
 ;; Important to note that setq-local is a macro and it needs to be
 ;; separate calls, not like setq
 (setq-local merlin-completion-with-doc t)
 (setq-local indent-tabs-mode nil)
 (setq-local show-trailing-whitespace t)
 (setq-local indent-line-function 'ocp-indent-line)
 (setq-local indent-region-function 'ocp-indent-region)
 (merlin-mode)))

 (add-hook 'utop-mode-hook (lambda ()
            (set-process-query-on-exit-flag
             (Get-process "utop") nil)))

cygwin-mount.el is in the site-lisp folder.

I don't see any change when I open a .ml file or when I type M-x merlin-mode


Solution

  • Are you sure Tuareg is actually loaded? If you go to *scratch*, type (locate-library "tuareg") and execute it (type C-xC-e when the cursor is after the closing brace), what do you see in the echo area?

    In the directory where you installed Tuareg, there should be a file tuareg-site-file.el. If so, put in your ~/.emacs, the line: (load "/path/to/tuareg-site-file") to enable Tuareg.