Summary: | Comments influence next line's indentation | ||
---|---|---|---|
Product: | [Applications] kate | Reporter: | Gerald Senarclens de Grancy <oss> |
Component: | indentation | Assignee: | KWrite Developers <kwrite-bugs-null> |
Status: | RESOLVED FIXED | ||
Severity: | minor | CC: | |
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
Latest Commit: | http://commits.kde.org/kate/db18ba1a5791240094c975a71d9d09f74e39a07b | Version Fixed In: | |
Sentry Crash Report: | |||
Attachments: |
rewrite of Paul Giannaros' python.js
allows manual testing allows manual testing PEP8 style indentation for Kate PEP8 style indentation for Kate |
Description
Gerald Senarclens de Grancy
2012-12-28 16:35:10 UTC
Yes, this is a bug. The functionality is provided by katepart tough, so I'll put it there. This behaviour is due to the very simple implementation of the python indenter in kate, which just looks at the last non-space character in a line for deciding whether to (un)indent. Ignoring comments would need to be implemented there. Right, it's a bug in the indenter. Best would be if you provide a fix for the file python.js. Dominik: I just had a short look at python.js; the fix is simple, but to make it proper I need to check whether a comment sign is part of a string; syntax/python.xml provides very proper definitions for StringDetect - hence I'd like to know if the scripting interface exposes information on whether a char is part of a string or not. Thanks for a short answer. @Gerald: The scripting API is documented here: http://docs.kde.org/stable/en/kde-baseapps/kate/advanced-editing-tools-scripting.html#advanced-editing-tools-scripting-api Maybe you can use: - bool document.isString(int line, int column); - bool document.isString(Cursor cursor); Description: Returns true, if the attribute of the character at the cursor position is dsString, otherwise false. A fix would be really cool :-) Created attachment 76701 [details] rewrite of Paul Giannaros' python.js After looking into Paul's version I decided to do a complete rewrite b/c much of the great indent magic that is implicitly asked by PEP8 would create a mess. I also through out all helper functions as they were essentially present in script/libraries/string.js; The file is a lot shorter now (I also removed all the debugging statements). For simplicity I removed a special case for closing strings (there was no explanation on why this was needed and it didn't make sense to me. To the best of my knowledge, this version of the file does exactly the same as the original, but fixes this bug and indents on closing backslashes (using a closing backslash is not considered pythonic, but some people still use/ need it if all else fails: http://www.python.org/dev/peps/pep-0008/#maximum-line-length). However, please don't commit/ push it yet as I still need to implement a proper unittest and the remaining behavior of PEP8 (as known eg. by emacs' python-mode.el). Created attachment 76702 [details]
allows manual testing
Attached my manual test file if anyone wants to have a look at the current workings. The way I test: simply place the cursor at the end of any line an press enter. The new indent should match the indent of the following line.
Of course, the not yet implemented logic fails atm (unfinished sequences and argument lists) - but those weren't present in the initial version either.
Created attachment 76738 [details]
allows manual testing
updated manual TC
Created attachment 76739 [details]
PEP8 style indentation for Kate
Just finished the python indentation script implementing automatic indentation and unindentation for sequences as implied by PEP8 (and known from Emacs' python-mode).
Tested against the attached manual test file (hitting enter at the end of each line indents to the next line's level as expected).
I'd be thankful if someone could run a few tests on this before committing. Enjoy :)
Gerald: Now there are two javascript attachedments. Which one is the correct "python.js" indenter? With respect to testing: We have a unit testing framework for indenters. The data is in kate/testdata/indent/python To run all indenter unit test, type: ./run.sh ~/kde/kate/build/part/tests/indenttest.shell To run python unit tests, type: ./run.sh ~/kde/kate/build/part/tests/indenttest.shell python Can you add a testcase for your case? Comment on attachment 76701 [details]
rewrite of Paul Giannaros' python.js
Dominik: go for "PEP8 style indentation for Kate". Thanks for the hint about the tests for the indentation scripts. Once I get to write such a test - should I post it here?
Created attachment 76769 [details]
PEP8 style indentation for Kate
updated required Kate version to 4.10 (b/c of using require)
Best is to post a patch on http://reviewboard.kde.org that includes all changes. And if you want, you can apply for a KDE contributor account. Once the patch is reviewed, you can commit yourself :-) Git commit 7aba1f30cf581bb71ebbc8b31d85016c5981d706 by Gerald Senarclens de Grancy. Committed on 30/01/2013 at 13:36. Pushed by geralds into branch 'master'. fixed and extended python indentation mode Indentation is now correct even if a comment is at the end of a line. Added two regression tests. The updated version of the script also deals with opening and closing argument lists and sequences as suggested in PEP8. REVIEW: 108644 M +119 -79 part/script/data/indentation/python.js A +3 -0 testdata/indent/python/dedentComment/expected A +3 -0 testdata/indent/python/dedentComment/input.js A +2 -0 testdata/indent/python/dedentComment/origin A +2 -0 testdata/indent/python/indentComment/expected A +3 -0 testdata/indent/python/indentComment/input.js A +1 -0 testdata/indent/python/indentComment/origin http://commits.kde.org/kate/7aba1f30cf581bb71ebbc8b31d85016c5981d706 Git commit e6b9c40f083b7f2e52ab15541a9af2993f409985 by Gerald Senarclens de Grancy. Committed on 04/02/2013 at 10:14. Pushed by geralds into branch 'master'. created additional tests for Python indentation A +4 -0 testdata/indent/python/dict1/expected A +7 -0 testdata/indent/python/dict1/input.js A +1 -0 testdata/indent/python/dict1/origin A +3 -0 testdata/indent/python/dict2/expected A +5 -0 testdata/indent/python/dict2/input.js A +1 -0 testdata/indent/python/dict2/origin A +3 -0 testdata/indent/python/function_args/expected A +5 -0 testdata/indent/python/function_args/input.js A +1 -0 testdata/indent/python/function_args/origin A +4 -0 testdata/indent/python/list1/expected A +7 -0 testdata/indent/python/list1/input.js A +1 -0 testdata/indent/python/list1/origin A +4 -0 testdata/indent/python/list2/expected A +7 -0 testdata/indent/python/list2/input.js A +1 -0 testdata/indent/python/list2/origin A +4 -0 testdata/indent/python/tuple1/expected A +7 -0 testdata/indent/python/tuple1/input.js A +1 -0 testdata/indent/python/tuple1/origin A +4 -0 testdata/indent/python/tuple2/expected A +7 -0 testdata/indent/python/tuple2/input.js A +1 -0 testdata/indent/python/tuple2/origin A +3 -0 testdata/indent/python/wrapped_line/expected A +5 -0 testdata/indent/python/wrapped_line/input.js A +1 -0 testdata/indent/python/wrapped_line/origin http://commits.kde.org/kate/e6b9c40f083b7f2e52ab15541a9af2993f409985 Git commit db18ba1a5791240094c975a71d9d09f74e39a07b by Gerald Senarclens de Grancy. Committed on 30/01/2013 at 13:36. Pushed by geralds into branch 'KDE/4.10'. fixed and extended python indentation mode Indentation is now correct even if a comment is at the end of a line. Added two regression tests. The updated version of the script also deals with opening and closing argument lists and sequences as suggested in PEP8. REVIEW: 108644 M +119 -79 part/script/data/indentation/python.js A +3 -0 testdata/indent/python/dedentComment/expected A +3 -0 testdata/indent/python/dedentComment/input.js A +2 -0 testdata/indent/python/dedentComment/origin A +2 -0 testdata/indent/python/indentComment/expected A +3 -0 testdata/indent/python/indentComment/input.js A +1 -0 testdata/indent/python/indentComment/origin http://commits.kde.org/kate/db18ba1a5791240094c975a71d9d09f74e39a07b Git commit cdc845febdac578b2635571fed287bafd13c4647 by Gerald Senarclens de Grancy. Committed on 04/02/2013 at 10:14. Pushed by geralds into branch 'KDE/4.10'. created additional tests for Python indentation A +4 -0 testdata/indent/python/dict1/expected A +7 -0 testdata/indent/python/dict1/input.js A +1 -0 testdata/indent/python/dict1/origin A +3 -0 testdata/indent/python/dict2/expected A +5 -0 testdata/indent/python/dict2/input.js A +1 -0 testdata/indent/python/dict2/origin A +3 -0 testdata/indent/python/function_args/expected A +5 -0 testdata/indent/python/function_args/input.js A +1 -0 testdata/indent/python/function_args/origin A +4 -0 testdata/indent/python/list1/expected A +7 -0 testdata/indent/python/list1/input.js A +1 -0 testdata/indent/python/list1/origin A +4 -0 testdata/indent/python/list2/expected A +7 -0 testdata/indent/python/list2/input.js A +1 -0 testdata/indent/python/list2/origin A +4 -0 testdata/indent/python/tuple1/expected A +7 -0 testdata/indent/python/tuple1/input.js A +1 -0 testdata/indent/python/tuple1/origin A +4 -0 testdata/indent/python/tuple2/expected A +7 -0 testdata/indent/python/tuple2/input.js A +1 -0 testdata/indent/python/tuple2/origin A +3 -0 testdata/indent/python/wrapped_line/expected A +5 -0 testdata/indent/python/wrapped_line/input.js A +1 -0 testdata/indent/python/wrapped_line/origin http://commits.kde.org/kate/cdc845febdac578b2635571fed287bafd13c4647 |