Accidentally 'reflowed', how to undo long-line breaks?
Asked Answered
H

1

7

Has anyone got any tricks for undoing long-line wrapping?

I've got a big chunk of code that has been reflowed to 120 columns and it's a minefield to debug effectively.

Edit0: I didn't do the reflow and the guy I'm collaborating with... doesn't get CVSs...

EDIT1: Example Yes most of them are 'appropriately' indented.

Hyatt answered 10/2, 2014 at 10:42 Comment(13)
undo in your editor? Or restore a older version from your CVS (which you are using, right?) :-)Cornish
No, there is no trick to apply here, this'll be a manual job. Indentation cannot be recovered from this, for example. Better hope you use a VCS and you can roll back to a previous revision.Manipulator
Usually line-wrapping is not permanent, it's just a visual representation? If you've actually cropped the width of the text, you're out of luck i think. If it's a mine-field to do manually it would be incredibly difficult for an application to do the job better than you. The only way to speed up the process is if you can define the syntax, count the length of the row+the last word and see if a chunk from the next following row togeather with the last "word" on the privous row matches up to a known word in your syntax definition.Hamer
Man, I feel your pain. Not much I can do to help. Have an upvote.Nora
@TimPietzcker I appreciate the sympathy; it's either deal with this bananas, cross indexed python or go back to the 4800 odd lines of Matlab...Hyatt
That example does not look that bad... so was this some smart, python-sensitive line wrapping, and you just don't like the style? Or is this the code before the wrap? The lines are longer than 80 characters.Meadowlark
@Meadowlark the issue is that some of these 'lines' are 6-10 lines deep and simliar lines aren't always similarly indented so when you're trying to port numerically sensitive code, I need to be able to see the full expression to work out weather it makes sense in Python or not. TL;DR I'm doing a fixer-upper on half-ported MatLab code that was abandoned a while ago. Probably by a smart man, however he didn't use CVS either.Hyatt
Oh, and @tobias_k, I meant to say 120, but force of habit.Hyatt
@Hyatt Now I'm confused: The second line (including the indent) is still longer than 120 columns, but the line that was wrapped wasn't.Meadowlark
@Meadowlark I suspect it's some content aware reflow that decides that arithmetic operations can sometimes be preserved if the only go X% over the line. I didn't reflow it, I've got no idea what's been done to the poor thing.Hyatt
How about a script: If line n+1 is indented more than 4 spaces / 1 tab more than line n, merge the lines? Or did you look for "python reflower tools", and use one of them to fix it? Could be worth a try.Meadowlark
I don't guarantee this will solve your issue, but check this out - [#2913824 [1]: #2913824Ahders
If you still have the original matlab file, and the guy did the translation more or less one to one, it should be reasonably easy to figure out the indentation level. But this will be handwork, I am afraid.Sojourn
P
1

Perhaps an automated script/tool like https://github.com/spulec/pep8ify will be able to handle pushing the format back to 80 columns

Pagurian answered 22/2, 2014 at 0:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.