intellij messes up with tabs in non-program files - intellij-idea

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.

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.

Intellij: Change project indent from 4 spaces to 2 spaces

Currently, all of my project files are indented with 4 spaces. I want to change that to 2 spaces as my organization uses 2 as an standard, but can't find any answers.
Depending on your version of IDEA, it should be in your settings under:
Editor > Code Style > (Specific language)
**Edit: Example, in IDEA 2016:
If you don't see it there, I found mine by searching "indent" in the settings window.
Finally, for organization-wide code settings, I highly recommend EditorConfig. It's compatible with just about every IDE out there and lets you enforce code style settings without requiring everyone to manually change their settings to match. IDEA supports it out of the box, without a plugin.

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)

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

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.

Is there an IDE or plugin which allows separation of code from layout?

I'm looking for something like CSS for code. Does it exist either in an IDE, or as a plugin?
The compiler often doesn't care how many more spaces or tabs or newlines you have between tokens in your code, but people do care.
I want to specify in my "style sheet" that braces always live on a seperate line, commas are always followed by spaces, and spaces always surround operators.
Somebody else could then take my code and in their style sheet, specify that no unnecessary spaces should be visible, braces should always be on the same line as their predecessor, and functions should always be separated by 3 line breaks. But the code itself should not actually change.
Is there such a tool?
I don't think such a thing exists, the best solution is to have a custom style for local coding (most IDE's allow this) and then use a tool to reformat your source code (like Jalopy for Java) when you commit it centrally.
That way you have something that's common centrally, but can still style how you want locally.
I don't know of any tool that can arbitrarily apply a style to code without actually modifying the text itself. Since you need to edit the code, that seems impractical.
This is called code formatting and if you google "code formatter" and your language of choice you should get a list of available options.
Try some eclipse based IDE (Aptana) or eclipse itsefl and and from there you can configure how the formatting works :)