• Stars
    star
    346
  • Rank 122,430 (Top 3 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created almost 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Emacs OCaml mode

NonGNU ELPA MELPA DebianBadge License GPL 3 Build Status

Tuareg: an Emacs OCaml mode

This archive contains files to help editing OCaml code, to highlight important parts of the code, to run an OCaml REPL (also called toplevel), and to run the OCaml debugger within Emacs.

Package Contents

  • README.md — This file.
  • HISTORY — Differences with previous versions.
  • tuareg.el — A major mode for editing OCaml code in Emacs.
  • ocamldebug.el — To run the OCaml debugger under Emacs.
  • sample.ml — Sample file to check the indentation engine.
  • compilation.txt — To check the compilation regexp tuareg--error-regexp.

Install

The easier way to install Tuareg is though the Emacs package system with NonGNU ELPA or MELPA (configuration).

You can also install it using OPAM:

opam install tuareg

and follow the instructions given at the end of the opam installation.

If you want to install from the Git checkout, just add to your Init File the line:

(load "path-to-git-checkout-dir/tuareg-site-file")

If you want to byte compile the files, issue make elc. If you do this in Darwin, make sure that the version of Emacs displayed at the end of make elc is the sole that you use (the .elc files may not be compatible with other versions of Emacs installed on your system).

Usage & Configuration

The Tuareg major mode is triggered by visiting a file with extension .ml, .mli, and .mlp or manually by M-x tuareg-mode. A Menhir mode, tuareg-menhir, supports .mly files. (A special mode for .mll has yet to be written.)

For the convenience of users of ocsigen, the extensions .eliom, .eliomi trigger tuareg-mode.

Start the OCaml REPL with M-x run-ocaml. To evaluate a phrase, simply type S-⟨return⟩ (shift and return). You can also evaluate a phrase in a different buffer by typing C-c C-e when the cursor is on it (it will start the OCaml REPL if needed).

Run the OCaml debugger with M-x ocamldebug FILE.

Tips & customization

  • You can comment/uncomment a single line with tuareg-comment-dwim which is bound to C-cC-;.

  • By default, Tuareg will align the arguments of functions as follows:

      function_name arg1
        arg2
    

    This is what most OCaml programmers expect and is convenient if you use the following style:

      function_name (fun x ->
          do_something
        )
        arg2
    

    If you prefer the “lisp style” indentation in which arguments on the second line are aligned with the arguments on the first line as in

      function_name arg1
                    arg2
    

    put (setq tuareg-indent-align-with-first-arg t) in your Init File.

    In both cases, if there are no argument on the line following the function name, the indentation will be:

      function_name
        arg1
        arg2
    
  • To make easier to distinguish pattern-match cases containing several patterns, sub-patterns are slightly indented as in

      match x with
      | A
        | B -> ...
      | C -> ...
    

    If you prefer all pipes to be aligned as

      match x with
      | A
      | B -> ...
      | C -> ...
    

    use (setq tuareg-match-patterns-aligned t).

  • Emacs ≥ 24.4 turned on electric-indent-mode mode by default. If you do not like it, call (electric-indent-mode 0) in tuareg-mode-hook.

  • Tuareg respects you default commenting style. However, in OCaml, commenting a region is usually done with a single multi-line comment and without leading stars on each line. You can have that behavior in OCaml buffers by setting:

      (add-hook 'tuareg-mode-hook
                (lambda()
                  (setq-local comment-style 'multi-line)
                  (setq-local comment-continue "   ")))
    
  • If you turn on show-paren-mode, the delimiters of comments will also be highlighted. If you do not like this behavior, set tuareg-comment-show-paren to nil.

  • Syntax highlighting has 3 levels. You can select the one you prefer by setting font-lock-maximum-decoration from 0 to 2. By default, font-lock-maximum-decoration is set to t which means that the maximum level of decoration will be used.

  • Fontifying all operators (as opposed to only non-standard ones) is a costly operation that slows down font-lock. This is why it is disabled by default. If you nonetheless want it, set tuareg-highlight-all-operators to t in your Init File (before tuareg-mode is initialized; in particular, not in a hook added to 'tuareg-mode-hook).

  • You can turn on and off the rendering of certain sequences of characters as symbols (such as and instead of +.and &&), use prettify-symbols-mode or use the check box in the Tuareg Options menu. To enable it by default when you start Tuareg, add the following to your Init File:

      (add-hook 'tuareg-mode-hook
                (lambda()
                  (when (functionp 'prettify-symbols-mode)
                    (prettify-symbols-mode))))
    

    If you want more symbols to be prettified (such as -> being displayed as ) at the expense of modifying the indentation in incompatible ways with those not using that option, add (setq tuareg-prettify-symbols-full t) to your Init File.

  • By default, constructors are highlighted with the default face because having too many colors is distracting. If you wish to customize the appearance of constructors, add to your Init File the following code adapted to your tastes.

      (face-spec-set
       'tuareg-font-lock-constructor-face
       '((((class color) (background light)) (:foreground "SaddleBrown"))
         (((class color) (background dark)) (:foreground "burlywood1"))))
    
  • To have a list of definitions in the buffer, use imenu. It is available by right clicking in the buffer. You can also launch the speedbar and click on file to have a list of definitions.

  • If you wish to have a nice 🐫 as the mode name, add

      (add-hook 'tuareg-mode-hook
                (lambda() (setq tuareg-mode-name "🐫")))
    

    to your Init File.

Thanks to the work of Stefan Monnier, a new indentation engine based on SMIE was written. This changes the indentation somewhat w.r.t. the previous versions of tuareg. If the indentation does not correspond to what you expect, please submit a motivated issue.

The standard Emacs customization tool can be used to configure Tuareg options. It is available from the Options menu and Tuareg's Customize sub-menu. Note that, at the moment, both customization options pertaining to the SMIE indentation mode and the old one are present.

You may also customize the appearance of OCaml code by twiddling the variables listed at the start of tuareg.el (preferably using tuareg-mode-hook, you should not patch the file directly). You should then add to your configuration file something like:

(add-hook 'tuareg-mode-hook
  (lambda () ... ; your customization code ))

For example:

(add-hook 'tuareg-mode-hook
          ;; Turn on auto-fill minor mode.
          #'auto-fill-mode)

See dot-emacs.el for some examples.

Additional packages

Merlin

It is recommended to install Merlin which is available in OPAM. Tuareg will automatically detect it and use some of its features (e.g. for imenu). Merlin offers auto-completion, the possibility to query the type with C-cC-t, to find the location of an identifier with C-cC-l, to go to the next (resp. previous) phrase with C-cC-n (resp. C-cC-p),... Highly recommended.

Caml mode

caml-mode (available in NonGNU ELPA and MELPA) is used to display types (using the obsolete *.annot files), open a module for documentation,...

Reporting

The official Tuareg home page is located at: https://github.com/ocaml/tuareg.

Bug reports & patches: use the tracker: https://github.com/ocaml/tuareg/issues.

Thanks

Ian Zimmerman for the previous mode, compilation interface and debugger enhancement.

Jacques Garrigue enhanced Zimmerman's mode along with an adaptation to OCaml (and Labl) syntax. Although this work was performed independently, his useful test file and comments were of great help.

Michel Quercia for excellent suggestions, patches, and helpful emacs-lisp contributions (full, ready-to-work implementations, I should say), especially for Tuareg interactive mode, and browser capacities.

Denis Barthou, Pierre Boulet, Jean-Christophe Filliatre and Rémi Vanicat for intensive testing, useful suggestions, and help.

Ralf Treinen for maintaining the Debian GNU/Linux package.

Every people who sent me bug reports, suggestions, comments and patches. Nothing would have improved since version 0.9.2 without their help. Special thanks to Eli Barzilay, Josh Berdine, Christian Boos, Carsten Clasohm, Yann Coscoy, Prakash Countcham, Alvarado Cuihtlauac, Erwan David, Gilles Défourneaux, Philippe Esperet, Gilles Falcon, Tim Freeman, Alain Frisch, Christian Lindig, Claude Marché, Charles Martin, Dave Mason, Stefan Monnier, Toby Moth, Jean-Yves Moyen, Alex Ott, Christopher Quinn, Ohad Rodeh, Rauli Ruohonen, Hendrik Tews, Christophe Troestler, Joseph Sudish, Mattias Waldau and John Whitley.

Tuareg mode have been maintained by Albert Cohen until version 1.45.

Jane Street took over maintenance based on Albert Cohen's version 1.46 (later retracted by him), and released its first version as 2.0.

License

Tuareg is distributed under the GNU General Public License, version 3 or later.

More Repositories

1

ocaml

The core OCaml system: compilers, runtime system, base libraries
OCaml
4,732
star
2

dune

A composable build system for OCaml.
OCaml
1,626
star
3

merlin

Context sensitive completion for OCaml in Vim and Emacs
OCaml
1,574
star
4

opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
OCaml
1,225
star
5

ocaml-lsp

OCaml Language Server Protocol implementation
OCaml
766
star
6

opam-repository

Main public package repository for opam, the source package manager of OCaml.
516
star
7

v2.ocaml.org

Implementation of the ocaml.org website.
HTML
323
star
8

odoc

Documentation compiler for OCaml and Reason
OCaml
320
star
9

ocamlunix

Unix system programming in OCaml book
TeX
276
star
10

Zarith

The Zarith library implements arithmetic and logical operations over arbitrary-precision integers and rational numbers. The implementation, based on GMP, is very efficient.
OCaml
223
star
11

ocaml-re

Pure OCaml regular expressions, with support for Perl and POSIX-style strings
OCaml
208
star
12

setup-ocaml

GitHub Action for the OCaml programming language
TypeScript
196
star
13

ocaml.org

The official OCaml website.
HTML
162
star
14

omd

extensible Markdown library and tool in "pure OCaml"
OCaml
152
star
15

RFCs

Design discussions about the OCaml language
150
star
16

oasis

Cabal like system for OCaml
OCaml
124
star
17

ocamlbuild

The legacy OCamlbuild build manager
OCaml
121
star
18

ocaml-ci-scripts

Skeletons for CI scripts
OCaml
101
star
19

flexdll

a dlopen-like API for Windows
OCaml
100
star
20

vim-ocaml

Vim runtime files for OCaml
Vim Script
85
star
21

v3.ocaml.org-rescript

The next implementation of ocaml.org, built on OCaml, ReScript, NextJS, and Tailwind.
ReScript
75
star
22

graphics

The Graphics library from OCaml, in a standalone repository
C
51
star
23

infrastructure

WIki to hold the information about the machine resources available to OCaml.org
HTML
40
star
24

num

The legacy Num library for arbitrary-precision integer and rational arithmetic that used to be part of the OCaml core distribution
OCaml
35
star
25

MPP-language-blender

MPP: a meta preprocessor that blends programming languages
OCaml
33
star
26

obi

OCaml Build Infrastructure
OCaml
30
star
27

oasis2opam

Tool to convert OASIS metadata to OPAM package descriptions
OCaml
27
star
28

ocamlfind

The OCaml findlib library manager
OCaml
26
star
29

ocaml-logo

Official Logo for OCaml
26
star
30

caml-mode

Emacs mode to edit OCaml files
Emacs Lisp
19
star
31

code-of-conduct

Documents related to the Code of Conduct
17
star
32

ocaml-beta-repository

Opam2 remote for beta versions of the OCaml compiler
Shell
16
star
33

ocaml-manual

OBSOLETE, ARCHIVED mirror of the OCaml manual
TeX
15
star
34

opam-file-format

Parser and printer for the opam file syntax
OCaml
15
star
35

ood

OCaml.org v3 data repository
OCaml
14
star
36

camlp-streams

The Stream and Genlex libraries for use with Camlp4 and Camlp5
OCaml
14
star
37

platform-blog

Repository for the Platform blog
13
star
38

oloop

Evaluate code through the OCaml toploop for inclusion in educational material.
OCaml
12
star
39

dbm

The legacy CamlDBM library for accessing NDBM/GDBM database files
OCaml
12
star
40

ocaml-library-standard

Documenting how OCaml libraries are managed
11
star
41

stdlib-shims

Shim to substitute `Pervasives` with `Stdlib` before 4.08.
Standard ML
10
star
42

dune-www

Website for dune.build
SCSS
10
star
43

0install-tools

Tools for distributing OCaml via 0install
8
star
44

platform-dev

Dev versions of the tools used to build the upcoming platform
Shell
8
star
45

opam.ocaml.org

Scripts and documentation for the opam.ocaml.org website
Shell
7
star
46

oasis-db

Hackage like system for OCaml based on OASIS
OCaml
7
star
47

uchar

Uchar compatibility library
OCaml
6
star
48

stdlib-random

Versioned random number library
OCaml
6
star
49

oasis-website

Devel website for OASIS http://oasis.forge.ocamlcore.org
JavaScript
5
star
50

cwn-data

The data repository for the Caml Weekly News
HTML
5
star
51

ocaml-pr-repository

opam switches for all the proposed pull requests against the compiler
5
star
52

oasis2debian

Convert _oasis to debian/ directory.
OCaml
5
star
53

homebrew-ocaml

A Homebrew tap for OCaml and OPAM distribution
Ruby
5
star
54

ocaml.org-media

Media files that we don't want to include in main ocaml.org repo.
HTML
4
star
55

opam-source-archives

mirror of precious opam repository packages whose source websites have disappeared
Shell
4
star
56

subsystem-meetings

sharing documents for specialized developer meetings
4
star
57

ocaml.org-scripts

Scripts for the ocaml.org infrastructure machines
Shell
2
star
58

ocaml.org-infratest

Tests for ocaml.org websites and services.
Shell
2
star
59

release-readiness

Tracking release readiness for OCaml compiler releases
1
star
60

opam-bulk-logs

Logs of daily OPAM bulk package builds
1
star
61

obi-logs

Logs for OCaml Build Infrastructure
1
star