]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Python mode error caused by incorrect indentation
authorkobarity <kobarity@gmail.com>
Sat, 16 Sep 2023 14:14:45 +0000 (23:14 +0900)
committerEshel Yaron <me@eshelyaron.com>
Sat, 8 Jun 2024 13:01:14 +0000 (15:01 +0200)
* lisp/progmodes/python.el (python-indent--calculate-indentation):
Guard against negative indentation.  (Bug #65870)

* test/lisp/progmodes/python-tests.el
(python-indent-badly-indented-block-end): New test.

(cherry picked from commit c03cafba390603de653def097fdcf9566d502061)

lisp/progmodes/python.el
test/lisp/progmodes/python-tests.el

index b5c00385ef3b299ca30766f22f573e17e5bdcd82..bb2bf1731b40047c12a5b8f8e91a31bc96157bc0 100644 (file)
@@ -1819,7 +1819,7 @@ possibilities can be narrowed to specific indentation points."
         (`(:after-block-end . ,start)
          ;; Subtract one indentation level.
          (goto-char start)
-         (- (current-indentation) python-indent-offset))
+         (max 0 (- (current-indentation) python-indent-offset)))
         (`(:at-dedenter-block-start . ,_)
          ;; List all possible indentation levels from opening blocks.
          (let ((opening-block-start-points
index 73fbd9a5bba5043ccc9533477dac75aa97f7112a..f8873bdd0dbd139595d96901d52158c61a478a99 100644 (file)
@@ -2116,6 +2116,15 @@ def test_re(string):
    (python-tests-look-at "else:")
    (should (= (python-indent-calculate-indentation) 4))))
 
+(ert-deftest python-indent-badly-indented-block-end ()
+  "Test BUG 65870 regression."
+  (python-tests-with-temp-buffer
+   "
+return
+"
+   (goto-char (point-max))
+   (should (= (python-indent-calculate-indentation) 0))))
+
 \f
 ;;; Filling