I've been unsuccessful in getting Emacs to switch from 8 space tabs to 4 space tabs when pressing the TAB in buffers with the major mode text-mode
. I've added the following to my .emacs
:
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
;;; And I have tried
(setq indent-tabs-mode nil)
(setq tab-width 4)
No matter how I change my .emacs
file (or my buffer's local variables) the TAB button always does the same thing.
- If there is no text above, indent 8 spaces
- If there is text on the previous line, indent to the beginning of the second word
As much as I love Emacs this is getting annoying. Is there a way to make Emacs to at least indent 4 space when there's not text in the previous line?
Best Answer
Short answer:
The key point is to tell emacs to insert whatever you want when indenting, this is done by changing the indent-line-function. It is easier to change it to insert a tab and then change tabs into 4 spaces than change it to insert 4 spaces. The following configuration will solve your problem:
Explanation:
From Indentation Controlled by Major Mode @ emacs manual:
From indent-relative @ emacs manual:
Just change the value of indent-line-function to the insert-tab function and configure tab insertion as 4 spaces.