Tuareg/Merlin on Cygwin

I have made Tuareg/Merlin work on Cygwin, and the Opam 2.2.1. I am using the emacs from Cygwin… then I had to adapt the usual .emacs/init.el:

Note: I won’t be able to autoload tuareg/merlin. This explain the load functions. You will see a Win/Cygwin path translation (Opam uses Win32 convention, Emacs/Cygwin, Cygwin). Perhaps I should try a Windows native Emacs.

Hope this help !

path)
  (replace-regexp-in-string
   "\\(.\\):/" "/cygdrive/\\1/" 
   (replace-regexp-in-string
    "\\\\" "/"
    path)))

(let ((opam-share
       (ignore-errors
	 (win-to-cygwin
	   (replace-regexp-in-string
	    "\r$" ""
	    (car (process-lines "opam" "var" "share")))))))
  (when (and opam-share (file-directory-p opam-share))
    ;; Register Merlin
    (add-to-list 'load-path
		 (expand-file-name "emacs/site-lisp" opam-share))
    (load "tuareg")
    (load "merlin")
    (add-hook 'tuareg-mode-hook 'merlin-mode t)
    (add-to-list 'auto-mode-alist '("\\.ml[iylp]?\\'" . tuareg-mode))
    (add-to-list 'auto-mode-alist '("\\.eliomi?\\'" . tuareg-mode))
    (add-to-list 'interpreter-mode-alist '("ocamlrun" . tuareg-mode))
    (add-to-list 'interpreter-mode-alist '("ocaml" . tuareg-mode))
    ))
2 Likes

Rather than hand-rolling the path conversions, are you able to shell out to a command to do it? Putting aside the usual editor wars (:grin:), I use this in my .vimrc to configure Cygwin’s Vim:

let g:opamshare = substitute(system('opam var share | cygpath -f -'),'\n$','','''')
execute "set rtp+=" . g:opamshare . "/merlin/vim"

(in Vim, the stray \r gets normalised to a stray newline)

Ok, that’s working too.

(let ((opam-share
       (ignore-errors
         (replace-regexp-in-string
          "\r$" ""
          (car (process-lines "sh" "-c" "opam var share | cygpath -f -"))))))
  (when (and opam-share (file-directory-p opam-share))
    ;; Register Merlin
    (add-to-list 'load-path
		 (expand-file-name "emacs/site-lisp" opam-share))
    (load "tuareg")
    (load "merlin")
    (add-hook 'tuareg-mode-hook 'merlin-mode t)
    (add-to-list 'auto-mode-alist '("\\.ml[iylp]?\\'" . tuareg-mode))
    (add-to-list 'auto-mode-alist '("\\.eliomi?\\'" . tuareg-mode))
    (add-to-list 'interpreter-mode-alist '("ocamlrun" . tuareg-mode))
    (add-to-list 'interpreter-mode-alist '("ocaml" . tuareg-mode))
    ))