I thought I had this set fine, however now occasionally emacs will go and insert an 8 character tab, or a 6 or 5 character tab....
Maybe this is caused by the document (this has occurred in a large text file which contains many different tab spacings, though mostly 4 character space increments or regular tab characters).
(setq-default indent-tabs-mode 0)
(setq-default tab-width 4)
(setq indent-line-function 'insert-tab)
The above is the code from my init.el, which leads me to wonder why it is occasionally failing and inserting 6 character tabs.
The major mode in question might have its own rules for indentation, but if we're talking about text-mode then indent-line-function
should indeed be called (eventually). You might want to double-check that this isn't buffer-local with a different value to the one you thought you'd set, but I would say the more likely culprit is the tab-stop-list
variable.
You can read about that and other related things here:
http://www.emacswiki.org/emacs/CategoryIndentation
It's tucked away near the bottom of that list of links, but it's critical to understanding the behaviour of tabs in the absence of automated-indentation rules.
If you enable ruler-mode
and the ruler-mode-show-tab-stops
variable, it may shed some light on things.