# Org-mode source code blocks indent when I RET

**URL:** <https://org-roam.discourse.group/t/org-mode-source-code-blocks-indent-when-i-ret/3750>\
**Category:** Troubleshooting\
**Created:** [February 24, 2025, 5:20pm UTC](https://org-roam.discourse.group/t/org-mode-source-code-blocks-indent-when-i-ret/3750 "2025-02-24T17:20:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![orgroamer](https://avatars.discourse-cdn.com/v4/letter/o/54ee81/32.png) [@orgroamer](https://org-roam.discourse.group/u/orgroamer)\
**Post date:** [February 24, 2025, 5:20pm UTC](https://org-roam.discourse.group/t/org-mode-source-code-blocks-indent-when-i-ret/3750/1 "2025-02-24T17:20:09Z")

</div>

When I click RET on any character other than the last in a line, in an Org-mode source code block, the whole block gets indented one tab. I then have to undo twice to get back to previous state. I cannot find anyone with similar problem online.

---

<div class="post-metadata">

**Author:** ![akashp](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/akashp/32/1383_2.png) [@akashp](https://org-roam.discourse.group/u/akashp)\
**Post date:** [February 24, 2025, 7:11pm UTC](https://org-roam.discourse.group/t/org-mode-source-code-blocks-indent-when-i-ret/3750/2 "2025-02-24T19:11:21Z")

</div>

```auto
org-edit-src-content-indentation is a variable defined in ‘org-src.el’.

Its value is 2

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.

```

> [@Source blocks are indented](https://org-roam.discourse.group/t/source-blocks-are-indented/3031):
>
> #+begin\_src python import sys #+end\_src This example shows a python source block in an orgroam file. OrgRoam always does an indention here of two spaces. Why? I see no advantage of that. Is there a way to turn this of? Here is a minimal init.el to reproduce ;; -\*- lexical-binding: t; -\*- (require 'package) (setq package-archives '(("melpa" . "https://melpa.org/packages/") ("elpa" . "https://elpa.gnu.org/packages/"))) ;; Initializes the package infrastructure (package-initializ…

---

<div class="post-metadata">

**Author:** ![orgroamer](https://avatars.discourse-cdn.com/v4/letter/o/54ee81/32.png) [@orgroamer](https://org-roam.discourse.group/u/orgroamer)\
**Post date:** [February 24, 2025, 8:31pm UTC](https://org-roam.discourse.group/t/org-mode-source-code-blocks-indent-when-i-ret/3750/3 "2025-02-24T20:31:35Z")

</div>

I don’t mind the 2 spaces source code indentation. The problem is, whenever I RET my entire code block gets indented an extra 4 spaces.

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [February 24, 2025, 9:22pm UTC](https://org-roam.discourse.group/t/org-mode-source-code-blocks-indent-when-i-ret/3750/4 "2025-02-24T21:22:45Z")

</div>

The docstring of `org-indent-line` has the following:

```auto
  - In the code part of a source block, use language major mode
    to indent current line if ‘org-src-tab-acts-natively’ is
    non-nil. If it is nil, do nothing.

```

I suggest you check the value of `org-src-tab-acts-natively`; it’s probably `t` for you. Then I think it’s the matter of the language major mode you use for the src block.

My guess is that it’s set to 4 spaces for the major mode, which gets added to `org-edit-src-content-indentation` as @akashp mentions above – my pure guess. I don’t use src block in Org mode extensively.

---

<div class="post-metadata">

**Author:** ![orgroamer](https://avatars.discourse-cdn.com/v4/letter/o/54ee81/32.png) [@orgroamer](https://org-roam.discourse.group/u/orgroamer)\
**Post date:** [February 24, 2025, 11:47pm UTC](https://org-roam.discourse.group/t/org-mode-source-code-blocks-indent-when-i-ret/3750/5 "2025-02-24T23:47:18Z")

</div>

Yes, `org-src-tab-acts-natively` is `t`, which the documentation says it uses language major mode.

I get the message `Can't guess python-indent-offset, using default: 4` when I use Python code blocks. `python-indent-offset` is set to `4`. So yes it is set to 4 spaces.

I just counted, and it’s indenting 2 spaces every time I RET.

Just set `org-edit-src-content-indentation` to `0`, and it’s stopped. Now my code blocks are not indented 2 spaces as they were before, which I think makes them less readable, so I’ll ask another question about that.
