mustardamus / line-length-break

Atom Editor Package - breaks all lines that go over the preferred line length
https://atom.io/packages/line-length-break
MIT License
1 stars 1 forks source link

Programming language adjustments (with correct intending) #9

Open rugk opened 8 years ago

rugk commented 8 years ago

It would be nice if the package can adjust the broken lines a bit to work in some programming languages, especially automatically indenting it correctly.

So for example take this Python example:

if True:
    str = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa very long variable'

This package converts it to:

if True:
    str = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa very long
variable'

This has two issues:

So in this example this would be correct:

if True:
    str = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa very long\
    variable'

Possibly even:

if True:
    str = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa very long\
           variable'

In other languages especially this example would possibly be more difficult as you may not break a string on multiple lines. In some languages you have to end the string and concatenate it with another string on the next line.

For what it's worth this is even a good idea in Phyton, because otherwise you would include spaces when you intend it like I said. So basically the best way would be this one:

if True:
    str = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa very' + \
    ' long variable'

Especially pay attention to the thing that you may not omit spaces if you're breaking strings, because this would not be suitable in most cases.