-
Notifications
You must be signed in to change notification settings - Fork 41
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
Reindent command breaks on (multiline) comments #1271
Comments
In fact, this can be fixed by editing the
to
although the way things stand, indentation can become broken when the comments include lines that would affect the indentation, and the contents of comments can become indented i.e.
becomes:
Related issue: using a scope of More detailed instructions can be found on SO: http://stackoverflow.com/a/38261481/4473405 I guess you could argue that comments shouldn't be reindented, because the programmer may have had the intention to make commented-out lines more visible by placing them out-of-indent. But then, a) it should be configurable and b) the text below the comment should be indented as though the comment wasn't there. |
This was my experience too, although I can't pin down exactly what the issue is. Indentation was broken when my syntax file applied the comment scope to the newline at the end of the comment. When I changed it so that the comment scope did not include the newline the indentation worked more reliably. (Comments are not ignored in tmPreferences) |
I suppose the most reasonable approach would be to only reindent comments if the preceding or following line has the same indentation originally (e.g. none) and generally not have comments affect the indentation level at all. There may still be edge cases on occasions, I suppose. |
I disagree. I think the reindent command should produce the same result no matter what the indentation of the original file was. It already acts weird where it will indent things differently depending on whether you remove all indentation first. Additionally, I prefer the "don't change the indentation of comments" option which already exists, because for some languages the comment character must be the first character on the line (i.e. no whitespace before it) |
where is this option @315234 ? the only way I found to alter this functionality was as mentioned earlier - to edit the |
Yes that's what I'm referring to. It's a setting/option for package maintainers, but it can still be overwritten by the user. |
where can i find Indentation Rules - Comments.tmPreferences file? |
Note that disabling |
It's broken everywhere. |
Particularly annoying in HTML email framework code like Zurb etc with conditional MSO comments:
end up getting these huge blocks of resets that have no correlated top-indent tag... the other option preserveindent false also doesn't work. what makes sense to me is: |
+1 |
Issue still exists :/ |
applies to c++ too, since many years back. |
Changed Comments.tmPreferences, tried playing round with this a few times, still can't get it working properly ( .scss/.less ) so annoying, I need comments and it's indent chaos! |
There should be a global fix to this! |
Is there a fix to this? I have a document that needs serious indenting and doing it manually is a PITA. |
Well it's still broken |
This is one of the biggest disappointments of SublimeText, one of the overlooked issues that are pushing me away from it. |
The problem is still exists. |
How can people claim sublime text is wonderful when simply putting a comment in you code breaks its ability to indent code. In addition the solution mentioned here refers to a non existent file so is of no help. SOOOOOO infuriating. |
@AlexFinch Sublime is Wonderful, this is basically the only serious glitch and it is not present for every language. Anyway Sublime need more love, more modern features (a debugger) to survive to this new wave of editors, mainly to attract more people and more plugins developers. IMO |
I got tired of this. |
I got tired too much also from this stupid thing. But Visual Studio is very slow. |
My recommendation, in general, would be to look for a language-specific formatting tool. This will typically give you more control, and generally they come out-of-the-box following the language community's idiomatic style. I am sure someone on the team will take the time to dig in and see what can be done. I don't, however, know exactly when that will be. We are still a very small organization, and only have a handful of engineers. This, combined with putting in extra effort to make sure our solutions aren't slow and can be maintained over the long term, means that some things end up taking longer. On the meta comments: we definitely do spend quite a bit of time working on "little" issues. However, the nature of little bugs is that they tend to affect a relatively small percentage of users. Thus you won't notice most of the little bugs fixed since you are unlikely to hit them. But if your little bug is not fixed, then you definitely notice. Also, sometimes little bugs take an extreme amount of work to fix, because they would require changing a general approach to some fundamental part of the codebase. I can't say for sure exactly what will go into fixing this, but people adding their voice about details where it doesn't work and adding reactions definitely helps us gauge where changes might be most felt. |
@wbond Your recommendation makes sense but nonetheless this bug is so frustrating and so old. Honestly I don't like to rely on an external tool just to reindent my code, especially for small projects where this For me Sublime is (or was) the default software, the first one I install on a new machine. It's my go to editor from years. Just my two cents |
They could just open source the project if man power is the issue. |
Old story, no way it will happen (probably) |
🤣 |
Been suffering with this issue for years, been putting up with it until now as I've reinstalled Sublime after reformatting my rig. Had to hunt down the fixes in https://forum.sublimetext.com/t/javascript-indentation-broken-after-comment/13609/12 again, which lets us re-indent code fine, sans-comments. Time spent having to re-indent comments one-by-one after one does a 'reindent all' adds up and quickly becomes meaningless work. Would love for indentation to work properly in my preferred editor. If someone knows of a package to make JS indentation work (and not a full re-formatter like jsformat or prettier) in Sublime please comment here, it's quite frustrating for many I'm sure. |
This seems to work for me on ST3:
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>JavaScript Indent</string>
<key>scope</key>
<string>source.js</string>
<key>settings</key>
<dict>
<key>decreaseIndentPattern</key>
<string>^(.*\*/)?\s*[}\]].*$</string>
<key>increaseIndentPattern</key>
<string>^.*[{\[][^}"'\]]*$</string>
<key>bracketIndentNextLinePattern</key>
<string>(?x)
^ \s* \b(if|while|else)\b [^;]* $
| ^ \s* \b(for)\b .* $
</string>
<key>unIndentedLinePattern</key>
<string>^\s*//.*$</string>
</dict>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>scope</key>
<string>comment</string>
<key>settings</key>
<dict>
<key>preserveIndent</key>
<false/>
</dict>
</dict>
</plist> |
By editing also this file : Sublime Text 3\Data\Packages\PHP\Indentation Rules - Annex.tmPreferences
Solves the problem for me PHP\Indentation Rules - Annex.tmPreferences
|
what about single line? i want a shortcut single line multiple HTML tag in proper structure format |
Since the instructions of how to fix this are hard to find in this massive thread and not for the general case, I will post the steps I took below.
|
wisnoskij, this works! |
Hopefully the devs will apply wisnoskii's fix to future updates of ST3 and thank him, considering they couldn't figure it out for 8 years. Thank you wisnoskii's. I never thought I would see this fixed... |
Just for clarification, everything relevant to this issue (including a workaround that does not satisfy all situations) has been posted by @keith-hall in the first comment. A better fix (or workaround) would require changes to the core reindentation code and it seemingly hasn't been a priority for the team. Please continue upvoting the issue if you're affected by it. |
Yes, nothing I wrote is my own work, other than the exact wording which I tried to make as simple and general as possible. I would urge the devs to just use this fix to the default configuration. I realize it is slightly off from being perfect in all cases, and it does not work with JS, php, and html, but it makes sublime text c9ompletl functional for languages like C or Rust. I realize that JS is really popular, but their are still a great many developers using languages who could have a out of the box working sublimeText auto-indentation. Also, maybe I am wrong here. But it sounds like this fix does not break some languages and fix others. This fix helps even js and html, it just does not completely fix them? |
Any news? This auto-indentation failure on lines that also have comments invalidates the use of the text editor. If someone needs auto indentation that works with lines that have comments, they can use VS code, successfully tested on Linux.
Ref.: https://stackoverflow.com/questions/68884005/what-is-the-shortcut-to-auto-indent-code-in-vscode |
Summary
Selecting an entire document that contains comments that span multiple lines, and using the
Edit
->Line
->Reindent
command, stops indenting at the comment.I believe that this is not a Indentation Rules issue for the Default packages repo, because they don't specify any rules for handling comments, and there are no problems while typing the document, just when re-indenting.
Expected behavior
The entire document should be re-indented correctly.
Actual behavior
Indentation stops at the comment and starts from the indentation level of the comment (i.e. 0) again after it.
Steps to reproduce
Edit
->Line
->Reindent
Example:
becomes:
same with Javascript:
becomes:
and even single line comments:
becomes
Environment
The text was updated successfully, but these errors were encountered: