Skip to content

spacemacs from scratch

Fourchaux edited this page Jan 24, 2018 · 22 revisions

Spacemacs for OCaml

The best editor is neither Emacs nor Vim, it's Emacs and Vim!

Spacemacs is organized in layers of configuration. You can create layers yourself but there are tons of community created layers (for various languages and functionalities) which make configuring Spacemacs easy by just adding a layer name in the .spacemacs configuration file.

Prerequisites

I'm going to have the steps listed for Linux but it should be very similar for OS X.

  • By default Spacemacs use the 'Source Code Pro' fonts. If not present, you can use:
git clone --depth 1 --branch release https://github.com/adobe-fonts/source-code-pro.git ~/.fonts/adobe-fonts/source-code-pro

and have the system aware of the new fonts with:

fc-cache -f -v
  • The OCaml layer requires Merlin, utop & ocp-indent. The easiest method is to install these OPAM packages with :
opam install merlin utop ocp-indent

The latest version of Merlin can also be used :

opam pin add merlin --dev-repo
  • A recent Emacs installation (version 24.4 or newer)

Spacemacs installation

  • Backup any existing Emacs configuration.
mv ~/.emacs.d ~/.emacs.backup
  • Clone Spacemacs in place of the old Emacs configuration.
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d

Before running Emacs you can switch to the develop branch so you will have all the latest additions to Spacemacs.
It seems pretty stable so far. In the github repository :

git checkout develop

Then launching Emacs as normal will automatically load Spacemacs, installing all required packages.
As it's the first time it will ask about :

  • the preferred style : vim (default) or emacs
  • the distribution of spacemacs : standard (default) or minimalist
  • (for develop branch only) the type of completion framework : helm (default) or ivy or none (not recommended).

Once it's done, just restart Emacs (now Spacemacs is installed).

Note: if you use the develop branch of Spacemacs, you have to update it manually with git.
Close Emacs and update the git repository with :

git pull --rebase

Enable OCaml

After opening Emacs, it should show ~/.spacemacs under Recent files.
Click on that file to open it. (or hit : SPC (or M-m) f e d)

In the dotspacemacs-configuration-layers

   '(
     ...
     ;; auto-completion
     ;; better-defaults
     emacs-lisp
     ;; git
     ;; markdown
     ...
     )
  • Uncomment the ';; auto-completion' line
  • Add a line with 'ocaml'

Restart Emacs.

And ... That's it ... You are in business. Enjoy a (nearly complete) IDE for OCaml.

Screenshots

Notes :

spacemacs

bench

  • ocaml layer key-bindings
    Note : , can be used for SPC m
    bindings_help

Conclusion

This is the simplest configuration possible but ,of course, you are free to change/add/modify absolutely everything.
As OCaml :) it's obvious right from the start that Spacemacs has been well thought out. It's a really nice piece of code with a rapid development, a great community and plenty of help.

Very special thanks to ranjitjhala, edwintorok (and others) for their works on the 'ocaml' layer.
See also : layer_ocaml