Is that possible? It solves the tab/space indentation debate, but how
is this done in Vim? For example, the code:
int main() {
<tab>if (1)
<tab><tab>int a = test(
<tab><tab>.............param1,
<tab><tab>.............param2,
<tab><tab>............);
}
would look perfectly fine no matter what tabwidth is, in whatever
editor. How do I enable this? It seems that Vim coerces all
indentation whitespace to tabs plus some spaces that aren't long
enough for the width of a tab. Does Vim also make this language
dependent? (E.g. For python, I would assume it has a different scheme
of handling automatic indentation.)
Thanks,
Oliver
Check out this [1] script.
1. http://www.vim.org/scripts/script.php?script_id=231
--
v4sw5RUYhw2ln3pr5ck0ma2u7Lw3+2Xm0l6/7Gi2e2t3b6AKMen5+7a16s0Sr1p-8.12/-6.56g6OR
Check out this [1] script.
I did. However, it looks like this only "automatically converts" tabs
to spaces during the middle of a line. For the example I gave:
int main() {
<tab>if (1)
<tab><tab>int a = test(
<tab><tab>.............param1, // [1]
<tab><tab>.............param2,
<tab><tab>............);
}
the script does not treat the param line [1] any differently than any
other line. It's not really context aware of the programming language.
Even if I *manually* space my way to param1 after the initial 2 tabs,
Vim will convert my spaces to tabs when I >> or <<. Is there no way to
let Vim recognize that spaces are a part of the contents and not
indent? Of course, it would be much better if Vim could automatically
insert spaces to the appropriate column when I break a statement into
multiple lines.
Cheers,
Oliver
> Even if I *manually* space my way to param1 after the initial 2 tabs,
> Vim will convert my spaces to tabs when I >> or <<. Is there no way to
> let Vim recognize that spaces are a part of the contents and not
> indent? Of course, it would be much better if Vim could automatically
> insert spaces to the appropriate column when I break a statement into
> multiple lines.
There is no way that I know of. The problem is the interface
between the function that determines how much a particular line
should be indented (based on the language, rules for that language,
etc.) and the code that actually performs the indentation as you
type or when you execute <<, >>, = and the like. That function
returns one number: the number of spaces by which the line should
be indented. There is no mechanism to split this into so-many tabs
followed by so-many spaces.
The 'preserveindent' and 'copyindent' options try to preserve the
pattern of spaces and tabs used to indent a line, but I don't think
they will do what you want.
I think your best bet is to write a formatting function that will
repartition the indenting whitespace code according to your rules
after you have typed it.
Regards,
Gary
No, this is a false illusion, you cannot expect a non-constant indent
level anyway, consider the following code.
suppose we have 4 space as indent level:
{
foobar1(); // comment1
if (fb2()) { // comment2
fb3(); // comment3
switch (x) { // comment4
case 1:
fb4(); // comment5
break;
default: // comment6
break;
}
}
}
now we change the indent level to 3:
{
foobar1(); // comment1
if (fb2()) { // comment2
fb3(); // comment3
switch (x) { // comment4
case 1:
fb4(); // comment5
break;
default: // comment6
break;
}
}
}
Got the idea? If anyone wants to change the indent level, the code is
ruined anyway.
Simply use only space for indent solves all problem above, personally I
do recommend not to use tab size other than 8 at all.
(Sorry I had just learned how to set plain-text message in thunderbird,
then send this message again.)
That is very unfortunate that Vim does not support such an
uncompromising way of solving the issue. (I know Emacs does =P)
Is there plans for this feature? How do users submit feature requests anyway?
Oliver
Strange to hear that, that is the way I am using now, and I don't see
any problems using only space for indent in Vim.
What do you really want?
--
Pan, Shi Zhu
Different people have different preferences regarding tabs vs spaces,
and mine are to use tabs for indentation since that what tabs are for.
Spaces are used for indentation due to the limitation of editors
(something I thought Vim of all editors could do) to interpret
indentation vs alignment.
Why tabs:
http://www.movementarian.org/docs/whytabs/
http://www.derkarl.org/why_to_tabs.html
> What do you really want?
As my original email in the thread describes, I want tabs for
indentation and spaces for alignment. Any whitespace that appears
after non-whitespace should be spaces. The Vim script Smart Tabs
handles this correctly.
The problem is when there are *multi-line* statements, which as Gary
mentioned Vim does not handle properly. When a statement is split over
multiple lines, alignment should not be solved using indentation.
E.g.:
foo (int a,
.....int b,
.....int c);
should not be
foo (int a,
<tab>int b,
<tab>int c);
I thought this would have been something Vim users would have
complained about. Emacs has a fix for it (with a few line of
configuration scripting), but it sounds like Vim's plugins cannot
extend into the editor for language-specific support. Is this correct
that this behavior cannot be reproduced in Vim with plugins?
Regards,
Oliver
Vim indent behavior for any specific language is scriptable of course,
only c-style-indent is built-in since it is widely used. You can just
disable the built-in c-style-indent and make your own indent script in
~/.vim/indent/c.vim
So, I've just proved that vim is *capable* of doing what you want with
some script work. The reason that you cannot do it now may have two reasons:
1. there is one script in vim.sf.net, but you cannot find it.
2. or nobody has written a script yet.
Anyway, you can visit the vim homepage and registered as a vim user to
vote or request new features.
See
:help 'copyindent'
:help 'preserveindent'
:help 'expandtab'
For Python, Vim forces hard tabs to 8 columns, because that's what the
Python standards say they are. You can still have "soft tabs" of a
different width, of course, or use 'expandtabs' to convert tabs to
spaces as you type them. Language-dependent settings of this kind are
usually set by a filetype-plugin.
See
:help ftplugins
:help filetype-plugins
Best regards,
Tony.
--
What does it mean if there is no fortune for you?
See
As of right now, it isn't possible without hacking vim's C code to
change how cindent() and 'indentexpr' work. 'preserveindent' and
'copyindent' are steps in the right direction, but nowhere close to a
working solution.
~Matt
set softtabstop=4
set shiftwidth=4
set tabstop=4
set expandtab
set softtabstop=4
set shiftwidth=4
set tabstop=4
set expandtab
On Mon, Dec 22, 2008 at 1:57 PM, Erik Hahn <erik...@gmx.de> wrote:
I may be missing something, but for the reasons I gave before, I
really don't see how a script can be used to get the requested
behavior unless the script intercepts every keystroke and
re-implements vim's internal formatting and indenting code. How are
you thinking this could be done?
Regards,
Gary
> As far as I know, the format on the 2nd and 3rd lines is not possible
> for Vim to do automatically.
:set copyident
will preserve it once you do it manually.
And I love how many other people are doing this. I always code with
:set list
and I often feel very alone.. ;)
Richard
I'm curious how the distinction between 'indent' and 'alignment' has
been made. I see them as exactly the same thing; as English words, I
mean. It's obvious from the diagram above what is meant, but the purpose
of the 'indent' is to 'align'...
...or am I missing something?
How is the difference between the two instances above best described?
Perhaps 'block indentation' as apposed to 'line-wrapping indentation'?
I wonder if it's getting to the point where vim would have to be a
compiler in order to make these distinctions accurately. Perhaps that's
something that is easier for something like Emacs to do.
I would like to be able to make use of a real compiler in order to do
this kind of code parsing. I'm told that the gcc people, for example,
aren't really interested in doing this.
Max.
The difference is it allows for a variable width display of tabs.
Different people have different preferences for their tab width.
Personally, I prefer 8 columns for a tab, but the guy next door might
like 3. A scheme that has tabs for indents allows for everybody's
preference.
The spaces are particular to the statement. The width of alignment
depends on the previous line of the statement, not on how wide I
prefer my tabs to be.
So it seems like there is no feature available. I guess I'll request
this feature on vim.org.
Thanks guys.
Oliver
On Tue, Dec 23, 2008 at 3:57 PM, Max Waterman <davidmax...@fastmail.co.uk> wrote:How is the difference between the two instances above best described? Perhaps 'block indentation' as apposed to 'line-wrapping indentation'?The difference is it allows for a variable width display of tabs. Different people have different preferences for their tab width. Personally, I prefer 8 columns for a tab, but the guy next door might like 3. A scheme that has tabs for indents allows for everybody's preference.
The spaces are particular to the statement. The width of alignment depends on the previous line of the statement, not on how wide I prefer my tabs to be.
So it seems like there is no feature available. I guess I'll request this feature on vim.org.
Don't. I use ":set list lcs=tab:\|_,eol:¶,nbsp:~" (and, in the light of
another thread, I don't forget to set 'encoding' to UTF-8 first, not
afterwards, if the locale is something else).
Best regards,
Tony.
--
You'd better beat it. You can leave in a taxi. If you can't get a
taxi, you can leave in a huff. If that's too soon, you can leave in a
minute and a huff.
-- Groucho Marx
It's hard for Vim to guess that in
if (a == b &&
c == d &&
e == f)
you want c aligned with a (and not, let's say, one level of indent
further than the "if"). However, as others have repeatedly said, with
":set autoindent copyindent" (and maybe 'preserveindent' but I'm less
sure what it does), when you hit Enter after "c == d &&", the third line
will get the exact same mixture of tabs and spaces as the second one.
Best regards,
Tony.
--
Shit makes the flowers grow and that's beautiful
Unless you're using, say, cindent, or an indentexpr, which give you
absolute control over that sort of thing.
> However, as others have repeatedly said, with
> ":set autoindent copyindent" (and maybe 'preserveindent' but I'm less
> sure what it does), when you hit Enter after "c == d &&", the third line
> will get the exact same mixture of tabs and spaces as the second one.
Which is still a far cry away from properly using tabs for indenting
blocks and spaces for aligning code automatically. Like I said
before, vim just isn't capable of doing the right thing here, and
changing that would require making a way for indentexpr's to specify
"number of spaces of indent" and "number of spaces for alignment"
independently.
~Matt
I think that OP does not satisfy with these plugins. I would really
use language specific pretty print program to do that job. Anyway
division of labour is what *nix meant, perhaps with the exception of
emacs.
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩169 僧皎然 尋陸鴻漸不遇
移家雖帶郭 野徑入桑麻 近種籬邊菊 秋來未著花
扣門無犬吠 欲去問西家 報到山中去 歸來每日斜
I think that OP does not satisfy with these plugins. I would really
In the case of Vim, division of labour means you can customize the
behaviour of Vim, even separately for different filetypes, just by
dropping an appropriate script in the appropriate directory. Anyone can
write the script (not only Bram and not only you), and no need to recompile.
When the internal :vimgrep command was added (shortly after :helpgrep)
to do essentially what the external :!grep already did, I thought it was
progress: maybe it was less division of labour between Vim and an
external grep program, but no need to search the web for grep if you
were on a platform (such as Windows) where it wasn't standard, and the
regular expressions were Vim regular expressions, which are well
documented in the Vim help and are the same as those used in :s or / And
of course (but you won't regard that as an advantage) the
process-calling overhead was totally eliminated.
Best regards,
Tony.
--
"What the hell are you getting so upset about? I thought you
didn't believe in God."
"I don't," she sobbed, bursting violently into tears, "but the
God I don't believe in is a good God, a just God, a merciful God. He's
not the mean and stupid God you make Him out to be."
-- Joseph Heller, "Catch-22"
> On Tue, 23 Dec 2008, Tony Mechelynck wrote:
>> See
>> :help ftplugins
>> :help filetype-plugins
>
> I think that OP does not satisfy with these plugins. I would really
> use language specific pretty print program to do that job.
The GNU "indent" utility seems to be full-featured tool for indenting C
code. So if gg=G does not do what user wants then maybe
:%!indent --preferred-indent-style-and-options
will.
This is verging on the autistic. The main problem with
complicated indentation schemes is getting all programmers
in a group to follow them. Complicated suggestion: write
a (simple) map to insert the correct number of spaces for
you. Simple suggestion: just use two extra levels of
indentation for continuation lines, like many people. --Antony
> Don't. I use ":set list lcs=tab:\|_,eol:¶,nbsp:~" (and, in the light of
> another thread, I don't forget to set 'encoding' to UTF-8 first, not
> afterwards, if the locale is something else).
if &encoding == "utf-8"
set listchars=eol:$,trail:·,tab:»·,extends:>,precedes:<
else
set listchars=eol:$,trail:-,tab:>-,extends:>,precedes:<
endif
That way, I can work on legacy/broken systems, as well.
Richard
> Which is still a far cry away from properly using tabs for indenting
> blocks and spaces for aligning code automatically. Like I said
> before, vim just isn't capable of doing the right thing here, and
> changing that would require making a way for indentexpr's to specify
> "number of spaces of indent" and "number of spaces for alignment"
> independently.
If anyone would write a patch for that, I am sure a lot of people who
use vim_extended would merge that, as well.
Richard
Max Waterman wrote:
> I feel the need to make my tuppence worth...so I'm gonna :
>
> I'm curious how the distinction between 'indent' and 'alignment' has
> been made. I see them as exactly the same thing; as English words, I
> mean. It's obvious from the diagram above what is meant, but the purpose
> of the 'indent' is to 'align'...
>
> ...or am I missing something?
>
> How is the difference between the two instances above best described?
> Perhaps 'block indentation' as apposed to 'line-wrapping indentation'?
>
> I wonder if it's getting to the point where vim would have to be a
> compiler in order to make these distinctions accurately. Perhaps that's
> something that is easier for something like Emacs to do.
>
> I would like to be able to make use of a real compiler in order to do
> this kind of code parsing. I'm told that the gcc people, for example,
> aren't really interested in doing this.
>
> Max.
>
Max,
The difference between indentation and alignment (in English, as you
say), is subtle, but it's there. You alluded to it yourself when you
said, "but the purpose of the 'indent' is to 'align'". "Indentation" is
refers to a line's (or block's) horizontal distance from the margin,
whereas "alignment" refers to its horizontal distance from other
(usually nearby) lines. So you're right that indentation (varying the
distance from the margin) is for the sake of alignment (adjusting the
x-distance from other lines) ... which is exactly why they are not the
same! It's why something is considered "aligned" (well) only when there
is uniformity of indentation, but something can be considered indented
(well) when the indentation varies quite a bit -- such as in code.
Etymologically, "align" is related to "line" -- it means "to line up";
whereas "indent" is related to "dent" -- it means, "to dent inward" (ok,
"indent" is a little more complex than that, but it's a reasonable
synopsis that captures the spirit of it!).
Hope that helps shed some light on it.
-Sir Robert Burbridge
>This is verging on the autistic. The main problem with
>complicated indentation schemes is getting all programmers
>in a group to follow them. Complicated suggestion: write
>a (simple) map to insert the correct number of spaces for
>you. Simple suggestion: just use two extra levels of
>indentation for continuation lines, like many people. --Antony
It's even worse, because people have their own styles, which they take
personally, and will fight you to the end before changing them.
Eg, me personally, and this is just personal preference and not judging
"right" or "wrong", but I'd personally put the joining operators in the
left margin, because the right margin would be too ragged to see what
joins what, especially when mixing ands and ors. So I'd have
if( a == b
&& c == d
&& e == f )
or to mix it up with different conditionals
if( ( ( a == b )
&& ( c == d ) )
|| ( e == f ) )
which is already starting to look rather lispy, but it aligns the
equations and lets you know "up front" (ie, in the left margin) what's
anded and what's ored. And if you were to say it aloud, how would your
inflection describe it? Typically:
*If*
<pause>
ay equalequal bee andand cee equalequal dee
<pause>
*oror* ee equalequal eff
<pause>
*then* ..."
Ie, you wouldn't use the "andand"s and "oror"s at the *end* of the
test-equality clause (vs assignment, where it'd be "equal" vs
"equalequal"), but at the beginning to introduce the clause.
Anyhoo, try getting 'vim' or *any* editor to autogenerate *that*...
You'd have to compile 'vim' with '+lex +yacc'...
In my case, that is not a problem at all - I follow the
established coding standards for any project I'm on, but
I would like to be able to use this indentation scheme for
any project that I write myself. Such projects usually have
few other people touching the code, so the convenience of
having them display properly aligned regardless of the value
of &tabstop that people prefer far outweighs the necessity
of having every committer using the same coding style.
> Complicated suggestion: write
> a (simple) map to insert the correct number of spaces for
> you.
Still wouldn't help for, eg, gg=G. Yes, I realize that
I can code with my preferred style manually. But coding in
*any* coding style manually is more frustrating than it's
worth.
> Simple suggestion: just use two extra levels of
> indentation for continuation lines, like many people.
I'd prefer to use noexpandtab instead. Using two levels of
indentation means that I can't make code line up for
readability, and using spaces instead of tabs means that
other people might think my code is too narrow or too wide
and have no way of automatically fixing it. Right now
I need to err on the side of what looks prettier to me, but
I wish I didn't have to - I'm sure many people think that my
code, with shiftwidth=2, is far too narrow, and if vim
supported using tabs for indent level followed by spaces for
alignment, I wouldn't need to choose between making things
look more readable for me and making things look more
readable for others.
~Matt
The characters I use are all below 0xFF, but the Pilcrow mark (0xB6) is
represented differently in Latin1 and in UTF-8, so I mustn't change
encodings after setting the value. My encoding-handling snippet is near
the top of my vimrc, framed within "if has('multi_byte')" so on
trimmed-down versions (such as my tiny "vi" build) I may remain in
Latin1 and use the same 'listchars'. What I don't understand though, is
that vi displays a hollow box in konsole, a reverse-video question mark
on /dev/tty, while Vim displays the Pilcrow mark in both -- and yet, my
.vimrc has "scriptencoding latin1"... Maybe the terminals don't
understand a Pilcrow mark in Latin1...
OK, let's do it slightly differently -- and remember that vi has no
expression evaluation, so every :if counts as a comment there: it's no
use trying to set values for it in an else-clause.
set list listchars=eol:$
if has('multi_byte')
set listchars=eol:¶
endif
set listchars+=tab:\|_
silent! set listchars+=nbsp:~
...it works: vi now displays a dollar sign, and vim a Pilcrow mark.
Best regards,
Tony.
--
No good deed goes unpunished.
-- Clare Boothe Luce
That is not going to work for someone who insists hard tabs should be
used in source code. Since gnu indent never use hard tabs at all.
For me it works just perfect, since our project forbids use of hard tabs
in source code at all. (Makefile is the only exception, but we use cmake
and we never write Makefile ourselves.)
I think you're still misunderstanding things. One last go at
explaining why this is the Right Way (which won't make much sense
unless you're using a fixed width font): consider a vim set up with
:set list listchars=tab:>- tabstop=8 shiftwidth=8 noexpandtab
Assuming this indent/alignment style is used, you could get code that
looked like this:
int main() {
>-------int returnval = 5; /* This is the value that I will return.
>------- It's nonzero, which means failure. */
>-------return returnval; /* This is where I return it. */
}
Note the nicely aligned comments at the end of the lines. If a person
viewing this code then decided that a tabstop of 8 is too wide, and
wanted to use tabstop=3 for more compact code, all he would need to do
is change tabstop to 3, and he would see this:
int main() {
>--int returnval = 5; /* This is the value that I will return.
>-- It's nonzero, which means failure. */
>--return returnval; /* This is where I return it. */
}
And the comments still line up! The advantage of this indentation
scheme is that changing tabstop will allow changing the width of the
code to fit personal preferences without hurting the alignment of
anything that was lined up. Compare this to what happens with the way
vim works now - let's say someone writes the same chunk of code with
:set ts=8 sw=8 noet:
int main() {
>-------int returnval = 5; /* This is the value that I will return.
>------->------->------- It's nonzero, which means failure. */
>-------return returnval; /* This is where I return it. */
}
Now, when our friend wants to display it with tabstop=3, things don't work out!
int main() {
>--int returnval = 5; /* This is the value that I will return.
>-->-->-- It's nonzero, which means failure. */
>--return returnval; /* This is where I return it. */
}
This is why using tabs for indenting a block, and spaces for aligning
code and comments within that block, is the nicest coding style to
work with. It allows anyone to change the width with which a tab is
displayed and change the width and look of the code, without screwing
up the alignment of comments and code.
~Matt
Let's add something more, okay?
> int main() {
> .-------int returnval = 5; /* This is the value that I will return.
> .------- It's nonzero, which means failure. */
> .-------if (foobar)
> .-------.-------return 0; /* This is where I return it.*/
> .-------else
> .-------.-------return 1; /* This is where I return it.*/
> }
Now we change the tab size to 3:
> int main() {
> .--int returnval = 5; /* This is the value that I will return.
> .-- It's nonzero, which means failure. */
> .--if (foobar)
> .--.--return 0; /* This is where I return it.*/
> .--else
> .--.--return 1; /* This is where I return it.*/
> }
The comment will not get aligned after you changed the tab size. mixed
tab and spaces does not help.
There's *no* way to use a variant tab size and retain a reasonable
output. Fix the tab size to 8 or use only spaces is the ultimate
solution anyway.
On Wed, Dec 24, 2008 at 9:24 PM, Max Waterman wrote:This leads me to think that the person requesting this feature should use tabs and not spaces, and put a tab in the middle of the text to which he wishes to align. <tab>if (<tab>thisIsTrue ) { <tab><tab>DoThis(); } ...or something like that. Of course, the flexibility to do what is asked/wanted would be nice, but I don't consider this particular case as being something that *should* be done because it's *the right way*. On the contrary, IMO, it's more a side case that is *the wrong way* but would be nice to be able to do. Yeah, I'm not afraid to say it's wrong (if that's what I think) ... religious or not :p ... let the flames begin ;)I think you're still misunderstanding things.
If you're saying yourself that that's what you want to do and that it is
the wrong way, who can disagree? Some people will agree that they want
to do it too, others will agree that it's the wrong way. :-)
Makes me think of "creado quia absurdum" ("I believe because it is absurd").
Best regards,
Tony.
--
Real World, The n.:
1. In programming, those institutions at which programming may
be used in the same sentence as FORTRAN, COBOL, RPG, IBM, etc. 2. To
programmers, the location of non-programmers and activities not related
to programming. 3. A universe in which the standard dress is shirt and
tie and in which a person's working hours are defined as 9 to 5. 4.
The location of the status quo. 5. Anywhere outside a university.
"Poor fellow, he's left MIT and gone into the real world." Used
pejoratively by those not in residence there. In conversation, talking
of someone who has entered the real world is not unlike talking about a
deceased person.
On 25/12/08 03:24, Max Waterman wrote: [...]Of course, the flexibility to do what is asked/wanted would be nice, but I don't consider this particular case as being something that *should* be done because it's *the right way*. On the contrary, IMO, it's more a side case that is *the wrong way* but would be nice to be able to do. Yeah, I'm not afraid to say it's wrong (if that's what I think) ... religious or not :p ... let the flames begin ;) Max.If you're saying yourself that that's what you want to do and that it is the wrong way, who can disagree? Some people will agree that they want to do it too, others will agree that it's the wrong way. :-) Makes me think of "creado quia absurdum" ("I believe because it is absurd").
Best regards, Tony.
Fair enough, I should have stipulated that this will only allow
correct alignment on lines with the same indent level - but that, in
and of itself, is more than is available in any other way.
> There's *no* way to use a variant tab size and retain a reasonable
> output. Fix the tab size to 8 or use only spaces is the ultimate
> solution anyway.
Except that still leaves the problem of what to do when Jane wants
more, or fewer, spaces per indent level than John wants.
~Matt
> Teemu Likonen 写道:
>> The GNU "indent" utility seems to be full-featured tool for indenting C
>> code. So if gg=G does not do what user wants then maybe
>>
>> :%!indent --preferred-indent-style-and-options
>>
>> will.
>
> That is not going to work for someone who insists hard tabs should be
> used in source code. Since gnu indent never use hard tabs at all.
I think the definition of "never" can be adjusted with these options:
-nut, --no-tabs
Use spaces instead of tabs.
See INDENTATION.
[...]
-ut, --use-tabs
Use tabs. This is the default.
See INDENTATION.
> The comment will not get aligned after you changed the tab size. mixed
> tab and spaces does not help.
You are cheating by trying to align across several levels of logical nesting.
It's obvious that there is no flexible method of alignment in that situation,
today. You would need a meta-tab or something similar if you wanted
to achieve this in a text interface.
I still maintain that this is not needed in the real world as maintaining
perfect alignment of behind-code comments is not practicable with
more than two or three level of indentation, anyway. _Especially_
with sw=8 which you seem to prefer.
> There's *no* way to use a variant tab size and retain a reasonable
> output. Fix the tab size to 8 or use only spaces is the ultimate
> solution anyway.
You definition of reasonable differs from mine.
The case you constructed serves as justification to force everyone
touching your code to adhere to your rules. Not a nice thing to do
at best, actively harming collaboration at best.
Point in case, the Perl guidelines suggest sw=4 using soft tabs.
What would happen if you edited those files and saved them?
Even if you were not to change any of the existing lines, you
would mess up the file for everyone not using sw=8.
Also, please keep in mind that many people code in Terminals
that are 80 chars wide. Forcing them to use sw=8 is just plain
unfair.
Richard
> It's obvious that there is no flexible method of alignment in that situation,
> today. You would need a meta-tab or something similar if you wanted
> to achieve this in a text interface.
Yes there is one method: use spaces.
> I still maintain that this is not needed in the real world as maintaining
> perfect alignment of behind-code comments is not practicable with
> more than two or three level of indentation, anyway. _Especially_
> with sw=8 which you seem to prefer.
No, I don't say sw=8, I'd say ts=8 and sw=(what ever you want). i.e.
don't rely on hard tab to do indent, tabs are used to create tables, not
indent. Using spaces to do indent isn't the right way either, but in
fixed-width-font world especially in programming, spaces are the most
natural way for indent.
> You definition of reasonable differs from mine.
> The case you constructed serves as justification to force everyone
> touching your code to adhere to your rules. Not a nice thing to do
> at best, actively harming collaboration at best.
If there is collaboration at all, developers need to use the same rule
or the same coding style in the project anyway. At least the same coding
style should be retained within one module. I see this to be a
reasonable rule.
> Point in case, the Perl guidelines suggest sw=4 using soft tabs.
> Forcing them to use sw=8 is just plain unfair.
Again, I'm saying ts=8 and sw=(what ever you want). And that is
*recommended* by official vim documents. If someone claims that spaces
waste more bytes than hard tabs, he can :set noet, which will change all
leading 8 spaces into hard tabs and there isn't too much bytes wasted by
the space character.
>
> Richard
Pan, Shi Zhu
> If there is collaboration at all, developers need to use the same rule
> or the same coding style in the project anyway. At least the same coding
> style should be retained within one module. I see this to be a
> reasonable rule.
And with tabs, people are a lot more flexible.
That as may be, let's agree to disagree.
Richard
But by using hard tabs for indent you're *forcing* a non-standard
tab-size, and you're forcing tab size to be the same as indent size. (In
vim, that means you're forcing ts=sw)
Indent size of 8 is too big for most programmers (except Linus Thorvald
and some kernel hackers), if you use hard tabs for indent you *forced*
that hard tab size should be the same as indent size and those people
viewing your code will have to change the tab size to a smaller value in
order to view your code more comfortably.
If you do not use hard tabs in source code, we can still keep tab size
as the standard 8 and view the code as indent size 4, since 4 spaces
will always be 4 spaces. Keep tab-size as 8 does not mean I want to use
shift-width or indent-size as 8, I use shift-width as 4 and keep
tab-size to 8.
Think considerably what is discouraging collaboration when you *force*
other programmers to change the standard tabsize=8 into 4 just in order
to view your code?
>
>
> Richard
Most text files uses tab-size as 8 and it is very common that a Linux
software source file contains not only C, thus it is heretical not to
keep ts=8. For Makefiles, assemblers, vim help files, and many script
languages of configuration files they have a standard tab-size=8, those
are not legacy code and ts=8 works perfect.
Only in C and C++ world there is a divergence, yes it is easy to change
the tab-size only for C, but if we must set ts=4 in 25% of C codes in
project X and ts=6 in 35% of C codes and ts=8 in the other 40% C codes
of project X things are really in a mess.
> Yes, that is what I'm stating, for programmers who have to read all kind
> of source codes, he will have to change the tab size from time to time
> to read those who uses hard tabs with non-standard size. life would be
> much easier if those sources use only spaces for indent.
Either the file you are editing is broken (in which case your own style
guide would not help you either. Obviously, whoever created and
maintained it did not heed it) or tabs will work perfectly if used as
intended.
No one is stopping you from using a width of 8. The thing we object
to is that you are forcing _everyone else_ to use _your_ style. Sorry
to say so, but this makes you part of the problem the rest of us is
facing.
I am not saying you must change your ways and I sincerely hope
you did not take the above personally. I just do not
understand you or your reasoning.
Richard
Agreed again. And if tabs "messing up" trailing comments is a huge
issue, then don't have trailing comments. Instead of
ptr += sizeof( foo ); // skip past header
use
// skip past header
ptr += sizeof( foo );
and be done with it.
I tend to do that for whole blocks vs individual lines, but hey, if
someone's so traumatised by different tabstops messing up alignment of
comments, the above's an easy fix...
But seriously, if someone uses some weird-ass indentation level like
ts=5 or whatnot, the *first* thing I do after "inheriting" the code is
either play games with ts=## and et/noet and try to get rid of it all
"cleanly", else do a global s&r for spaces and tabify 'em all, then
worry about stragglers and trailing comments later on.
>And with tabs, people are a lot more flexible.
Absolutely. And as for leading indentation, whether tabs or spaces
makes no difference to me, as I convert everything to tabs and ts=8
anyway. >:D
That being said, if I have lots of nesting going on and too many levels
means I start the line halfway across the screen, I'll stick a modeline
at the very end of the file that'll specify ts=4 or even ts=2, depending
how much of a rat's nest it happens to be.
As for hairy alignments to pretty-up an overly long conditional, etc.,
hey, if a few spaces can't preserve the alignment someone wants, then
just indent it to the next tablevel and leave the rest of us alone. I
object to someone "committing" a file to his/her own preferred style via
endless leading spaces with ts=3 or something, just so he/she can have a
nicely-aligned table of conditionals in an if() statement.
It's an *editor*, not a word-processor.