GNU bug report logs -
#20742
24.5; python mode indentation fails pep8
Previous Next
Reported by: Tommi Komulainen <tommi.komulainen <at> iki.fi>
Date: Fri, 5 Jun 2015 15:22:02 UTC
Severity: normal
Tags: fixed, patch
Merged with 19906
Found in version 24.5
Fixed in version 27.1
Done: Noam Postavsky <npostavs <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
From da684af7265bf40e4140328c36011fea6b040373 Mon Sep 17 00:00:00 2001
From: Tommi Komulainen <tommi.komulainen <at> iki.fi>
Date: Fri, 19 Jun 2015 18:53:52 +0200
Subject: [PATCH] python.el: fix close paren indentation to match pep8
When opening paren is followed by newline the closing paren should follow
the current indentation. Otherwise the closing paren should be aligned
with the opening paren. This fixes the latter case. #20742
---
lisp/progmodes/python.el | 12 +++++++++---
test/automated/python-tests.el | 42 +++++++++++++++++++++++++++++++++---------
2 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index de2d2d1..013a565 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -952,12 +952,18 @@ possibilities can be narrowed to specific
indentation points."
(`(,(or :after-line
:after-comment
:inside-string
- :after-backslash
- :inside-paren-at-closing-paren
- :inside-paren-at-closing-nested-paren) . ,start)
+ :after-backslash) . ,start)
;; Copy previous indentation.
(goto-char start)
(current-indentation))
+ (`(,(or :inside-paren-at-closing-paren
+ :inside-paren-at-closing-nested-paren) . ,start)
+ (goto-char (+ 1 start))
+ (if (looking-at "[ \t]*\\(?:#\\|$\\)")
+ ;; Copy previous indentation.
+ (current-indentation)
+ ;; Align with opening paren.
+ (current-column)))
(`(,(or :after-block-start
:after-backslash-first-line
:inside-paren-newline-start) . ,start)
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index 42c26fc..f35f188 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -171,16 +171,28 @@ aliqua."
"First pep8 case."
(python-tests-with-temp-buffer
"# Aligned with opening delimiter
-foo = long_function_name(var_one, var_two,
- var_three, var_four)
+foo = long_function_name(var_one=[var_two, # comment
+ var_three
+ ],
+ var_four=0,
+ )
"
(should (eq (car (python-indent-context)) :no-indent))
(should (= (python-indent-calculate-indentation) 0))
- (python-tests-look-at "foo = long_function_name(var_one, var_two,")
+ (python-tests-look-at "foo = long_function_name(var_one")
(should (eq (car (python-indent-context)) :after-comment))
(should (= (python-indent-calculate-indentation) 0))
- (python-tests-look-at "var_three, var_four)")
+ (python-tests-look-at "var_three")
(should (eq (car (python-indent-context)) :inside-paren))
+ (should (= (python-indent-calculate-indentation) 34))
+ (python-tests-look-at "]")
+ (should (eq (car (python-indent-context))
:inside-paren-at-closing-nested-paren))
+ (should (= (python-indent-calculate-indentation) 34))
+ (python-tests-look-at "var_four")
+ (should (eq (car (python-indent-context)) :inside-paren))
+ (should (= (python-indent-calculate-indentation) 25))
+ (python-tests-look-at ")")
+ (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
(should (= (python-indent-calculate-indentation) 25))))
(ert-deftest python-indent-pep8-2 ()
@@ -215,20 +227,32 @@ def long_function_name(
(python-tests-with-temp-buffer
"# Extra indentation is not necessary.
foo = long_function_name(
- var_one, var_two,
- var_three, var_four)
+ var_one, var_two=[ # comment
+ var_three,
+ ],
+ var_four=0,
+)
"
(should (eq (car (python-indent-context)) :no-indent))
(should (= (python-indent-calculate-indentation) 0))
(python-tests-look-at "foo = long_function_name(")
(should (eq (car (python-indent-context)) :after-comment))
(should (= (python-indent-calculate-indentation) 0))
- (python-tests-look-at "var_one, var_two,")
+ (python-tests-look-at "var_one")
(should (eq (car (python-indent-context)) :inside-paren-newline-start))
(should (= (python-indent-calculate-indentation) 4))
- (python-tests-look-at "var_three, var_four)")
+ (python-tests-look-at "var_three")
(should (eq (car (python-indent-context)) :inside-paren-newline-start))
- (should (= (python-indent-calculate-indentation) 4))))
+ (should (= (python-indent-calculate-indentation) 8))
+ (python-tests-look-at "]")
+ (should (eq (car (python-indent-context))
:inside-paren-at-closing-nested-paren))
+ (should (= (python-indent-calculate-indentation) 4))
+ (python-tests-look-at "var_four")
+ (should (eq (car (python-indent-context)) :inside-paren-newline-start))
+ (should (= (python-indent-calculate-indentation) 4))
+ (python-tests-look-at ")")
+ (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
+ (should (= (python-indent-calculate-indentation) 0))))
(ert-deftest python-indent-base-case ()
"Check base case does not trigger errors."
--
2.4.4
This bug report was last modified 6 years and 22 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.