all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Can I have my electric cake and eat it too? (Python mode question)
@ 2017-01-30 21:23 Skip Montanaro
  2017-01-30 21:28 ` Skip Montanaro
  2017-01-31 14:54 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Skip Montanaro @ 2017-01-30 21:23 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Can I have my electric cake and eat it too? (Python mode question)
  2017-01-30 21:23 Can I have my electric cake and eat it too? (Python mode question) Skip Montanaro
@ 2017-01-30 21:28 ` Skip Montanaro
  2017-01-31 14:54 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Skip Montanaro @ 2017-01-30 21:28 UTC (permalink / raw)
  To: help-gnu-emacs

On Mon, Jan 30, 2017 at 3:23 PM, Skip Montanaro <skip.montanaro@gmail.com>
wrote:

> 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)


Even easier will be the just bind C-j to 'newline-and-indent' in my
python-mode-map. :-)

Still curious why python-mode doesn't do it this way now.

Skip


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Can I have my electric cake and eat it too? (Python mode question)
  2017-01-30 21:23 Can I have my electric cake and eat it too? (Python mode question) Skip Montanaro
  2017-01-30 21:28 ` Skip Montanaro
@ 2017-01-31 14:54 ` Stefan Monnier
  2017-01-31 18:06   ` Skip Montanaro
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2017-01-31 14:54 UTC (permalink / raw)
  To: help-gnu-emacs

> figured out I needed to call (electric-indent-mode) in my python-mode-hook.

electric-indent-mode is a *global* mode, so putting it into a major
mode' hook doesn't make sense.

> 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..."

electric-indent-mode swaps the meaning of RET and C-j, so just use RET
to do the "newline and indent".

> Even easier will be the just bind C-j to 'newline-and-indent' in my
> python-mode-map. :-)

Or in the global-map.


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Can I have my electric cake and eat it too? (Python mode question)
  2017-01-31 14:54 ` Stefan Monnier
@ 2017-01-31 18:06   ` Skip Montanaro
  0 siblings, 0 replies; 4+ messages in thread
From: Skip Montanaro @ 2017-01-31 18:06 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

On Tue, Jan 31, 2017 at 8:54 AM, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> electric-indent-mode is a *global* mode


Thanks, was unaware of that.

Skip


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-01-31 18:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-30 21:23 Can I have my electric cake and eat it too? (Python mode question) Skip Montanaro
2017-01-30 21:28 ` Skip Montanaro
2017-01-31 14:54 ` Stefan Monnier
2017-01-31 18:06   ` Skip Montanaro

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.