Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align equation blocks #29

Closed
MRedies opened this issue Sep 5, 2018 · 5 comments
Closed

Align equation blocks #29

MRedies opened this issue Sep 5, 2018 · 5 comments
Labels
enhancement Enhancement to existing feature wontfix

Comments

@MRedies
Copy link

MRedies commented Sep 5, 2018

Often you will have blocks of equations in fortran and this is what fprettify does now:

            rou = ro/2
            rdru = rhdr(i, 1)/2
            rdtu = rhdt(i, 1)/2
            rdfu = rhdf(i, 1)/2
            rdrru = rhdrr(i, 1)/2
            rdttu = rhdtt(i, 1)/2
            rdffu = rhdff(i, 1)/2
            rdtfu = rhdtf(i, 1)/2
            rdrtu = rhdrt(i, 1)/2
            rdrfu = rhdrf(i, 1)/2

            rod = rou
            rdrd = rdru
            rdtd = rdtu
            rdfd = rdfu
            rdrrd = rdrru
            rdttd = rdttu
            rdffd = rdffu
            rdtfd = rdtfu
            rdrtd = rdrtu
            rdrfd = rdrfu

            rdr = rdru + rdrd
            rdt = rdtu + rdtd
            rdf = rdfu + rdfd
            drdr = rdrru + rdrrd
            rdtt = rdttu + rdttd
            rdff = rdffu + rdffd
            rdtf = rdtfu + rdtfd
            rdrt = rdrtu + rdrtd
            rdrf = rdrfu + rdrfd

My editor plugin does something like this:

            rou   = ro/2
            rdru  = rhdr(i,  1)/2
            rdtu  = rhdt(i,  1)/2
            rdfu  = rhdf(i,  1)/2
            rdrru = rhdrr(i, 1)/2
            rdttu = rhdtt(i, 1)/2
            rdffu = rhdff(i, 1)/2
            rdtfu = rhdtf(i, 1)/2
            rdrtu = rhdrt(i, 1)/2
            rdrfu = rhdrf(i, 1)/2

            rod   = rou
            rdrd  = rdru
            rdtd  = rdtu
            rdfd  = rdfu
            rdrrd = rdrru
            rdttd = rdttu
            rdffd = rdffu
            rdtfd = rdtfu
            rdrtd = rdrtu
            rdrfd = rdrfu

            rdr  = rdru  + rdrd
            rdt  = rdtu  + rdtd
            rdf  = rdfu  + rdfd
            drdr = rdrru + rdrrd
            rdtt = rdttu + rdttd
            rdff = rdffu + rdffd
            rdtf = rdtfu + rdtfd
            rdrt = rdrtu + rdrtd
            rdrf = rdrfu + rdrfd

I think this makes it easier to read. Maybe this could be an optional feature.

@pseewald
Copy link
Collaborator

pseewald commented Sep 5, 2018

See my comment in #21 (which is just my opinion). I leave this issue open for discussion, I may reconsider 😉

@pseewald pseewald added enhancement Enhancement to existing feature wontfix labels Sep 5, 2018
@MRedies
Copy link
Author

MRedies commented Sep 5, 2018

I agree that it is subjective. This is why i was thinking it might make sense to do this optionally.

Would this function not work for certain types of code?

@pseewald
Copy link
Collaborator

pseewald commented Sep 5, 2018

The problem is that alignment would depend on the context. Just because two subsequent lines are both of the form a=b+c does not mean that they are related in any way... An option to always align lines containing the same operators will lead to strange formatting. So I just think this can't be done in an easy and general way.

However fprettify could respect vertical alignment by not overriding two or more consecutive spaces. Then manual alignment would be possible. By the way, I noticed this was already discussed in #12.

@MRedies
Copy link
Author

MRedies commented Sep 5, 2018

I think this

However fprettify could respect vertical alignment by not overriding two or more consecutive spaces.

Would probably be enough in most cases

@pseewald
Copy link
Collaborator

pseewald commented Sep 5, 2018

Ok so this is now definitely on my todo list and I opened a new issue #31 specifically for this feature.

@pseewald pseewald closed this as completed Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to existing feature wontfix
Projects
None yet
Development

No branches or pull requests

2 participants