GithubHelp home page GithubHelp logo

bad identation about codemirror-v1 HOT 16 CLOSED

codemirror avatar codemirror commented on May 24, 2024
bad identation

from codemirror-v1.

Comments (16)

marijnh avatar marijnh commented on May 24, 2024

The JavaScript parser doesn't do automatic semicolon insertion, and won't properly indent code with semicolons missing.

from codemirror-v1.

iliakan avatar iliakan commented on May 24, 2024

This seems strange, because from the language point of view missing semicolons is ok, even for ECMAScript 5. If javascript standard-makers allow missing semicolon, why codemirror doesn't handle it...

from codemirror-v1.

marijnh avatar marijnh commented on May 24, 2024

Feel free to implement this.

from codemirror-v1.

iliakan avatar iliakan commented on May 24, 2024

Does that seem difficult?

from codemirror-v1.

marijnh avatar marijnh commented on May 24, 2024

It's not easy, semicolon insertion is specified to happen on a parse error, and parse errors are not well-defined in CodeMirror's JavaScript parser---it typically just skips tokens it doesn't recognize.

from codemirror-v1.

iliakan avatar iliakan commented on May 24, 2024

I tried to switch to "shift" indentation with tab and sighed with relief, but that didn't help.

When I type "var a" and press enter, new line is indented the wrong way. Is there any way to fix it somehow?

I spent quite a lot of time making codemirror play really well with my site, is there anything I can do besides rewriting tokenizer ?

from codemirror-v1.

marijnh avatar marijnh commented on May 24, 2024

You do realize that if you've only typed 'var a', there is no way for the editor to know whether the next line will continue with '= 10' or with 'var b ...', right?

Apart from getting used to inserting proper semicolons, you could try commenting out the 'this.indentAtCursor()' line under the '// enter' case in the keydown handler. If that suits your need, I can make it an option.

from codemirror-v1.

marijnh avatar marijnh commented on May 24, 2024

This may be useful here: I just added an enterMode option, that you can set to "flat" or "keep" to override the way new lines are indented. See the manual for details.

from codemirror-v1.

iliakan avatar iliakan commented on May 24, 2024

Thanks, I'll give it a roll right now.

from codemirror-v1.

iliakan avatar iliakan commented on May 24, 2024

BTW, I gave this issue a thought and decided to put semicolons for now, because indentation is really nice thing. Just disabling it does not make editor look cool enough ;)

from codemirror-v1.

iliakan avatar iliakan commented on May 24, 2024

Unfortunately, there is still a problem.
E.g.

function User() {
   this.setName = function(name) {
      this.name = name;
   }
}

This syntax is ok. But codemirror requires one more ; after function. It's just too much to be sane and convinient ;(

from codemirror-v1.

marijnh avatar marijnh commented on May 24, 2024

An assignment is a regular statement requiring a semicolon. Since CodeMirror does not do automatic semicolon insertion, it does not currently handle what you have. Though if you upgrade to the development snapshot, I guess (though I am not sure) that it will be handled correctly.

from codemirror-v1.

iliakan avatar iliakan commented on May 24, 2024

I updated to lates git. Please check this screenshot, it tells what I mean: http://img251.imageshack.us/img251/2503/ss20100826224040.png

from codemirror-v1.

marijnh avatar marijnh commented on May 24, 2024

Yes, I see. It will now indent lines after this one correctly, but still mess up at the semicolon insertion point. There is no easy way to handle this. If you need proper semicolon insertion, you'll have to implement it yourself.

from codemirror-v1.

iliakan avatar iliakan commented on May 24, 2024

Do I get it right that the only way to edit:

var func = function() {
...
}
...

without indentation problems is disabling auto-indent ?

from codemirror-v1.

marijnh avatar marijnh commented on May 24, 2024

Correct.

from codemirror-v1.

Related Issues (20)

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.