I have a very simple thing I want to do in Emacs. I want to set it so that when I press the TAB key, it inserts two spaces. Just this. It's all I ask. I have tried doing this for a couple of years now, and there's just no way to do it. In every file type it blows up in a different way. HTML file? Random choice between getting four spaces or tabbing to previous line indent. Python file? Just four spaces and I'll ignore any setting you have. It also randomly seems to stop working depending on the phase of the moon when it was previously working.In my .emacs:(setq indent-tabs-mode nil)(setq tab-width 2)This should work, right? No. No it doesn't. It seems emacs has a magical fairy file mode for each extension that completely overrides what I tell it. So do I have to find this magical fairy configuration and override it for each file type? What can I do to get this simple thing to work. Halp.
Set tab indent in Emacs
emacs
Each language has its own indentation convention, so it's not very useful to have the same effect from the easily-accessible Tab key all the time. That's why many major modes override the key's binding.To override the setting for a particular mode, bind it in its keymap.(defun insert-two-spaces (&optional count)  (interactive *p)  (insert (make-string (* 2 count) ?\ )))(add-hook 'python-mode-hook '(local-set-key \t 'insert-two-spaces))To override the setting everywhere, you can define an always-on minor mode. See the Elisp manual for how to define a minor mode.(define-minor-mode magnus-minor-mode  Override the binding of the TAB key.  :keymap '(([?\t] . insert-two-spaces))  :global t)(magnus-minor-mode 1)  What you call magical fairy file mode is a major mode. If you don't like an editor that does things automatically, I suggest nano.  