Search code examples
javascriptpythoncodemirror

Change indentation unit for CodeMirror Python


I don't see a way to change indentation unit to two-space or best, make it automatically detect the unit: http://codemirror.net/mode/python/index.html

enter image description here

As you can see, the if showed read since it got cm-error class. It has two-space indent. But the print is fine. Although this code block works fine.

So:

  1. Is there a way to make the code using two-space indentation?

  2. Is it possible to make automatic indentation unit?

I tried to play around with http://codemirror.net/mode/python/python.js and cannot come up with any conclusion.


Solution

  • See the indentUnit option. There's no auto-detection in the library, but you might be able to write a little script that finds the first line that's indented more than the one above it, and take the difference as a likely guess.