Clean up vim config
This commit is contained in:
parent
6a8db9df8d
commit
48a11a0e02
21 changed files with 0 additions and 2114 deletions
|
@ -1,328 +0,0 @@
|
|||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <kchmck@gmail.com>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetCoffeeIndent(v:lnum)
|
||||
" Make sure GetCoffeeIndent is run when these are typed so they can be
|
||||
" indented or outdented.
|
||||
setlocal indentkeys+=0],0),0.,=else,=when,=catch,=finally
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetCoffeeIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
" Keywords to indent after
|
||||
let s:INDENT_AFTER_KEYWORD = '^\%(if\|unless\|else\|for\|while\|until\|'
|
||||
\ . 'loop\|switch\|when\|try\|catch\|finally\|'
|
||||
\ . 'class\)\>'
|
||||
|
||||
" Operators to indent after
|
||||
let s:INDENT_AFTER_OPERATOR = '\%([([{:=]\|[-=]>\)$'
|
||||
|
||||
" Keywords and operators that continue a line
|
||||
let s:CONTINUATION = '\<\%(is\|isnt\|and\|or\)\>$'
|
||||
\ . '\|'
|
||||
\ . '\%(-\@<!-\|+\@<!+\|<\|[-=]\@<!>\|\*\|/\@<!/\|%\||\|'
|
||||
\ . '&\|,\|\.\@<!\.\)$'
|
||||
|
||||
" Operators that block continuation indenting
|
||||
let s:CONTINUATION_BLOCK = '[([{:=]$'
|
||||
|
||||
" A continuation dot access
|
||||
let s:DOT_ACCESS = '^\.'
|
||||
|
||||
" Keywords to outdent after
|
||||
let s:OUTDENT_AFTER = '^\%(return\|break\|continue\|throw\)\>'
|
||||
|
||||
" A compound assignment like `... = if ...`
|
||||
let s:COMPOUND_ASSIGNMENT = '[:=]\s*\%(if\|unless\|for\|while\|until\|'
|
||||
\ . 'switch\|try\|class\)\>'
|
||||
|
||||
" A postfix condition like `return ... if ...`.
|
||||
let s:POSTFIX_CONDITION = '\S\s\+\zs\<\%(if\|unless\)\>'
|
||||
|
||||
" A single-line else statement like `else ...` but not `else if ...
|
||||
let s:SINGLE_LINE_ELSE = '^else\s\+\%(\<\%(if\|unless\)\>\)\@!'
|
||||
|
||||
" Max lines to look back for a match
|
||||
let s:MAX_LOOKBACK = 50
|
||||
|
||||
" Syntax names for strings
|
||||
let s:SYNTAX_STRING = 'coffee\%(String\|AssignString\|Embed\|Regex\|Heregex\|'
|
||||
\ . 'Heredoc\)'
|
||||
|
||||
" Syntax names for comments
|
||||
let s:SYNTAX_COMMENT = 'coffee\%(Comment\|BlockComment\|HeregexComment\)'
|
||||
|
||||
" Syntax names for strings and comments
|
||||
let s:SYNTAX_STRING_COMMENT = s:SYNTAX_STRING . '\|' . s:SYNTAX_COMMENT
|
||||
|
||||
" Get the linked syntax name of a character.
|
||||
function! s:SyntaxName(linenum, col)
|
||||
return synIDattr(synID(a:linenum, a:col, 1), 'name')
|
||||
endfunction
|
||||
|
||||
" Check if a character is in a comment.
|
||||
function! s:IsComment(linenum, col)
|
||||
return s:SyntaxName(a:linenum, a:col) =~ s:SYNTAX_COMMENT
|
||||
endfunction
|
||||
|
||||
" Check if a character is in a string.
|
||||
function! s:IsString(linenum, col)
|
||||
return s:SyntaxName(a:linenum, a:col) =~ s:SYNTAX_STRING
|
||||
endfunction
|
||||
|
||||
" Check if a character is in a comment or string.
|
||||
function! s:IsCommentOrString(linenum, col)
|
||||
return s:SyntaxName(a:linenum, a:col) =~ s:SYNTAX_STRING_COMMENT
|
||||
endfunction
|
||||
|
||||
" Check if a whole line is a comment.
|
||||
function! s:IsCommentLine(linenum)
|
||||
" Check the first non-whitespace character.
|
||||
return s:IsComment(a:linenum, indent(a:linenum) + 1)
|
||||
endfunction
|
||||
|
||||
" Repeatedly search a line for a regex until one is found outside a string or
|
||||
" comment.
|
||||
function! s:SmartSearch(linenum, regex)
|
||||
" Start at the first column.
|
||||
let col = 0
|
||||
|
||||
" Search until there are no more matches, unless a good match is found.
|
||||
while 1
|
||||
call cursor(a:linenum, col + 1)
|
||||
let [_, col] = searchpos(a:regex, 'cn', a:linenum)
|
||||
|
||||
" No more matches.
|
||||
if !col
|
||||
break
|
||||
endif
|
||||
|
||||
if !s:IsCommentOrString(a:linenum, col)
|
||||
return 1
|
||||
endif
|
||||
endwhile
|
||||
|
||||
" No good match found.
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Skip a match if it's in a comment or string, is a single-line statement that
|
||||
" isn't adjacent, or is a postfix condition.
|
||||
function! s:ShouldSkip(startlinenum, linenum, col)
|
||||
if s:IsCommentOrString(a:linenum, a:col)
|
||||
return 1
|
||||
endif
|
||||
|
||||
" Check for a single-line statement that isn't adjacent.
|
||||
if s:SmartSearch(a:linenum, '\<then\>') && a:startlinenum - a:linenum > 1
|
||||
return 1
|
||||
endif
|
||||
|
||||
if s:SmartSearch(a:linenum, s:POSTFIX_CONDITION) &&
|
||||
\ !s:SmartSearch(a:linenum, s:COMPOUND_ASSIGNMENT)
|
||||
return 1
|
||||
endif
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Find the farthest line to look back to, capped to line 1 (zero and negative
|
||||
" numbers cause bad things).
|
||||
function! s:MaxLookback(startlinenum)
|
||||
return max([1, a:startlinenum - s:MAX_LOOKBACK])
|
||||
endfunction
|
||||
|
||||
" Get the skip expression for searchpair().
|
||||
function! s:SkipExpr(startlinenum)
|
||||
return "s:ShouldSkip(" . a:startlinenum . ", line('.'), col('.'))"
|
||||
endfunction
|
||||
|
||||
" Search for pairs of text.
|
||||
function! s:SearchPair(start, end)
|
||||
" The cursor must be in the first column for regexes to match.
|
||||
call cursor(0, 1)
|
||||
|
||||
let startlinenum = line('.')
|
||||
|
||||
" Don't need the W flag since MaxLookback caps the search to line 1.
|
||||
return searchpair(a:start, '', a:end, 'bcn',
|
||||
\ s:SkipExpr(startlinenum),
|
||||
\ s:MaxLookback(startlinenum))
|
||||
endfunction
|
||||
|
||||
" Try to find a previous matching line.
|
||||
function! s:GetMatch(curline)
|
||||
let firstchar = a:curline[0]
|
||||
|
||||
if firstchar == '}'
|
||||
return s:SearchPair('{', '}')
|
||||
elseif firstchar == ')'
|
||||
return s:SearchPair('(', ')')
|
||||
elseif firstchar == ']'
|
||||
return s:SearchPair('\[', '\]')
|
||||
elseif a:curline =~ '^else\>'
|
||||
return s:SearchPair('\<\%(if\|unless\|when\)\>', '\<else\>')
|
||||
elseif a:curline =~ '^catch\>'
|
||||
return s:SearchPair('\<try\>', '\<catch\>')
|
||||
elseif a:curline =~ '^finally\>'
|
||||
return s:SearchPair('\<try\>', '\<finally\>')
|
||||
endif
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Get the nearest previous line that isn't a comment.
|
||||
function! s:GetPrevNormalLine(startlinenum)
|
||||
let curlinenum = a:startlinenum
|
||||
|
||||
while curlinenum > 0
|
||||
let curlinenum = prevnonblank(curlinenum - 1)
|
||||
|
||||
if !s:IsCommentLine(curlinenum)
|
||||
return curlinenum
|
||||
endif
|
||||
endwhile
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Try to find a comment in a line.
|
||||
function! s:FindComment(linenum)
|
||||
let col = 0
|
||||
|
||||
while 1
|
||||
call cursor(a:linenum, col + 1)
|
||||
let [_, col] = searchpos('#', 'cn', a:linenum)
|
||||
|
||||
if !col
|
||||
break
|
||||
endif
|
||||
|
||||
if s:IsComment(a:linenum, col)
|
||||
return col
|
||||
endif
|
||||
endwhile
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Get a line without comments or surrounding whitespace.
|
||||
function! s:GetTrimmedLine(linenum)
|
||||
let comment = s:FindComment(a:linenum)
|
||||
let line = getline(a:linenum)
|
||||
|
||||
if comment
|
||||
" Subtract 1 to get to the column before the comment and another 1 for
|
||||
" zero-based indexing.
|
||||
let line = line[:comment - 2]
|
||||
endif
|
||||
|
||||
return substitute(substitute(line, '^\s\+', '', ''),
|
||||
\ '\s\+$', '', '')
|
||||
endfunction
|
||||
|
||||
function! s:GetCoffeeIndent(curlinenum)
|
||||
let prevlinenum = s:GetPrevNormalLine(a:curlinenum)
|
||||
|
||||
" Don't do anything if there's no previous line.
|
||||
if !prevlinenum
|
||||
return -1
|
||||
endif
|
||||
|
||||
let curline = s:GetTrimmedLine(a:curlinenum)
|
||||
|
||||
" Try to find a previous matching statement. This handles outdenting.
|
||||
let matchlinenum = s:GetMatch(curline)
|
||||
|
||||
if matchlinenum
|
||||
return indent(matchlinenum)
|
||||
endif
|
||||
|
||||
" Try to find a matching `when`.
|
||||
if curline =~ '^when\>' && !s:SmartSearch(prevlinenum, '\<switch\>')
|
||||
let linenum = a:curlinenum
|
||||
|
||||
while linenum > 0
|
||||
let linenum = s:GetPrevNormalLine(linenum)
|
||||
|
||||
if getline(linenum) =~ '^\s*when\>'
|
||||
return indent(linenum)
|
||||
endif
|
||||
endwhile
|
||||
|
||||
return -1
|
||||
endif
|
||||
|
||||
let prevline = s:GetTrimmedLine(prevlinenum)
|
||||
let previndent = indent(prevlinenum)
|
||||
|
||||
" Always indent after these operators.
|
||||
if prevline =~ s:INDENT_AFTER_OPERATOR
|
||||
return previndent + &shiftwidth
|
||||
endif
|
||||
|
||||
" Indent after a continuation if it's the first.
|
||||
if prevline =~ s:CONTINUATION
|
||||
let prevprevlinenum = s:GetPrevNormalLine(prevlinenum)
|
||||
|
||||
" If the continuation is the first in the file, don't run the other checks.
|
||||
if !prevprevlinenum
|
||||
return previndent + &shiftwidth
|
||||
endif
|
||||
|
||||
let prevprevline = s:GetTrimmedLine(prevprevlinenum)
|
||||
|
||||
if prevprevline !~ s:CONTINUATION && prevprevline !~ s:CONTINUATION_BLOCK
|
||||
return previndent + &shiftwidth
|
||||
endif
|
||||
|
||||
return -1
|
||||
endif
|
||||
|
||||
" Indent after these keywords and compound assignments if they aren't a
|
||||
" single-line statement.
|
||||
if prevline =~ s:INDENT_AFTER_KEYWORD || prevline =~ s:COMPOUND_ASSIGNMENT
|
||||
if !s:SmartSearch(prevlinenum, '\<then\>') && prevline !~ s:SINGLE_LINE_ELSE
|
||||
return previndent + &shiftwidth
|
||||
endif
|
||||
|
||||
return -1
|
||||
endif
|
||||
|
||||
" Indent a dot access if it's the first.
|
||||
if curline =~ s:DOT_ACCESS && prevline !~ s:DOT_ACCESS
|
||||
return previndent + &shiftwidth
|
||||
endif
|
||||
|
||||
" Outdent after these keywords if they don't have a postfix condition or are
|
||||
" a single-line statement.
|
||||
if prevline =~ s:OUTDENT_AFTER
|
||||
if !s:SmartSearch(prevlinenum, s:POSTFIX_CONDITION) ||
|
||||
\ s:SmartSearch(prevlinenum, '\<then\>')
|
||||
return previndent - &shiftwidth
|
||||
endif
|
||||
endif
|
||||
|
||||
" No indenting or outdenting is needed.
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
" Wrap s:GetCoffeeIndent to keep the cursor position.
|
||||
function! GetCoffeeIndent(curlinenum)
|
||||
let oldcursor = getpos('.')
|
||||
let indent = s:GetCoffeeIndent(a:curlinenum)
|
||||
call setpos('.', oldcursor)
|
||||
|
||||
return indent
|
||||
endfunction
|
|
@ -1,2 +0,0 @@
|
|||
setlocal indentexpr=fish#Indent()
|
||||
setlocal indentkeys+==end,=else,=case
|
|
@ -1,65 +0,0 @@
|
|||
" Copyright 2011 The Go Authors. All rights reserved.
|
||||
" Use of this source code is governed by a BSD-style
|
||||
" license that can be found in the LICENSE file.
|
||||
"
|
||||
" indent/go.vim: Vim indent file for Go.
|
||||
"
|
||||
" TODO:
|
||||
" - function invocations split across lines
|
||||
" - general line splits (line ends in an operator)
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
" C indentation is too far off useful, mainly due to Go's := operator.
|
||||
" Let's just define our own.
|
||||
setlocal nolisp
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GoIndent(v:lnum)
|
||||
setlocal indentkeys+=<:>,0=},0=)
|
||||
|
||||
if exists("*GoIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! GoIndent(lnum)
|
||||
let prevlnum = prevnonblank(a:lnum-1)
|
||||
if prevlnum == 0
|
||||
" top of file
|
||||
return 0
|
||||
endif
|
||||
|
||||
" grab the previous and current line, stripping comments.
|
||||
let prevl = substitute(getline(prevlnum), '//.*$', '', '')
|
||||
let thisl = substitute(getline(a:lnum), '//.*$', '', '')
|
||||
let previ = indent(prevlnum)
|
||||
|
||||
let ind = previ
|
||||
|
||||
if prevl =~ '[({]\s*$'
|
||||
" previous line opened a block
|
||||
let ind += &sw
|
||||
endif
|
||||
if prevl =~# '^\s*\(case .*\|default\):$'
|
||||
" previous line is part of a switch statement
|
||||
let ind += &sw
|
||||
endif
|
||||
" TODO: handle if the previous line is a label.
|
||||
|
||||
if thisl =~ '^\s*[)}]'
|
||||
" this line closed a block
|
||||
let ind -= &sw
|
||||
endif
|
||||
|
||||
" Colons are tricky.
|
||||
" We want to outdent if it's part of a switch ("case foo:" or "default:").
|
||||
" We ignore trying to deal with jump labels because (a) they're rare, and
|
||||
" (b) they're hard to disambiguate from a composite literal key.
|
||||
if thisl =~# '^\s*\(case .*\|default\):$'
|
||||
let ind -= &sw
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
|
@ -1,294 +0,0 @@
|
|||
" File: swift.vim
|
||||
" Author: Keith Smiley
|
||||
" Description: The indent file for Swift
|
||||
" Last Modified: December 05, 2014
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
setlocal nosmartindent
|
||||
setlocal indentkeys-=e
|
||||
setlocal indentkeys+=0]
|
||||
setlocal indentexpr=SwiftIndent()
|
||||
|
||||
function! s:NumberOfMatches(char, string, index)
|
||||
let instances = 0
|
||||
let i = 0
|
||||
while i < strlen(a:string)
|
||||
if a:string[i] == a:char && !s:IsExcludedFromIndentAtPosition(a:index, i + 1)
|
||||
let instances += 1
|
||||
endif
|
||||
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
return instances
|
||||
endfunction
|
||||
|
||||
function! s:SyntaxNameAtPosition(line, column)
|
||||
return synIDattr(synID(a:line, a:column, 0), "name")
|
||||
endfunction
|
||||
|
||||
function! s:SyntaxName()
|
||||
return s:SyntaxNameAtPosition(line("."), col("."))
|
||||
endfunction
|
||||
|
||||
function! s:IsExcludedFromIndentAtPosition(line, column)
|
||||
let name = s:SyntaxNameAtPosition(a:line, a:column)
|
||||
return s:IsSyntaxNameExcludedFromIndent(name)
|
||||
endfunction
|
||||
|
||||
function! s:IsExcludedFromIndent()
|
||||
return s:IsSyntaxNameExcludedFromIndent(s:SyntaxName())
|
||||
endfunction
|
||||
|
||||
function! s:IsSyntaxNameExcludedFromIndent(name)
|
||||
return a:name ==# "swiftComment" || a:name ==# "swiftString" || a:name ==# "swiftInterpolatedWrapper" || a:name ==# "swiftMultilineInterpolatedWrapper" || a:name ==# "swiftMultilineString"
|
||||
endfunction
|
||||
|
||||
function! s:IsCommentLine(lnum)
|
||||
return synIDattr(synID(a:lnum,
|
||||
\ match(getline(a:lnum), "\\S") + 1, 0), "name")
|
||||
\ ==# "swiftComment"
|
||||
endfunction
|
||||
|
||||
function! SwiftIndent(...)
|
||||
let clnum = a:0 ? a:1 : v:lnum
|
||||
|
||||
let line = getline(clnum)
|
||||
let previousNum = prevnonblank(clnum - 1)
|
||||
while s:IsCommentLine(previousNum) != 0
|
||||
let previousNum = prevnonblank(previousNum - 1)
|
||||
endwhile
|
||||
|
||||
let previous = getline(previousNum)
|
||||
let cindent = cindent(clnum)
|
||||
let previousIndent = indent(previousNum)
|
||||
|
||||
let numOpenParens = s:NumberOfMatches("(", previous, previousNum)
|
||||
let numCloseParens = s:NumberOfMatches(")", previous, previousNum)
|
||||
let numOpenBrackets = s:NumberOfMatches("{", previous, previousNum)
|
||||
let numCloseBrackets = s:NumberOfMatches("}", previous, previousNum)
|
||||
|
||||
let currentOpenBrackets = s:NumberOfMatches("{", line, clnum)
|
||||
let currentCloseBrackets = s:NumberOfMatches("}", line, clnum)
|
||||
|
||||
let numOpenSquare = s:NumberOfMatches("[", previous, previousNum)
|
||||
let numCloseSquare = s:NumberOfMatches("]", previous, previousNum)
|
||||
|
||||
let currentCloseSquare = s:NumberOfMatches("]", line, clnum)
|
||||
if numOpenSquare > numCloseSquare && currentCloseSquare < 1
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
if currentCloseSquare > 0 && line !~ '\v\[.*\]'
|
||||
let column = col(".")
|
||||
call cursor(line("."), 1)
|
||||
let openingSquare = searchpair("\\[", "", "\\]", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line("."), column)
|
||||
|
||||
if openingSquare == 0
|
||||
return -1
|
||||
endif
|
||||
|
||||
" - Line starts with closing square, indent as opening square
|
||||
if line =~ '\v^\s*]'
|
||||
return indent(openingSquare)
|
||||
endif
|
||||
|
||||
" - Line contains closing square and more, indent a level above opening
|
||||
return indent(openingSquare) + shiftwidth()
|
||||
endif
|
||||
|
||||
if line =~ ":$" && (line =~ '^\s*case\W' || line =~ '^\s*default\W')
|
||||
let switch = search("switch", "bWn")
|
||||
return indent(switch)
|
||||
elseif previous =~ ":$" && (previous =~ '^\s*case\W' || previous =~ '^\s*default\W')
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
if numOpenParens == numCloseParens
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
if currentCloseBrackets > currentOpenBrackets || line =~ "\\v^\\s*}"
|
||||
let column = col(".")
|
||||
call cursor(line("."), 1)
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line("."), column)
|
||||
if openingBracket == 0
|
||||
return -1
|
||||
else
|
||||
return indent(openingBracket)
|
||||
endif
|
||||
endif
|
||||
|
||||
return previousIndent + shiftwidth()
|
||||
elseif previous =~ "}.*{"
|
||||
if line =~ "\\v^\\s*}"
|
||||
return previousIndent
|
||||
endif
|
||||
|
||||
return previousIndent + shiftwidth()
|
||||
elseif line =~ "}.*{"
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
|
||||
let bracketLine = getline(openingBracket)
|
||||
let numOpenParensBracketLine = s:NumberOfMatches("(", bracketLine, openingBracket)
|
||||
let numCloseParensBracketLine = s:NumberOfMatches(")", bracketLine, openingBracket)
|
||||
if numOpenParensBracketLine > numCloseParensBracketLine
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(openingParen, column)
|
||||
let openingParenCol = searchpairpos("(", "", ")", "bWn", "s:IsExcludedFromIndent()")[1]
|
||||
call cursor(line, column)
|
||||
return openingParenCol
|
||||
endif
|
||||
|
||||
return indent(openingBracket)
|
||||
elseif currentCloseBrackets > currentOpenBrackets
|
||||
let column = col(".")
|
||||
let line = line(".")
|
||||
call cursor(line, 1)
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
|
||||
let bracketLine = getline(openingBracket)
|
||||
|
||||
let numOpenParensBracketLine = s:NumberOfMatches("(", bracketLine, openingBracket)
|
||||
let numCloseParensBracketLine = s:NumberOfMatches(")", bracketLine, openingBracket)
|
||||
if numCloseParensBracketLine > numOpenParensBracketLine
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(openingParen, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return indent(openingParen)
|
||||
elseif numOpenParensBracketLine > numCloseParensBracketLine
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(openingParen, column)
|
||||
let openingParenCol = searchpairpos("(", "", ")", "bWn", "s:IsExcludedFromIndent()")[1]
|
||||
call cursor(line, column)
|
||||
return openingParenCol
|
||||
endif
|
||||
|
||||
return indent(openingBracket)
|
||||
elseif line =~ '^\s*)$'
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(line, 1)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return indent(openingParen)
|
||||
else
|
||||
" - Current line is blank, and the user presses 'o'
|
||||
return previousIndent
|
||||
endif
|
||||
endif
|
||||
|
||||
if numCloseParens > 0
|
||||
if currentOpenBrackets > 0 || currentCloseBrackets > 0
|
||||
if currentOpenBrackets > 0
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
if line =~ "}.*{"
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
return indent(openingBracket)
|
||||
endif
|
||||
|
||||
if numCloseParens > numOpenParens
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(line - 1, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return indent(openingParen)
|
||||
endif
|
||||
|
||||
return previousIndent
|
||||
endif
|
||||
|
||||
if currentCloseBrackets > 0
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
return indent(openingBracket)
|
||||
endif
|
||||
|
||||
return cindent
|
||||
endif
|
||||
|
||||
if numCloseParens < numOpenParens
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
let previousParen = match(previous, '\v\($')
|
||||
if previousParen != -1
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(previousNum, col([previousNum, "$"]))
|
||||
let previousParen = searchpairpos("(", "", ")", "cbWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
|
||||
" Match the last non escaped paren on the previous line
|
||||
return previousParen[1]
|
||||
endif
|
||||
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(previousNum, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return openingParen + 1
|
||||
endif
|
||||
|
||||
" - Previous line has close then open braces, indent previous + 1 'sw'
|
||||
if previous =~ "}.*{"
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(previousNum, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
|
||||
return indent(openingParen)
|
||||
endif
|
||||
|
||||
" - Line above has (unmatched) open paren, next line needs indent
|
||||
if numOpenParens > 0
|
||||
let savePosition = getcurpos()
|
||||
let lastColumnOfPreviousLine = col([previousNum, "$"]) - 1
|
||||
" Must be at EOL because open paren has to be above (left of) the cursor
|
||||
call cursor(previousNum, lastColumnOfPreviousLine)
|
||||
let previousParen = searchpairpos("(", "", ")", "cbWn", "s:IsExcludedFromIndent()")[1]
|
||||
" If the paren on the last line is the last character, indent the contents
|
||||
" at shiftwidth + previous indent
|
||||
if previousParen == lastColumnOfPreviousLine
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
" The previous line opens a closure and doesn't close it
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
return previousParen + shiftwidth()
|
||||
endif
|
||||
|
||||
call setpos(".", savePosition)
|
||||
return previousParen
|
||||
endif
|
||||
|
||||
return cindent
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
Loading…
Add table
Add a link
Reference in a new issue