diff options
| author | Kenichi Handa <handa@gnu.org> | 2014-07-05 23:07:57 +0900 |
|---|---|---|
| committer | Kenichi Handa <handa@gnu.org> | 2014-07-05 23:07:57 +0900 |
| commit | aeb894a9a06d84d29b93ca04432d7cbed366e665 (patch) | |
| tree | e2b73f9a76bc826c7a443e9a8d4fb3b49bdf7332 /lisp/progmodes/python.el | |
| parent | 763a11d0d0dcf543e89a22c98f55ea07c40ceefa (diff) | |
| parent | a984543a4488ed08778eb775d62f7091db117945 (diff) | |
| download | emacs-aeb894a9a06d84d29b93ca04432d7cbed366e665.tar.gz | |
merge trunk
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 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." (when (and electric-indent-mode (eq (char-before) last-command-event)) (cond - ((and (not (bolp)) - (memq (char-after) '(?\) ?\] ?\}))) + ;; Electric indent inside parens + ((and + (not (bolp)) + (let ((paren-start (python-syntax-context 'paren))) + ;; Check that point is inside parens. + (when paren-start + (not + ;; Filter the case where input is happening in the same + ;; line where the open paren is. + (= (line-number-at-pos) + (line-number-at-pos paren-start))))) + ;; When content has been added before the closing paren or a + ;; comma has been inserted, it's ok to do the trick. + (or + (memq (char-after) '(?\) ?\] ?\})) + (eq (char-before) ?,))) (save-excursion (goto-char (line-beginning-position)) - ;; If after going to the beginning of line the point - ;; is still inside a paren it's ok to do the trick - (when (python-syntax-context 'paren) - (let ((indentation (python-indent-calculate-indentation))) - (when (< (current-indentation) indentation) - (indent-line-to indentation)))))) + (let ((indentation (python-indent-calculate-indentation))) + (when (< (current-indentation) indentation) + (indent-line-to indentation))))) + ;; Electric colon ((and (eq ?: last-command-event) (memq ?: electric-indent-chars) (not current-prefix-arg) |
