summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkobarity <kobarity@gmail.com>2023-03-10 14:26:22 +0900
committerDmitry Gutov <dgutov@yandex.ru>2023-03-11 15:18:47 +0200
commitc0cf69f7a17b657c784518434e1a049ce6970a43 (patch)
tree762ed7c3862345a08310a65940c199e1aff78f7b
parentdb178517ce73618f7a659e355639893748db2e45 (diff)
downloademacs-c0cf69f7a17.tar.gz
Make "case" keyword a dedenter in Python
* lisp/progmodes/python.el (python-rx): Add "case" to dedenter. (python-info-dedenter-opening-block-positions): Add "case" to pairs. * test/lisp/progmodes/python-tests.el (python-indent-dedenters-9): New test.
-rw-r--r--lisp/progmodes/python.el5
-rw-r--r--test/lisp/progmodes/python-tests.el15
2 files changed, 18 insertions, 2 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 1980815bae9..8793fdc6458 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -426,7 +426,7 @@ This variant of `rx' supports common Python named REGEXPS."
(or "def" "for" "with")))
symbol-end))
(dedenter (seq symbol-start
- (or "elif" "else" "except" "finally")
+ (or "elif" "else" "except" "finally" "case")
symbol-end))
(block-ender (seq symbol-start
(or
@@ -5783,7 +5783,8 @@ likely an invalid python file."
(pairs '(("elif" "elif" "if")
("else" "if" "elif" "except" "for" "while")
("except" "except" "try")
- ("finally" "else" "except" "try")))
+ ("finally" "else" "except" "try")
+ ("case" "case")))
(dedenter (match-string-no-properties 0))
(possible-opening-blocks (cdr (assoc-string dedenter pairs)))
(collected-indentations)
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 2568299bb66..e5a9d128bc5 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -1658,6 +1658,21 @@ a == 4):
(python-indent-line t)
(should (= (python-indent-calculate-indentation t) 6))))
+(ert-deftest python-indent-dedenters-9 ()
+ "Test de-indentation for the case keyword."
+ (python-tests-with-temp-buffer
+ "
+match a:
+ case 1:
+ print(1)
+ case 2
+"
+ (python-tests-look-at "case 2")
+ (should (eq (car (python-indent-context)) :at-dedenter-block-start))
+ (should (= (python-indent-calculate-indentation) 4))
+ (python-indent-line t)
+ (should (= (python-indent-calculate-indentation t) 4))))
+
(ert-deftest python-indent-inside-string-1 ()
"Test indentation for strings."
(python-tests-with-temp-buffer