It is described in Michael Friendly's American Statistician paper on corrgrams, Preprint PDF here. See section on correlation ordering. Also of potential interest, a presentation by Leland Wilkinson on other potential ways to order heatmaps. Also if you look at the source of the corrgram library you will see some other potential ways to order the data as well.
To describe what the code is doing in a nut-shell, the variables in the correlation matrix are ordered according to the correlation with the first principle component extracted from that same correlation matrix. If you look at the Eigenvector plot in the Friendly paper, the code atan(e2/e1) is the angle of the eigen-vector associated with a particular variable against the first principle component (the horizontal axis). Apparently this approximates the correlation (although to be honest I have not walked myself through the necessary math to convince myself of such an approximation!)
Again the reason for the ordering is given in the Friendly paper, but we almost always want more similar things next to more similar things (in either graphics or tables). Frequently the ordering is more informative than the numbers or the graph! Here in this example more similar is defined by correlation to the first principle component.
Also note I assume the first if statement in the code prevents this ordering from occurring if the correlation matrix is not full rank.