Re: python-mode.el

Sjoerd Mullender (
Thu, 14 Apr 1994 12:31:12 +0200

On Wed, Apr 13 1994 Donald Beaudry wrote:

> I just made a small change to python-mode.el to change the way that
> continuation lines are handled. By replacing the existing
> py-compute-indentation function with the one that follows,
> continuation lines will be indented to just inside of the paren that
> contains the expression (just like in c-mode). If you are not nested
> inside of parens, indentation is computed as before. The variable
> py-nested-indent (also defined below) can be used to enable and
> disable this behavior.

I made a small fix to this. The problem was that if the open
parenthesis is on a line with tabs the indentation of the following
line was not correct. Replace with the following version.
BTW, Guido changed the official python-mode.el to incorporate this

(defvar py-nested-indent t
"*If non-nil, indent nested continuation lines to inside the opening paren")

(defun py-compute-indentation ()
;; are we on a continuation line?
( (py-continuation-line-p)
(let ((nest (and py-nested-indent (py-nesting-level))))
(if nest
(goto-char nest)
(1+ (current-column)))
(forward-line -1)
(if (py-continuation-line-p) ; on at least 3rd line in block
(current-indentation) ; so just continue the pattern
;; else on 2nd line in block, so indent more
(+ (current-indentation) py-indent-offset
;; not on a continuation line

;; if at start of restriction, or on a non-indenting comment line,
;; assume they intended whatever's there
( (or (bobp) (looking-at "[ \t]*#[^ \t\n]"))
(current-indentation) )

;; else indentation based on that of the statement that precedes
;; us; use the first line of that statement to establish the base,
;; in case the user forced a non-std indentation for the
;; continuation lines (if any)
( t
;; skip back over blank & non-indenting comment lines
;; note: will skip a blank or non-indenting comment line that
;; happens to be a continuation line too
(re-search-backward "^[ \t]*\\([^ \t\n#]\\|#[ \t\n]\\)"
nil 'move)
(if (py-statement-opens-block-p)
(+ (current-indentation) py-indent-offset)

Sjoerd Mullender, CWI, P.O. Box 94079, 1090 GB Amsterdam, The Netherlands
E-Mail:; Phone: +31 20 592 4127; Fax: +31 20 592 4199
URL: <>