An Emacs minor mode that guesses the indentation offset originally used for creating source code files and transparently adjusts the corresponding settings in Emacs, making it more convenient to edit foreign files.
See dtrt-indent.el
for full documentation, including installation instructions.
vim-sleuth provides similar functionality for Vim.