all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Skip Montanaro <skip.montanaro@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Can I have my electric cake and eat it too? (Python mode question)
Date: Mon, 30 Jan 2017 15:23:04 -0600	[thread overview]
Message-ID: <CANc-5UxY14mLnB1fHYCymz4fb9LOzFb0dz9av+Q9KVGroSqMBA@mail.gmail.com> (raw)

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	other threads:[~2017-01-30 21:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-30 21:23 Skip Montanaro [this message]
2017-01-30 21:28 ` Can I have my electric cake and eat it too? (Python mode question) Skip Montanaro
2017-01-31 14:54 ` Stefan Monnier
2017-01-31 18:06   ` Skip Montanaro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANc-5UxY14mLnB1fHYCymz4fb9LOzFb0dz9av+Q9KVGroSqMBA@mail.gmail.com \
    --to=skip.montanaro@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.