I'm using Spacemacs, and my org-mode file contains an org-babel block of Makefile code, which I want to "tangle" so it becomes part of the source code while remaining in sync with the documentation. All of this is working, except when I auto-indent the org-mode file, the tabs inside my makefile source code block get replaced with spaces.

Spaces aren't valid indentation in makefiles, but I may accidentally use gg=G at some point, so I would like to tell emacs to not replace those tab characters.

This behavior persists when I set org-src-preserve-indentation to t in the file, so I don't know what else to do.

I already found this but my question is about auto-indenting the org-mode file itself, not exporting to another format.

# -*- org-src-preserve-indentation: t -*-
* some header
** another header

   #+begin_src makefile :tangle src/Makefile :mkdirp yes :exports code
all: people

main.o: main.c
    gcc -g -c -o main.o main.c

linked_list.o: linked_list.c
    gcc -g -c -o linked_list.o linked_list.c

    rm -f people *.o

people: main.o linked_list.o
    gcc -g -o people linked_list.o main.o

test: people

1 Answer 1


Based on suggestions from the spacemacs issue pages [1,2], I arrived at the following configuration that so far solves my issue completely:

(setq org-src-fontify-natively t
      org-src-preserve-indentation t
      evil-indent-convert-tabs nil
      org-src-tab-acts-natively nil)

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.