如何在tuareg模式下配置匿名结构和功能缩进?

时间:2013-11-18 23:52:41

标签: emacs ocaml tuareg

我试图弄清楚如何修复tuareg模式中的缩进,以便它不会在匿名函数和结构中插入大量缩进。我过去曾经使用过它并没有这样做,但现在却是这样。我想知道如何配置它以免这个问题消失。

例如。此代码通过tuareg模式缩进:

let m = List.map (fun (va,vb) ->
                  (va,vb)
                 ) m
in

我希望它像这样缩进:

let m = List.map (fun (va,vb) ->
  (va,vb)
) m
in

同样,tuareg会像这样缩进这段代码:

module SMap = Map.Make(struct
                        type t = string
                        let compare = compare
                      end)

我希望它像这样缩进:

module SMap = Map.Make(struct
  type t = string
  let compare = compare
end)

我正在使用2013年11月12日发布的tuareg模式2.0.7。

更新:我可以确认回滚到2.0.6可以解决这个问题。但是,我仍然在寻找配置选项来解决这个问题。

2 个答案:

答案 0 :(得分:0)

使用 〜/ .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)

您的示例缩进为

tuareg-mode

随意将缩进调整为2个空格。


更新: 似乎版本2.0.7确实使用了新的缩进算法。但是,在 tuareg-el 中评论这两行:

1213 ;;(when (require 'smie nil 'noerror)
1214 ;;  (setq tuareg-use-smie t))

恢复为'旧'缩进模式。

答案 1 :(得分:0)

另一种解决方案是使用ocp-indent。使用opam

安装它
opam install ocp-indent

然后在.emacs文件中的某处使用以下elisp代码加载和配置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)))
相关问题