From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Matthew Woodcraft Newsgroups: gmane.emacs.bugs Subject: bug#22661: 25.0.91; python.el electric-indent misbehaviour with 'else:' and nested 'if:' Date: Sat, 21 Jan 2017 17:34:57 +0000 Message-ID: <87d1fgiaf2.fsf@golux.woodcraft.me.uk> References: <878trky4d9.fsf@topbug.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1485020204 29391 195.159.176.226 (21 Jan 2017 17:36:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 21 Jan 2017 17:36:44 +0000 (UTC) To: 22661@debbugs.gnu.org, Hong Xu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jan 21 18:36:27 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 1cUzaE-0006CE-GV for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Jan 2017 18:36:10 +0100 Original-Received: from localhost ([::1]:32784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUzaJ-0005Lr-L0 for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Jan 2017 12:36:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUzaB-0005Li-5c for bug-gnu-emacs@gnu.org; Sat, 21 Jan 2017 12:36:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cUza6-0005C2-7j for bug-gnu-emacs@gnu.org; Sat, 21 Jan 2017 12:36:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39513) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cUza6-0005By-3m for bug-gnu-emacs@gnu.org; Sat, 21 Jan 2017 12:36:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cUza5-0005nR-Uk for bug-gnu-emacs@gnu.org; Sat, 21 Jan 2017 12:36:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Matthew Woodcraft Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Jan 2017 17:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22661 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22661-submit@debbugs.gnu.org id=B22661.148502010522213 (code B ref 22661); Sat, 21 Jan 2017 17:36:01 +0000 Original-Received: (at 22661) by debbugs.gnu.org; 21 Jan 2017 17:35:05 +0000 Original-Received: from localhost ([127.0.0.1]:37712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUzZB-0005mC-1T for submit@debbugs.gnu.org; Sat, 21 Jan 2017 12:35:05 -0500 Original-Received: from hark.woodcraft.me.uk ([213.138.109.203]:58369) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUzZ9-0005m4-Qc for 22661@debbugs.gnu.org; Sat, 21 Jan 2017 12:35:04 -0500 Original-Received: from cpc92320-cmbg19-2-0-cust4086.5-4.cable.virginm.net ([82.13.79.247] helo=golux.woodcraft.me.uk) by hark.woodcraft.me.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1cUzZ8-0005Y5-Ey; Sat, 21 Jan 2017 17:35:02 +0000 Original-Received: from mjw by golux.woodcraft.me.uk with local (Exim 4.84_2) (envelope-from ) id 1cUzZ3-0004x3-5f; Sat, 21 Jan 2017 17:34:57 +0000 In-Reply-To: <878trky4d9.fsf@topbug.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:128297 Archived-At: Hong Xu writes: >> If I have the following code and add the colon after the 'else', >> python.el's electric-indent moves the 'else' to align with the inner >> 'if'. >> def foo() >> if aaa: >> if bbb: >> x = 1 >> y = 1 >> else > I've attached a patch to fix this issue: It is caused by incorrect > detection of opening blocks. > > From: Hong Xu > Date: Mon, 12 Dec 2016 17:55:25 -0800 > Subject: [PATCH] python-mode: Fix detection for opening blocks (bug# 22661). > > * python.el (python-info-dedenter-opening-block-positions): There > can't be any back-indented lines between an opening block and the > current line. I have tested this patch and it does fix the case I posted. But it misbehaves if I add a blank line before the 'else': def foo() if aaa: if bbb: x = 1 y = 1 else Now when I add the colon after the 'else', electric-indent moves the 'else' to align with the 'def'. I agree that python-info-dedenter-opening-block-positions is the right thing to fix. I think it's sufficient to look at the last nonblank line above the current line, rather than all lines between the candidate opening block and the current line. -M-