From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ross Donaldson Newsgroups: gmane.emacs.bugs Subject: bug#28475: 25.3; python double-indents multi-line function argument blocks Date: Sun, 24 Sep 2017 16:25:48 +0000 Message-ID: References: <87tvzsmgep.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a11354582bda58d0559f1e585" X-Trace: blaine.gmane.org 1506270432 30987 195.159.176.226 (24 Sep 2017 16:27:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 24 Sep 2017 16:27:12 +0000 (UTC) Cc: 28475@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 24 18:27:07 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dw9kI-0007in-8c for geb-bug-gnu-emacs@m.gmane.org; Sun, 24 Sep 2017 18:27:06 +0200 Original-Received: from localhost ([::1]:38732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dw9kP-0000Hl-L1 for geb-bug-gnu-emacs@m.gmane.org; Sun, 24 Sep 2017 12:27:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dw9kH-0000GJ-FV for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2017 12:27:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dw9kE-0008RT-5n for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2017 12:27:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47592) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dw9kE-0008RL-1J for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2017 12:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dw9kD-0005S5-Ll for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2017 12:27:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ross Donaldson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 24 Sep 2017 16:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28475 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 28475-submit@debbugs.gnu.org id=B28475.150627036820895 (code B ref 28475); Sun, 24 Sep 2017 16:27:01 +0000 Original-Received: (at 28475) by debbugs.gnu.org; 24 Sep 2017 16:26:08 +0000 Original-Received: from localhost ([127.0.0.1]:56273 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dw9jL-0005Qw-Ga for submit@debbugs.gnu.org; Sun, 24 Sep 2017 12:26:07 -0400 Original-Received: from mail-pg0-f44.google.com ([74.125.83.44]:50795) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dw9jK-0005QT-78 for 28475@debbugs.gnu.org; Sun, 24 Sep 2017 12:26:06 -0400 Original-Received: by mail-pg0-f44.google.com with SMTP id p5so2778592pgn.7 for <28475@debbugs.gnu.org>; Sun, 24 Sep 2017 09:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=E+KJbRgBqcFfLayUvqTdEL+LZMomtR5RLOQ/s8DlGfI=; b=I7MtyTiNWL5X+T7ykMu8ytGByImGt2hPwUwhHHPlhHf41uEFafcsvFEK9K617od7sZ xw42AhSK6SNrwrbqQF0SvslToSdU23jBv35GXk1KatI9fVr9A1WpDjWWABZgRIZCcvRM WbYuLVkWYF6wmTUODlifVKQoeqChfpbCTN+LQtcIl/KSCDe5En8PrgqSK7ltIhqb1734 4U1AeCSLGvPiwmskrrioT+/5vfFXsYzqAEJxqayAm4vedUjISKkJPadK3w3cVSgrZ/A7 G49/oyGz/CX4QS4yLMoP/8wQpaf9hr95Lgqt6iadPQ9OFCybu0MQLiWDRJ1zxA8WySJ4 Y2zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=E+KJbRgBqcFfLayUvqTdEL+LZMomtR5RLOQ/s8DlGfI=; b=DsAnyiPtTxA2OD/uMlF1wr5HE+dshatN77pEmYrSy7M9Hr9S6qswmkRlFlcuFmqOg9 4ewLUK0W/xGsv7clT0muPAzVXYxDX9UM3a7EmbFPBcrkl7y5BapL/ep/1ncXgJqu5rvH Hp9V0f4NYbSQppGHQykM8dd+4Rx/4AcsqoMc0xbFQvA0AP2Hu9u5T4entTIn5y0Ue4dh dtGFrX7Pf7hlHDd/OJE5NaFIRmLDqnUG9KuUf3iCLVU93sOdFdk0Y9XrR8NgEU+INPH9 f3ABo3Rk4+vR6Ov8KPa2v+BXfCLs8+WXlQHPyBnz55lNiFBKXqpumeu+jhFG4qfNAp0d XvzQ== X-Gm-Message-State: AHPjjUgcSbDC/6xKUCMPZpV+JgfiXUrEwc8BJ8txR9hFg7qzdy3U0+Fd xVqs+fPonFiZqAtjfQ5VbQLCcX1fc5fpDQ9+qqE= X-Google-Smtp-Source: AOwi7QANUq3pDFI9LVZag0VBmTaHyLaygZSQK3EfC6KSY625Le6VbisvJtHS6snxa6fEg8C6iqrmt4bX09soMeAAvF0= X-Received: by 10.98.103.89 with SMTP id b86mr4858492pfc.319.1506270359952; Sun, 24 Sep 2017 09:25:59 -0700 (PDT) In-Reply-To: <87tvzsmgep.fsf@users.sourceforge.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:137345 Archived-At: --001a11354582bda58d0559f1e585 Content-Type: text/plain; charset="UTF-8" First: apologies for the whitespace cleanup, but yes, you correctly figured out what the bug report was intended to be. Thanks! I was thrown off by the `prog-FOO` commands because of this message in the ChangeLog: ``` 2016-03-27 Dmitry Gutov Remove prog-indentation-context * lisp/progmodes/prog-mode.el: (prog-indentation-context) (prog-first-column, prog-widen): Remove, as discussed in http://lists.gnu.org/archive/html/emacs-devel/2016-03/msg01425.html. ``` But I see you are correct, and only `prog-indentation-context` was removed. I haven't assigned copyright to Emacs yet; I'd be happy to, and also, I suspect this patch will be quite short. I'll send it over soon. On Sun, Sep 24, 2017 at 5:26 AM Noam Postavsky < npostavs@users.sourceforge.net> wrote: > Ross Donaldson writes: > > > python-mode double-indents the arguments to function definitions. > > > > To reproduce: > > 1. emacs -Q > > 2. Enter the following: > > It seems your email client dropped the whitespace, but I guess you meant > > # This is fine: > def foo(arg): > print('hello') > > # This is indented double: > def foo( > bar, > baz > ): > print('hello') > > # It should be: > def foo( > bar, > baz > ): > print('hello') > > # Only seems to be true for `def`s so far, eg: > baz = list( > 'good' > ) > > > > This is caused by the function `python-indent--calculate-indentation`, > > line ~1023 of `python.el`. Frustratingly, the behavior is hardcoded, > > and apparently intentional, as we see at the end of the function: > > > > ``` > > (`(,(or :inside-paren-newline-start-from-block) . ,start) > > ;; Add two indentation levels to make the suite stand out. > > (goto-char start) > > (+ (current-indentation) (* python-indent-offset 2))) > > ``` > > > > This is problematic. Python's holy grail of style, PEP-8, does not > > specify how this indentation should be done. However, many companies > > which write python -- like my employer -- create internal style guides > > to fill in gaps left by PEP-8. So far, in my career, they *all* > > indicate a single indent to be appropriate in this context. > > > > I'd like to propose two solutions; I don't know which will suit best: > > > > 1. Stop doubling indentation > > 2. Make the indent scaling integer a variable, so that this behavior can > be changed. > > I think the latter will be best, in case some people want the current > indentation still. > > > A final complication for me is that, at least on `master` of the > > Github emacs-mirror (https://github.com/emacs-mirror/emacs), this > > function still uses `prog-widen` and `prog-first-column`, which have > > been removed from emacs. I'm not sure how to correctly patch this > > function to remove them. > > I think it's rather that `prog-widen' and `prog-first-column' have been > *added* to Emacs. > > > So! With a little guidance on `prog-widen`/`prog-first-column`, I'm > > happy to create and submit a patch, or I can leave this in y'all's > > capable hands. > > If you can build from the git checkout write your patch against the > emacs-26 branch then you should be able to use the prog-FOO functions. > Otherwise, just write it against 25.3, it should be easy enough to > update the patch afterwards, if needed. > > Have you assigned copyright to Emacs? If the patch ends up more than > about 15 lines we won't be able to accept it until you do. I guess just > adding and using the new custom variable should fit within that limit > though. > --001a11354582bda58d0559f1e585 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
First: apologies for the whitespace cleanup, but yes, you = correctly figured out what the bug report was intended to be. Thanks!
<= br>
I was thrown off by the `prog-FOO` commands because of this m= essage in the ChangeLog:

