[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#24809: 25.1; Python.el improper indention after backslash-assignment
From: |
npostavs |
Subject: |
bug#24809: 25.1; Python.el improper indention after backslash-assignment-continuation |
Date: |
Mon, 22 May 2017 20:47:31 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) |
From: Jules Tamagnan <jtamagnan@gmail.com>
> an_overly_long_variable_name =
> some_object.some_method(some_argument_to_some_method)
>
> could be split like this:
>
> an_overly_long_variable_name = (
> some_object.some_method(some_argument_to_some_method))
>
> or if someone wanted to use a backslash like this:
>
> an_overly_long_variable_name = \
> some_object.some_method(some_argument_to_some_method)
>
> instead of like:
>
> an_overly_long_variable_name = \
>
> some_object.some_method(some_argument_to_some_method)
> ----------
Ah, I'd been looking at stuff from the test suite which looked like:
an_overly_long_variable_name = something \
another.thing(etc)
which seems a bit neater than
an_overly_long_variable_name = something \
another.thing(etc)
but I find your example convincing. And we still have parens if the
first kind of indentation is preferred:
an_overly_long_variable_name = (something
another.thing(etc))
I actually have the fix for the tests already written anyway. I'll wait
a week or so before pushing, in case anyone else has some comments on
this.
>From 5476e881e1d302bcd40a407de0946d383012384f Mon Sep 17 00:00:00 2001
From: Jules Tamagnan <jtamagnan@gmail.com>
Date: Thu, 27 Oct 2016 15:03:31 -0700
Subject: [PATCH v2 1/3] Comply with pep 8 style guide for backslash in
assignment (Bug#24809)
* lisp/progmodes/python.el (python-indent--calculate-indentation):
Increase indent by `python-indent-offset' after
`:after-backslash-assignment-continuation'.
Copyright-paperwork-exempt: yes
---
lisp/progmodes/python.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 9cebc81bfc..02a2e4046d 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1054,13 +1054,13 @@ (defun python-indent--calculate-indentation ()
(max line-indentation base-indent)))
(`(,(or :after-block-start
:after-backslash-first-line
+ :after-backslash-assignment-continuation
:inside-paren-newline-start) . ,start)
;; Add one indentation level.
(goto-char start)
(+ (current-indentation) python-indent-offset))
(`(,(or :inside-paren
:after-backslash-block-continuation
- :after-backslash-assignment-continuation
:after-backslash-dotted-continuation) . ,start)
;; Use the column given by the context.
(goto-char start)
--
2.11.1
>From e931c8bd772be41dc4b98bc2614eacff529af195 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Mon, 22 May 2017 12:32:04 -0400
Subject: [PATCH v2 2/3] ; Update test for previous change
* test/lisp/progmodes/python-tests.el
(python-indent-after-backslash-4): Indent after backslash is now
python-indent-offset.
---
test/lisp/progmodes/python-tests.el | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/test/lisp/progmodes/python-tests.el
b/test/lisp/progmodes/python-tests.el
index cd05710000..cea597acea 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -753,8 +753,8 @@ (ert-deftest python-indent-after-backslash-4 ()
(python-tests-with-temp-buffer
"
super_awful_assignment = some_calculation() and \\\\
- another_calculation() and \\\\
- some_final_calculation()
+ another_calculation() and \\\\
+ some_final_calculation()
"
(python-tests-look-at
"super_awful_assignment = some_calculation() and \\\\")
@@ -763,10 +763,10 @@ (ert-deftest python-indent-after-backslash-4 ()
(python-tests-look-at "another_calculation() and \\\\")
(should (eq (car (python-indent-context))
:after-backslash-assignment-continuation))
- (should (= (python-indent-calculate-indentation) 25))
+ (should (= (python-indent-calculate-indentation) python-indent-offset))
(python-tests-look-at "some_final_calculation()")
(should (eq (car (python-indent-context)) :after-backslash))
- (should (= (python-indent-calculate-indentation) 25))))
+ (should (= (python-indent-calculate-indentation) python-indent-offset))))
(ert-deftest python-indent-after-backslash-5 ()
"Dotted continuation bizarre example."
--
2.11.1
v2-0003-Fix-backslashes-in-python-tests.patch
Description: patch