2015-12-02 14:23:39 +00:00
|
|
|
#+TITLE: Ocaml layer
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2019-05-07 08:53:56 +00:00
|
|
|
#+TAGS: general|layer|multi-paradigm|programming
|
2019-05-05 17:26:40 +00:00
|
|
|
|
2015-06-10 16:44:30 +00:00
|
|
|
[[file:img/ocaml.png]]
|
|
|
|
|
2019-05-07 20:05:06 +00:00
|
|
|
* Table of Contents :TOC_5_gh:noexport:
|
2017-05-22 14:16:12 +00:00
|
|
|
- [[#description][Description]]
|
|
|
|
- [[#features][Features:]]
|
|
|
|
- [[#install][Install]]
|
|
|
|
- [[#layer][Layer]]
|
2018-01-24 23:47:26 +00:00
|
|
|
- [[#using-merlin-for-error-reporting][Using merlin for error reporting]]
|
2017-05-22 14:16:12 +00:00
|
|
|
- [[#opam-packages][OPAM packages]]
|
2018-12-05 03:03:03 +00:00
|
|
|
- [[#key-bindings][Key bindings]]
|
2017-05-22 14:16:12 +00:00
|
|
|
- [[#repl-utop][REPL (utop)]]
|
2019-04-28 11:40:42 +00:00
|
|
|
- [[#dune][Dune]]
|
2018-09-19 03:54:47 +00:00
|
|
|
- [[#layer-improvements-list][layer improvements list]]
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
* Description
|
|
|
|
This is a very basic layer for editing ocaml files.
|
|
|
|
|
2015-06-10 21:16:01 +00:00
|
|
|
** Features:
|
2015-06-10 16:44:30 +00:00
|
|
|
- Syntax highlighting (major-mode) via [[https://github.com/ocaml/tuareg][tuareg-mode]]
|
2017-04-26 13:50:19 +00:00
|
|
|
- Error reporting, completion and type display via [[https://github.com/ocaml/merlin][merlin]]
|
|
|
|
- auto-completion with company mode via [[https://github.com/ocaml/merlin][merlin]]
|
2018-01-24 23:47:26 +00:00
|
|
|
- syntax-checking via [[https://github.com/flycheck/flycheck-ocaml][flycheck-ocaml]] (or alternatively [[https://github.com/ocaml/merlin][merlin]])
|
2019-04-28 11:40:42 +00:00
|
|
|
- =dune= file syntax highlighting and template insertion via [[https://github.com/ocaml/dune/][dune-mode]]
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
* Install
|
|
|
|
** Layer
|
2016-01-06 05:21:55 +00:00
|
|
|
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
|
|
|
|
add =ocaml= to the existing =dotspacemacs-configuration-layers= list in this
|
|
|
|
file.
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2018-01-24 23:47:26 +00:00
|
|
|
** Using merlin for error reporting
|
|
|
|
By default [[https://github.com/flycheck/flycheck-ocaml][flycheck-ocaml]] is used for error reporting when the
|
|
|
|
=syntax-checking= layer is also enabled as this is common throughout spacemacs.
|
2019-05-26 20:58:52 +00:00
|
|
|
You can disable this and switch back to [[https://github.com/ocaml/merlin][merlin]]'s default error reporting method
|
2018-01-24 23:47:26 +00:00
|
|
|
by adding [[https://github.com/flycheck/flycheck-ocaml][flycheck-ocaml]] to your excluded packages list in =.spacemacs=:
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-09-19 03:54:47 +00:00
|
|
|
dotspacemacs-excluded-packages '(... flycheck-ocaml ... )
|
2018-01-24 23:47:26 +00:00
|
|
|
#+END_SRC
|
|
|
|
|
2015-06-10 16:44:30 +00:00
|
|
|
** OPAM packages
|
2015-06-12 01:23:07 +00:00
|
|
|
This layer requires some [[http://opam.ocaml.org][opam]] packages:
|
2015-06-10 16:44:30 +00:00
|
|
|
- =merlin= for auto-completion
|
|
|
|
- =utop=
|
|
|
|
- =ocp-indent=
|
|
|
|
|
2016-04-13 03:31:38 +00:00
|
|
|
To install them, use the following command:
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
opam install merlin utop ocp-indent
|
|
|
|
#+END_SRC
|
|
|
|
|
2015-10-01 14:20:04 +00:00
|
|
|
Make sure opam is initialized and configured.
|
|
|
|
|
2018-09-19 03:54:47 +00:00
|
|
|
#+BEGIN_SRC sh
|
2015-10-01 14:20:04 +00:00
|
|
|
opam init
|
|
|
|
opam config setup -a
|
2018-09-19 03:54:47 +00:00
|
|
|
#+END_SRC
|
2015-10-01 14:20:04 +00:00
|
|
|
|
2018-12-05 03:03:03 +00:00
|
|
|
* Key bindings
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2018-12-05 03:03:03 +00:00
|
|
|
| Key binding | Description |
|
2015-06-10 16:44:30 +00:00
|
|
|
|-------------+----------------------------------------------------------|
|
2016-05-17 03:57:15 +00:00
|
|
|
| ~SPC m =~ | Indent buffer. |
|
2015-06-10 16:44:30 +00:00
|
|
|
| ~SPC m c c~ | Compile |
|
|
|
|
| ~SPC m c p~ | Check .merlin for errors |
|
|
|
|
| ~SPC m c r~ | Refresh changed .cmis in merlin |
|
|
|
|
| ~SPC m e C~ | Check for errors in current buffer |
|
|
|
|
| ~SPC m e n~ | Jump to next error |
|
|
|
|
| ~SPC m e N~ | Jump back to previous error |
|
|
|
|
| ~SPC m g a~ | Switch ML <-> MLI |
|
|
|
|
| ~SPC m g b~ | Go back to the last position where the user did a locate |
|
|
|
|
| ~SPC m g g~ | Locate the identifier under point (same window) |
|
|
|
|
| ~SPC m g G~ | Locate the identifier under point (different window) |
|
|
|
|
| ~SPC m g i~ | Prompt for module name and switch to ML file |
|
|
|
|
| ~SPC m g I~ | Prompt for module name and switch to MLI file |
|
2019-05-13 01:57:17 +00:00
|
|
|
| ~SPC m g l~ | Prompt for identifier and locate |
|
|
|
|
| ~SPC m g o~ | List occurrences for identifier under point |
|
2015-06-10 16:44:30 +00:00
|
|
|
| ~SPC m h h~ | Document the identifier under point |
|
|
|
|
| ~SPC m h t~ | Highlight identifier under cursor and print its type |
|
|
|
|
| ~SPC m h T~ | Prompt for expression and show its type |
|
|
|
|
| ~SPC m r d~ | Case analyze the current enclosing |
|
2019-04-28 11:40:42 +00:00
|
|
|
| ~SPC m t p~ | Dune run tests and promote. |
|
|
|
|
| ~SPC m t P~ | Dune promote. |
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
** REPL (utop)
|
|
|
|
|
2018-12-05 03:03:03 +00:00
|
|
|
| Key binding | Description |
|
2015-06-10 16:44:30 +00:00
|
|
|
|-------------+------------------------------------------------------------------|
|
2019-05-13 01:57:17 +00:00
|
|
|
| ~C-j~ | (in REPL) next item in history |
|
|
|
|
| ~C-k~ | (in REPL) previous item in history |
|
2015-06-10 16:44:30 +00:00
|
|
|
| ~SPC m s b~ | Send buffer to the REPL |
|
|
|
|
| ~SPC m s B~ | Send buffer to the REPL and switch to the REPL in =insert state= |
|
|
|
|
| ~SPC m s i~ | Start a REPL |
|
|
|
|
| ~SPC m s p~ | Send phrase to the REPL |
|
|
|
|
| ~SPC m s P~ | Send phrase to the REPL and switch to the REPL in =insert state= |
|
|
|
|
| ~SPC m s r~ | Send region to the REPL |
|
|
|
|
| ~SPC m s R~ | Send region to the REPL and switch to the REPL in =insert state= |
|
|
|
|
|
2019-04-28 11:40:42 +00:00
|
|
|
** Dune
|
|
|
|
|
|
|
|
| Key binding | Description |
|
|
|
|
|-------------+--------------------------------|
|
|
|
|
| ~SPC m c c~ | Compile. |
|
|
|
|
| ~SPC m i a~ | Insert ~alias~ stanza. |
|
|
|
|
| ~SPC m i c~ | Insert ~copyfiles~ stanza. |
|
2019-05-13 01:57:17 +00:00
|
|
|
| ~SPC m i d~ | Insert ignored subdirs stanza. |
|
|
|
|
| ~SPC m i e~ | Insert ~executable~ stanza. |
|
|
|
|
| ~SPC m i i~ | Insert ~install~ stanza. |
|
|
|
|
| ~SPC m i l~ | Insert ~library~ stanza. |
|
|
|
|
| ~SPC m i m~ | Insert ~menhir~ stanza. |
|
|
|
|
| ~SPC m i p~ | Insert ~ocamllex~ stanza. |
|
|
|
|
| ~SPC m i r~ | Insert ~rule~ stanza. |
|
2019-04-28 11:40:42 +00:00
|
|
|
| ~SPC m i t~ | Insert ~tests~ stanza. |
|
|
|
|
| ~SPC m i v~ | Insert ~env~ stanza. |
|
2019-05-13 01:57:17 +00:00
|
|
|
| ~SPC m i x~ | Insert ~executables~ stanza. |
|
|
|
|
| ~SPC m i y~ | Insert ~ocamlyacc~ stanza. |
|
2019-04-28 11:40:42 +00:00
|
|
|
| ~SPC m t p~ | Dune run tests and promote. |
|
|
|
|
| ~SPC m t P~ | Dune promote. |
|
|
|
|
|
2018-09-19 03:54:47 +00:00
|
|
|
* TODO layer improvements list
|
2018-10-23 14:18:21 +00:00
|
|
|
1. Add more proper spacemacs key bindings for basic merlin tasks
|
|
|
|
2. Add proper key bindings for ocamldebug
|
|
|
|
3. Add more key bindings for tuareg-mode
|