help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Can I have my electric cake and eat it too? (Python mode question)


From: Skip Montanaro
Subject: Can I have my electric cake and eat it too? (Python mode question)
Date: Mon, 30 Jan 2017 15:23:04 -0600

I was annoyed that entering a colon at the end of a line in a Python buffer
didn't automatically reindent the line (say, entering a colon after typing
"else" didn't line it up with its matching "if"). After a little reading, I
figured out I needed to call (electric-indent-mode) in my python-mode-hook.
Done. Now, however, C-j (bound to electric-newline-and-maybe-indent) no
longer indents. The doc for that function says, "Insert a newline. If
`electric-indent-mode' is enabled, that's it..."

Is there no way to have my cake (colon reindents the current line) and eat
it too (C-j inserts a newline *and* reindents the line)? I've been
programming in Python for over 20 years (my how time flies). (re)Indenting
lines is a really common activity. Having it happen automatically only
about half the time seems suboptimal. If there was an
electric-newline-and-indent function, I could just bind it to C-j in my
python-mode-hook. It obviously won't be hard to write (just remove the mode
check), but maybe I'm missing some good reason why you wouldn't always want
to reindent after a newline while entering Python code.

My environment is currently Emacs 24.5.1 on RH Linux, using the Emacs which
apparently comes with Continuum Analytics' Anaconda distro.

Thx,

Skip Montanaro


reply via email to

[Prev in Thread] Current Thread [Next in Thread]