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: Sat, 21 Jan 2017 18:08:48 -0800 Message-ID: <877f5nu9qn.fsf@topbug.net> References: <878trky4d9.fsf@topbug.net> <87d1fgiaf2.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 1485051018 18409 195.159.176.226 (22 Jan 2017 02:10:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 22 Jan 2017 02:10:18 +0000 (UTC) User-Agent: mu4e 0.9.19; emacs 25.1.91.8 Cc: 22661@debbugs.gnu.org To: Matthew Woodcraft Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jan 22 03:10:14 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 1cV7bd-0003kL-3D for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Jan 2017 03:10:09 +0100 Original-Received: from localhost ([::1]:34105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cV7be-0007V7-Tx for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Jan 2017 21:10:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cV7bZ-0007Ux-5H for bug-gnu-emacs@gnu.org; Sat, 21 Jan 2017 21:10:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cV7bV-0005E8-UD for bug-gnu-emacs@gnu.org; Sat, 21 Jan 2017 21:10:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39675) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cV7bV-0005E0-RU for bug-gnu-emacs@gnu.org; Sat, 21 Jan 2017 21:10:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cV7bV-0000rm-Iu for bug-gnu-emacs@gnu.org; Sat, 21 Jan 2017 21:10:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Hong Xu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 22 Jan 2017 02:10: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.14850509423255 (code B ref 22661); Sun, 22 Jan 2017 02:10:01 +0000 Original-Received: (at 22661) by debbugs.gnu.org; 22 Jan 2017 02:09:02 +0000 Original-Received: from localhost ([127.0.0.1]:37874 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cV7aY-0000qR-2L for submit@debbugs.gnu.org; Sat, 21 Jan 2017 21:09:02 -0500 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:21373) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cV7aW-0000q2-5g for 22661@debbugs.gnu.org; Sat, 21 Jan 2017 21:09:00 -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 1485050932000180.90958886618023; Sat, 21 Jan 2017 18:08:52 -0800 (PST) In-reply-to: <87d1fgiaf2.fsf@golux.woodcraft.me.uk> 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:128306 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain On 2017-01-21 Sat 09:34 GMT-0800, Matthew Woodcraft wrote: > > 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- Thanks for your suggestion, Matthew. I've now fixed it in the new patch as attached. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-python-mode-Fix-detection-for-opening-blocks.patch Content-Transfer-Encoding: quoted-printable From=20b9b742e15174de6abe5134427964fe4e0f852461 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Mon, 12 Dec 2016 17:55:25 -0800 Subject: [PATCH] python-mode: Fix detection for opening blocks. * python.el (python-info-dedenter-opening-block-positions): There can't be any back-indented lines between an opening block and the current line. =2D-- lisp/progmodes/python.el | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 306402d8e3b4..ae9b0890cfc2 100644 =2D-- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -4659,7 +4659,8 @@ python-info-dedenter-opening-block-positions (let ((dedenter-pos (python-info-dedenter-statement-p))) (when dedenter-pos (goto-char dedenter-pos) =2D (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"))) @@ -4675,7 +4676,22 @@ python-info-dedenter-opening-block-positions (let ((indentation (current-indentation))) (when (and (not (memq indentation collected-indentations)) (or (not collected-indentations) =2D (< indentation (apply #'min collected-ind= entations)))) + (< indentation (apply #'min collected-inden= tations))) + ;; There must be no line with indentation + ;; smaller than `indentation' (except for + ;; blank lines) 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 + (or (> (current-indentati= on) indentation) + (save-match-data + (python-info-curren= t-line-empty-p))))) + (forward-line)) + no-back-indent))) (setq collected-indentations (cons indentation collected-indentations)) (when (member (match-string-no-properties 0) =2D-=20 2.1.4 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJYhBQwAAoJECZsfTOCL4R4qSIQAMrSJBLb83MUoY5Ofkd/IxMX ahd/YF549kn/2ufkIGsPlG7gbICHQLuU7fWrSzh1pJJxEioKSMeY44Ke6V8F5Wam ADcZcy1rv89HhwwZ/tRRiMj7PA4tRCoPmIREQxJCDlJ8DA4YUKn2xejh4v2The1C EARTLbWfRsgYJt+Ip7+K9nnyElrChq0/+9f9w4V5SIOUfHgVppDIMN1EQ0cDbf1i VjM/YwsB0QF8wGdrpxZjXA7psRbPz0ngBXg8W3LBI1EBFomGaLXgMxl0AMsY8o/d +h21GYciLyKwNsUefsxTVvdGRogsNekmkLhBCh/UshRLuLp5WYO7mU7pzJLHYiIW ivJHoGR0HW06HvwhvKp7j2nA1X8qDrmDkjpiR+4FiFheKYeQvtqkXUehvnv06Qzd 7USjYGBTkEgd8XHposSmafJTBLjY070FVW59rSv1Rzr6n1UfMkIVYvQGtGR6uHlm 33i/GRTknSy7yzsvMOFgRS7B6kGjdSbbtrqeigvfARZVIWCXrr/JOKrImrwxwcO6 byiw1IFiYDxEr2VPuNgBS5Xf/DrzMF1rcz3Fg7p3CbBtT9Jb0zjDNA4hAh6VzsIF q2aW8EFdp1WiFJB6d4Kv3ZKqmQneBIZ7vwlUTt6zGmxja6BBqqPdJoW1MMeKjkfK PwJ3XwIWWy/YYBmTeiN7 =Wb7+ -----END PGP SIGNATURE----- --==-=-=--