doomemacs/modules/lang/ocaml
Henrik Lissner a3e262c7ac
💥 Refactor add-hook! macro & change arg order
This update may potentially break your usage of add-hook! if you pass
the :local or :append properties to it. This is how they used to work:

  (add-hook! :append 'some-mode-hook #'do-something)

Thsoe properties must now follow the hooks, e.g.

  (add-hook! 'some-mode-hook :append #'do-something)

Other changes:
- Various add-hook calls have been renamed to add-hook! because I
  incorrectly assumed `defun` always returned its definition's symbol,
  when in fact, its return value is "undefined" (so sayeth the
  documentation). This should fix #1597.
- This update adds the ability to add multiple functions to hooks
  without a list:

    (add-hook! 'some-mode-hook
               #'do-something
               #'do-something-else)

- The indentation logic has been changed so that consecutive function
  symbols at indented at the same level as the first argument, but forms
  are indent like a defun.

    (add-hook! 'some-mode-hook
               #'do-something
               #'do-something-else)

    (add-hook! 'some-mode-hook
      (message "Hello"))
2019-07-26 20:17:29 +02:00
..
autoload.el lang/ocaml: ensure * in block comments are padded 2019-07-08 22:08:59 +02:00
config.el 💥 Refactor add-hook! macro & change arg order 2019-07-26 20:17:29 +02:00
doctor.el Add :tools lsp checks for +lsp flag 2019-04-24 18:16:05 -04:00
packages.el 💥 Replace package.el/quelpa with straight #374 2019-07-22 02:30:40 +02:00
README.org 💥 Remove :feature category 2019-04-24 18:16:04 -04:00

:lang ocaml

This module adds OCaml support, powered by tuareg-mode.

Module Flags

This module provides the +opam-site-lisp flag to compile editor support .el files from opam's site-lisp directory. By default all editor plugins are installed from MELPA/GitHub even if the corresponding opam package isn't installed. If this flag is enabled then you must have all of the packages listed in package.el installed via opam.

To enable this, use:

(doom! :lang (ocaml +opam-site-lisp))

Prerequisites

It is highly recommended to install opam. To get all the features you should also install these opam packages, however they are not all required (features should be disabled gracefully when a tool is missing):

opam install merlin utop ocp-indent dune ocamlformat

Features

  • the following files should have syntax highlighting support:

.ml{i,p,y,}, .eliom{i,}, jbuild, dune, opam

  • merlin-mode is activated whenever a .merlin file is found (including in a parent directory) and ocamlmerlin executable is present
  • line-based auto-indentation is provided by ocp-indent when installed

Configuration

  • if :completion company is enabled then autocomplete is provided by merlin
  • when :tools flycheck is enabled then flycheck-ocaml is activated to do on-the-fly syntax/type checking via merlin, otherwise this is only done when the file is saved.
  • spell checking is activated in comments if :tools flyspell is active
  • a REPL is provided if utop is installed and :tools eval is active
  • if :editor format is enabled, the ocamlformat executable is available and there is an .ocamlformat file present then format-all-buffer is bound to ocamlformat, otherwise to ocp-indent
  • if :editor multiple-cursors is enabled then identifiers can be refactored with v R and multiple cursors (this correctly matches identifier occurrences according to scope, it is not purely a textual match)
  • if :emacs imenu is enabled then top level symbols (modules, type, functions, etc.) can be looked up using SPC / i

Run make install to install all packages, and make doctor to diagnose missing tools.

Appendix

Commands

command key / ex command description
merlin-type-enclosing SPC m t display type under point
tuareg-find-alternate-file SPC m a switch between .ml and .mli
merlin-locate gd lookup definition
merlin-occurences SPC c D lookup references
merlin-document K lookup documentation
merlin-imenu SPC / i symbol lookup in file
merlin-iedit-occurrences v R visual refactor identifier under point (multiple cursors)
utop SPC o r open utop as REPL
utop-eval-region SPC c e evaluate selected region in utop

Hacks

  • set-pretty-symbols! is called with the full tuareg prettify symbol list, this can cause columns to change as certain keywords are shortened (e.g. fun becomes λ.
  • tuareg-opam-update-env is called the first time tuareg is loaded