jalvesaq / R-Vim-runtime

Vim runtime scripts of file types that include R code
GNU General Public License v2.0
24 stars 28 forks source link

Respect `cindent` `mN` alignment rule #24

Closed ashiklom closed 4 years ago

ashiklom commented 7 years ago

The RStudio way of indenting code is like this:

x <- list(
  a = 3,
  b = 1:5,
  c = "hello"
)

This should be achievable by setting g:r_indent_align_args = 0 and set cinoptions = (0,W2,m1. However, this combination produces the following:

x <- list(
  a = 3,
  b = 1:5,
  c = "hello"
  )  # <--- This parenthesis should be aligned with `x` per the `m1` cindent option

Is there a way to make vim respect the m1 cindent option, at least when g:r_indent_align_args = 0?

ashiklom commented 7 years ago

I haven't done extensive testing, but it seems like something like this in the GetRIndent() function does the trick:

  " Unindent a closing parenthesis. For example:
  " list(
  "   a = 5,
  "   b = 8
  " ) <--- Line this up with the beginning of `list`
  if cline =~ '^\s*)'
    let indline = s:Get_matching_brace(clnum, '(', ')', 1)
    return indent(indline)
  endif

This also requires adding 0) to the indentkeys at the top of the indent file.

jalvesaq commented 7 years ago

The procedure that I follow to test changes in indent/r.vim is:

jalvesaq commented 6 years ago

Actually, your suggestion fixes the issue without introducing any new bug. I'm sorry for not testing it earlier.