Reputation: 394
I am trying to figure out how to fix the indentation in tuareg mode so that it does not insert a massive amount of indentation in anonymous functions and structures. I have used it in the past and it has not done this, but now it is. I would like to know how to configure it so that this problem goes away.
For example. This code is indented like this by tuareg mode:
let m = List.map (fun (va,vb) ->
(va,vb)
) m
in
I would like it to be indented like this:
let m = List.map (fun (va,vb) ->
(va,vb)
) m
in
Similarly, tuareg indents this code like this:
module SMap = Map.Make(struct
type t = string
let compare = compare
end)
I would prefer it to be indented like this:
module SMap = Map.Make(struct
type t = string
let compare = compare
end)
I am using tuareg mode 2.0.7 that was released on November 12, 2013.
Update: I can confirm that rolling back to 2.0.6 resolves this problem for me. However, I'm still looking for the configuration option to fix this.
Upvotes: 1
Views: 544
Reputation: 750
An alternative solution is to use ocp-indent. Install it using opam
opam install ocp-indent
Then somewhere in your .emacs file use the following elisp code to load and configure ocp-indent.
;; Add opam emacs directory to the load-path
(setq opam-share (substring (shell-command-to-string "opam config var share 2> /dev/null") 0 -1))
(add-to-list 'load-path (concat opam-share "/emacs/site-lisp"))
;; Setup environment variables using OPAM
(dolist (var (car (read-from-string (shell-command-to-string "opam config env --sexp"))))
(setenv (car var) (cadr var)))
;; One of the `opam config env` variables is PATH. Update `exec-path` to that.
(setq exec-path (split-string (getenv "PATH") path-separator))
(require 'ocp-indent)
(add-hook 'tuareg-mode-hook (lambda ()
;; Your other tuareg specific settings here.
(setq indent-line-function 'ocp-indent-line)))
Upvotes: 0
Reputation: 10309
With my ~/.emacs
(custom-set-variables
'(custom-enabled-themes (quote (tango-dark)))
'(tool-bar-mode nil)
'(tuareg-begin-indent 4)
'(tuareg-class-indent 4)
'(tuareg-default-indent 4)
'(tuareg-do-indent 4)
'(tuareg-for-while-indent 4)
'(tuareg-fun-indent 4)
'(tuareg-if-then-else-indent 4)
'(tuareg-let-indent 4)
'(tuareg-match-indent 4)
'(tuareg-method-indent 4)
'(tuareg-pipe-extra-unindent 4)
'(tuareg-sig-struct-indent 4)
'(tuareg-try-indent 4)
'(tuareg-val-indent 4))
(custom-set-faces
'(default ((t (:family "DejaVu Sans Mono" :foundry "unknown" :slant normal :weight normal :height 98 :width normal)))))
;disable backup
(setq backup-inhibited t)
;disable auto save
(setq auto-save-default nil)
;disable line wrapping
(setq-default truncate-lines t)
;space only indentation
(setq-default indent-tabs-mode nil)
your examples are indented as
Feel free to adjust indents to 2 spaces.
Update: It seems that version 2.0.7 indeed uses new indentation algorithm. However, commenting these two lines in tuareg-el:
1213 ;;(when (require 'smie nil 'noerror)
1214 ;; (setq tuareg-use-smie t))
reverts to 'old' indentation mode.
Upvotes: 0