From: Tommi Komulainen <tommi.komulainen@iki.fi>
To: 20742@debbugs.gnu.org
Subject: bug#20742: 24.5; [PATCH] python.el: fix close paren indentation to match pep8
Date: Sat, 20 Jun 2015 12:56:40 +0200 [thread overview]
Message-ID: <CAEFOACbOfz2oO1sg9MRaFg_O11NFo5MLNt9BAvRDgRt3+jz+2Q@mail.gmail.com> (raw)
In-Reply-To: <CAEFOACZwFq7T-9yginNyQ3hd72tssYykcE9wh3RXXRQQvsJ=Eg@mail.gmail.com>
From da684af7265bf40e4140328c36011fea6b040373 Mon Sep 17 00:00:00 2001
From: Tommi Komulainen <tommi.komulainen@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
next prev parent reply other threads:[~2015-06-20 10:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-05 7:58 bug#20742: 24.5; python mode indentation fails pep8 Tommi Komulainen
2015-06-05 20:16 ` Glenn Morris
2015-06-05 20:25 ` Tommi Komulainen
2015-06-08 16:28 ` Andreas Röhler
2015-06-19 17:04 ` bug#20742: Testcase for #20742 Tommi Komulainen
2015-06-20 10:56 ` Tommi Komulainen [this message]
2017-03-02 2:47 ` bug#20742: 24.5; [PATCH] python.el: fix close paren indentation to match pep8 npostavs
2019-04-20 20:51 ` Noam Postavsky
2019-04-28 20:47 ` Noam Postavsky
2020-09-17 18:59 ` bug#20560: " Lars Ingebrigtsen
2020-09-17 19:22 ` Noam Postavsky
2020-09-18 11:11 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAEFOACbOfz2oO1sg9MRaFg_O11NFo5MLNt9BAvRDgRt3+jz+2Q@mail.gmail.com \
--to=tommi.komulainen@iki.fi \
--cc=20742@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.