mirror of
https://github.com/keith/swift.vim.git
synced 2026-05-26 11:24:35 +02:00
Merge pull request #130 from keith/indent-parens
Make indent line up with opening parens
This commit is contained in:
+25
-10
@@ -223,7 +223,7 @@ struct ArgumentList {
|
||||
var arguments: String[]
|
||||
|
||||
init(argv: UnsafePointer<CString>,
|
||||
count: CInt)
|
||||
count: CInt)
|
||||
{
|
||||
foo
|
||||
}
|
||||
@@ -249,9 +249,9 @@ func simpleDescription() -> String {
|
||||
|
||||
let library = [
|
||||
Movie(name: "foo bar",
|
||||
dfasdfsdfdirector: "someone",
|
||||
foo: "bar",
|
||||
bazzzer: "qux")
|
||||
dfasdfsdfdirector: "someone",
|
||||
foo: "bar",
|
||||
bazzzer: "qux")
|
||||
]
|
||||
|
||||
|
||||
@@ -266,7 +266,9 @@ class MainViewController: UIViewController, UITableViewDataSource {}
|
||||
|
||||
@IBAction func changePostFilter(sender: UISegmentedControl) {}
|
||||
override func prepareForSegue(segue: UIStoryboardSegue,
|
||||
sender: AnyObject) {}
|
||||
sender: AnyObject) {}
|
||||
override func prepareForSegue(
|
||||
segue: UIStoryboardSegue, sender: AnyObject) {}
|
||||
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {}
|
||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {}
|
||||
lazy var foo : String
|
||||
@@ -293,7 +295,7 @@ func foo () {
|
||||
}
|
||||
|
||||
let foo = CGRectMake(0, (5 - 2),
|
||||
100, 200)
|
||||
100, 200)
|
||||
|
||||
|
||||
let dict = [
|
||||
@@ -351,10 +353,10 @@ let data = NSData(contentsOfFile: path) else
|
||||
}
|
||||
|
||||
UIView.animateWithDuration(duration, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .CurveEaseInOut, animations: {
|
||||
view.backgroundColor = UIColor.redColor()
|
||||
}) { finished in
|
||||
print("indent?")
|
||||
}
|
||||
view.backgroundColor = UIColor.redColor()
|
||||
}, completion: { finished in
|
||||
print("indent?")
|
||||
})
|
||||
|
||||
// Indent last line should hold
|
||||
self.init(className: "Item", dictionary: [
|
||||
@@ -374,3 +376,16 @@ NSWorkspace.sharedWorkspace().notificationCenter.addObserver(
|
||||
public func find(closure: @noescape Element throws -> Bool) rethrows -> Element? {
|
||||
|
||||
}
|
||||
|
||||
UIView.animate(withDuration: 0.2, animations: {
|
||||
self.foo.alpha = 1.0
|
||||
self.bar.alpha = 1.0
|
||||
}, completion: { _ in
|
||||
completion()
|
||||
})
|
||||
|
||||
A.b().application(
|
||||
application, didFinishLaunchingWithOptions: launchOptions)
|
||||
|
||||
A.application(b(),
|
||||
application, didFinishLaunchingWithOptions: launchOptions)
|
||||
|
||||
+68
-12
@@ -40,11 +40,15 @@ endfunction
|
||||
|
||||
function! s:IsExcludedFromIndentAtPosition(line, column)
|
||||
let name = s:SyntaxNameAtPosition(a:line, a:column)
|
||||
return name ==# "swiftComment" || name ==# "swiftString"
|
||||
return s:IsSyntaxNameExcludedFromIndent(name)
|
||||
endfunction
|
||||
|
||||
function! s:IsExcludedFromIndent()
|
||||
return s:SyntaxName() ==# "swiftComment" || s:SyntaxName() ==# "swiftString"
|
||||
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)
|
||||
@@ -101,10 +105,10 @@ function! SwiftIndent(...)
|
||||
return indent(openingSquare) + shiftwidth()
|
||||
endif
|
||||
|
||||
if line =~ ":$"
|
||||
if line =~ ":$" && (line =~ '^\s*case\W' || line =~ '^\s*default\W')
|
||||
let switch = search("switch", "bWn")
|
||||
return indent(switch)
|
||||
elseif previous =~ ":$"
|
||||
elseif previous =~ ":$" && (previous =~ '^\s*case\W' || previous =~ '^\s*default\W')
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
@@ -131,12 +135,26 @@ function! SwiftIndent(...)
|
||||
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(".")
|
||||
call cursor(line("."), 1)
|
||||
let line = line(".")
|
||||
call cursor(line, 1)
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line("."), column)
|
||||
call cursor(line, column)
|
||||
|
||||
let bracketLine = getline(openingBracket)
|
||||
|
||||
@@ -149,8 +167,23 @@ function! SwiftIndent(...)
|
||||
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
|
||||
@@ -194,8 +227,19 @@ function! SwiftIndent(...)
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
let previousParen = match(previous, "(")
|
||||
return indent(previousParen) + shiftwidth()
|
||||
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
|
||||
@@ -204,7 +248,7 @@ function! SwiftIndent(...)
|
||||
call cursor(previousNum, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return indent(openingParen) + shiftwidth()
|
||||
return openingParen + 1
|
||||
endif
|
||||
|
||||
" - Previous line has close then open braces, indent previous + 1 'sw'
|
||||
@@ -224,11 +268,23 @@ function! SwiftIndent(...)
|
||||
" - 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, [previousNum, col("$")])
|
||||
let previousParen = searchpair("(", "", ")", "cbWn", "s:IsExcludedFromIndent()")
|
||||
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 indent(previousParen) + shiftwidth()
|
||||
return previousParen
|
||||
endif
|
||||
|
||||
return cindent
|
||||
|
||||
+3
-3
@@ -52,10 +52,10 @@ delfunction s:CommentKeywordMatch
|
||||
|
||||
" Literals
|
||||
" Strings
|
||||
syntax region swiftString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=swiftMultilineInterpolatedWrapper oneline
|
||||
syntax region swiftString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=swiftInterpolatedWrapper oneline
|
||||
syntax region swiftMultilineString start=/"""/ end=/"""/ contains=swiftMultilineInterpolatedWrapper
|
||||
syntax region swiftMultilineInterpolatedWrapper start="\v\\\(\s*" end="\v\s*\)" contained containedin=swiftMultilineString contains=swiftInterpolatedString oneline
|
||||
syntax region swiftInterpolatedWrapper start="\v[^\\]\zs\\\(\s*" end="\v\s*\)" contained containedin=swiftString contains=swiftInterpolatedString,swiftString oneline
|
||||
syntax region swiftMultilineInterpolatedWrapper start='\v\zs\\\(\s*' end='\v\s*\)' contained containedin=swiftMultilineString contains=swiftInterpolatedString oneline
|
||||
syntax region swiftInterpolatedWrapper start='\v(^|[^\\])\zs\\\(\s*' end='\v\s*\)' contained containedin=swiftString contains=swiftInterpolatedString,swiftString oneline
|
||||
syntax match swiftInterpolatedString "\v\w+(\(\))?" contained containedin=swiftInterpolatedWrapper,swiftMultilineInterpolatedWrapper oneline
|
||||
|
||||
" Numbers
|
||||
|
||||
Reference in New Issue
Block a user