From 49df44bf51b0a3b2a8c90180764aa37d5f3e95de Mon Sep 17 00:00:00 2001 From: Nathan Trapuzzano Date: Wed, 6 Nov 2013 08:11:43 -0500 Subject: [PATCH] Fix python-mode indentation bug #15812, and add regression test. * progmodes/python.el (python-indent-calculate-indentation): When determining indentation, don't treat "return", "pass", etc., as operators when they are just string constituents. (Bug#15812) * automated/python-test.el (python-indent-block-enders) (python-indent-block-enders-1, python-indent-block-enders-2): Rename one test, add another. --- lisp/ChangeLog | 6 ++++++ lisp/progmodes/python.el | 2 +- test/ChangeLog | 6 ++++++ test/automated/python-tests.el | 23 ++++++++++++++++++++++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d69ea7c..847a335 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-11-06 Nathan Trapuzzano + + * progmodes/python.el (python-indent-calculate-indentation): When + determining indentation, don't treat "return", "pass", etc., as + operators when they are just string constituents. (Bug#15812) + 2013-11-06 Eli Zaretskii * menu-bar.el (popup-menu, menu-bar-open): When displaying TTY diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 7a90f0b..4d4c504 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -775,7 +775,7 @@ START is the buffer position where the sexp starts." (save-excursion (python-util-forward-comment -1) (python-nav-beginning-of-statement) - (member (current-word) python-indent-block-enders))) + (looking-at (regexp-opt python-indent-block-enders)))) python-indent-offset 0))) ;; When inside of a string, do nothing. just use the current diff --git a/test/ChangeLog b/test/ChangeLog index e032af4..a0ad888 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,9 @@ +2013-11-06 Nathan Trapuzzano + + * automated/python-test.el (python-indent-block-enders) + (python-indent-block-enders-1, python-indent-block-enders-2): + Rename one test, add another. + 2013-11-06 Michael Albinus * automated/tramp-tests.el (tramp-test07-file-exists-p): diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index ef1c015..798e21f 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el @@ -447,7 +447,7 @@ objects = Thing.objects.all() \\\\ (should (eq (car (python-indent-context)) 'after-line)) (should (= (python-indent-calculate-indentation) 0)))) -(ert-deftest python-indent-block-enders () +(ert-deftest python-indent-block-enders-1 () "Test `python-indent-block-enders' value honoring." (python-tests-with-temp-buffer " @@ -469,6 +469,27 @@ Class foo(object): (forward-line 1) (should (= (python-indent-calculate-indentation) 8)))) +(ert-deftest python-indent-block-enders-2 () + "Test `python-indent-block-enders' value honoring." + (python-tests-with-temp-buffer + " +Class foo(object): + '''raise lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do + + eiusmod tempor incididunt ut labore et dolore magna aliqua. + ''' + def bar(self): + \"return (1, 2, 3).\" + if self.baz: + return (1, + 2, + 3) +" + (python-tests-look-at "def") + (should (= (python-indent-calculate-indentation) 4)) + (python-tests-look-at "if") + (should (= (python-indent-calculate-indentation) 8)))) + ;;; Navigation -- 1.8.4.2