What the .emacs.d!?

Uneven application of white-space is bad, m'kay?

(defun cleanup-buffer-safe ()
  "Perform a bunch of safe operations on the whitespace content of a buffer.
Does not indent buffer, because it is used for a before-save-hook, and that
might be bad."
  (untabify (point-min) (point-max))
  (set-buffer-file-coding-system 'utf-8))

;; Various superfluous white-space. Just say no.
(add-hook 'before-save-hook 'cleanup-buffer-safe)

(defun cleanup-buffer ()
  "Perform a bunch of operations on the whitespace content of a buffer.
Including indent-buffer, which should not be called automatically on save."
  (indent-region (point-min) (point-max)))

(global-set-key (kbd "C-c n") 'cleanup-buffer)

I use these two literally all the time. The first one removes trailing whitespace and replaces all tabs with spaces before save.

The last one I've got on a key - it also indents the entire buffer.

These might not be for everybody. Sometimes you do want tabs (I'm looking at you Makefile grrrrr). Then this isn't optimal. The same can be said for when Emacs doesn't indent correctly. But that is a horrid, unacceptable situation in any case. I always fix those as soon as I can.

blog comments powered by Disqus