Use #flat_map to shorten a long line.
Re-order methods to preserve dependency order.
Wrap long line.
Fix escaping on multiple spaces.

This uses a regular expression look ahead to avoid escaping a space at the
end of the completion. The final space is there to separate this argument
from the next argument, it's not part of the argument itself.