Skip to content

solve eq_sub indention in general #127

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

Merged
merged 1 commit into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion R/modify_pd.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ indent_op <- function(pd,
indent_eq_sub <- function(pd,
indent_by,
token = "EQ_SUB") {
indent_indices <- compute_indent_indices(pd, token, indent_last = FALSE)
eq_sub <- which(pd$token == "EQ_SUB")
if (length(eq_sub) == 0) return(pd)
has_line_break <- which(pd$lag_newlines > 0)
indent_indices <- intersect(eq_sub + 1, has_line_break)
pd$indent[indent_indices] <- pd$indent[indent_indices] + indent_by
pd
}
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/indention_operators/eq_assign-in.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
switch(engine,
pdftex = {
if (any) {
x
}
},
new=(
2
) )

{
a <-
3
}
42 changes: 42 additions & 0 deletions tests/testthat/indention_operators/eq_assign-in_tree

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/testthat/indention_operators/eq_assign-out.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
switch(engine,
pdftex = {
if (any) {
x
}
},
new = (
Copy link
Member

Choose a reason for hiding this comment

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

This pattern is rare enough, but what happens if we use {} instead of ()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Like at line 2 you mean? It also indents by two spaces.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but what happens to the closing brace?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is unindented

switch(engine,
  pdftex = {
    if (any) {
      x
    }
  },
  new = {
    2
})

{
  a <-
    3
}

Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a FIXME that refers to #125?

2
))

{
a <-
3
}
4 changes: 4 additions & 0 deletions tests/testthat/test-indention_operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ test_that("logical, special and EQ_SUB tokens are indented correctly", {
expect_warning(test_collection("indention_operators",
"logical_special",
transformer = style_text), NA)

expect_warning(test_collection("indention_operators",
"eq",
transformer = style_text), NA)
})

test_that("dollar is indented and spaced correctl", {
Expand Down