Swift Mode

Emacs support for Apple's Swift programming language.
Alternatives To Swift Mode
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Swift Mode347
2 months ago5gpl-3.0Emacs Lisp
Emacs support for Apple's Swift programming language.
Emacs Grammarly107
2 years ago3gpl-3.0Emacs Lisp
an Emacs extension to send a text to/from Grammarly
Lsp Sourcekit87
3 months ago7gpl-3.0Emacs Lisp
lsp-mode :heart: Apple's sourcekit
Emacs Sourcekit Lsp25
4 years agoEmacs Lisp
Emacs LSP client for SourceKit-LSP (https://github.com/apple/sourcekit-lsp), a Swift/Objective-C/C++ language server created by Apple
Flycheck Swift11
6 years agogpl-3.0Emacs Lisp
Flycheck extension for Apple's Swift programming language.
Emoji Fontset.el11
9 months agoEmacs Lisp
Set font face for Emoji
8 years agogpl-3.0Emacs Lisp
Autonomy is Organization
Emacs Applenotes8
5 years agogpl-3.0Emacs Lisp
Use Apple Notes in Emacs through Applescript
Tramp Virtualenv8
10 years ago1Emacs Lisp
A collection of prototype code to make coding Python in Emacs work better over TRAMP and with virtualenv.
6 years ago3otherC#
SushiRotator - A reason for aborted working
Alternatives To Swift Mode
Select To Compare

Alternative Project Comparisons

License GPL 3 Run Tests MELPA MELPA


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 for the .tar archive.


  • Font Lock

  • Indentation

    switch foo {
    case let .P1(x)
             x > 0,
         let .P2(x)
             x > 0:
          .then { x in
              return baz(x)
          .then {(
                 ) in
              return moo(x + y)
    // Hanging brace
    let x = [
    // Brace on its own line
    let y =
    // Utrecht style
    let z =
      [ 1
      , 2
      , 3
  • forward-sexp

  • beginning-of-defun, end-of-defun, mark-defun, and narrow-to-defun.

  • beginning-of-sentence, end-of-sentence, kill-sentence, backward-kill-sentence, mark-sentence, and narrow-to-sentence. A sentence is a statement outside comments or strings, or an ordinal sentence inside comments or strings.

  • indent-new-comment-line

  • Imenu

  • Running Swift REPL in a buffer (M-x run-swift)

  • Build Swift module (M-x swift-mode:build-swift-module)

  • Build iOS app (M-x swift-mode:build-ios-app)

  • Running debugger on Swift module (M-x swift-mode:debug-swift-module)

  • Running debugger on iOS app in simulator or device (M-x swift-mode:debug-ios-app) (ios-deploy is required to debug on device).

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 let instead:

    if let x = x,
       let y = y {

Indentation may not accurate. For example, foo(Bar < A, B > (c)) can be indented like either

foo(Bar < A,
    B > (c)) // Passing two Boolean arguments to foo


foo(Bar < A,
          B > (c)) // Passing a new Bar with two type arguments and a value

The 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 of the below snippet. 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
  .then { x in

while we also want to indent the body of if like this:

if anotherVeryLongVariableName
     .veryLongPropertyName {

That is, we have to indent the closing brace with offset if it is a part of expressions while it should be aligned with the beginning of the statement/declaration if it is a part of a statement/declaration.

Then, how should we indent the following code when the cursor is before @?

var x = foo
  .bar {

This could be

var x = foo
  .bar {
    @abc willSet {
// property declaration


var x = foo
  .bar {
      @abc var x = 1
// property initialization

Both are syntactically correct code. We cannot handle this case properly. This is also a future work.

Other example is regex literals and custom operators. The following example is valid Swift code with regex literals and custom operators.

let x = /^/ /^/ /^/

We parse them as regex literals rather than custom operators for now.


To build the package locally, run make package.

To install the built package, run make install.

To run tests, run make test.

For other commands, run make help.

Related projects


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:

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-2021 taku0, Chris Barrett, Bozhidar Batsov, Arthur Evstifeev.

Popular Apple Projects
Popular Emacs Projects
Popular Companies Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Emacs Lisp
Emacs Mode
Apple Swift