-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add auto-indent for Python #15159
Add auto-indent for Python #15159
Conversation
@BlueBatSamurai |
Can any one here knows Python test auto-indent of this PR please? |
Test by inserting the caret to the EOL and pressing Enter :
": #"
""":
:#"""
else:
elsse: The Currently, the Python Indent plugin installable from Plugin Admin is the better choice IMO as it determines conditionally to indent or not to indent. Indenting almost any line with a colon at EOL as the PR does can be disruptive if the indenting is incorrect. When both plugin and PR indenting are enabled, the plugin fixes the actions of the PR indenting and then needs more undo actions so it is worse for undo to have both enabled. Disabling Auto-indent checkbox prevents the extra undo behaviour though affects all tabs that may have other languages where Auto-indent is preferred. Builtin auto indenting for Python seems like a nice idea and the code looks tidy, I suggest to improve the regex to lessen indenting that should not occur:
or perhaps make
The Python Indent plugin checks for these keywords. plugin code |
Thanks for killing my PR. :-) I was unaware that there was a plugin that did this functionality; I have long used a script to do it, but when the 15122 issue came along I thought it made sense to code it natively. The idea behind the PR code was to keep it simple: If a line "ends" with a colon ( C-like auto-indent behavior for other languages in N++ is far from perfect, and again I was trying to keep Python indenting simple and not "perfect".
I don't know what this means. IMO indenting after any line with a
Why even try it with plugin and this PR together? Makes no sense.
I'd prefer not, mainly because I don't think it is necessary.
Well...something positive! :-) |
@mpheath
Not necessarily. |
OK, I like your "basic functionality" statement. ...So what should be done next to move this PR forward? |
I will test it as well, to make sure it's useful for the new users, then do the code review. :) |
Sorry but I’m new on GitHub… |
@BlueBatSamurai |
@alankilborn |
I've dowloaded and renamed the new And it works! Even if there is a comment behind the colon before you press Enter. (And yes, it doesn't check whether there is a valid keyword before the colon... Something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the suggestion:
PowerEditor/src/Notepad_plus.cpp
Outdated
|
||
_pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP | SCFIND_POSIX); | ||
_pEditView->execute(SCI_SETTARGETRANGE, _pEditView->execute(SCI_POSITIONFROMLINE, prevLine), | ||
_pEditView->execute(SCI_GETLINEENDPOSITION, prevLine)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve readability:
auto startPos = _pEditView->execute(SCI_POSITIONFROMLINE, prevLine);
auto endPos = _pEditView->execute(SCI_GETLINEENDPOSITION, prevLine);
_pEditView->execute(SCI_SETTARGETRANGE, startPos, endPos);
Fix #15122