4

I'm working through the Real World OCaml book. Based on the installation instructions, I installed tuareg-mode for editing OCaml code. It is version 2.0.9, which appears to be the latest version.

The corresponding code in my init.el looks like:

  (add-hook 'tuareg-mode-hook 'tuareg-imenu-set-imenu)
  (setq auto-mode-alist
        (append '(("\\.ml[ily]?$" . tuareg-mode)
                  ("\\.topml$" . tuareg-mode))
                auto-mode-alist)) 
  (autoload 'utop-setup-ocaml-buffer "utop" "Toplevel for OCaml" t)
  (add-hook 'tuareg-mode-hook 'utop-setup-ocaml-buffer)
  (add-hook 'tuareg-mode-hook 'merlin-mode)
  (setq merlin-use-auto-complete-mode t)
  (setq merlin-error-after-save nil)

When I try to type code into a .ml file, it indents things weirdly. For example, if I type

open Core.Std
       (* it indents like this *)
       (* for every line in the rest of the file *)
(* But I would expect it to indent like this *)

When I type a let statement, it does move to the left, but only after I press return to move on to the next line.

Inside a function definition, indentation works as expected, but the top level of the file indents like the example above. How can I make the top-level indentation behave?

  • 1
    What version of Tuareg mode is this? With my version (2.0.6), the line below open starts out intended, but when I type a phrase-starting keyword (e.g. let …) or when I type a comment's closing parenthesis, the line moves flush left. – Gilles Feb 18 '15 at 21:36
  • It is version 2.0.9, which appears to be the latest version. When I type a let statement, it does move to the left, but only after I press return to move on to the next line. – InFreefall Feb 18 '15 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.