aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el28
1 files changed, 20 insertions, 8 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 743981b3714..065a182904f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1096,16 +1096,28 @@ the line will be re-indented automatically if needed."
1096 (when (and electric-indent-mode 1096 (when (and electric-indent-mode
1097 (eq (char-before) last-command-event)) 1097 (eq (char-before) last-command-event))
1098 (cond 1098 (cond
1099 ((and (not (bolp)) 1099 ;; Electric indent inside parens
1100 (memq (char-after) '(?\) ?\] ?\}))) 1100 ((and
1101 (not (bolp))
1102 (let ((paren-start (python-syntax-context 'paren)))
1103 ;; Check that point is inside parens.
1104 (when paren-start
1105 (not
1106 ;; Filter the case where input is happening in the same
1107 ;; line where the open paren is.
1108 (= (line-number-at-pos)
1109 (line-number-at-pos paren-start)))))
1110 ;; When content has been added before the closing paren or a
1111 ;; comma has been inserted, it's ok to do the trick.
1112 (or
1113 (memq (char-after) '(?\) ?\] ?\}))
1114 (eq (char-before) ?,)))
1101 (save-excursion 1115 (save-excursion
1102 (goto-char (line-beginning-position)) 1116 (goto-char (line-beginning-position))
1103 ;; If after going to the beginning of line the point 1117 (let ((indentation (python-indent-calculate-indentation)))
1104 ;; is still inside a paren it's ok to do the trick 1118 (when (< (current-indentation) indentation)
1105 (when (python-syntax-context 'paren) 1119 (indent-line-to indentation)))))
1106 (let ((indentation (python-indent-calculate-indentation))) 1120 ;; Electric colon
1107 (when (< (current-indentation) indentation)
1108 (indent-line-to indentation))))))
1109 ((and (eq ?: last-command-event) 1121 ((and (eq ?: last-command-event)
1110 (memq ?: electric-indent-chars) 1122 (memq ?: electric-indent-chars)
1111 (not current-prefix-arg) 1123 (not current-prefix-arg)