;; - proper interaction with pending-del and del-sel modes.
;; - Better support for outdenting: py-electric-colon (:) and
;; py-indent-line (TAB) improvements; one level of outdentation
-;; added after a return, raise, break, or continue statement
+;; added after a return, raise, break, pass, or continue statement.
+;; Defeated by prefixing command with C-u.
;; - New py-electric-colon (:) command for improved outdenting Also
;; py-indent-line (TAB) should handle outdented lines better
;; - improved (I think) C-c > and C-c <
- (indent (py-compute-indentation)))
+ (indent (py-compute-indentation)))
(= indent (save-excursion
(setq outdent py-indent-offset))
;; Don't indent, only outdent. This assumes that any lines that
(put 'py-delete-char 'delete-selection 'supersede)
(put 'py-delete-char 'pending-delete 'supersede)
-(defun py-indent-line ()
- "Fix the indentation of the current line according to Python rules."
+(defun py-indent-line (&optional arg)
+ "Fix the indentation of the current line according to Python rules.
+With \\[universal-argument], ignore outdenting rules for block
+closing statements (e.g. return, raise, break, continue, pass)
+This function is normally bound to `indent-line-function' so
+\\[indent-for-tab-command] will call it."
(let* ((ci (current-indentation))
(move-to-indentation-p (<= (current-column) ci))
- (need (py-compute-indentation)))
+ (need (py-compute-indentation)))
;; see if we need to outdent
(setq need (- need py-indent-offset)))
-(defun py-compute-indentation ()
+(defun py-compute-indentation (honor-block-close-p)
+ ;; implements all the rules for indentation computation. when
+ ;; honor-block-close-p is non-nil, statements such as return, raise,
+ ;; break, continue, and pass force one level of outdenting.
(let ((pps (parse-partial-sexp (save-excursion
- (if (py-statement-closes-block-p)
+ (if (py-statement-closes-block-p)
(target-column 0) ; column to which to indent
(base-shifted-by 0) ; amount last base line was shifted
(indent-base (if (looking-at "[ \t\n]")
(defun py-statement-closes-block-p ()
;; true iff the current statement `closes' a block == the line
- ;; starts with `return', `raise', `break' or `continue'. doesn't
- ;; catch embedded statements
+ ;; starts with `return', `raise', `break', `continue', and `pass'.
+ ;; doesn't catch embedded statements
- (looking-at "\\(return\\|raise\\|break\\|continue\\)\\>")
+ (looking-at "\\(return\\|raise\\|break\\|continue\\)\\>")
;; go to point right beyond final line of block begun by the current