-
Notifications
You must be signed in to change notification settings - Fork 51
Smart-indent not outdenting correctly with Python #41
Comments
I just confirmed that the CodeMirror Python demo (Light Table uses CodeMirror) also suffers from this problem. |
@kenny-evitt so does that mean that if the next release of LightTable has updated codemirror as was mentioned in the blog that it would still suffer this problem? |
@MortalCatalyst Yes. We should submit a fix for this, if it's possible, upstream to CodeMirror and then pull in the new version to LT. Would you mind checking for an existing issue for CodeMirror that covers this? |
@kenny-evitt is this a codemirror error or do we need to define the indentation, I found this answer on SO http://stackoverflow.com/a/15969118/461887 If you want your mode to provide smart indentation (through the indentLine method and the indentAuto and newlineAndIndent commands, to which keys can be bound), you must define an indent(state, textAfter) method on your mode object. If a mode does not support smart indentation out of the box, you can always implement it yourself. See the section on writing CodeMirror modes in the docs. |
This is the mode in codemirror http://codemirror.net/mode/python/python.js are the extra codemirror settings defined in LT? |
@MortalCatalyst Interesting – thanks for looking into this. If extra settings are required by CodeMirror, e.g. for Python, I'm confused why their Python demo doesn't provide them. More generally, is it even possible to indent Python code correctly for these scenarios? Is there some way to know, apart from existing indentation or other scoping info, that a subsequent class defined in a file is or is not nested inside the former class? Or, in other words, why is this failing at all? |
Well indentation works perfectly in LT when typing the code, except for if/else, a lot of editors get that wrong though. It's actually only when running the smart indent does the error occur, so the error likely occurs only in its version. |
As a test I loaded the latest pyhon.js from https://github.com/codemirror/CodeMirror/edit/master/mode/python/python.js into LT 0.8.0 . Still works fine on indent but smart indent a fail. It's like smart indent keeps resetting what it thinks column 0 is and adds 2 over and over again. |
@kenny-evitt I did post in the gitter tonight no one around currently. It seems that in pool.cljs the trigger to subtract indentation for line is not met in python and so the continual add. This is the code I am referring to (cmd/command {:command :indent-selection
:desc "Editor: Indent line(s)"
:exec (fn []
(when-let [cur (last-active)]
(let [line (-> cur (editor/->cursor "start") :line)]
(if (editor/selection? cur)
(editor/indent-selection cur "add")
(editor/indent-line cur line "add")))))})
(cmd/command {:command :unindent-selection
:desc "Editor: Unindent line(s)"
:exec (fn []
(when-let [cur (last-active)]
(let [line (-> cur (editor/->cursor "start") :line)]
(if (editor/selection? cur)
(editor/indent-selection cur "subtract")
(editor/indent-line cur line "subtract")))))}) |
Copied from the original comment on LightTable/LightTable#1627:
The text was updated successfully, but these errors were encountered: