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