Multiple-Key Sorting

CJam, 13 bytes

{W%{{X=}$}fX}

An unnamed block which expects the list of lists and the list of priorities on top of the stack and replaces them with the sorted list of lists.

Try it online! (As a test suite.)

Explanation

Sorting with tie breakers can be implemented by repeatedly sorting the entire list stably going from the lowest-priority key to the highest-priority key.

W%      e# Reverse priority list.
{       e# For each priority X...
  {     e#   Sort the lists by the result of this block...
    X=  e#     Extract the Xth element from the current list.
  }$
}fX

Jelly, 4 bytes

⁴ị$Þ

Try it online!


Mathematica, 22 19 bytes

SortBy[Extract/@#]&

Uses 1-based indices. This unnamed function is curried, so the calling convention is:

SortBy[Extract/@#]&[{2, 1, 3}][{{5, 3, 4}, {6, 2, 1}, {5, 2, 1}}]

Mathematica's SortBy can take a list of functions in which case the individual functions are used as successive tie-breakers, so that's just what we want. All we need to do is create a list of functions which return the corresponding list element. This can be done with Extract. Extract is normally a binary function Extract[list, index] which returns a list element. However if used unarily, then Extract[index] returns a function which retrieves the element at index from a list passed to it. In other words, the index parameter of Extract can be curried. We make use of this by mapping Extract over the list of indices we're given, which creates the list of functions we need.