Permalink
Browse files

Several small fixes for in-comment indentation

following requests from JS:
- {v is indented
- in-comment indent when starting with '(*\n' is 3, not 2
- no free-form comments when strict_comments=true, even when starting with a newline
  • Loading branch information...
1 parent e6c577c commit 1dbfe612c4583f71e867a0bb4e1d9aa74baa0824 @AltGr AltGr committed Mar 14, 2013
View
@@ -1008,7 +1008,7 @@ let rec update_path config t stream tok =
let i = ref 2 in
while !i < len && s.[!i] = '*' do incr i done;
while !i < len && s.[!i] = ' ' do incr i done;
- if !i >= len || s.[!i] = '\n' || s.[!i] = '\r' then 2 else !i
+ if !i >= len || s.[!i] = '\n' || s.[!i] = '\r' then 3 else !i
in
if not starts_line then
let col = t.toff + tok.offset in
View
@@ -146,7 +146,7 @@ let print_token output block t =
| _ -> Some 1 (* length of '"' *))
| COMMENT ->
(match String.trim text with
- | "(*" -> None
+ | "(*" when not output.config.IndentConfig.i_strict_comments -> None
| _ -> Some (IndentBlock.padding block))
| COMMENTCONT ->
Some (IndentBlock.padding block)
@@ -205,8 +205,7 @@ let rec loop output is_first_line block stream =
let kind = match t.token with
| COMMENT when is_prefix "(*\n" t.substr ->
Fixed (String.length blank)
- | OCAMLDOC_VERB ->
- Fixed (String.length blank)
+ | OCAMLDOC_VERB -> Padded
| EOF | EOF_IN_COMMENT | EOF_IN_QUOTATION _ | EOF_IN_STRING _ ->
Empty
| COMMENTCONT -> Padded
@@ -1,128 +0,0 @@
-(* ocp-indent is not going to be confused by comment-embedded tokens. *)
-
-
-
-type t = {
- (* This is a comment *)
- a: int;
-}
-
-type t = {
- (* This is a comment : with a colon. *)
- a: int;
-}
-
-type t = {
- a: int;
- (* with the : second field *)
- b: int;
-}
-
-type t = {
- a: int;
- b: int;
- (* and : the third... *)
- c: int;
-}
-
-
-
-(* colon in CR comment messes Tuareg up *)
-type cfg = {
- foo : int; (* CR mburns: float? *)
- bar : string;
-}
-
-(* To be more precise about the Tuareg bug, it is the fact that the colon in the comment
- is the first or second colon after the start of the record definition. If the comment
- occurs after the first 2 fields in the record everything is fine.
-
- For example, this is OK: *)
-type t= {
- foo : int;
- bar : string; (* CR mburns: float? *)
- baz : string;
-}
-
-(* but Tuareg messes this up *)
-type t= {
- foo : int;
- (* CR mburns: float? *)
- bar : string;
-}
-
-
-
-(* Now that we have support for {v v} and {[ ]}, reindent inside comments,
- unless they are explicitly delimited as code or pre-formatted text. These
- three all end up flattened to the same level. *)
-(*
-type t = {
- (* This is a comment *)
- a: int;
-}
-*)
-(*
- type t = {
- (* This is a comment *)
- a: int;
- }
-*)
-(*
- type t = {
- (* This is a comment *)
- a: int;
- }
-*)
-
-
-
-(* Possible to-do warning: Star-prefixed lines are allowed and indented a little
- less, to line up with the star in the opening comment parenthesis. Maybe we
- don't care enough about them to worry about it, though. *)
-
-
-
-(** Doc comment text should be aligned with the first line, so indented more
- than otherwise. *)
-
-(* We're now using some ocamldoc block syntax to control indentation, and sweeks
- and the rest of us have been relying on it, in and out of doc comments.
-
- {[
- let code =
- should be reindented like code
- so as to work also with vim
- ]}
-
- {v g
- This is totally verbatim text and shouldn't be reindented. Maybe you don't
- need to special-case this, since you will not be reindenting comments. It
- probably doesn't matter what the indentation of the first line of a
-verbatim block is. But how will this be done in vim?
- xx
- yy
- zz
- c v}
-
- Does this even confront ocp-indent? I think, when reindenting whole files,
- source code blocks do confront ocp-indent.
-*)
-
-
-
-(* {v
-
-(* comments embedded in verbatim sections *)
-(* want to be able to verbatim-out big chunks of code *)
-
-v} *)
-
-
-
-(* {v
-
-non-comments in verbatim sections
-duh
-
-v} *)
Oops, something went wrong.

0 comments on commit 1dbfe61

Please sign in to comment.