0

My javascript mode indents with a mix of tabs and spaces. I'm ok with the mix if spaces are used for cosmetic alignment, but this is just wrong:

enter image description here

First level of indentation is spaces, second is tab, third is tab and spaces.

I tried looking for relevant variables. js-indent-level is 4.

This is this way with emacs -q as well (just using my config above for illustration purpose).

How do I fix this, preferably using spaces only?

Emacs 25.2.2


EDIT: Yeah, so I can set indent-tabs-mode to nil, but isn't the behavior with it at t still wrong?

0

How do I fix this, preferably using spaces only?

(setq indent-tabs-mode nil)

Yeah, so I can set indent-tabs-mode to nil, but isn't the behavior with it at t still wrong?

Emacs tries to insert the "the shortest possible series of tab and space characters". This usually means that as soon as you cross 8 characters (the default tab-width), you end up with a mixture of tabs and spaces.

Normally, indentation commands insert (or remove) the shortest possible series of tab and space characters so as to align to the desired column. Tab characters are displayed as a stretch of empty space extending to the next “display tab stop”. By default, there is one display tab stop every ‘tab-width’ columns (the default is 8). [emphasis mine]

See (emacs) Just Spaces for more information (C-h r m Just Spaces RET).

| improve this answer | |
  • I'd say that this behavior will never be correct if tab-width and *-indent-level are not the same. – Gauthier Oct 21 at 12:19
  • What do you mean by "correct"? – NickD Oct 21 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.