aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorkobarity2023-06-18 23:47:25 +0900
committerEli Zaretskii2023-06-24 15:11:39 +0300
commit9c2cbfa49db96eae95bb40c5fc3ce7f09781a97d (patch)
tree2c894775d3092898b6ef6cd993b66e64256aab8d /lisp/progmodes/python.el
parent5b7e999e24f6cd446961ac441f69af021528623b (diff)
downloademacs-9c2cbfa49db96eae95bb40c5fc3ce7f09781a97d.tar.gz
emacs-9c2cbfa49db96eae95bb40c5fc3ce7f09781a97d.zip
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.el26
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
1406 - Point is inside a paren from a block start followed by some 1406 - Point is inside a paren from a block start followed by some
1407 items on the same line. 1407 items on the same line.
1408 - START is the first non space char position *after* the open paren. 1408 - START is the first non space char position *after* the open paren.
1409:inside-paren-continuation-line
1410 - Point is on a continuation line inside a paren.
1411 - START is the position where the previous line (excluding lines
1412 for inner parens) starts.
1409 1413
1410:after-backslash 1414:after-backslash
1411 - Fallback case when point is after backslash. 1415 - Fallback case when point is after backslash.
@@ -1460,7 +1464,21 @@ keyword
1460 (= (line-number-at-pos) 1464 (= (line-number-at-pos)
1461 (progn 1465 (progn
1462 (python-util-forward-comment) 1466 (python-util-forward-comment)
1463 (line-number-at-pos)))))))) 1467 (line-number-at-pos)))))))
1468 (continuation-start
1469 (when start
1470 (save-excursion
1471 (forward-line -1)
1472 (back-to-indentation)
1473 ;; Skip inner parens.
1474 (cl-loop with prev-start = (python-syntax-context 'paren)
1475 while (and prev-start (>= prev-start start))
1476 if (= prev-start start)
1477 return (point)
1478 else do (goto-char prev-start)
1479 (back-to-indentation)
1480 (setq prev-start
1481 (python-syntax-context 'paren)))))))
1464 (when start 1482 (when start
1465 (cond 1483 (cond
1466 ;; Current line only holds the closing paren. 1484 ;; Current line only holds the closing paren.
@@ -1476,6 +1494,9 @@ keyword
1476 (back-to-indentation) 1494 (back-to-indentation)
1477 (python-syntax-closing-paren-p)) 1495 (python-syntax-closing-paren-p))
1478 (cons :inside-paren-at-closing-nested-paren start)) 1496 (cons :inside-paren-at-closing-nested-paren start))
1497 ;; This line is a continuation of the previous line.
1498 (continuation-start
1499 (cons :inside-paren-continuation-line continuation-start))
1479 ;; This line starts from an opening block in its own line. 1500 ;; This line starts from an opening block in its own line.
1480 ((save-excursion 1501 ((save-excursion
1481 (goto-char start) 1502 (goto-char start)
@@ -1591,7 +1612,8 @@ possibilities can be narrowed to specific indentation points."
1591 (`(,(or :after-line 1612 (`(,(or :after-line
1592 :after-comment 1613 :after-comment
1593 :inside-string 1614 :inside-string
1594 :after-backslash) . ,start) 1615 :after-backslash
1616 :inside-paren-continuation-line) . ,start)
1595 ;; Copy previous indentation. 1617 ;; Copy previous indentation.
1596 (goto-char start) 1618 (goto-char start)
1597 (current-indentation)) 1619 (current-indentation))