Is there a way to get eclipse to automatically detect a space/tab mismatch the way Visual Studio does? - ide

In Visual Studio 2010, when I open a source code file that has a mix of tabs and spaces, a message will appear warning me as such and give me a chance to correct it. Is there such a feature in Eclipse whether native or via plugins?

I have not noticed such a feature, but there are settings you can change so you can detect it yourself. Essentially I show whitespace characters (specifically tabs and spaces). To show whitespace characters:
Preferences > General > Editors > Text Editors > Show whitespace characters
Click on the "whitespace characters" link to modify which whitespaces characters to show.
Then modify your language formatters to enforced tabs over spaces (or vice versa). Then when you format code (Ctrl+Shift+F) it will enforce the convention you set in your formatter. This has the other side effect of formatting the rest of your code, but that might not be a bad thing.
If you want to remove trailing whitespace when you format your code, you can do that by editing your "Clean Up" profile and clicking the "Remove trailing whitespace" option int the "Code Organizing" tab

Admittedly, this is not as nice as Visual Studio's solution and very similar to the answer above, but here's how I resolved this.
Go to Window > Preferences > General > Editors > Text Editors
Check the box "Show whitespace characters"
Click on "Configure Visibility"
Check the boxes under the Leading column for Ideographic space and Tab
Check the boxes under the Trailing column for Space, Ideographic space, and Tab
All other boxes should be unchecked.
"Ok" everything. You may have to reopen existing windows for this to take effect.
If you prefer having your code tabbed instead of using spaces, then you'll slightly modify these instructions to show leading spaces instead of leading tabs. In any case, having this set up as such gives me instant visibility when I have a file that uses tabs instead of spaces or mixed tabs and spaces.
I would not recommend using CTRL+SHIFT+F as it makes for a subversion nightmare when diffing old and new code. Alternatively, simply do a CTRL+F, check the Regex box, replace \t with four spaces. You'll still see a lot of diffs in subversion, but it's easy to pick out that you simply updated the spaces.

Related

How to set tab indentation with GNAT GPS

I installed GNAT GPS 2017 and I would like it to indent my code with tabs using the same width as 4 space characters. I've gone into Edit->Preferences->Editor->Ada and tried all sorts of options (Use tabulations, default indentation 4, etc) but nothing seems to make it work:
Opening existing file with tabs causes GPS to display tabs with 8 spaces wide instead of 4.
Adding new code causes GPS to indent with 4 spaces but it inserts space characters instead of a single tab character.
Any ideas?
I think that GPS is working as-designed; unfortunately, that isn’t the way you want it to work.
The Preferences > Editor > Ada > Default indentation setting (and the four settings following it) say what screen appearance is required (assuming a monospace font, of course) if you hit the TAB key in a line.
The Preferences > Editor > Ada > Use tabulations setting says whether the editor should use 8-column-width tabs when possible to achieve the above.
#Jean-François Fabre suggested that "Their code parser doesn't support tabulations properly" - I think this may be that Jean-François compiles with -gnaty (style checks), and one of the default style checks is that the file isn’t indented with tabs.

How to disable auto changing tabs to spaces in the code in Intellij Idea?

How to disable auto changing tabs to spaces and removing empty lines, whitespaces in the sourcefiles after it opened?
In other words if the line contains tabs and spaces in one line Idea shouldn't change them. For example if file contains "-->-->....-->public void setAttribute();" Idea shouldn't change tabs to spaces or spaces to tabs. I can disable all autoformattig.
To restate the problem, you want the editor to not affect the whitespace indentations. Spaces should remain spaces and tabs should remain tabs.
I'm having a similar problem. It looks like IntelliJ has this feature:
Settings > Editor > Code Style,
Indents Detection section,
Detect and use existing file indents for editing option
Unfortunately, I don't think I can get it to work as expected for myself (version 2016.3.6), but it seems to be working for others.
Here's the original jetbrains blog post about it.
There is an option 'keep indents on empty line'
Assuming Java: Settings > Code Style > Java > Tabs and Indents > Use tab character. You can do the same for other languages too.
Besides noted IDE settings, please check if .editorconfig file exists in your project. The file may silently override IDE settings.
In Editor - Code Style - Java/JSON/etc - Tabs and Indents are two checkboxes:
Use tab character - when not checked, Idea replaces tabs by spaces while typing
Keep indents on empty line - when not checked, Idea removes tabs and spaces from lines where is no other content

intellij messes up with tabs in non-program files

so i just spent some time fussing over why my String.split call in scala failed - i was trying to split on a tab.
Problem wasn't what i was doing, but rather the fact that intelliJ changes tabs to spaces. Fair enough, but can i tell intelliJ to not do that for some files - like say random text files I might be using for test/learning purposes?
First, I would turn on Settings > Editor > Appearance > Show whitespaces, that way you're SURE what white space characters are there.
Next, under Settings > Code Style > General there should be a Use tab character check box. This says "use tabs for anything that's not Java, Scala, HTML, etc.". Just make sure Java, Scala*, etc. Use tab character setting is set to what you want.
Unfortunately, I don't know of any way to be more fine grained with what file types do and do not use tabs vs. spaces.
*I'm assuming the IntelliJ Scala plugin adds a tab in Settings > Code Style.

Remove spaces in IntelliJ

Does anyone know how I can remove spaces in my code. I usually do reformat code, but this does not remove all the doubl spaces and such. I assume there is a way in the preferences but I am unable to find it.
Assuming that this is for Java code (although the general mechanism is true for most file types), you can modify when/how spaces are used in code.
Go to File->Settings->Code Style->Java
If you then click on the Spaces tab you can specify the code layout you want. After you've done this if you reformat your code it should format according to your preferences.
You can specify this for other types too (General, CSS, JavaScript and so on)

How are tabs treated differently in different systems?

To maintain portability, tab
characters must not be used in
indentation, since different systems
treat tabs differently.
Anyone knows?
Where is this quote from? Does it talk about indentation in code, or in WYSIWYG documents, or in output of console programs that must be parsable?
As for code indentation, tabs can have same size as any number of spaces (usually 2, 4 or 8). So if you mix spaces and tabs, once you open same file in different editor with different tab settings you would see broken indentation. The solution to that is not to use spaces for indentation (opposite of what your quote says).
Another advantage of all-tabs indentation is ability to adjust visual size of tabs (some people like 'em bigger).
Python has this insane whitespace scoping mechanism that would cause inconsistent indentation to break code.