From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Hong Xu Newsgroups: gmane.emacs.bugs Subject: bug#22661: 25.0.91; python.el electric-indent misbehaviour with 'else:' and nested 'if:' Date: Mon, 12 Dec 2016 18:01:06 -0800 Message-ID: <878trky4d9.fsf@topbug.net> References: <87a8n3z0ac.fsf@golux.woodcraft.me.uk> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1481594533 2640 195.159.176.226 (13 Dec 2016 02:02:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 13 Dec 2016 02:02:13 +0000 (UTC) User-Agent: mu4e 0.9.18; emacs 25.1.90.9 Cc: matthew@woodcraft.me.uk To: 22661@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Dec 13 03:02:07 2016 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 1cGcPu-00087q-VI for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Dec 2016 03:02:07 +0100 Original-Received: from localhost ([::1]:34829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGcPz-000760-8D for geb-bug-gnu-emacs@m.gmane.org; Mon, 12 Dec 2016 21:02:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGcPt-00075u-K9 for bug-gnu-emacs@gnu.org; Mon, 12 Dec 2016 21:02:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cGcPq-0003hc-I4 for bug-gnu-emacs@gnu.org; Mon, 12 Dec 2016 21:02:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cGcPq-0003hW-Fd for bug-gnu-emacs@gnu.org; Mon, 12 Dec 2016 21:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cGcPq-0001kv-0Q for bug-gnu-emacs@gnu.org; Mon, 12 Dec 2016 21:02:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87a8n3z0ac.fsf@golux.woodcraft.me.uk> Resent-From: Hong Xu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Dec 2016 02:02: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.14815944826705 (code B ref 22661); Tue, 13 Dec 2016 02:02:01 +0000 Original-Received: (at 22661) by debbugs.gnu.org; 13 Dec 2016 02:01:22 +0000 Original-Received: from localhost ([127.0.0.1]:39863 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGcPC-0001k5-AM for submit@debbugs.gnu.org; Mon, 12 Dec 2016 21:01:22 -0500 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:21357) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGcPA-0001jw-JG for 22661@debbugs.gnu.org; Mon, 12 Dec 2016 21:01:20 -0500 Original-Received: from localhost (cpe-104-32-170-214.socal.res.rr.com [104.32.170.214]) by mx.zohomail.com with SMTPS id 1481594473126759.2157075553487; Mon, 12 Dec 2016 18:01:13 -0800 (PST) X-Zoho-Virus-Status: 1 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:126955 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain > 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-python-mode-Fix-detection-for-opening-blocks.patch 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. --- lisp/progmodes/python.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d0d4a7f766ef..8d3bd3194151 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -4660,7 +4660,8 @@ python-info-dedenter-opening-block-positions (let ((dedenter-pos (python-info-dedenter-statement-p))) (when dedenter-pos (goto-char dedenter-pos) - (let* ((pairs '(("elif" "elif" "if") + (let* ((cur-line (line-beginning-position)) + (pairs '(("elif" "elif" "if") ("else" "if" "elif" "except" "for" "while") ("except" "except" "try") ("finally" "else" "except" "try"))) @@ -4676,7 +4677,18 @@ python-info-dedenter-opening-block-positions (let ((indentation (current-indentation))) (when (and (not (memq indentation collected-indentations)) (or (not collected-indentations) - (< indentation (apply #'min collected-indentations)))) + (< indentation (apply #'min collected-indentations))) + ;; There must be no line with indentation smaller than + ;; `indentation' between the found opening block and the + ;; current line, otherwise it is not an opening block. + (save-excursion + (forward-line) + (let ((no-back-indent t)) + (while (and (< (point) cur-line) + (setq no-back-indent + (> (current-indentation) indentation))) + (forward-line)) + no-back-indent))) (setq collected-indentations (cons indentation collected-indentations)) (when (member (match-string-no-properties 0) --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJYT1ZiAAoJECZsfTOCL4R4/7MQAKmMs4Zd/LrM9IrAi9P9fqpK RBcbG2yoZHqtnh14m497Bl+qwLEp7jHcLBkdELpVlYpy/sIMvCVBXdmbLnITIyyL sa/scrLeb/fzUZ6A5Oln0yv8ofY8nRfGOxJCZ5L4WXO/p0foiHQVQi1x6PJBNDKz Nvs+yz7nfW/SNvgOlaZqnF/R29W9vDp/DqHVjKD1E5tvZa7cEamq10rT2HQEjVzr DDleWJMY3RLmJytO2bw9mitssQaHRe1K9Jczr1RTaYXclpl8NjQbaFclShI66zeX L6VJTUwbcTNGuhVDlvSGl2KF/5Xl4INnDkjJF/sV2X+RbUoCde+gAXq+x36wX2UY PKJhZdnAJz6DNlv7KKt3fk/xxxdjA7nQFKPoSAA+GbH32Ztg488m3VCRicfjl9fO Roj80dWIgBNmRDwUwt20+8wiEN/gaK9BEmgKLrMbnVX2y8FeBbxJI2ys7nY0ltz/ qZx4EkYQ0GdKUawM59MQej/vMgDfg7/YDMk54fX4JHI4HeC6ikxbzIv2QkEiJVnW Moio0UNU41GGJ8Fk3Lr6Z1+SRnaZqRnEoWBHRpxewtzxJ6NQC9vdvJebspBMU4rJ 4vXkIgG0gyJJSYvKIM8YcwGFIpBi0g0EX47YKehzw8rKlDz2Pw4JAmCB5xmtVUXB Nnj3JYu+QzWJn2fhpM3I =33g/ -----END PGP SIGNATURE----- --==-=-=--