ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - swift-emacs/swift-mode: Emacs support for Apple's Swift programming language.
Emacs support for Apple's Swift programming language. - swift-emacs/swift-mode
Visit Site

GitHub - swift-emacs/swift-mode: Emacs support for Apple's Swift programming language.

GitHub - swift-emacs/swift-mode: Emacs support for Apple's Swift programming language.

License GPL 3 Run Tests MELPA MELPA

swift-mode

Major-mode for Apple's Swift programming language.

Installation

Install swift-mode package from MELPA.

To install without MELPA, download latest release and execute M-x package-install-file for the .tar archive.

Features

  • 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-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.

Limitations

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

or

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
      aaa
  }
  .then { x in
      aaa
  }

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

if anotherVeryLongVariableName
     .veryLongPropertyName {
    aaa
}

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 {
        aaa
    }
}
// property declaration

or

var x = foo
  .bar {
      @abc var x = 1
      x
  }
// 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.

Hacking

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

Contributing

Yes, please do! See CONTRIBUTING for guidelines.

Acknowledgements

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.

License

GPLv3. See COPYING for details. Copyright (C) 2014-2021 taku0, Chris Barrett, Bozhidar Batsov, Arthur Evstifeev.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory