OCamlPro / ocp-indent

Indentation tool for OCaml, to be used from editors like Emacs and Vim.
http://www.typerex.org/ocp-indent.html
Other
200 stars 63 forks source link

Indentation of "monadic match" #125

Open dbuenzli opened 10 years ago

dbuenzli commented 10 years ago

Would it be possible to reconcile the following two forms so that in both cases the matches start under the let ?

> cat indent.ml # desired
let f x = g x >>= function 
| None -> () 
| Some -> ()

let f x = g x >>= fun x -> match x with
| None -> ()
| Some -> () 

> ocp-indent -c "strict_with=always,match_clause=4,strict_else=never" indent.ml 
let f x = g x >>= function 
  | None -> () 
  | Some -> ()

let f x = g x >>= fun x -> match x with
| None -> ()
| Some -> () 

Thanks !

dbuenzli commented 10 years ago

Note that it seems to not work only at top level, in the following code the invocation leaves the second function unchanged.

let f x = g x >>= function
| None -> ()
| Some ->
    g x >>= function
    | None -> ()
    | Some -> ()
>  ocp-indent -c "strict_with=always,match_clause=4,strict_else=never" indent.ml
let f x = g x >>= function 
  | None -> () 
  | Some ->
      g x >>= function 
      | None -> () 
      | Some -> ()
dbuenzli commented 10 years ago

Same is true for other ops e.g. ( @@ ).

dbuenzli commented 8 years ago

Along the same line it would be nice if the following first let binding wouldn't have its match bars idented:

 > ocp-indent --config="strict_with=always,match_clause=4,strict_else=never" < bla.ml 

let _ =
  begin op b >>= function
    | true -> ()
    | false -> ()
  end

let _ =
  op b >>= function
  | true -> ()
  | false -> ()

let _ =
  begin match op b with
  | true -> ()
  | false -> ()
  end