[OT] CVS diff: hard vs. soft tabs
hey all, this is kind of off-topic, but i figured this is the community most likley to have dealt with this sort of thing in the past, and be opinionated about it. i've been editing a lot of code over the past few months that was originally saved to disk with hard tabs for indenting. i can't work with hard tabs, and so managed to reformat the entire thing to use spaces (basically a s,^I, , iirc) before i began my massive overhaul of this file. now it's time to check it into CVS. i don't want every single line to show up as different just because of tab characters, so i need to find a good solution on how to transform my indents back into tab characters. clearly the reverse -- s, ,^I, -- won't just work, as there are places where two spaces exist that i wouldn't want a tab. is there some way to open the file in emacs (in which i assumer it was originally written; i use vim) and run it through a re-indentder with hard tabs on? or could i do this in vim? suggestions opinions welcome. thanks a lot, /nori -- .~. nori @ sccs.swarthmore.edu /V\ http://www.sccs.swarthmore.edu/~nori/jnl/ // \\ @ maenad.net /( )\ www.maenad.net ^`~'^ get my (*new*) key here: http://www.maenad.net/geek/gpg/7ede5499.asc (please *remove* old key 11e031f1!) pgp0.pgp Description: PGP signature
Re: [OT] CVS diff: hard vs. soft tabs
Nori Heikkinen wrote: hey all, this is kind of off-topic, but i figured this is the community most likley to have dealt with this sort of thing in the past, and be opinionated about it. i've been editing a lot of code over the past few months that was originally saved to disk with hard tabs for indenting. i can't work with hard tabs, and so managed to reformat the entire thing to use spaces (basically a s,^I, , iirc) before i began my massive overhaul of this file. now it's time to check it into CVS. i don't want every single line to show up as different just because of tab characters, so i need to find a good solution on how to transform my indents back into tab characters. clearly the reverse -- s, ,^I, -- won't just work, as there are places where two spaces exist that i wouldn't want a tab. is there some way to open the file in emacs (in which i assumer it was originally written; i use vim) and run it through a re-indentder with hard tabs on? or could i do this in vim? suggestions opinions welcome. thanks a lot, /nori You could probably write a quick script that will eliminate all leading spaces on every line. Once that is done, just run it through indent. man indent shows that there are tons options that will let you tune the look of your source file. HTH, -Roberto pgp0.pgp Description: PGP signature
Re: [OT] CVS diff: hard vs. soft tabs
Nori Heikkinen wrote: hey all, this is kind of off-topic, but i figured this is the community most likley to have dealt with this sort of thing in the past, and be opinionated about it. i've been editing a lot of code over the past few months that was originally saved to disk with hard tabs for indenting. i can't work with hard tabs, and so managed to reformat the entire thing to use spaces (basically a s,^I, , iirc) before i began my massive overhaul of this file. now it's time to check it into CVS. i don't want every single line to show up as different just because of tab characters, so i need to find a good solution on how to transform my indents back into tab characters. clearly the reverse -- s, ,^I, -- won't just work, as there are places where two spaces exist that i wouldn't want a tab. is there some way to open the file in emacs (in which i assumer it was originally written; i use vim) and run it through a re-indentder with hard tabs on? or could i do this in vim? suggestions opinions welcome. thanks a lot, /nori I've done this with mixed results. In general if you're going to work on projects, its a good idea to come up with your format conventions first. :) However, sometimes you just inherit code and really there isnt much you can do about it. Its right up there with cuddled elses, some people do it, others dont. CVS is going to have huge deltas due to indent formatting. If I'm going to change the format of the code, I will usually commit ONLY format changes with a comment to that effect, then commit code changes. It makes it easier to see what was actually changed that way. When you do huge reformats, you're going to wind up in merge hell if you have lots of developers or multiple branches of the code. It'll be difficult to tell what actually changed, vs what was merely moved around. For things like indenting, etc, you could always adjust what you have your tabstop set to. -- Mental ([EMAIL PROTECTED]) The Torah... The Gospels... The Koran... Each claimed as the infallible word of GOD. Misquoted, misinterpreted, misunderstood, and misapplied. Maybe that's why he doesn't do any more interviews. - sinfest.net CARPE NOCTEM, QUAM MINIMUM CREDULA POSTERO. GPG public key: http://www.neverlight.com/pas/Mental.asc pgp0.pgp Description: PGP signature
Re: [OT] CVS diff: hard vs. soft tabs
On Fri, Oct 10, 2003 at 09:48:34AM -0400, Nori Heikkinen wrote: i've been editing a lot of code over the past few months that was originally saved to disk with hard tabs for indenting. i can't work with hard tabs, and so managed to reformat the entire thing to use spaces (basically a s,^I, , iirc) before i began my massive overhaul of this file. now it's time to check it into CVS. i don't want every single line to show up as different just because of tab characters, so i need to find a good solution on how to transform my indents back into tab characters. clearly the reverse -- s, ,^I, -- won't just work, as there are places where two spaces exist that i wouldn't want a tab. is there some way to open the file in emacs (in which i assumer it was originally written; i use vim) and run it through a re-indentder with hard tabs on? or could i do this in vim? Perhaps you could set up vim's C indenting to produce the results you want naturally, then run the whole thing through '='? You could also use the 'indent' program, which has an insane range of options so can probably reproduce most reasonable and unreasonable styles. Cheers, -- Colin Watson [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: [OT] CVS diff: hard vs. soft tabs
on Fri, 10 Oct 2003 11:44:14AM -0400, Roberto Sanchez insinuated: Nori Heikkinen wrote: [...] now it's time to check it into CVS. i don't want every single line to show up as different just because of tab characters, so i need to find a good solution on how to transform my indents back into tab characters. clearly the reverse -- s, ,^I, -- won't just work, as there are places where two spaces exist that i wouldn't want a tab. is there some way to open the file in emacs (in which i assumer it was originally written; i use vim) and run it through a re-indentder with hard tabs on? or could i do this in vim? You could probably write a quick script that will eliminate all leading spaces on every line. Once that is done, just run it through indent. wow, that's a neat program! but (a) this is Java code; and (b) indent looks like it has so many tweakable options that to find every single preference the original coder used would take way too much reformatting, checking in, diffing ... i'd just like to turn whitespace into tabs here, without having my code completely re-formatted. if that's possible. thanks, /nori -- .~. nori @ sccs.swarthmore.edu /V\ http://www.sccs.swarthmore.edu/~nori/jnl/ // \\ @ maenad.net /( )\ www.maenad.net ^`~'^ get my (*new*) key here: http://www.maenad.net/geek/gpg/7ede5499.asc (please *remove* old key 11e031f1!) pgp0.pgp Description: PGP signature
Re: [OT] CVS diff: hard vs. soft tabs
on Fri, 10 Oct 2003 12:06:07PM -0400, Mental Patient insinuated: Nori Heikkinen wrote: [...] now it's time to check it into CVS. i don't want every single line to show up as different just because of tab characters, so i need to find a good solution on how to transform my indents back into tab characters. clearly the reverse -- s, ,^I, -- won't just work, as there are places where two spaces exist that i wouldn't want a tab. is there some way to open the file in emacs (in which i assumer it was originally written; i use vim) and run it through a re-indentder with hard tabs on? or could i do this in vim? I've done this with mixed results. In general if you're going to work on projects, its a good idea to come up with your format conventions first. :) right, that would have been nice ... but, as you say, i just inherited this one. not much i could have done about setting conventions first. For things like indenting, etc, you could always adjust what you have your tabstop set to. what i have my tabstop set to doesn't matter -- that's how my editor interprets hard tabs on disk. what i have is _no_ hard tabs on disk, and i want to put them there. that's more complex, right? /nori -- .~. nori @ sccs.swarthmore.edu /V\ http://www.sccs.swarthmore.edu/~nori/jnl/ // \\ @ maenad.net /( )\ www.maenad.net ^`~'^ get my (*new*) key here: http://www.maenad.net/geek/gpg/7ede5499.asc (please *remove* old key 11e031f1!) pgp0.pgp Description: PGP signature
Re: [OT] CVS diff: hard vs. soft tabs
On Fri, Oct 10, 2003 at 09:48:34AM -0400, Nori Heikkinen wrote: | hey all, | | this is kind of off-topic, but i figured this is the community most | likley to have dealt with this sort of thing in the past, and be | opinionated about it. | | i've been editing a lot of code over the past few months that was | originally saved to disk with hard tabs for indenting. i can't work | with hard tabs, and so managed to reformat the entire thing to use | spaces (basically a s,^I, , iirc) before i began my massive | overhaul of this file. Read :help retab. It is so much nicer :-). | now it's time to check it into CVS. i don't want every single line to | show up as different just because of tab characters, so i need to find | a good solution on how to transform my indents back into tab | characters. clearly the reverse -- s, ,^I, -- won't just work, as | there are places where two spaces exist that i wouldn't want a tab. :set noet sts=2 sw=2 ts=2 :retab! | is there some way to open the file in emacs (in which i assumer it was | originally written; i use vim) and run it through a re-indentder with | hard tabs on? or could i do this in vim? You can do everything you need to in vim. | suggestions opinions welcome. thanks a lot, I would either revert the source back to the original formatting and commit that, or make a commit on just the format changes. Key settings in vim you should familiarize yourself with are : expandtab (et) shiftwidth (sw) softtabstop (sts) tabstop (ts) and also familiarize yourself with the retab command. My style/rule/preference is: tabs are always 8 spaces (ts=8) except for the moments you need to change the setting so that :retab creates the proper indentation levels (then revert back to ts=8) use shiftwidth and softtabstop to control indentation levels. I like a 4-space indentation, so I use sw=4 and sts=4. never use tabs (:set et) The retab command converts the indentation between tabs and spaces and does so according to how et, sw, sts, and ts are set. The details are in the manual (:help). -D -- One man gives freely, yet gains even more; another withholds unduly, but comes to poverty. Proverbs 11:24 http://dman13.dyndns.org/~dman/ pgp0.pgp Description: PGP signature
Re: [OT] CVS diff: hard vs. soft tabs
Mental Patient wrote: I've done this with mixed results. In general if you're going to work on projects, its a good idea to come up with your format conventions first. :) However, sometimes you just inherit code and really there isnt much you can do about it. Its right up there with cuddled elses, some people do it, others dont. CVS is going to have huge deltas due to indent formatting. If I'm going to change the format of the code, I will usually commit ONLY format changes with a comment to that effect, then commit code changes. It makes it easier to see what was actually changed that way. When you do huge reformats, you're going to wind up in merge hell if you have lots of developers or multiple branches of the code. It'll be difficult to tell what actually changed, vs what was merely moved around. For things like indenting, etc, you could always adjust what you have your tabstop set to. Another way is to *always* run your source files (and have your colleagues do the same) through indent before committing changes. Of course, everyone needs to use the same options. This ensures consistent formatting, regardless of the individual text editors in use. -Roberto pgp0.pgp Description: PGP signature
Re: [OT] CVS diff: hard vs. soft tabs
Nori Heikkinen wrote: right, that would have been nice ... but, as you say, i just inherited this one. not much i could have done about setting conventions first. For things like indenting, etc, you could always adjust what you have your tabstop set to. what i have my tabstop set to doesn't matter -- that's how my editor interprets hard tabs on disk. what i have is _no_ hard tabs on disk, and i want to put them there. that's more complex, right? Indeed it is. What you're essentially saying is along the lines of I've made sweeping format changes to the code before working on it, and now I only want to commit the actual code changes. How do I do that?, right? I'm not sure how well this would work, but you could try something like this: Checkout the original, unaltered file you started with. Do a diff -uNrw originalfile newfile changes.diff patch -p0 changes.diff This should (I've only done some basic, rudimentary tests) only change the orignial file in the way that you want. In other words, the original file should be formated in its original state, but your new code should now be in it. Please make backups/check the output. Keep in mind that you may want to go back and reformat your bits of code so that the styles match, but this should get you most of the way there. My general rule of thumb is that unless I'm taking over the code for an extended period, I simply preserve the style it is written in. Its easier to deal with that way, especially if you know you're either not going to work on it again, or infrequently. -- Mental ([EMAIL PROTECTED]) The Torah... The Gospels... The Koran... Each claimed as the infallible word of GOD. Misquoted, misinterpreted, misunderstood, and misapplied. Maybe that's why he doesn't do any more interviews. - sinfest.net CARPE NOCTEM, QUAM MINIMUM CREDULA POSTERO. GPG public key: http://www.neverlight.com/pas/Mental.asc pgp0.pgp Description: PGP signature
Re: [OT] CVS diff: hard vs. soft tabs
Nori Heikkinen [EMAIL PROTECTED] writes: now it's time to check it into CVS. Here's what I do in similar situations. Do a diff between your work file and the latest in CVS with diff -cb (or diff -ub, according to preference). The -b ignores changes in whitespace. Then get a fresh copy of the file from CVS, apply the patch with patch -l. Then fix up whatever lines are left that aren't indented right. The lines you added will need fixing, the lines you modified shouldn't. Diff also has a switch -E which is supposed to ignore tab expansion, but since you converted tabs to two spaces, I don't know how well it will work. -- Alan Shutko [EMAIL PROTECTED] - I am the rocks. EEG: Electroencephalogram, EKG: Electrocardiogram, EGG: Breakfast food -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: [OT] CVS diff: hard vs. soft tabs
On Fri, Oct 10, 2003 at 09:48:34AM -0400, Nori Heikkinen wrote: is there some way to open the file in emacs (in which i assumer it was originally written; i use vim) and run it through a re-indentder with hard tabs on? or could i do this in vim? In case this was not mentioned... Also for your tool box: : info expand info unexpand -- Bill Moseley [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: [OT] CVS diff: hard vs. soft tabs
On Fri, 2003-10-10 at 11:28, Nori Heikkinen wrote: on Fri, 10 Oct 2003 12:06:07PM -0400, Mental Patient insinuated: Nori Heikkinen wrote: [...] now it's time to check it into CVS. i don't want every single line to show up as different just because of tab characters, so i need to find a good solution on how to transform my indents back into tab characters. clearly the reverse -- s, ,^I, -- won't just work, as there are places where two spaces exist that i wouldn't want a tab. is there some way to open the file in emacs (in which i assumer it was originally written; i use vim) and run it through a re-indentder with hard tabs on? or could i do this in vim? I've done this with mixed results. In general if you're going to work on projects, its a good idea to come up with your format conventions first. :) right, that would have been nice ... but, as you say, i just inherited this one. not much i could have done about setting conventions first. For things like indenting, etc, you could always adjust what you have your tabstop set to. what i have my tabstop set to doesn't matter -- that's how my editor interprets hard tabs on disk. what i have is _no_ hard tabs on disk, and i want to put them there. that's more complex, right? /nori Assuming that all of your indentation is at the beginning of a line, (I can't think where else it would be, but had to mention it just in case), you can just use a relatively simple regexp to do it for you. Using Perl, I'd do: #!/usr/bin/perl open (INFILE, $ARGV[0]); open (OUTFILE, $ARGV[1]); foreach (INFILE) { $_ =~ s/^ {2}/\t/; while ($_ =~ /^\t {2}/) { $_ =~ s/\t {2}/\t\t/; } print OUTFILE $_; } close INFILE; close OUTFILE; -- Alex Malinovich Support Free Software, delete your Windows partition TODAY! Encrypted mail preferred. You can get my public key from any of the pgp.net keyservers. Key ID: A6D24837 signature.asc Description: This is a digitally signed message part
Re: [OT] CVS diff: hard vs. soft tabs
dman, you rock as usual. on Fri, 10 Oct 2003 12:33:17PM -0400, Derrick 'dman' Hudson insinuated: On Fri, Oct 10, 2003 at 09:48:34AM -0400, Nori Heikkinen wrote: | hey all, | | this is kind of off-topic, but i figured this is the community most | likley to have dealt with this sort of thing in the past, and be | opinionated about it. | | i've been editing a lot of code over the past few months that was | originally saved to disk with hard tabs for indenting. i can't work | with hard tabs, and so managed to reformat the entire thing to use | spaces (basically a s,^I, , iirc) before i began my massive | overhaul of this file. Read :help retab. It is so much nicer :-). i just did -- and should have to begin with. awesome. | now it's time to check it into CVS. i don't want every single line to | show up as different just because of tab characters, so i need to find | a good solution on how to transform my indents back into tab | characters. clearly the reverse -- s, ,^I, -- won't just work, as | there are places where two spaces exist that i wouldn't want a tab. :set noet sts=2 sw=2 ts=2 :retab! oh, so that's what the ! is about at the end of retab ... very cool, and exactly what i was asking for. turns out my original file wasn't quite in the format i thought it was, but knowing these tricks, i was able to reformat and re-check-in the original before committing the changes. very clean. thanks a lot to all who responded! /nori -- .~. nori @ sccs.swarthmore.edu /V\ http://www.sccs.swarthmore.edu/~nori/jnl/ // \\ @ maenad.net /( )\ www.maenad.net ^`~'^ get my (*new*) key here: http://www.maenad.net/geek/gpg/7ede5499.asc (please *remove* old key 11e031f1!) pgp0.pgp Description: PGP signature
Re: [OT] CVS diff: hard vs. soft tabs
On Fri, 10 Oct 2003 at 16:26 GMT, Nori Heikkinen penned: but (a) this is Java code; and (b) indent looks like it has so many tweakable options that to find every single preference the original coder used would take way too much reformatting, checking in, diffing =2E.. i'd just like to turn whitespace into tabs here, without having my code completely re-formatted. if that's possible. If you don't mind spending some cash, I've used jindent before with good results. There's also a free trial version, though it's slightly crippled. http://www.jindent.com/ -- monique Unless you need to share ultra-sensitive super-spy stuff with me, please don't email me directly. I will most likely see your post before I read your mail, anyway. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: [OT] CVS diff: hard vs. soft tabs
On Fri, 10 Oct 2003 at 16:40 GMT, Roberto Sanchez penned: Another way is to *always* run your source files (and have your colleagues do the same) through indent before committing changes. Of course, everyone needs to use the same options. This ensures consistent formatting, regardless of the individual text editors in use. -Roberto I believe there's a way to use cvs wrapper scripts (may have terminology wrong) to automatically run an indent program on checkin. Probably a bad idea for, say, python or make files, but maybe okay for non-whitespace-dependent languages. -- monique Unless you need to share ultra-sensitive super-spy stuff with me, please don't email me directly. I will most likely see your post before I read your mail, anyway. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]