Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-mode indentation not working upon hitting enter

I just installed python-mode from ELPA and when I hit Enter the cursor goes straight to the beginning of the next line. For instance for the following code:

def hello_world():
    print "hello world!"
    for i in range(3):
        print "hello again"
    return 0

I have to hit TAB after Enter every time after I hit Enter to go to a new-line (although interestingly TAB sends the cursor to the right place).

When I installed python-mode I got some warning messages relating to indentation which I don't really understand, here is a link to those warning messages.

like image 767
Mike Vella Avatar asked Mar 27 '26 16:03

Mike Vella


1 Answers

C-j is the key I was looking for ('newline-and-indent' command). I managed to rebind Enter to this by putting the following hook in my init.el:

(add-hook 'python-mode-hook
          (lambda ()
             (define-key python-mode-map "\r" 'newline-and-indent)))
like image 73
Mike Vella Avatar answered Apr 01 '26 10:04

Mike Vella



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!