Major-mode for Apple's Swift programming language.
Install swift-mode package from MELPA.
To install without MELPA, download latest release and execute M-x package-install-file.
- 
Font Lock
 - 
Indentation
switch foo { case let .P1(x) where x > 0, let .P2(x) where x > 0: bar() .then { x in return baz(x) } .then {( x, y ) in return moo(x + y) } } // Hanging brace let x = [ 1, 2, 3 ] // Brace on its own line let y = [ 1, 2, 3 ] // Utrecht style let z = [ 1 , 2 , 3 ]
 - 
forward-sexp - 
beginning-of-defunandend-of-defun, somark-defunandnarrow-to-defunwork fine. - 
indent-new-comment-line - 
Running Swift REPL in a buffer (
M-x run-swift) 
This package does not provide flycheck. See flycheck-swift.
Some syntax constructs removed from Swift 3.0 are not supported:
- 
C-style for-loop:
for var i = 1; i < 10; i++ { } - 
Multiple assignments in single
if let:if let x = x, y = y { }
Use multiple
letinstead:if let x = x, let y = y { }
 
Indentation may not accurate. For example, foo(Bar < A, B > (c)) is indented like either
foo(Bar < A,
    B > (c)) // Passing two Boolean arguments to fooor
foo(Bar < A,
          B > (c)) // constructing Bar with two type arguments and a valueThe Swift compiler disambiguates this case using tokens after >, but those tokens may not available at editing time. We use some heuristic for this.
Another example is difficulty of handling of colons. We have to pair all ? and : of conditional operators to decide indentation. This is a future work.
switch foo {
  case let P(x) where x is Foo? ? a ? b : c ?? d : e ? f : g :
    h ? i?.j() : k()
}
switch foo {
  case let P(x) where (x is Foo?) ? (a ? b : c ?? d) : (e ? f : g) :
    h ? i?.j() : k()
}Yet another difficult case is consistency of blocks. We want to indent method chains like this:
var x = foo
  .then { x in
      aaa
  }
  .then { x in
      aaa
  }while we also want to indent if body like this:
if anotherVeryLongVariableName
     .veryLongPropertyName {
    aaa
}Then, how should we indent this when the cursor is before @?
var x = foo
  .bar {
    @This could be
var x = foo
  .bar {
    @abc willSet {
        aaa
    }
}or
var x = foo
  .bar {
      @abc var x = 1
      x
  }Both are syntactically correct code. We cannot handle this case properly. This is also a future work.
To build the package locally, run make package. You need Cask.
To install the built package, run make install.
To run tests, run make check.
For other commands, run make help.
- Official swift-mode.el by Apple Seems still in very early stage for now. We cannot contribute to it due to the license incompatibility.
 - company-sourcekit Completion for Swift projects via SourceKit with the help of SourceKitten.
 - flycheck-swift Flycheck extensions for Swift.
 
Yes, please do! See CONTRIBUTING for guidelines.
The REPL code is based on js-comint.
Thanks to the following original developer and users for their contributions:
- @chrisbarrett (Chris Barrett)
 - @ap4y (Arthur Evstifeev)
 - @bbatsov (Bozhidar Batsov)
 - @ckruse (Christian Kruse)
 - @syohex (Syohei Yoshida)
 - @uk-ar (Yuuki Arisawa)
 
You can find a full list of those people here.
Thanks to @purcell (Steve Purcell) for advices on the code and arrangement for merging swift3-mode and swift-mode.
GPLv3. See COPYING for details. Copyright (C) 2014-2016 taku0, Chris Barrett, Bozhidar Batsov, Arthur Evstifeev.
