I'm going kinda crazy trying to understand what's going on here... Asked this question on the r/emacs subreddit so apologies if any of you are seeing this again.
Do org blocks allow TAB
indentation without going into special editing mode via C-c '
?
I have the following relevant settings in my custom-set-variables
block (i.e. edited via customize-mode
.
'(org-edit-src-content-indentation 0)
'(org-src-preserve-indentation nil)
I used these settings because I was getting sick of editing code in the source block and having all the lines jump 2 spaces to the right.
org-src-tab-acts-natively
is set to t
as well.
But now when I write
#+begin_src python
def hello():
|
#+end_src
the cursor is stuck at the start of the line and I can't use TAB
to indent to add a new line, i.e. to make it look like:
def hello( ):
print("hello)
TAB
used to work -- or atleast, I thought it was working. This github comment suggests that this facility was never actually available, and we always had to use C-c '
to edit code properly. But then this Stackoverflow post and answers, as well as this github issue seem to imply otherwise.
Now, I have also set org-adapt-indentation
to nil
, because I prefer org-headings, sub-headings and text to be aligned with the buffer edge. If I set it to 1
, it looks like there is some aligning going on when I hit TAB
, but this is not perfect. Does this explain the "pseudo-indenting" that I had before, and there really is no inherent TAB
indent in org blocks?
I have also been recommended poly-mode
and poly-org
, but I'd first like to understand what is going on here.
EDIT: I have neglected to say that the message Can’t guess python-indent-offset, using defaults: 4
appears in the minibuffer after each failed TAB
press. I wouldn't have thought that would be the difference, as long as it guessed a non-zero offset.
EDIT: Org mode version 9.4.4 (release_9.4.4 @ /usr/share/emacs/27.2/lisp/org/)
EDIT: Here is the tab-indentation behavior when running emacs -Q
https://i.stack.imgur.com/Bm05v.jpg
org-cycle-emulate-tab
? Ifnil
, set it tot
and try again. Check the doc string of the variable withC-h v org-cycle-emulate-tab
.Can't guess ...
add this to your python configuration:(setq python-indent-guess-indent-offset-verbose nil)
. Take care also to inittab-width
to 4 and configpython-indent-offset
also to 4.