And more stuff added to Emacs Python mode ...

Tim Peters (tim@ksr.com)
Fri, 07 Feb 92 02:21:06 EST

Rather than burden y'all with a gazillabyte of new&improved Python-mode
every day, I'll just send the latest change log, and not broadcast the
code again until it settles down for a week. Happy to send intermediate
versions on request (& if "too many" people request it, I'll just
broadcast it to the list instead).

The focus of the latest version is to allow blank lines & comment lines
"in the middle" without losing track of the proper indentation. E.g.,

if whatever:
print 'indenting this right is no trick'

# some blank lines & a strangely-placed comment line

print 'but this is'

Python mode handles this now.

The idea is that if Python accepts it without griping, so should Python-
mode. The bulk of the changes actually had to do with esoteric
consequences of that principle, involving the sometimes darned-hard-to-
parse-backwards <grin> interactions among indentation, comment symbols,
and backslashes. A couple examples of pathologies are given in the
change log below.

Uncomfortable but unavoidable side effect: Suppose you type:

def oneplus(n):
return 1+n
<an empty line>

The new Python mode, unlike the previous ones (which looked only at the
immediately preceding line), thinks the next line you type should be
indented to match the "return" line. There's no general way to stop
this and still allow blank/empty lines where you want them -- the
paradox of Python-mode is that it wants to help you indent, but in
effect it needs you to tell it the proper indentation first since
there's no other way to figure out the grouping you intend (most other
language modes can figure out the grouping by looking at keywords and
bracketing constructs (begin/end if/endif {/} (/) etc) ...).

Question: in looking over the to-do's at the bottom of the code, I
don't think I want to do this one:

- switch back to previous buffer when starting shell

That is, after "C-c !", I *like* winding up in the Python buffer (the
current behavior). How do other people feel about that?

and-about-the-portability-thread-all-i-can-say-is-that-if-god-wanted-
us-to-move-programs-from-machine-to-machine-he-wouldn't-have-
invented-heart-disease<snort>-ly y'rs - tim

Tim Peters Kendall Square Research Corp
tim@ksr.com, ksr!tim@uunet.uu.net

Latest python-mode.el change-log entry:

taught py-compute-indentation about blank & comment lines:
accept comment line indentation as-is
skip blank & comment lines when looking for the indentation of
the preceding statement
change py-shift-region docs accordingly
reversed order of change log (now most-recent first)
changed "\C-c\C-i" to "\C-c\t" for clarity
rearranged mode-map & syntax-table code to match other language modes
taught py-continuation-line-p that a trailing backslash does not
indicate continuation when it ends a comment line
ditto py-goto-initial-line
fixed some pathological cases; e.g.,
if \
1 \
:\
\
\
# continued comment
print 'I should be indented'
if a == b : # \
print 'I should be indented, but not like a continuation'
added consts py-stringlit-re and py-continued-re to support the above;
made py-colon-line-re even hairier

>>> END OF MSG