Reputation: 5040
Opening .txt file in file in emacs and pressing tab is not always giving the same result. Sometime 4, and after sometime pressing tab show 2.
The same thing is also happening in .c/.cpp files.
Is this a feature in emacs 24.2?
How can I get consistence tab width?
Upvotes: 1
Views: 1044
Reputation: 9370
When you press the key TAB, depending on the mode and the position of the cursor, emacs will try to indent the line (in the files you call .txt, only if at beggining of the line, in the middle of the line it will insert a tab or spaces up to the next tab-stop, depending on your preferences).
Indentation is relative to the lines preceding the line you are in. So you will see that pressing TAB key does not always insert the same number of spaces (or tab characters). That is a feature. You can bind your tab key to do a different thing (insert a tab character or a fixed amount of spaces) if you want, but you would be losing very useful functionality.
You should play with variables indent-tabs-mode
, tab-width
, and c-basic-offset
to have emacs behave as you like in thise regards.
For instance:
(setq-default c-basic-offset 4
tab-width 4
indent-tabs-mode nil)
If you like to use 4 spaces in .txt, .c and .cpp files (additional variables might be needed for additional modes, like nxml, but I don't now what else you use).
Upvotes: 1
Reputation: 4804
Emacs -Q: "tab-width is a variable defined in `C source code'. Its value is 8
Automatically becomes buffer-local when set. "
Which IMO is a useful behavior, as programming-modes will employ different styles, set it in a different way, so it's important being able to change that.
In Python for example a tab-width of 4 is common.
Upvotes: 0