colostomy
Niklas Frykholm
r2d2 at montezuma.acc.umu.se
Wed Mar 29 06:27:47 EST 2000
In article <8bsb8n$2ki$1 at nnrp1.deja.com>, dirck at pacbell.net wrote:
>I brought it up because there was
>some discussion about Python 3k being source level incompatible, which
>indicates some ideas are in flux. Doesn't sound like anyone shares my
>enthusiasm for the minimalist syntax, which isn't a big deal. Over
>time I will adapt ok. In the mean time, if i ever get frustrated when
>I keep messing up, I can switch to a slightly more tolerant python and
>focus on the programming, not on the programming language.
I sometimes forget the colon too, but I believe that this should be
addressed in the editor rather than in the compiler. (You don't want your
printer driver to do spell checking.)
May I suggest adding the following to your python-mode.el file:
(Disclaimer: I am not an elisp programmer.)
(defun colostomy-fix ()
"Adds a colon to a python line if necessary."
(let ( (need-colon-regexp "[\\t]*\\(if\\|def\\|else\\|elif\\|\
while\\|for\\|except\\|finally\\|try\\|class\\)")
(has-colon-regexp ".*:[ \\t]*$")
(need-colon nil)
(has-colon nil))
(save-excursion
(beginning-of-line)
(setq need-colon (looking-at need-colon-regexp))
(setq has-colon (looking-at has-colon-regexp))
)
(if (and need-colon (not has-colon)) (insert ":") ())
))
And modifying the definition of py-newline-and-indent so that it reads:
(defun py-newline-and-indent ()
(interactive)
(colostomy-fix)
(let ((ci (current-indentation)))
...
This is a bit of a hack... for example it doesn't work when lines
have been broken with \. But it works in most cases.
// Niklas
More information about the Python-list
mailing list