When I open Java files originally created and edited in Emacs, the indentation shows up correctly, as in the image below:

Java file made in emacs

However, when I open the same file in Sublime Text, or any other editor besides Emacs, the indentation is messed up, and I can see that it's because Emacs inconsistently mixes spaces and tabs:

The same file opened in sublime text

Has anyone else encountered this?

  • That's happening because your Emacs is using a tab width of 8, while sublime is using a tab width of 4. That's easy to fix, but if it's an option at all I would just follow Drew's answer and stop using tabs.
    – Malabarba
    Commented Mar 7, 2015 at 7:44

2 Answers 2


Set option indent-tabs-mode to nil:

Put this in your init file, to make Emacs always indent using SPC characters, never TAB characters.

(setq-default indent-tabs-mode nil)
  • Also for reference: the manual page on tabs vs spaces, which discusses precisely this issue.
    – Dan
    Commented Mar 7, 2015 at 4:50

a new answer to an old question.


It reformats buffers on save. You can add different reformatters for different languages. Apheleia can drive any of these formatters:

works really nicely.

  • Props for responding to a post I made in university 😅
    – Adam R
    Commented Jul 19 at 0:02

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.