Cycle spacing

In the comments on my post on deleting whitespace, Vargonaut pointed out the useful function cycle-spacing. This function, when called multiple times, cycles through

  1. replacing all spaces with a single space
  2. removing all spaces
  3. restoring the original spacing

As Vargonaut recommends, it is convenient to bind this to M-SPACE in place of the just-one-space function. Do this with

;; cycle through amounts of spacing
(global-set-key (kbd "M-SPC") 'cycle-spacing)

Here is an animation of this in action