GithubHelp home page GithubHelp logo

isabella232 / swift-mode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from swift-emacs/swift-mode

0.0 0.0 0.0 1.07 MB

Emacs support for Apple's Swift programming language.

License: GNU General Public License v3.0

Emacs Lisp 89.18% Makefile 0.27% Swift 10.18% Shell 0.37%

swift-mode's Introduction

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.

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.

swift-mode's People

Contributors

ap4y avatar apiology avatar bbatsov avatar dalgong avatar danielmartin avatar dougbeal avatar jmibanez avatar msanders avatar n4tr0n avatar nathankot avatar nhojb avatar swsnr avatar syohex avatar taku0 avatar uk-ar avatar wiruzx avatar woolsweater avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.