I have been using emacs for a while now, I am relatively new to it but while editing i noticed that sometimes emacs will show the code correctly formatted, when i open it with another text editor however, the code blocks will be all messed up and incorrectly placed. It is most notable when i try to carry a function or expression arguments to the next line to make a given line shorter etc. As you can see below the text editor (in this case CLion shows insane amounts of misalignment, emacs however shows the code differently. For example: enter image description here enter image description here enter image description here enter image description here

I have the following configurations (setq-default indent-line-function 'insert-tab) (setq-default indent-tabs-mode t) (setq-default tab-width 1)

If i comment out those settings it gets even worse, here is the last block in CLion again, completely mangled. In emacs it looks EXACTLY the same as with the tabs settings above enables. I am confused and I really need some feedback here, as i said i am rather new to it. enter image description here


1 Answer 1


I have the following configurations

(setq-default indent-tabs-mode t)
(setq-default tab-width 1)

What you're seeing is 100% expected with such settings.

When you use tabs for indentation there's always a chance that other editors will not be configured with the same tab width and will therefore render differently; but I'm confident that there isn't a text editor in existence that will default to a tab width of 1 space. (That's a crazy setting.)

If a line of code was indented to column 4, your settings would use 4 tabs to achieve that, and an editor with a tab width of 8 (which is pretty standard) would therefore indent that line to column 32.

Configure the tab width in your other editor to match, however, and you should see the same thing in both editors.

I suggest that you set your tab-width to something sane and re-indent; however if you want to guarantee that code will look the same in any editor regardless of configuration, then don't use tabs at all.

  • Agree, changed to using spaces and disabled using tabs using the following (setq-default indent-tabs-mode nil). Is there a way to set a default space offset - instead of defaulting to 1 space per block level, say 2 or 3 whatever. Oct 30, 2021 at 17:23
  • The c-basic-offset variable tends to control that; but... indentation is a much more complicated topic than you'd probably like it to be -- the emacs way is for indentation to be largely automated, and so configuration is complex, as there are many possibilities. You should start by customizing the user option c-default-style (and figuring out which style is the best match for your preferences), and then look at the manual with C-h i g (ccmode) and look thorough "Introduction", "Overview", "Getting Started", "Config Basics", "Indentation Engine Basics", "Customizing Indentation".
    – phils
    Oct 31, 2021 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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