1

When I try to write code in source block in Org mode, pressing return once acts as expected while hitting it a second time increases the indentation to two levels if it's currently less than that. Here's an example of how the cursor moves when I press return at various initial indentation levels:

#+begin_src python
def my_function():
    # Each "." shows where the cursor goes after pressing RET.
    .
        .
        .
        .
        

    def internal_function():
        # Same thing from here.
        .
        .
        .
        .
        
        def double_internal_function():
            # Same thing from here.
            .
            .
            .
            .
            
        
# Same thing from here.
.
        .
        .
        .

#+end_src

It is (org-return electric-indent-mode) that is being called when I press return, and I'm able to reproduce this behavior by calling this myself. Some other function calls that don't exhibit the same behavior are (org-return-and-maybe-indent), (org-return), (org-newline-and-indent), and (newline-and-indent). If I disable electric-indent-mode, then the second return eliminates all indentation entirely. Ideally, I would want repeatedly pressing return to maintain the same indentation level.

Ivanna
  • 111
  • 1

1 Answers1

0

You need to set the variable: org-adapt-indentation to off.

Punit Arya
  • 141
  • 4
  • This is already `nil` for me when I see this behavior. – Ivanna May 18 '21 at 22:12
  • Share your .emacs without the irrelevant portions, do include the python mode configurations. Does this happen in python mode buffers also or just in org source blacks ? Does this happen in any other programming modes ? – Punit Arya May 19 '21 at 20:27