On this example, cursor is at beginning of if when I press tab 2 space indent is added beginning of if block, which is aligned.

** TODO help            |  ** TODO help
#+begin_src python      |  #+begin_src python
if True                 |    if True             # 2 space added to beginning
  print(True)           |      print(True)       #
  if True:              |      if True:          #
    print("World")      |        print("World")  #
#+end_src               |  #+end_src

Would it be possible to apply (setq org-adapt-indentation nil) into #+begin_src...#+end_src region as well where pressing TAB will no do initial tab alignment.

Also would it be possible to set the indent as four spaces instead of two?

Wanted behaviour:

** TODO help 
#+begin_src python 
if True          # Indent does not added            
    print(True)  # Four spcace added at the beginning   
    if True:


(setq org-adapt-indentation nil)
(require 'org-tempo)
(defun my-tab-related-stuff ()
   (setq tab-width 4))


1 Answer 1


Customize the variable org-edit-src-content-indentation and set it to 0. The doc string of the variable says:

org-edit-src-content-indentation is a variable defined in ‘org-src.el’.
Its value is 2

  This variable is safe as a file local variable if its value
  satisfies the predicate ‘wholenump’.
  You can customize this variable.

Indentation for the content of a source code block.

This should be the number of spaces added to the indentation of the #+begin
line in order to compute the indentation of the block content after
editing it with ‘M-x org-edit-src-code’.

It has no effect if ‘org-src-preserve-indentation’ is non-nil.

As a corollary, you should also make sure that org-src-preserve-indentation is 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.