diff options
author | kobarity <kobarity@gmail.com> | 2023-04-16 22:18:39 +0900 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2023-04-22 12:28:37 +0300 |
commit | 711e8bc7178d5dd78f4db5c34b2b23f605521fc4 (patch) | |
tree | c0098a8c508081e051274b0c6c965cedc23aed2b /test | |
parent | 2f013c46f7116d53468de78c00903c87d100bbd9 (diff) | |
download | emacs-711e8bc7178d5dd78f4db5c34b2b23f605521fc4.tar.gz |
Add a new user option in Python mode to improve the indentation
* lisp/progmodes/python.el (python-indent-block-paren-deeper): New
user option.
(python-indent-context): Add a new context :inside-paren-from-block.
(python-indent--calculate-indentation): Modify according to
`python-indent-block-paren-deeper' and :inside-paren-from-block.
* test/lisp/progmodes/python-tests.el
(python-indent-inside-paren-block-1)
(python-indent-inside-paren-block-2)
(python-indent-inside-paren-block-3)
(python-indent-inside-paren-block-4): New tests.
(python-indent-inside-paren-5, python-indent-dedenters-8): Modify
according to the new context.
* etc/NEWS: Document the new user option. (Bug#62696)
Diffstat (limited to 'test')
-rw-r--r-- | test/lisp/progmodes/python-tests.el | 116 |
1 files changed, 114 insertions, 2 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 50153e66da5..60b11d572cf 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -1139,7 +1139,7 @@ while ((not some_condition) and (should (eq (car (python-indent-context)) :no-indent)) (should (= (python-indent-calculate-indentation) 0)) (forward-line 1) - (should (eq (car (python-indent-context)) :inside-paren)) + (should (eq (car (python-indent-context)) :inside-paren-from-block)) (should (= (python-indent-calculate-indentation) 7)) (forward-line 1) (should (eq (car (python-indent-context)) :after-block-start)) @@ -1174,6 +1174,118 @@ CHOICES = (('some', 'choice'), ;; This signals an error if the test fails (should (eq (car (python-indent-context)) :inside-paren-newline-start)))) +(ert-deftest python-indent-inside-paren-block-1 () + "`python-indent-block-paren-deeper' set to nil (default). +See Bug#62696." + (python-tests-with-temp-buffer + " +if ('VALUE' in my_unnecessarily_long_dictionary and + some_other_long_condition_case): + do_something() +elif (some_case or + another_case): + do_another() +" + (python-tests-look-at "if") + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-from-block)) + (should (= (python-indent-calculate-indentation) 4)) + (forward-line 1) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4)) + (forward-line 1) + (should (eq (car (python-indent-context)) :at-dedenter-block-start)) + (should (= (python-indent-calculate-indentation) 0)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-from-block)) + (should (= (python-indent-calculate-indentation) 6)) + (forward-line 1) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4)))) + +(ert-deftest python-indent-inside-paren-block-2 () + "`python-indent-block-paren-deeper' set to t. +See Bug#62696." + (python-tests-with-temp-buffer + " +if ('VALUE' in my_unnecessarily_long_dictionary and + some_other_long_condition_case): + do_something() +elif (some_case or + another_case): + do_another() +" + (let ((python-indent-block-paren-deeper t)) + (python-tests-look-at "if") + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-from-block)) + (should (= (python-indent-calculate-indentation) 8)) + (forward-line 1) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4)) + (forward-line 1) + (should (eq (car (python-indent-context)) :at-dedenter-block-start)) + (should (= (python-indent-calculate-indentation) 0)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-from-block)) + (should (= (python-indent-calculate-indentation) 6)) + (forward-line 1) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4))))) + +(ert-deftest python-indent-inside-paren-block-3 () + "With backslash. `python-indent-block-paren-deeper' set to nil (default). +See Bug#62696." + (python-tests-with-temp-buffer + " +if 'VALUE' in my_uncessarily_long_dictionary and\\ + (some_other_long_condition_case or + another_case): + do_something() +" + (python-tests-look-at "if") + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (forward-line 1) + (should (eq (car (python-indent-context)) + :after-backslash-block-continuation)) + (should (= (python-indent-calculate-indentation) 3)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-from-block)) + (should (= (python-indent-calculate-indentation) 4)) + (forward-line 1) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4)))) + +(ert-deftest python-indent-inside-paren-block-4 () + "With backslash. `python-indent-block-paren-deeper' set to t. +See Bug#62696." + (python-tests-with-temp-buffer + " +if 'VALUE' in my_uncessarily_long_dictionary and\\ + (some_other_long_condition_case or + another_case): + do_something() +" + (let ((python-indent-block-paren-deeper t)) + (python-tests-look-at "if") + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (forward-line 1) + (should (eq (car (python-indent-context)) + :after-backslash-block-continuation)) + (should (= (python-indent-calculate-indentation) 3)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-from-block)) + (should (= (python-indent-calculate-indentation) 8)) + (forward-line 1) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4))))) + (ert-deftest python-indent-after-block-1 () "The most simple after-block case that shouldn't fail." (python-tests-with-temp-buffer @@ -1670,7 +1782,7 @@ a == 4): (should (= (python-indent-calculate-indentation) 0)) (should (= (python-indent-calculate-indentation t) 0)) (python-tests-look-at "a == 4):\n") - (should (eq (car (python-indent-context)) :inside-paren)) + (should (eq (car (python-indent-context)) :inside-paren-from-block)) (should (= (python-indent-calculate-indentation) 6)) (python-indent-line) (should (= (python-indent-calculate-indentation t) 4)) |