OCaml: Difference between revisions

imported>Mic92
fix markup
imported>Mic92
syntax highlighting
Line 18: Line 18:
Emacs must be configured to be able to find this package: you may need to add a line like this to your '''.emacs''' file, somewhere between <code>(require 'package)</code> and <code>(package-initialize)</code>:
Emacs must be configured to be able to find this package: you may need to add a line like this to your '''.emacs''' file, somewhere between <code>(require 'package)</code> and <code>(package-initialize)</code>:


  (add-to-list 'package-directory-list "~/.nix-profile/share/emacs/site-lisp/elpa")
<syntaxHighlight lang=emacs>
(add-to-list 'package-directory-list "~/.nix-profile/share/emacs/site-lisp/elpa")
</syntaxHighlight>


There is some more documentation in the [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/emacs-packages.nix nixpkgs sources].
There is some more documentation in the [https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/emacs-packages.nix nixpkgs sources].
Line 28: Line 30:
To configure Emacs and enable the merlin mode, add the following to your '''.emacs''':
To configure Emacs and enable the merlin mode, add the following to your '''.emacs''':


  (add-to-list 'load-path "~/.nix-profile/share/emacs/site-lisp")
<syntaxHighlight lang=emacs>
  (require 'merlin)
(add-to-list 'load-path "~/.nix-profile/share/emacs/site-lisp")
  (add-hook 'tuareg-mode-hook 'merlin-mode t)
(require 'merlin)
(add-hook 'tuareg-mode-hook 'merlin-mode t)
</syntaxHighlight>


Also, a specific variable ('''merlin-command''') of the merlin mode must be overridden (its default is '''opam'''):
Also, a specific variable ('''merlin-command''') of the merlin mode must be overridden (its default is '''opam'''):


  (custom-set-variables
<syntaxHighlight lang=emacs>
  '(merlin-command "ocamlmerlin")
(custom-set-variables
  )
  '(merlin-command "ocamlmerlin")
)
</syntaxHighlight>


A useful complement to merlin is [https://www.typerex.org/ocp-indent.html '''ocp-indent'''], a customizable tool to indent OCaml code. It can be installed using <code>nix-env -iA nixpkgs.ocamlPackages.ocpIndent</code>. To enable it in Emacs, don’t forget to add the following line to your '''.emacs''':
A useful complement to merlin is [https://www.typerex.org/ocp-indent.html '''ocp-indent'''], a customizable tool to indent OCaml code. It can be installed using <code>nix-env -iA nixpkgs.ocamlPackages.ocpIndent</code>. To enable it in Emacs, don’t forget to add the following line to your '''.emacs''':


  (require 'ocp-indent)
<syntaxHighlight lang=emacs>
(require 'ocp-indent)
</syntaxHighlight>


== Specific version of the OCaml compiler ==
== Specific version of the OCaml compiler ==


Various versions of the '''ocamlPackage'' attribute set are available, corresponding to various versions of OCaml. For instance, the attribute set '''ocaml-ng.ocamlPackages_4_04''' contains the OCaml compiler at version 4.04 and OCaml libraries compiled with that particular compiler.
Various versions of the '''ocamlPackage'' attribute set are available, corresponding to various versions of OCaml. For instance, the attribute set '''ocaml-ng.ocamlPackages_4_04''' contains the OCaml compiler at version 4.04 and OCaml libraries compiled with that particular compiler.