aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2013-12-12 20:32:05 -0300
committerFabián Ezequiel Gallina2013-12-12 20:32:05 -0300
commitbc9222c93463e8aaaf116ed945c3d2007adf771d (patch)
tree7ee2d0bb246dcdf1e1341011b14d8bb2386671d8 /lisp/progmodes/python.el
parentb55e11bf851ac73e1041a4a24cca3f81d93039e4 (diff)
downloademacs-bc9222c93463e8aaaf116ed945c3d2007adf771d.tar.gz
emacs-bc9222c93463e8aaaf116ed945c3d2007adf771d.zip
* 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."
780 ;; indentation, in the case current line starts with a 780 ;; indentation, in the case current line starts with a
781 ;; `python-indent-dedenters' de-indent one level. 781 ;; `python-indent-dedenters' de-indent one level.
782 (`after-line 782 (`after-line
783 (- 783 (let* ((pair (save-excursion
784 (save-excursion 784 (goto-char context-start)
785 (goto-char context-start) 785 (cons
786 (current-indentation)) 786 (current-indentation)
787 (if (or (save-excursion 787 (python-info-beginning-of-block-p))))
788 (back-to-indentation) 788 (context-indentation (car pair))
789 (looking-at (regexp-opt python-indent-dedenters))) 789 (after-block-start-p (cdr pair))
790 (save-excursion 790 (adjustment
791 (python-util-forward-comment -1) 791 (if (or (save-excursion
792 (python-nav-beginning-of-statement) 792 (back-to-indentation)
793 (looking-at (regexp-opt python-indent-block-enders)))) 793 (and
794 python-indent-offset 794 ;; De-indent only when dedenters are not
795 0))) 795 ;; next to a block start. This allows
796 ;; one-liner constructs such as:
797 ;; if condition: print "yay"
798 ;; else: print "wry"
799 (not after-block-start-p)
800 (looking-at (regexp-opt python-indent-dedenters))))
801 (save-excursion
802 (python-util-forward-comment -1)
803 (python-nav-beginning-of-statement)
804 (looking-at (regexp-opt python-indent-block-enders))))
805 python-indent-offset
806 0)))
807 (- context-indentation adjustment)))
796 ;; When inside of a string, do nothing. just use the current 808 ;; When inside of a string, do nothing. just use the current
797 ;; indentation. XXX: perhaps it would be a good idea to 809 ;; indentation. XXX: perhaps it would be a good idea to
798 ;; invoke standard text indentation here 810 ;; invoke standard text indentation here