-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PR: Comment lines taking into account code indentation and pep8 #3958
Conversation
Lets add a space between the So that # def hello():
# pass
#def hello():
#pass Both work when removing the comment |
Hmm, this was the original solution, but we can't expect that lines will be always comment out with spyder shortcut, because of that I make code folding ignore commented lines in #4728, they could have an arbitrary indentation and that will break codefolding Although I really like this change, IMO commented out lines at the first of the line is visually annoying. also other editors comment out lines according identation |
I really like this style because it keeps the flow of the code even with comments in the middle. The code is good at undoing the comments even crazy stuff like this:
However, it is not backwards compatible with the previous block comments, and can break code that has been manually commented out at the beginning of the line. These can be hard to spot and make whitespace management a difficult chore. But I think this problem can be fixed. The code fails on this:
It deletes the spaces in front of the indented section leaving 3 spaces instead of four. Should be possible to tell whether a space needs to be deleted or not by:
This wouldn't work perfectly for long line continuations, but those won't break your programs like other indents do. |
Hello @dalthviz! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on October 05, 2017 at 21:23 Hours UTC |
20e9752
to
e54623a
Compare
You can take a look at PR #4720 to see how to do it. |
37f32dc
to
31d6426
Compare
674d3a7
to
92f4070
Compare
@ccordoba12 @bcolsen this is a preview: @bcolsen could you test it please? thanks :) |
@bcolsen thanks again for the good feedback 👍, could you test the latest changes? I think this is almost finished :) |
Issue 1 and 4 are solved now. 👍 I'm back on my laptop so I made some gifs of the other two. Issue 2The blank lines getting skipped now but they are still counting as smallest indent so the comments are still on the far left. Issue 3The comment in block comments are still getting uncommented when I use |
Maybe to resolve these issues we could consider two shortcuts for comment/uncomment code, instead of only one. (i.e |
I was actually thinking the same thing Crtl-shift-1 is a little awkward but it makes sense |
@bcolsen I made some more changes can you test again? :). About the reasons of the issues still there: in the case of the unblockcomment I was not returning in the method and in the case of the indentation level of the comment it was a missing validation. About the suggestion of @rlaverde (by the way, thanks for the feedback 👍), thinking beyond the issues that @bcolsen helped to find, you guys think that could be helpful to have a different shortcut to manage the comment/uncomment? What do you think @ccordoba12? |
@dalthviz Everything looks great to me here! I couldn't find anything that would I would normally do or end up with that can break. 👍 As for the Keep the current commenting tool the sameI think Add an option for just uncommentingI have had times when I wanted to uncomment a whole section that had mixed commented and uncommented code. A For example, pressing # if language.lower() in value:
# self.supported_language = True
# # sh_class, comment_string, CFMatch = self.LANGUAGES[key]
# # self.comment_string = comment_string
if key in CELL_LANGUAGES:
self.supported_cell_language = True
self.cell_separators = CELL_LANGUAGES[key]
# if CFMatch is None:
# self.classfunc_match = None
# else:
# self.classfunc_match = CFMatch() This way we can keep the commenting tool "smart"(or contextual) like it is now about when to comment or uncomment, as well as give the option to take an arbitrary block of code and uncomment all of it. |
Thanks a lot @bcolsen for all your help with this 👍 About the new shortcut for only uncommenting, from that point of view could be interesting, however I think that it could be left for another issue @ccordoba12 @rlaverde what do you guys think? |
@bcolsen, thanks a lot for your careful and detailed review! It helped us a lot to improve this! About adding an option for just uncommenting, it looks like a reasonable idea. Please open a new issue about it, so we can continue our discussion there. |
self.__remove_prefix(prefix, cursor, line_text) | ||
|
||
def __remove_prefix(self, prefix, cursor, line_text): | ||
"""Handle the remove of the prefix for a single line.""" |
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 change this to
Handle the removal of prefix comment for a single line
@dalthviz, I left a couple of minor comments, then I'll merge ;-) |
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.
Great work @dalthviz!
Fixes #2845
Fixes #1785
Edit:
Takes into account some ideas from @bcolsen and @Ericvulpi, thanks for your help in this one :)