diff options
Diffstat (limited to 'runtime/indent/r.vim')
-rw-r--r-- | runtime/indent/r.vim | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/runtime/indent/r.vim b/runtime/indent/r.vim index ca85a2e62d..07dfd13881 100644 --- a/runtime/indent/r.vim +++ b/runtime/indent/r.vim @@ -2,7 +2,7 @@ " Language: R " Author: Jakson Alves de Aquino <jalvesaq@gmail.com> " Homepage: https://github.com/jalvesaq/R-Vim-runtime -" Last Change: Sun Aug 19, 2018 09:13PM +" Last Change: Mon Feb 27, 2023 07:16PM " Only load this indent file when no other was loaded. @@ -14,6 +14,8 @@ let b:did_indent = 1 setlocal indentkeys=0{,0},:,!^F,o,O,e setlocal indentexpr=GetRIndent() +let b:undo_indent = "setl inde< indk<" + " Only define the function once. if exists("*GetRIndent") finish @@ -28,7 +30,7 @@ let g:r_indent_ess_comments = get(g:, 'r_indent_ess_comments', 0) let g:r_indent_comment_column = get(g:, 'r_indent_comment_column', 40) let g:r_indent_ess_compatible = get(g:, 'r_indent_ess_compatible', 0) let g:r_indent_op_pattern = get(g:, 'r_indent_op_pattern', - \ '\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\)\s*$') + \ '\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\||>\)\s*$') function s:RDelete_quotes(line) let i = 0 @@ -108,7 +110,7 @@ function s:RDelete_parens(line) return line1 endfunction -function! s:Get_paren_balance(line, o, c) +function s:Get_paren_balance(line, o, c) let line2 = substitute(a:line, a:o, "", "g") let openp = strlen(a:line) - strlen(line2) let line3 = substitute(line2, a:c, "", "g") @@ -116,7 +118,7 @@ function! s:Get_paren_balance(line, o, c) return openp - closep endfunction -function! s:Get_matching_brace(linenr, o, c, delbrace) +function s:Get_matching_brace(linenr, o, c, delbrace) let line = SanitizeRLine(getline(a:linenr)) if a:delbrace == 1 let line = substitute(line, '{$', "", "") @@ -132,7 +134,7 @@ endfunction " This function is buggy because there 'if's without 'else' " It must be rewritten relying more on indentation -function! s:Get_matching_if(linenr, delif) +function s:Get_matching_if(linenr, delif) let line = SanitizeRLine(getline(a:linenr)) if a:delif let line = substitute(line, "if", "", "g") @@ -160,7 +162,7 @@ function! s:Get_matching_if(linenr, delif) endif endfunction -function! s:Get_last_paren_idx(line, o, c, pb) +function s:Get_last_paren_idx(line, o, c, pb) let blc = a:pb let line = substitute(a:line, '\t', s:curtabstop, "g") let theidx = -1 @@ -359,17 +361,19 @@ function GetRIndent() let olnum = s:Get_prev_line(lnum) let oline = getline(olnum) if olnum > 0 - if line =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0 - if oline =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0 + if substitute(line, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0 + if substitute(oline, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0 return indent(lnum) else return indent(lnum) + shiftwidth() endif else - if oline =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0 + if substitute(oline, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0 return indent(lnum) - shiftwidth() endif endif + elseif substitute(line, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0 + return indent(lnum) + shiftwidth() endif let post_fun = 0 |