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

Indent rules for line after “{” #133

Closed
klmr opened this issue Nov 2, 2014 · 4 comments
Closed

Indent rules for line after “{” #133

klmr opened this issue Nov 2, 2014 · 4 comments
Labels

Comments

@klmr
Copy link

klmr commented Nov 2, 2014

The indent rules for Vim-R are generally very sensible but they fail in cases such as this (testthat code, but the same situation is generally applicable):

test_that('the function works', {
          |
})

The position of the cursor is indicated by “|”, and I think it’s uncontroversial to call this wrong: in such a case, we want to simply shift the indent by shiftwidth from the previous level, rather than aligning it with the previous opening parenthesis.

I’ve read the FAQ and I realise this may be related to #77 but it looks sufficiently dissimilar – maybe there’s hope?

@jalvesaq
Copy link

jalvesaq commented Nov 2, 2014

I added the file that I use to test the indentation to the github repository:
https://github.com/jcfaria/Vim-R-plugin/blob/master/r-plugin/indent_test.R

And I managed to add a rule that fixed the bug you reported and did not break anything in the previous 500 lines of indent_test.R: 4b3abb8

Note: I think that the correct indentation of the closing brace is aligned with the opening parenthesis.

@klmr
Copy link
Author

klmr commented Nov 3, 2014

Note: I think that the correct indentation of the closing brace is aligned with the opening parenthesis.

I disagree. First of all, this means that the block between the braces is indented extremely widely. Secondly, it would mean that the statements inside the block are no longer indented at a multiple of shiftwidth, which brings a whole bag of problems.

Compare (shiftwidth = 4):

test_that('my unit test', {
▸---------------------  if (some_condition)
▸------------------------  result---------------------  else------------------------  other_result------------------  })

With:

test_that('my unit test', {
▸---if (some_condition)
▸------result---else------other_result
})

@jalvesaq
Copy link

jalvesaq commented Nov 3, 2014

I had made a mistake while copying you example. I did not set 'paste' and the underline was converted into <-. I updated the r-plugin/indent_test.R. I also added a new file: r-plugin/indent_test_noalign.R.
The indent/r.vim script supports two main styles:

  1. Function arguments are aligned with the opening parenthesis.
  2. Function arguments follow the general rule of 1 shiftwidth for each opening bracket (parenthesis, square bracket or braces).

Other options control how to align comments and top level functions (:h ft-r-indent).

I think that the indentation is closer to what you want when r_indent_align_args=0, but some bugs remain. I have tried to fix them, but did not succeed. So, we may let this issue open.

For people wanting to improve the indent/r.vim script, I suggest the following:

  1. Put the cursor on the line that is being wrongly indented.
  2. In Normal mode do :debug call GetRIndent() then press s, press n and press <Enter> to see the function working. For details, see :h :debug.

@jalvesaq jalvesaq added the Bug label Nov 8, 2014
@jalvesaq
Copy link

jalvesaq commented Apr 8, 2015

I deleted from the Vim-R-plugin the files that are already distributed as official Vim runtime files. Now, there is a new repository with these files: https://github.com/jalvesaq/R-Vim-runtime

Since the official runtime files are no longer in this repository, I'm closing this bug. This bug is already described in the Known bugs section of the README.md, and new bugs should be reported in the new repository.

@jalvesaq jalvesaq closed this as completed Apr 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants