I'm using the Python REPL in a comint window via the run-python
command, and I'm seeing bad behavior when I use the TAB key to do my indentation. For example:
>>> for i in range(3):
... print(i)
File "<stdin>", line 2
print(i)
^
IndentationError: expected an indented block
Here, the indentation before print
was created using TAB. I use TAB when editing normal Python buffers, and it inserts 4 spaces in those cases. Here it seems to be inserting an actual TAB and it results in an IndentationError
.
I'd like it if TAB would just insert 4 spaces. I'm sure this is something really simple, but it's eluding me. Anyone know what I'm doing wrong?
emacs -Q
?-Q
. I'm sure (as you've confirmed) that it's something in my config, but I'm too brain-tired right now to make an effective stab at tracking down the right setting. I guess a more concrete question is: What variable - if any - controls what TAB does in the REPL?C-h
k
TAB
say? It should lead you topython-shell-completion-complete-or-indent
. That, in turn callsindent-for-tab-command
, which is part of the regular emacs indentation code.C-h k TAB
is actually bound toyas-expand
. However, if I run eitherpython-shell-completion-complete-or-indent
orindent-for-tab-command
directly to insert the indentation, I still get the odd behavior.M-:
(setq tab-width 4 indent-tabs-mode nil)
RET
in the python buffer.