2015-02-07 17:37:53 +00:00
|
|
|
;;; packages.el --- ocaml Layer packages File for Spacemacs
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
|
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2015-04-19 03:40:24 +00:00
|
|
|
(setq ocaml-packages
|
2015-02-07 17:37:53 +00:00
|
|
|
'(
|
|
|
|
tuareg
|
|
|
|
merlin
|
2015-04-18 16:22:03 +00:00
|
|
|
utop
|
|
|
|
ocp-indent
|
2015-04-18 16:22:34 +00:00
|
|
|
company
|
2015-04-18 16:26:24 +00:00
|
|
|
flycheck
|
|
|
|
flycheck-ocaml
|
2015-02-07 17:37:53 +00:00
|
|
|
;; package ocamls go here
|
2015-04-19 03:40:24 +00:00
|
|
|
))
|
2015-02-07 17:37:53 +00:00
|
|
|
|
|
|
|
(defun ocaml/init-tuareg ()
|
|
|
|
(add-hook 'tuareg-mode-hook #'merlin-mode)
|
2015-04-18 18:13:24 +00:00
|
|
|
(evil-leader/set-key-for-mode 'tuareg-mode
|
|
|
|
"mcc" 'compile
|
|
|
|
)
|
2015-04-18 19:00:27 +00:00
|
|
|
;; don't auto-close apostrophes (type 'a = foo)
|
|
|
|
(when (fboundp 'sp-local-pair)
|
|
|
|
(sp-local-pair 'tuareg-mode "'" nil :actions nil)
|
|
|
|
)
|
2015-02-07 17:37:53 +00:00
|
|
|
)
|
|
|
|
|
2015-04-18 16:22:03 +00:00
|
|
|
(defun ocaml/opam ()
|
|
|
|
(setq opam-share (substring (shell-command-to-string "opam config var share 2> /dev/null") 0 -1))
|
|
|
|
(setq opam-load-path (concat opam-share "/emacs/site-lisp"))
|
|
|
|
(add-to-list 'load-path opam-load-path))
|
|
|
|
|
|
|
|
(defun ocaml/init-utop ()
|
|
|
|
(use-package utop
|
|
|
|
:init
|
|
|
|
(autoload 'utop "utop" "Toplevel for OCaml" t)
|
|
|
|
(autoload 'utop-minor-mode "utop" "Minor mode for utop" t)
|
|
|
|
(add-hook 'tuareg-mode-hook 'utop-minor-mode)
|
|
|
|
:config
|
|
|
|
;; Setup environment variables using opam
|
|
|
|
(dolist (var (car (read-from-string (shell-command-to-string "opam config env --sexp"))))
|
|
|
|
(setenv (car var) (cadr var)))
|
|
|
|
;; Update the emacs path
|
|
|
|
(setq exec-path (append (parse-colon-path (getenv "PATH"))
|
|
|
|
(list exec-directory)))
|
2015-04-18 18:13:24 +00:00
|
|
|
(defun utop-eval-phrase-and-go ()
|
|
|
|
(interactive)
|
|
|
|
(utop-eval-phrase)
|
|
|
|
(utop))
|
|
|
|
(defun utop-eval-buffer-and-go ()
|
|
|
|
(interactive)
|
|
|
|
(utop-eval-buffer)
|
|
|
|
(utop))
|
|
|
|
(defun utop-eval-region-and-go (start end)
|
|
|
|
(interactive "r")
|
|
|
|
(utop-eval-region start end)
|
|
|
|
(utop))
|
|
|
|
(evil-leader/set-key-for-mode 'tuareg-mode
|
|
|
|
"msb" 'utop-eval-buffer
|
|
|
|
"msB" 'utop-eval-buffer-and-go
|
|
|
|
"msi" 'utop
|
|
|
|
"msp" 'utop-eval-phrase
|
|
|
|
"msP" 'utop-eval-phrase-and-go
|
|
|
|
"msr" 'utop-eval-region
|
|
|
|
"msR" 'utop-eval-region-and-go
|
|
|
|
)
|
2015-04-18 16:22:03 +00:00
|
|
|
)
|
2015-04-18 18:13:24 +00:00
|
|
|
(define-key utop-mode-map (kbd "C-j") 'utop-history-goto-next)
|
|
|
|
(define-key utop-mode-map (kbd "C-k") 'utop-history-goto-prev)
|
2015-04-18 16:22:03 +00:00
|
|
|
)
|
2015-04-03 21:35:33 +00:00
|
|
|
|
2015-04-18 16:22:03 +00:00
|
|
|
(defun ocaml/init-ocp-indent ()
|
|
|
|
(use-package ocp-indent
|
|
|
|
:init
|
|
|
|
(ocaml/opam)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2015-04-18 16:22:34 +00:00
|
|
|
(defun ocaml/init-merlin ()
|
|
|
|
(use-package merlin
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(ocaml/opam)
|
|
|
|
(set-default 'merlin-use-auto-complete-mode 'easy)
|
|
|
|
(when (configuration-layer/package-usedp 'company)
|
|
|
|
(push 'merlin-company-backend company-backends-merlin-mode))
|
|
|
|
)
|
2015-04-18 18:13:24 +00:00
|
|
|
(evil-leader/set-key-for-mode 'tuareg-mode
|
|
|
|
"mgg" 'merlin-locate
|
|
|
|
"met" 'merlin-type-enclosing
|
|
|
|
;; "mhh" 'merlin-document
|
|
|
|
)
|
2015-04-18 16:22:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
(when (configuration-layer/layer-usedp 'auto-completion)
|
|
|
|
;; Hook company to merlin-mode
|
|
|
|
(defun ocaml/post-init-company ()
|
2015-04-18 16:26:24 +00:00
|
|
|
(spacemacs|add-company-hook merlin-mode)
|
|
|
|
))
|
2015-04-18 16:22:34 +00:00
|
|
|
|
2015-04-18 16:26:24 +00:00
|
|
|
(when (configuration-layer/layer-usedp 'syntax-checking)
|
|
|
|
(defun ocaml/init-flycheck-ocaml ()
|
|
|
|
(use-package flycheck-ocaml
|
|
|
|
:if (configuration-layer/package-usedp 'flycheck)
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(add-hook 'merlin-mode-hook 'flycheck-mode)
|
|
|
|
(with-eval-after-load 'merlin
|
|
|
|
;; Disable Merlin's own error checking
|
|
|
|
(setq merlin-error-after-save nil)
|
|
|
|
;; Enable Flycheck checker
|
|
|
|
(flycheck-ocaml-setup))
|
|
|
|
)))
|
2015-02-07 17:37:53 +00:00
|
|
|
|
|
|
|
;; For each package, define a function ocaml/init-<package-ocaml>
|
|
|
|
;;
|
|
|
|
;; (defun ocaml/init-my-package ()
|
|
|
|
;; "Initialize my package"
|
|
|
|
;; )
|
|
|
|
;;
|
|
|
|
;; Often the body of an initialize function uses `use-package'
|
|
|
|
;; For more info on `use-package', see readme:
|
|
|
|
;; https://github.com/jwiegley/use-package
|