```
2016-0= 3-27=C2=A0 Dmitry Gutov=C2=A0 <dguto= v@yandex.ru>

Remove prog-indentation-context

* lisp/progmodes/prog-mode.el: (prog-indent= ation-context)
(prog-firs= t-column, prog-widen): Remove, as discussed in
```

But I= see you are correct, and only `prog-indentation-context` was removed.=C2= =A0

I haven't assigned copyright to Emacs yet;= I'd be happy to, and also, I suspect this patch will be quite short. I= 'll send it over soon.

On Sun, Sep 24, 2017 at 5:26 AM Noam Postavsky <npostavs@users.sourceforge.net>= wrote:
Ross Donaldson <gastove@gmail.com> w= rites:

> python-mode double-indents the arguments to function definitions.
>
> To reproduce:
> 1. emacs -Q
> 2. Enter the following:

It seems your email client dropped the whitespace, but I guess you meant
# This is fine:
def foo(arg):
=C2=A0 =C2=A0 print('hello')

# This is indented double:
def foo(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 bar,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 baz
):
=C2=A0 =C2=A0 print('hello')

# It should be:
def foo(
=C2=A0 =C2=A0 bar,
=C2=A0 =C2=A0 baz
):
=C2=A0 =C2=A0 print('hello')

# Only seems to be true for `def`s so far, eg:
baz =3D list(
=C2=A0 =C2=A0 'good'
)


