mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-25 07:28:20 +00:00
Improve indenting "case" in Python
* lisp/progmodes/python.el (python-info-dedenter-statement-p): Do not consider the first "case" in the block as dedenter. * test/lisp/progmodes/python-tests.el (python-info-dedenter-opening-block-positions-7) (python-info-dedenter-statement-p-6): New tests. (Bug#62092)
This commit is contained in:
parent
c4d490490d
commit
8f42db010d
@ -5854,7 +5854,14 @@ statement."
|
||||
(save-excursion
|
||||
(python-nav-beginning-of-statement)
|
||||
(when (and (not (python-syntax-context-type))
|
||||
(looking-at (python-rx dedenter)))
|
||||
(looking-at (python-rx dedenter))
|
||||
;; Exclude the first "case" in the block.
|
||||
(not (and (string= (match-string-no-properties 0)
|
||||
"case")
|
||||
(save-excursion
|
||||
(back-to-indentation)
|
||||
(python-util-forward-comment -1)
|
||||
(equal (char-before) ?:)))))
|
||||
(point))))
|
||||
|
||||
(defun python-info-line-ends-backslash-p (&optional line-number)
|
||||
|
@ -5940,6 +5940,26 @@ def func():
|
||||
(equal (list (python-tests-look-at "if (" -1 t))
|
||||
(python-info-dedenter-opening-block-positions)))))
|
||||
|
||||
(ert-deftest python-info-dedenter-opening-block-positions-7 ()
|
||||
"Test case blocks."
|
||||
(python-tests-with-temp-buffer
|
||||
"
|
||||
match a:
|
||||
case 1:
|
||||
match b:
|
||||
case 2:
|
||||
something()
|
||||
case 3:
|
||||
"
|
||||
(python-tests-look-at "case 1:")
|
||||
(should-not (python-info-dedenter-opening-block-positions))
|
||||
(python-tests-look-at "case 2:")
|
||||
(should-not (python-info-dedenter-opening-block-positions))
|
||||
(python-tests-look-at "case 3:")
|
||||
(equal (list (python-tests-look-at "case 2:" -1)
|
||||
(python-tests-look-at "case 1:" -1 t))
|
||||
(python-info-dedenter-opening-block-positions))))
|
||||
|
||||
(ert-deftest python-info-dedenter-opening-block-message-1 ()
|
||||
"Test dedenters inside strings are ignored."
|
||||
(python-tests-with-temp-buffer
|
||||
@ -6125,6 +6145,24 @@ elif b:
|
||||
(point))
|
||||
(python-info-dedenter-statement-p)))))
|
||||
|
||||
(ert-deftest python-info-dedenter-statement-p-6 ()
|
||||
"Test case keyword."
|
||||
(python-tests-with-temp-buffer
|
||||
"
|
||||
match a: # Comment
|
||||
case 1:
|
||||
match b:
|
||||
case 2:
|
||||
something()
|
||||
case 3:
|
||||
"
|
||||
(python-tests-look-at "case 1:")
|
||||
(should-not (python-info-dedenter-statement-p))
|
||||
(python-tests-look-at "case 2:")
|
||||
(should-not (python-info-dedenter-statement-p))
|
||||
(python-tests-look-at "case 3:")
|
||||
(should (= (point) (python-info-dedenter-statement-p)))))
|
||||
|
||||
(ert-deftest python-info-line-ends-backslash-p-1 ()
|
||||
(python-tests-with-temp-buffer
|
||||
"
|
||||
|
Loading…
Reference in New Issue
Block a user