In 40d, it worked like this:
1) decide on square to dig:
A) if a designated square is adjacent to the one you just finished, choose that one (random is several to choose from)
B) else, top most "block" with a designated square ("blocks" are large areas... smaller than embark squares, I think, but still quite large)
C) choose farthest left designated square in block - if several in the same column, choose top-most square
D) I don't know how that works by z-levels, but they seem to prefer lowest z-level first in many cases
2) after choosing square to dig, dig it from an adjacent square, with this order of preference:
A) left
B) right
C) up
D) down
E) up-left
F) up-right
G) down-left
H) down-right
I) from a different z-level (by ramp)
It doesn't matter if the miner is ALREADY adjacent to the square he is supposed to dig, if he can reach the square to the LEFT of the dig-square, he will go there to dig it, NO MATTER HOW FAR IT IS. Yeah, it's really annoying sometimes. Notice that the second choice (#2, above) does NOT take into account how far any of those squares are from current location.
As best I can tell, that's the preference order for pretty much everything (which is why it's so easy for masons to build themselves into a wall).
As also mentioned above, you can use these rules to get them to do what you want (or at least pretty close) - designate 1-square dig-paths, they will follow them (until they come to a corner, dig diagonal first, then get the one in the corner, and go "start over" with step 1, above - note that step 1 ALSO doesn't take distance from current location into account).