From fcffcd724afe1a45e2c79f79ed0ca465869f10f8 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sat, 16 Sep 2023 23:14:45 +0900 Subject: [PATCH] Fix Python mode error caused by incorrect indentation * 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 | 2 +- test/lisp/progmodes/python-tests.el | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index b5c00385ef3..bb2bf1731b4 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -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 diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 73fbd9a5bba..f8873bdd0db 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -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)))) + ;;; Filling -- 2.39.2