python-mode.el

Donald Beaudry (don@vicorp.com)
Wed, 13 Apr 94 10:41:06 EDT

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.

--Don

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

(defun py-compute-indentation ()
(save-excursion
(beginning-of-line)
(cond
;; are we on a continuation line?
( (py-continuation-line-p)
(let ((nest (and py-nested-indent (py-nesting-level))))
(if nest
(save-excursion
(goto-char nest)
(beginning-of-line)
(1+ (- nest (point))))
(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
py-continuation-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)
(py-goto-initial-line)
(if (py-statement-opens-block-p)
(+ (current-indentation) py-indent-offset)
(current-indentation))))))

______ ______
\_\_\_\ /#/#/#/
\_\_\_\ ______
\_\_\_V#/#/#/ Donald Beaudry don@vicorp.com
\_\_/#/#/#/ V. I. Corporation uunet!vicorp!don
\_/#/#/#/ 47 Pleasant Street PHONE: (413) 586-4144
V#/#/#/ Northampton, MA 01060 FAX: (413) 586-3805