Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce prepend/append_multiline_delimiter #205

Merged
merged 3 commits into from
Feb 1, 2023
Merged

Conversation

nbacquey
Copy link
Member

@append_multiline_delimiter / @prepend_multiline_delimiter

The matched nodes will have a multiline-only delimiter appended to them.
It will be printed only in multi-line nodes, and omited in single-line nodes. The delimiter must be specified using the predicate #delimiter!.

Example

; Add a semicolon at the end of lists only if they are multiline, to avoid [1; 2; 3;].
(list_expression
  (#delimiter! ";")
  (_) @append_multiline_delimiter
  .
  ";"? @do_nothing
  .
  "]"
  .
)

This allows proper formatting of the following:

let _ =
  [
    1;
    2;
    3;
  ]

let _ = [1; 2; 3]

Closes #199

README.md Outdated
### @append_multiline_delimiter / @prepend_multiline_delimiter

The matched nodes will have a multiline-only delimiter appended to them.
It will be printed only in multi-line nodes, and omited in single-line nodes. The delimiter must be specified using the predicate `#delimiter!`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It will be printed only in multi-line nodes, and omited in single-line nodes. The delimiter must be specified using the predicate `#delimiter!`.
It will be printed only in multi-line nodes, and omitted in single-line nodes. The delimiter must be specified using the predicate `#delimiter!`.

README.md Outdated
@@ -197,6 +197,29 @@ Otherwise, the `";"*` captures nothing and in this case the associated instructi

Note that `@append_delimiter` is the same as `@append_space` when the delimiter is set to `" "` (space).

### @append_multiline_delimiter / @prepend_multiline_delimiter

The matched nodes will have a multiline-only delimiter appended to them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The matched nodes will have a multiline-only delimiter appended to them.
The matched nodes will have a multi-line-only delimiter appended to them.

README.md Outdated
```

If there is already a semicolon, the `@do_nothing` instruction will be activated
and prevent the other instruction in the query (the `@append_multiline_delimiter`) to activate. Likewise, if the node is single-line, the delimiter will not be apended either.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and prevent the other instruction in the query (the `@append_multiline_delimiter`) to activate. Likewise, if the node is single-line, the delimiter will not be apended either.
and prevent the other instruction in the query (the `@append_multiline_delimiter`) to activate. Likewise, if the node is single-line, the delimiter will not be appended either.

@nbacquey nbacquey force-pushed the nb/multiline_delimiter branch from 35f0760 to 2289743 Compare February 1, 2023 13:27
@nbacquey nbacquey merged commit e721ed8 into main Feb 1, 2023
@nbacquey nbacquey deleted the nb/multiline_delimiter branch February 1, 2023 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Softline-like predicates for list/tuple/record delimiters
2 participants