Rewrap text seems to put everything in a single line style when selecting multiple lines

Asked by Didier Roche on 2009-12-31

I tried the format -> Rewrap option on this text:
        for line in fin:
            fields = line.split(' = ') # Separate variable from value
            if fields[0] == '__quickly_data_directory__':
                # update to prefix, store oldvalue
                if not oldvalue:
                    oldvalue = fields[1]
                    line = "%s = '%s'\n" % (fields[0], prefix)
                else: # restore oldvalue
                    line = "%s = %s" % (fields[0], oldvalue)
              # update version if we forget it
            # This is a very long long line, more than 80 characters unfortunately and that's bad... so bad...
            elif fields[0] == '__version__':
                line = "%s = '%s'\n" % (fields[0], VERSION)

You can notice the extra spaces before "# update version if we forget it" and the trailing spaces at the end of the same line. Rewrap should remove them and align the commentary.
Also, the next line (a comment) should be splitted in two comment lines.

* If I select this text and go to "rewrap text", I got this:
        for line in fin: fields = line.split(' = ') # Separate variable from
        value if fields[0] == '__quickly_data_directory__': # update to
        prefix, store oldvalue if not oldvalue: oldvalue = fields[1] line =
        "%s = '%s'\n" % (fields[0], prefix) else: # restore oldvalue line =
        "%s = %s" % (fields[0], oldvalue) # update version if we forget it #
        This is a very long long line, more than 80 caracters infortunately
        and that's bad... so bad... elif fields[0] == '__version__': line =
        "%s = '%s'\n" % (fields[0], VERSION) fout.write(line)

So, ok, nothing is gets more than 80 characters, but I don't think the code will work :)

* Also, if I only select the long comment line, I get:
            # This is a very long long line, more than 80 characters
            unfortunately and that's bad... so bad...
No comment character on the second line

* List and function definition seems to be better treated:
def update_data_path(prefix, oldvalue=None, foo='bar', ti='to',
But if possible, ttttttt should be aligned with prefix for readability

* Last thing (I won't bother you after :)), is that if I don't select the first spaces in a lines, only the selected portion is rewrap at 80 characters, without counting the prepending spaces. I think that the plugin should select the whole line(s) first.

I didn't opened it as a bug, should I?
Thanks again for your work on this project.

0.3.1-0ubuntu0 installed on karmic from your ppa.

Question information

English Edit question
Gedit Developer Plugins Edit question
No assignee Edit question
Solved by:
Curtis Hovey
Last query:
Last reply:
Best Curtis Hovey (sinzui) said : #1

The rewrap text feature is for narrative text, such in emails and doctests. The feature cannot be used with code, sorry.

The Menu > Tools > 'Reformat doctest' uses all the formatting tools to make a doctest consistent, but it may report long code lines after you run it because it does not know how to wrap code. :( I may solve this with newer features in python's textwrap module, but I many users are using older distros without python 2.6.

Didier Roche (didrocks) said : #2

Ok, looking forward to get or to help you extending the feature.

Thanks a lot!

Didier Roche (didrocks) said : #3

Thanks Curtis Hovey, that solved my question.