swift-emacs / swift-mode

Emacs support for Apple's Swift programming language.
GNU General Public License v3.0
372 stars 47 forks source link

Importing modules that end with "in" causes indentation issues #102

Closed preetpalS closed 9 years ago

preetpalS commented 9 years ago

For example, if you import the "Darwin" module, the next line gets indented incorrectly. The following indentation examples were all indented by selecting all text in the buffer and indenting everything.

Good

import Cocoa

class Test {
}

Incorrect indentation


import Cocoa
import Darwin

       class Test {
    }

Incorrect indentation

import Darwin
           import Cocoa

class Test {
}

Workaround (use semicolon)

import Cocoa
import Darwin;

class Test {
}
ap4y commented 9 years ago

Hey @preetpalS I checked this against latest master and it looks ok. Can you try updating the package, melpa has 20150818.1958?

preetpalS commented 9 years ago

I am using that version of the package (and its the latest version at this time). Here is some information about my Emacs installation and the version of package I am using.

(emacs-version)

"GNU Emacs 25.0.50.1 (x86_64-apple-darwin14.0.0, NS appkit-1343.16 Version 10.10.1 (Build 14B25))
 of 2015-01-21 on Preetpals-Air"

;;;; Copied from Swift-Mode package
;; Authors: Chris Barrett <chris.d.barrett@me.com>
;;       Bozhidar Batsov <bozhidar@batsov.com>
;;       Arthur Evstifeev <lod@pisem.net>
;; Version: 0.4.0-cvs
;; Package-Version: 20150818.1958
;; Package-Requires: ((emacs "24.4"))
;; Keywords: languages swift

I was able to reproduce the bug by starting Emacs with the --no-init flag, opening and evaluating the swift-mode.el file from the melpa package on my computer (Package-Version: 20150818.1958), and then opening and indenting a file containing all of the cases I reported in the issue.

Results of indenting the file containing all cases initially reported in the issue are below:

import Cocoa

class Test {
}

import Cocoa
import Darwin

       class Test {
    }

import Darwin
           import Cocoa

class Test {
}

import Cocoa
import Darwin;

class Test {
}

Screenshots taken while trying to reproduce issue. screen shot of file after being indented using swift-mode screen shot of package version

ap4y commented 9 years ago

Oh sorry, I missed the title of the issue :) Yep that's definitelly an issue with lexer's regex for in token. Seems like we are not tokenizing it, so it's a default lexer's issue. Will look into it.

preetpalS commented 9 years ago

No worries :), thanks for fixing this issue.