It so happened that many companies have their own code standard that regulates how to indent: spaces or tabs, and how wide they should be. What makes a newbie the first thing when working on a project where the code is already designed according to the standard? That's right, he commits the fruits of his labor and receives a header from the headline for not seeing exactly how its editor works with indents. If you are a beginner (or not very fortunate) user of emacs and want to avoid this sad, but natural, if you have not yet come across this outcome, then welcome to the cat.
What are we dealing with?
First, it's nice to know what code we got. Curiously, already at this stage you can see a jumble of indents of different widths, if the editor of your predecessor put tabs / spaces in the file where the tabulation was already represented as spaces / tabs. I’ll make a reservation that you can only see this if the width of the tab display you have does not match the width of the tab (in spaces) in the predecessor editor.
If you did not see anything, then do not despair, to see what is actually happening in the file, you can use whitespace-mode. It has been added to the standard emacs distribution, starting with version 23, but in which case it can always be found here:
WhiteSpace .
This is how 2 files look like, at first glance they are the same, but using different characters to form indents, externally:

')
And using whitespace-mode:

If the code is normal and homogeneous, and either tabs or spaces are used for indentation, then just remember what is used and in what quantity - this will be useful to you during setup. If not, then tell tmlid about this, because to take responsibility for the choice of the tab character is a deliberate mistake. Whichever option you choose,
there will
always be a person who will tell you that your choice turned out to be wrong.
Indent setting
In order to choose which character will form indents, the value of the variable indent-tabs-mode is changed.
To set spaces as indentation, it must be set to nil:
(setq indent-tabs-mode nil)
accordingly, for tabs, the value should be t:
(setq indent-tabs-mode t)
At the same time, the existing indents in the file will not change, i.e. you must make sure that the new indent settings match the existing indents in the file, otherwise you will get a mess.
With the characters figured out, now you need to set the width of the indent. And there is some trick here. Most of the most common languages like js, php, c ++, java have backlight modes coming from c-mode, in which there is a variable c-basic-offset. It is responsible for how wide the tab will be during indentation in all these modes. There is also a variable tab-width, it is responsible for the width of the tab. It so happened historically that in order for everything to be formatted correctly, the values of these variables must be equal. If you put different values for each, the result will be a little predictable, to the extent that emacs will use spaces along with tabs.
So, for modes based on c-mode, you need to use the following scheme:
If you use cperl-mode, then the indent is set via the variable cperl-indent-level. Again, it is very important that its value and the value of the tab-width match.
In conclusion, I’ll say that to change the html indentation, you need to set the variable sgml-basic-offset (not forgetting the tab-width).
Each language has its own rules
Different languages require different rules described in the PEP, perl-tidy configuration, and even in your company's code standard. With this editor for everything you want to use one. The easiest way to do this is to use hooks. Here is an example configuration file for python and perl:
Reduction to a common denominator
If you still became the happy owner of the code where both tabs and spaces are used at the same time, then the untabify and tabify commands will help you (thanks to user
fader44 for the reminder). The first command translates all indents into spaces, the second, respectively, into tabs. Regardless of how each line was formatted, indentation will be reduced to a single form.