@@ -403,6 +403,19 @@ py-beep-if-tab-change\tring the bell if tab-width is changed"
403403
404404
405405; ; electric characters
406+ (defun py-outdent-p ()
407+ ; ; returns non-nil if the current line should outdent one level
408+ (save-excursion
409+ (and (progn (back-to-indentation )
410+ (looking-at py-outdent-re))
411+ (progn (backward-to-indentation 1 )
412+ (while (or (looking-at py-blank-or-comment-re)
413+ (bobp ))
414+ (backward-to-indentation 1 ))
415+ (not (looking-at py-no-outdent-re)))
416+ )))
417+
418+
406419(defun py-electric-colon (arg )
407420 " Insert a colon.
408421In certain cases the line is outdented appropriately. If a numeric
@@ -414,13 +427,7 @@ argument is provided, that many colons are inserted non-electrically."
414427 (outdent 0 )
415428 (indent (py-compute-indentation)))
416429 (if (and (not arg)
417- (progn
418- (back-to-indentation )
419- (looking-at py-outdent-re))
420- (prog2
421- (backward-to-indentation 1 )
422- (not (looking-at py-no-outdent-re))
423- (goto-char here))
430+ (py-outdent-p)
424431 (= indent (progn
425432 (forward-line -1 )
426433 (py-compute-indentation)))
@@ -650,11 +657,7 @@ needed so that only a single column position is deleted."
650657 (move-to-indentation-p (<= (current-column ) ci))
651658 (need (py-compute-indentation)))
652659 ; ; see if we need to outdent
653- (if (save-excursion
654- (and (progn (back-to-indentation )
655- (looking-at py-outdent-re))
656- (progn (backward-to-indentation 1 )
657- (not (looking-at py-no-outdent-re)))))
660+ (if (py-outdent-p)
658661 (setq need (- need py-indent-offset)))
659662 (if (/= ci need)
660663 (save-excursion
0 commit comments