-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ocaml: refactor layer to make it better for spacemacs idioms
Fix activation of auto-complete Sort packages Improvement with hook usage Move opam init function in funcs.el and call it only in tuareg config Fix errors if opam is not installed, warn if it has not been found Small edition of the README Rename additional REPL functions with spacemacs prefix
- Loading branch information
Showing
4 changed files
with
128 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
;;; funcs.el --- ocaml Layer functions 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 | ||
|
||
(defun spacemacs//init-ocaml-opam () | ||
(if (executable-find "opam") | ||
(let ((share (substring (shell-command-to-string | ||
"opam config var share 2> /dev/null") 0 -1))) | ||
(when share | ||
(setq opam-share share | ||
opam-load-path (concat share "/emacs/site-lisp"))) | ||
(add-to-list 'load-path opam-load-path)) | ||
(spacemacs-buffer/warning | ||
(concat "Cannot find \"opam\" executable. " | ||
"The ocaml layer won't work properly.")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,120 +12,112 @@ | |
|
||
(setq ocaml-packages | ||
'( | ||
tuareg | ||
merlin | ||
utop | ||
ocp-indent | ||
company | ||
flycheck | ||
flycheck-ocaml | ||
;; package ocamls go here | ||
merlin | ||
ocp-indent | ||
tuareg | ||
utop | ||
)) | ||
|
||
(defun ocaml/init-tuareg () | ||
(add-hook 'tuareg-mode-hook #'merlin-mode) | ||
(evil-leader/set-key-for-mode 'tuareg-mode | ||
"mcc" 'compile | ||
) | ||
;; don't auto-close apostrophes (type 'a = foo) | ||
(when (fboundp 'sp-local-pair) | ||
(sp-local-pair 'tuareg-mode "'" nil :actions nil) | ||
) | ||
) | ||
(defun ocaml/post-init-company () | ||
(spacemacs|add-company-hook merlin-mode)) | ||
|
||
(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)) | ||
(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 | ||
(progn | ||
(add-to-hook 'merlin-mode-hook '(flycheck-mode | ||
flycheck-ocaml-setup)) | ||
(eval-after-load 'merlin | ||
(setq merlin-use-auto-complete-mode nil)))))) | ||
|
||
(defun ocaml/init-utop () | ||
(use-package utop | ||
(defun ocaml/init-merlin () | ||
(use-package merlin | ||
:defer t | ||
: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))) | ||
(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 | ||
) | ||
) | ||
(define-key utop-mode-map (kbd "C-j") 'utop-history-goto-next) | ||
(define-key utop-mode-map (kbd "C-k") 'utop-history-goto-prev) | ||
) | ||
(progn | ||
(add-hook 'tuareg-mode-hook 'merlin-mode) | ||
;; disable integration with auto-complete, we use flycheck | ||
(set-default 'merlin-use-auto-complete-mode nil) | ||
(push 'merlin-company-backend company-backends-merlin-mode) | ||
(evil-leader/set-key-for-mode 'tuareg-mode | ||
"met" 'merlin-type-enclosing | ||
"mgg" 'merlin-locate | ||
;;"mhh" 'merlin-document | ||
)))) | ||
|
||
(defun ocaml/init-ocp-indent () | ||
(use-package ocp-indent | ||
:defer t | ||
:init | ||
(ocaml/opam) | ||
) | ||
) | ||
(add-hook 'tuareg-mode-hook 'ocp-indent-caml-mode-setup))) | ||
|
||
(defun ocaml/init-merlin () | ||
(use-package merlin | ||
(defun ocaml/init-tuareg () | ||
(use-package tuareg | ||
: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)) | ||
) | ||
(evil-leader/set-key-for-mode 'tuareg-mode | ||
"mgg" 'merlin-locate | ||
"met" 'merlin-type-enclosing | ||
;; "mhh" 'merlin-document | ||
) | ||
) | ||
(progn | ||
(spacemacs//init-ocaml-opam) | ||
(evil-leader/set-key-for-mode 'tuareg-mode | ||
"mcc" 'compile)) | ||
:config | ||
(when (fboundp 'sp-local-pair) | ||
;; don't auto-close apostrophes (type 'a = foo) | ||
(sp-local-pair 'tuareg-mode "'" nil :actions nil)))) | ||
|
||
(when (configuration-layer/layer-usedp 'auto-completion) | ||
;; Hook company to merlin-mode | ||
(defun ocaml/post-init-company () | ||
(spacemacs|add-company-hook merlin-mode) | ||
)) | ||
(defun ocaml/init-utop () | ||
(use-package utop | ||
:defer t | ||
:init (add-hook 'tuareg-mode-hook 'utop-minor-mode) | ||
:config | ||
(progn | ||
;; Setup environment variables using opam | ||
(if (executable-find "opam") | ||
(let ((vars (car (read-from-string | ||
(shell-command-to-string "opam config env --sexp"))))) | ||
(dolist (var vars) | ||
(setenv (car var) (cadr var)))) | ||
(spacemacs-buffer/warning "Cannot find \"opam\" executable.")) | ||
;; Update the emacs path | ||
(setq exec-path (append (parse-colon-path (getenv "PATH")) | ||
(list exec-directory))) | ||
|
||
(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)) | ||
))) | ||
(defun spacemacs/utop-eval-phrase-and-go () | ||
"Send phrase to REPL and evaluate it and switch to the REPL in | ||
`insert state'" | ||
(interactive) | ||
(utop-eval-phrase) | ||
(utop) | ||
(evil-insert-state)) | ||
|
||
;; 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 | ||
(defun spacemas/utop-eval-buffer-and-go () | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
syl20bnr
Author
Owner
|
||
"Send buffer to REPL and evaluate it and switch to the REPL in | ||
`insert state'" | ||
(interactive) | ||
(utop-eval-buffer) | ||
(utop) | ||
(evil-insert-state)) | ||
|
||
(defun spacemacs/utop-eval-region-and-go (start end) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
"Send region to REPL and evaluate it and switch to the REPL in | ||
`insert state'" | ||
(interactive "r") | ||
(utop-eval-region start end) | ||
(utop) | ||
(evil-insert-state)) | ||
|
||
(evil-leader/set-key-for-mode 'tuareg-mode | ||
"msb" 'utop-eval-buffer | ||
"msB" 'spacemas/utop-eval-buffer-and-go | ||
"msi" 'utop | ||
"msp" 'utop-eval-phrase | ||
"msP" 'spacemacs/utop-eval-phrase-and-go | ||
"msr" 'utop-eval-region | ||
"msR" 'spacemacs/utop-eval-region-and-go)) | ||
(define-key utop-mode-map (kbd "C-j") 'utop-history-goto-next) | ||
(define-key utop-mode-map (kbd "C-k") 'utop-history-goto-prev))) |
@syl20bnr You made a typo here :)