Common implementation for first_non_empty_prev_line