Wednesday, December 15, 2010

One key to delete whitespace

I was inspired by the functionality of C-l (recenter-top-bottom) and made a sequential combination of just-one-space (normally M-SPC), delete-blank-lines (C-x C-o) and join-line:

;; I recommend (global-set-key (kbd "S-SPC") 'ph/delete-whitespace)

(defvar ph/delete-whitespace-counter 0)

(defvar ph/delete-whitespace-counter 0)
(defun ph/delete-whitespace (arg)
(interactive "*p")
(if (eq this-command last-command)
(progn
(incf ph/delete-whitespace-counter)
(if (= ph/delete-whitespace-counter 1)
(delete-blank-lines)
(join-line arg)))
(setq ph/delete-whitespace-counter 0)
(just-one-space arg)))


What other idempotent commands which deserve their own combination like this?