swift-emacs / swift-mode

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

M-C-f and M-C-v broken? #97

Closed themetaschemer closed 9 years ago

themetaschemer commented 9 years ago

I use M-C-f and M-C-v to navigate across matching parentheses. These seem to be broken in 0.3.0. The symptom is that they will put me in the middle of a codeblock instead of at a matching '}'.

e.g. try a sequence of M-C-f starting at the first character of this code block:

        let rect=CGRect(x: x, y: y, width: width, height: height)
        let view = UIImageView(frame: rect)

        let imageRequestOptions=PHImageRequestOptions()

        let origHeight=Double(img.pixelHeight)
        let origWidth=Double(img.pixelWidth)
        let displayRect=CGRect(x: x,y: y,width: width,height: height)

        var positionX : Double
        var positionY : Double
        var scale = 1.0
        var origScale = 1.0

        if origHeight < origWidth {
            //Landscape
            scale=height/origHeight
            positionX=x-(width*scale/2)
            positionY=y
        }else{
            //Portrait
            scale=width/origWidth
            positionY=y-(height*scale/2)
            positionX=x
        }

You'll find your cursor ends up before the final '}' at the beginning of that line

ap4y commented 9 years ago

@themetaschemer can you check if you have the same problems with master? Quite a few fixes were merged since the latest stable release.

themetaschemer commented 9 years ago

@ap4y Thanks for the suggestion, but, the problem is present in the latest build as as well (I'm assuming that melpa is in sync with the master .. I have swift-mode-20150611.1440).

I have isolated the problem some more: The issue is that any '{' that does not have a space in front of it is skipped over by the paren-matcher (In my example above, it is the '{' right after the else in the 6th line from the bottom.

ap4y commented 9 years ago

I will see what I can do, though I want to encourage you to use spaces a bit more.

themetaschemer commented 9 years ago

Sadly, I cannot undo 30 years of programming practice as easily :-) I am trying to debug the issue some more before I give up.

One other issue, for example, if I skip spaces before braces is that the font-lock mode starts to misbehave as well. E.g Double{ will get highlighted the same as Double (i.e., the { will absorb the color of the type) which leads me to wonder: is this is a syntax-table issue?

ap4y commented 9 years ago

I'm not sure right now but I suspect that it's either smie related problem (as far as I know sexp movements depend on smie) or this small hack that was applied to the syntax-table. I will try to fix this once I have some time.

themetaschemer commented 9 years ago

Ok. Sounds good. In the mean time, I'll keep trying to investigate as much as I can.