question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to align multiple assignments

See original GitHub issue

Often the following convention is used:

a   = 1
bb  = 2
ccc = 3

whilst this is against pep8, it seems like this would be a nice option to support for those people that are (forced??) to use this convention.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:35
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
kamahencommented, Apr 26, 2020

“After 5 years, this is still an open issue…” – yapf is Open Source, and no doubt a contribution would be accepted.

5reactions
rwarrencommented, May 6, 2019

In case this does ever get worked on (even if by me), I’ll add some more notes…

It would be nice to go further and preserve alignment for more than just equals signs. Maybe an option along the lines of this:

PRESERVE_VERTICALLY_ALIGNED_SYMBOLS = true

When enabled, yapf could try and detect and preserve alignments such as this:

len1 = (foo                + 12) - somevar
len2 = (longer_var         + 19) - x
l3   = (an_even_longer_var + 19) - x
l3   = (yyy                +  4) - a_really_long_var_name_that_is_right_here

However, this could get confusing/complex if different symbols are used (+ vs -), or with commented lines (which I think should be ignored in a contiguous line block), or alternative object constructs…

len1 = (foo                + 12) - somevar
#len2 = (longer_var         + 19) - x
l3   = (an_even_longer_var + 19) - x
l3   = ((yyy + 9)          +  4) + a_really_long_var_name_that_is_right_here

My opinion on that example block is that it would still be be untouched with the alignment feature enabled. Reasons being: A) the commented line should be ignored from an alignment perspective (could be a pure comment); B) the the + and - could be recognized as symbols for alignment, and; C) the nested (yyy + 9) doesn’t have symbols that consistently align across the block so aren’t part of any alignment consideration.

Additional notes/ideas:

  • There are many potential symbols/tokens to align on…
    • All operators for sure.
    • Most of the assignment delimiters, too. i.e. =, +=, |=, >>=, etc… but not delimiters used for literal definitions (all bracket forms, :, ., etc)
  • line width changing such as converting (x+1) to (x + 1) would alter alignment, so any alignment detection (and any stashing of in-line alignment positions) would have to be determined in advance.
  • Starting with simple alignment of = would be great, with possible expansion to aligning other tokens left as a future option/pipe-dream.
  • # yapf: enable/disable works well enough for now
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to align several assignments in vim - Stack Overflow
I use Align and I think it does the job: Whole file: :Align = Visual line: <leader>t= or :'<,'>Align = (i.e. : from...
Read more >
Align or arrange objects - Microsoft Support
Align multiple objects. Select the objects you want to align. Click the first object, and then press and hold Ctrl while you click...
Read more >
3 Tips to Increase Alignment when Managing Multiple Projects
Are you having alignment and visibility troubles in your multi-project paradise? Read about 3 common mistakes project managers do and how to ...
Read more >
Align Your Code With Align Assignments Visual Studio ...
To align assignment select all the lines which you want to align and press Ctrl+Alt+] and all the assignment will be aligned properly...
Read more >
Code Style: Align Consecutive Assignments?
At the bottom of this article, you see the feature "Align Consecutive Assignments". I'd like to do the same in AppCode, but I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found