Slawomir Nowaczyk wrote: > On Wed, 09 Aug 2006 07:33:41 -0700 > Rob Wolfe <[EMAIL PROTECTED]> wrote: > > #> Slawomir Nowaczyk wrote: > #> > #> > Really, typing brace after function/if/etc should add newlines and > #> > indent code as required -- automatically. Actually, for me, it is even > #> > *less* typing in C and similar languages... I probably should teach my > #> > Emacs to automatically add newline after colon in Python, just as it > #> > does after a brace in C... As soon as I figure out how to deal with > #> > dictionary literals. Hmmm. > #> > #> Are you sure? My Emacs already know how to do it with the help > #> of python-mode and magic function py-newline-and-indent. > #> > #> emacs-version "21.3.1" > #> py-version "$Revision: 4.63 $" > > OK, my python-mode.el was older, so I upgraded to 4.75, but it still > doesn't work. Did you mean that after you write > > if x==1: > > the newline is inserted automatically when you type ":"? That's a
Exactly. > functionality I would like to see, but it doesn't seem to work this > way. Here is fragment of my python-mode.el: """ The \\[indent-for-tab-command] and \\[py-newline-and-indent] keys try to suggest plausible indentation, based on the indentation of preceding statements. E.g., assuming py-indent-offset is 4, after you enter \tif a > 0: \\[py-newline-and-indent] the cursor will be moved to the position of the `_' (_ is not a character in the file, it's just used here to indicate the location of the cursor): \tif a > 0: \t _ If you then enter `c = d' \\[py-newline-and-indent], the cursor will move to \tif a > 0: \t c = d \t _ Python-mode cannot know whether that's what you intended, or whether \tif a > 0: \t c = d \t_ was your intent. In general, Python-mode either reproduces the indentation of the (closest code or indenting-comment) preceding statement, or adds an extra py-indent-offset blanks if the preceding statement has `:' as its last significant (non-whitespace and non- comment) character. If the suggested indentation is too much, use \\[py-electric-backspace] to reduce it. """ Regards, Rob -- http://mail.python.org/mailman/listinfo/python-list