This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/ocaml/README.org

101 lines
4.6 KiB
Org Mode
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#+TITLE: Ocaml layer
[[file:img/ocaml.png]]
* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
- [[#layer][Layer]]
- [[#using-merlin-for-error-reporting][Using merlin for error reporting]]
- [[#opam-packages][OPAM packages]]
- [[#key-bindings][Key bindings]]
- [[#repl-utop][REPL (utop)]]
- [[#layer-improvements-list][layer improvements list]]
* Description
This is a very basic layer for editing ocaml files.
** Features:
- Syntax highlighting (major-mode) via [[https://github.com/ocaml/tuareg][tuareg-mode]]
- 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]]
- syntax-checking via [[https://github.com/flycheck/flycheck-ocaml][flycheck-ocaml]] (or alternatively [[https://github.com/ocaml/merlin][merlin]])
* Install
** Layer
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.
** 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.
You can disable this and switch back to [[https://github.com/ocaml/merlin][merlin]]s default error reporting method
by adding [[https://github.com/flycheck/flycheck-ocaml][flycheck-ocaml]] to your excluded packages list in =.spacemacs=:
#+BEGIN_SRC emacs-lisp
dotspacemacs-excluded-packages '(... flycheck-ocaml ... )
#+END_SRC
** OPAM packages
This layer requires some [[http://opam.ocaml.org][opam]] packages:
- =merlin= for auto-completion
- =utop=
- =ocp-indent=
To install them, use the following command:
#+BEGIN_SRC sh
opam install merlin utop ocp-indent
#+END_SRC
Make sure opam is initialized and configured.
#+BEGIN_SRC sh
opam init
opam config setup -a
#+END_SRC
* Key bindings
| Key binding | Description |
|-------------+----------------------------------------------------------|
| ~SPC m =~ | Indent buffer. |
| ~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 o~ | List occurrences for identifier under point |
| ~SPC m g l~ | Prompt for identifier and locate |
| ~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 |
| ~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 |
** REPL (utop)
| Key binding | Description |
|-------------+------------------------------------------------------------------|
| ~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= |
| ~C-j~ | (in REPL) next item in history |
| ~C-k~ | (in REPL) previous item in history |
* TODO layer improvements list
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