M-x all-things-emacs

Indent Whole Buffer

January 17th, 2007 by Rob Christie · 1 Comment

I use this function almost daily. Why? Well, it’s because too many developers use editors that muck the alignment of the source.

1
2
3
4
5
6
(defun iwb ()
  "indent whole buffer"
  (interactive)
  (delete-trailing-whitespace)
  (indent-region (point-min) (point-max) nil)
  (untabify (point-min) (point-max)))

Open a file, M-x iwb, save, commit, and edit happily.

I can’t take credit for it, but it seems like it should be passed along. I think I originally copied it from another co-worker’s .emacs file when I started using emacs.

Tags: elisp · tips

1 response so far ↓

  • 1 Jake // Nov 15, 2007 at 10:33 pm

    that’s cool.
    i’ve tried to write one,but with no luck.

    and here you iwb() is.

    thanks~

Leave a Comment