QT Creator, mixed tabs/spaces alignment issue in Text Editor
-
Hi,
I am running the latest build of QT Creator 12 on Windows.
I would like to use tabs for indentation and spaces for alignment, e.g.
void test(int a, ..........int b,
Instead I get something like:
void test(int a, \t\t\t....int b
('\t' is tab, '.' is space)
Below if a picture that should illustrate the problem I am experiencing, and how I've setup QT Creator.
Cheers,
-
@frejur hi,
Mixing both is usually a bad idea. It will work for you because of the configuration of your editor but as soon as the tab is rendered with a different width, your alignement will be broken.
You should rather use one or the other to keep things clean.
@SGaist I respectfully disagree. It's not what I prefer personally, but there are codebases that enforce the kind of style I'm referring to.
It seems like this is not supported or not implemented very well by the Text Editor's own auto-indent.
Luckily it is supported by ClangFormat, but you need to disable all the other indentation related shenanigans.
Here are the settings that worked for me:
- Disable Text Editor>Typing> Enable automatic indentation
- Disable Text Editor>Cleanups Upon Saving> Clean whitespace
- (If using FakeVim) Disable FakeVim>General>Vim Behaviour> Automatic indentation
- Enable C++>Code Style>ClangFormat settings> Format while typing, and Format edited code on file save
- In C++>Code Style, in the panel named ClangFormat, scroll way down and set:
UseTab=ForIndentation
- In that same panel make sure to set ColumnLimit to whatever you're using, this does not sync with whatever you set up under Text Editor>Display.
Note that the auto-alignment mostly only "kicks in" when the line you're editing exceeds the maximum column limit. E.g. If you are listing a bunch of arguments, they will always be put on a single line if they fit within the limit. But there's more freedom when it comes to string literals.
It does seems to work though, you may have to trigger the alignment/indentation manually by hitting save.
Unfortunately, statements using the stream insertion operator mess things up, but from what I gather that's due to a bug in ClangFormat.
-
Hi,
I am running the latest build of QT Creator 12 on Windows.
I would like to use tabs for indentation and spaces for alignment, e.g.
void test(int a, ..........int b,
Instead I get something like:
void test(int a, \t\t\t....int b
('\t' is tab, '.' is space)
Below if a picture that should illustrate the problem I am experiencing, and how I've setup QT Creator.
Cheers,
-
@jsulm When I do that I get:
void test(int a, ..........int b) { ....int c = 0; }
Instead of the desired:
void test(int a, ..........int b) { \t int c = 0; }
('\t ' is tab, '.' is space)
@frejur hi,
Mixing both is usually a bad idea. It will work for you because of the configuration of your editor but as soon as the tab is rendered with a different width, your alignement will be broken.
You should rather use one or the other to keep things clean.
-
@frejur hi,
Mixing both is usually a bad idea. It will work for you because of the configuration of your editor but as soon as the tab is rendered with a different width, your alignement will be broken.
You should rather use one or the other to keep things clean.
@SGaist I respectfully disagree. It's not what I prefer personally, but there are codebases that enforce the kind of style I'm referring to.
It seems like this is not supported or not implemented very well by the Text Editor's own auto-indent.
Luckily it is supported by ClangFormat, but you need to disable all the other indentation related shenanigans.
Here are the settings that worked for me:
- Disable Text Editor>Typing> Enable automatic indentation
- Disable Text Editor>Cleanups Upon Saving> Clean whitespace
- (If using FakeVim) Disable FakeVim>General>Vim Behaviour> Automatic indentation
- Enable C++>Code Style>ClangFormat settings> Format while typing, and Format edited code on file save
- In C++>Code Style, in the panel named ClangFormat, scroll way down and set:
UseTab=ForIndentation
- In that same panel make sure to set ColumnLimit to whatever you're using, this does not sync with whatever you set up under Text Editor>Display.
Note that the auto-alignment mostly only "kicks in" when the line you're editing exceeds the maximum column limit. E.g. If you are listing a bunch of arguments, they will always be put on a single line if they fit within the limit. But there's more freedom when it comes to string literals.
It does seems to work though, you may have to trigger the alignment/indentation manually by hitting save.
Unfortunately, statements using the stream insertion operator mess things up, but from what I gather that's due to a bug in ClangFormat.
-
-
@SGaist I respectfully disagree. It's not what I prefer personally, but there are codebases that enforce the kind of style I'm referring to.
It seems like this is not supported or not implemented very well by the Text Editor's own auto-indent.
Luckily it is supported by ClangFormat, but you need to disable all the other indentation related shenanigans.
Here are the settings that worked for me:
- Disable Text Editor>Typing> Enable automatic indentation
- Disable Text Editor>Cleanups Upon Saving> Clean whitespace
- (If using FakeVim) Disable FakeVim>General>Vim Behaviour> Automatic indentation
- Enable C++>Code Style>ClangFormat settings> Format while typing, and Format edited code on file save
- In C++>Code Style, in the panel named ClangFormat, scroll way down and set:
UseTab=ForIndentation
- In that same panel make sure to set ColumnLimit to whatever you're using, this does not sync with whatever you set up under Text Editor>Display.
Note that the auto-alignment mostly only "kicks in" when the line you're editing exceeds the maximum column limit. E.g. If you are listing a bunch of arguments, they will always be put on a single line if they fit within the limit. But there's more freedom when it comes to string literals.
It does seems to work though, you may have to trigger the alignment/indentation manually by hitting save.
Unfortunately, statements using the stream insertion operator mess things up, but from what I gather that's due to a bug in ClangFormat.