summaryrefslogtreecommitdiff
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina <fgallina@gnu.org>2013-12-12 20:32:05 -0300
committerFabián Ezequiel Gallina <fgallina@gnu.org>2013-12-12 20:32:05 -0300
commitbc9222c93463e8aaaf116ed945c3d2007adf771d (patch)
tree7ee2d0bb246dcdf1e1341011b14d8bb2386671d8 /lisp/progmodes/python.el
parentb55e11bf851ac73e1041a4a24cca3f81d93039e4 (diff)
downloademacs-bc9222c93463e8aaaf116ed945c3d2007adf771d.tar.gz
* lisp/progmodes/python.el (python-indent-calculate-indentation): Fix
de-denters cornercase. * test/automated/python-tests.el (python-indent-dedenters-2): New test. Fixes: debbugs:15731
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el38
1 files changed, 25 insertions, 13 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 33039a4d087..8de1717096f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -780,19 +780,31 @@ START is the buffer position where the sexp starts."
;; indentation, in the case current line starts with a
;; `python-indent-dedenters' de-indent one level.
(`after-line
- (-
- (save-excursion
- (goto-char context-start)
- (current-indentation))
- (if (or (save-excursion
- (back-to-indentation)
- (looking-at (regexp-opt python-indent-dedenters)))
- (save-excursion
- (python-util-forward-comment -1)
- (python-nav-beginning-of-statement)
- (looking-at (regexp-opt python-indent-block-enders))))
- python-indent-offset
- 0)))
+ (let* ((pair (save-excursion
+ (goto-char context-start)
+ (cons
+ (current-indentation)
+ (python-info-beginning-of-block-p))))
+ (context-indentation (car pair))
+ (after-block-start-p (cdr pair))
+ (adjustment
+ (if (or (save-excursion
+ (back-to-indentation)
+ (and
+ ;; De-indent only when dedenters are not
+ ;; next to a block start. This allows
+ ;; one-liner constructs such as:
+ ;; if condition: print "yay"
+ ;; else: print "wry"
+ (not after-block-start-p)
+ (looking-at (regexp-opt python-indent-dedenters))))
+ (save-excursion
+ (python-util-forward-comment -1)
+ (python-nav-beginning-of-statement)
+ (looking-at (regexp-opt python-indent-block-enders))))
+ python-indent-offset
+ 0)))
+ (- context-indentation adjustment)))
;; When inside of a string, do nothing. just use the current
;; indentation. XXX: perhaps it would be a good idea to
;; invoke standard text indentation here