Temporal and spatial design of x-ray pulses based on free-electron–crystal interaction