1
0
mirror of https://github.com/amix/vimrc synced 2025-08-01 10:25:01 +08:00

Updated plugins

This commit is contained in:
Amir
2021-07-30 22:52:54 +02:00
parent a8f0b6f678
commit 65de68fa88
66 changed files with 1368 additions and 404 deletions

View File

@ -89,6 +89,9 @@ let s:ruby_indent_keywords =
\ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' .
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>'
" Def without an end clause: def method_call(...) = <expression>
let s:ruby_endless_def = '\<def\s\+\k\+[!?]\=\%((.*)\|\s\)\s*='
" Regex used for words that, at the start of a line, remove a level of indent.
let s:ruby_deindent_keywords =
\ '^\s*\zs\<\%(ensure\|else\|rescue\|elsif\|when\|end\):\@!\>'
@ -108,10 +111,26 @@ let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue:\@!\>
" Regex that defines the end-match for the 'end' keyword.
let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\<end:\@!\>'
" Expression used for searchpair() call for finding match for 'end' keyword.
let s:end_skip_expr = s:skip_expr .
\ ' || (expand("<cword>") == "do"' .
\ ' && getline(".") =~ "^\\s*\\<\\(while\\|until\\|for\\):\\@!\\>")'
" Expression used for searchpair() call for finding a match for an 'end' keyword.
function! s:EndSkipExpr()
if eval(s:skip_expr)
return 1
elseif expand('<cword>') == 'do'
\ && getline(".") =~ '^\s*\<\(while\|until\|for\):\@!\>'
return 1
elseif getline('.') =~ s:ruby_endless_def
return 1
elseif getline('.') =~ '\<def\s\+\k\+[!?]\=([^)]*$'
" Then it's a `def method(` with a possible `) =` later
call search('\<def\s\+\k\+\zs(', 'W', line('.'))
normal! %
return getline('.') =~ ')\s*='
else
return 0
endif
endfunction
let s:end_skip_expr = function('s:EndSkipExpr')
" Regex that defines continuation lines, not including (, {, or [.
let s:non_bracket_continuation_regex =
@ -571,6 +590,11 @@ function! s:AfterUnbalancedBracket(pline_info) abort
call cursor(info.plnum, closing.pos + 1)
normal! %
if strpart(info.pline, closing.pos) =~ '^)\s*='
" special case: the closing `) =` of an endless def
return indent(s:GetMSL(line('.')))
endif
if s:Match(line('.'), s:ruby_indent_keywords)
return indent('.') + info.sw
else
@ -609,7 +633,7 @@ function! s:AfterIndentKeyword(pline_info) abort
let info = a:pline_info
let col = s:Match(info.plnum, s:ruby_indent_keywords)
if col > 0
if col > 0 && s:Match(info.plnum, s:ruby_endless_def) <= 0
call cursor(info.plnum, col)
let ind = virtcol('.') - 1 + info.sw
" TODO: make this better (we need to count them) (or, if a searchpair
@ -656,7 +680,7 @@ function! s:IndentingKeywordInMSL(msl_info) abort
" TODO: this does not take into account contrived things such as
" module Foo; class Bar; end
let col = s:Match(info.plnum_msl, s:ruby_indent_keywords)
if col > 0
if col > 0 && s:Match(info.plnum_msl, s:ruby_endless_def) <= 0
let ind = indent(info.plnum_msl) + info.sw
if s:Match(info.plnum_msl, s:end_end_regex)
let ind = ind - info.sw

View File

@ -27,5 +27,20 @@ describe "Indenting" do
foo = bar; class One; end
end
EOF
assert_correct_indenting <<~EOF
nested do
while true do
def foo
if bar
for i in collection
def baz
end
end
end
end
end
end
EOF
end
end

View File

@ -37,4 +37,40 @@ describe "Indenting" do
end
EOF
end
specify "endless methods" do
# Note: A case that doesn't work at this time:
#
# def foo()
# = 42
#
assert_correct_indenting <<~EOF
indented_block do
def foo(bar) = puts(bar)
def foo!(bar) = puts(bar)
def foo?(bar) = puts(bar)
def foo(bar)=puts(bar)
def foo(bar) = bar + 1
def foo() = 1 + 1
def foo = 1 + 1
private def foo(bar) = bar + 1
def foo(bar) =
bar + 1
def foo(bar = default_function()) = puts(bar)
def foo(bar = default_function()) =
puts(bar)
def foo(
bar
) = puts(bar)
end
EOF
end
end

View File

@ -65,7 +65,7 @@ endfunction
com! -nargs=* SynFold call s:run_syntax_fold(<q-args>)
" Not-Top Cluster {{{1
syn cluster rubyNotTop contains=@rubyCommentNotTop,@rubyStringNotTop,@rubyRegexpSpecial,@rubyDeclaration,@rubyExceptionHandler,@rubyClassOperator,rubyConditional,rubyModuleName,rubyClassName,rubySymbolDelimiter,rubyParentheses,@Spell
syn cluster rubyNotTop contains=@rubyCommentNotTop,@rubyStringNotTop,@rubyRegexpSpecial,@rubyDeclaration,@rubyExceptionHandler,@rubyClassOperator,rubyConditional,rubyModuleName,rubyClassName,rubySymbolDelimiter,rubyDoubleQuoteSymbolDelimiter,rubySingleQuoteSymbolDelimiter,rubyParentheses,@Spell
" Whitespace Errors {{{1
if exists("ruby_space_errors")
@ -464,6 +464,10 @@ syn match rubyDefinedOperator "\%#=1\<defined?" display
syn match rubySymbol "\%(\w\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[?!]\=::\@!"he=e-1 contained containedin=rubyBlockParameterList,rubyCurlyBlock
syn match rubySymbol "[]})\"':]\@1<!\<\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[!?]\=:[[:space:],;]\@="he=e-1
syn match rubySymbol "[[:space:],{(]\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[!?]\=:[[:space:],;]\@="hs=s+1,he=e-1
syn match rubySingleQuoteSymbolDelimiter "'" contained
syn match rubySymbol "'\%(\\.\|[^']\)*'::\@!"he=e-1 contains=rubyQuoteEscape,rubyBackslashEscape,rubySingleQuoteSymbolDelimiter
syn match rubyDoubleQuoteSymbolDelimiter "\"" contained
syn match rubySymbol "\"\%(\\.\|[^\"]\)*\"::\@!"he=e-1 contains=@rubyStringSpecial,rubyDoubleQuoteSymbolDelimiter
" __END__ Directive {{{1
SynFold '__END__' syn region rubyData matchgroup=rubyDataDirective start="^__END__$" end="\%$"
@ -564,6 +568,8 @@ hi def link rubyHeredocDelimiter rubyStringDelimiter
hi def link rubyPercentRegexpDelimiter rubyRegexpDelimiter
hi def link rubyPercentStringDelimiter rubyStringDelimiter
hi def link rubyPercentSymbolDelimiter rubySymbolDelimiter
hi def link rubyDoubleQuoteSymbolDelimiter rubySymbolDelimiter
hi def link rubySingleQuoteSymbolDelimiter rubySymbolDelimiter
hi def link rubyRegexpDelimiter rubyStringDelimiter
hi def link rubySymbolDelimiter rubySymbol
hi def link rubyString String