diff options
| author | kobarity <kobarity@gmail.com> | 2023-06-18 23:47:25 +0900 |
|---|---|---|
| committer | Eli Zaretskii <eliz@gnu.org> | 2023-06-24 15:11:39 +0300 |
| commit | 9c2cbfa49db96eae95bb40c5fc3ce7f09781a97d (patch) | |
| tree | 2c894775d3092898b6ef6cd993b66e64256aab8d /lisp/progmodes/python.el | |
| parent | 5b7e999e24f6cd446961ac441f69af021528623b (diff) | |
Fix Python indentation of continuation lines within parens
* lisp/progmodes/python.el (python-indent-context): Add a new indent
context `:inside-paren-continuation-line'.
(python-indent--calculate-indentation): Use the new indent context.
* test/lisp/progmodes/python-tests.el (python-indent-pep8-2)
(python-indent-pep8-3)
(python-indent-inside-paren-1)
(python-indent-inside-paren-2)
(python-indent-inside-paren-3)
(python-indent-inside-paren-6)
(python-indent-after-backslash-2): Change to use the new indent
context.
(python-indent-inside-paren-8)
(python-indent-inside-paren-9): New tests. (Bug#63959)
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 26dafde7591..50d712ebb0c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1406,6 +1406,10 @@ keyword - Point is inside a paren from a block start followed by some items on the same line. - START is the first non space char position *after* the open paren. +:inside-paren-continuation-line + - Point is on a continuation line inside a paren. + - START is the position where the previous line (excluding lines + for inner parens) starts. :after-backslash - Fallback case when point is after backslash. @@ -1460,7 +1464,21 @@ keyword (= (line-number-at-pos) (progn (python-util-forward-comment) - (line-number-at-pos)))))))) + (line-number-at-pos))))))) + (continuation-start + (when start + (save-excursion + (forward-line -1) + (back-to-indentation) + ;; Skip inner parens. + (cl-loop with prev-start = (python-syntax-context 'paren) + while (and prev-start (>= prev-start start)) + if (= prev-start start) + return (point) + else do (goto-char prev-start) + (back-to-indentation) + (setq prev-start + (python-syntax-context 'paren))))))) (when start (cond ;; Current line only holds the closing paren. @@ -1476,6 +1494,9 @@ keyword (back-to-indentation) (python-syntax-closing-paren-p)) (cons :inside-paren-at-closing-nested-paren start)) + ;; This line is a continuation of the previous line. + (continuation-start + (cons :inside-paren-continuation-line continuation-start)) ;; This line starts from an opening block in its own line. ((save-excursion (goto-char start) @@ -1591,7 +1612,8 @@ possibilities can be narrowed to specific indentation points." (`(,(or :after-line :after-comment :inside-string - :after-backslash) . ,start) + :after-backslash + :inside-paren-continuation-line) . ,start) ;; Copy previous indentation. (goto-char start) (current-indentation)) |