> This is caused by the function `python-indent--calculate-indentation`,=
> line ~1023 of `python.el`. Frustratingly, the behavior is hardcoded, > and apparently intentional, as we see at the end of the function:
>
> ```
> (`(,(or :inside-paren-newline-start-from-block) . ,start)
> ;; Add two indentation levels to make the suite stand out.
> (goto-char start)
> (+ (current-indentation) (* python-indent-offset 2)))
> ```
>
> This is problematic. Python's holy grail of style, PEP-8, does not=
> specify how this indentation should be done. However, many companies > which write python -- like my employer -- create internal style guides=
> to fill in gaps left by PEP-8. So far, in my career, they *all*
> indicate a single indent to be appropriate in this context.
>
> I'd like to propose two solutions; I don't know which will sui= t best:
>
> 1. Stop doubling indentation
> 2. Make the indent scaling integer a variable, so that this behavior c= an be changed.

I think the latter will be best, in case some people want the current
indentation still.

> A final complication for me is that, at least on `master` of the
> Github emacs-mirror (https://github.com/emacs-mirror/emacs= ), this
> function still uses `prog-widen` and `prog-first-column`, which have > been removed from emacs. I'm not sure how to correctly patch this<= br> > function to remove them.

I think it's rather that `prog-widen' and `prog-first-column' h= ave been
*added* to Emacs.

> So! With a little guidance on `prog-widen`/`prog-first-column`, I'= m
> happy to create and submit a patch, or I can leave this in y'all&#= 39;s
> capable hands.

If you can build from the git checkout write your patch against the
emacs-26 branch then you should be able to use the prog-FOO functions.
Otherwise, just write it against 25.3, it should be easy enough to
update the patch afterwards, if needed.

Have you assigned copyright to Emacs?=C2=A0 If the patch ends up more than<= br> about 15 lines we won't be able to accept it until you do.=C2=A0 I gues= s just
adding and using the new custom variable should fit within that limit
though.
--001a11354582bda58d0559f1e585--