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: Sun, 22 Jan 2017 16:50:22 -0800 Message-ID: <3defc94b-3d38-95ec-1d18-e272a412f5fc@topbug.net> References: <878trky4d9.fsf@topbug.net> <87d1fgiaf2.fsf@golux.woodcraft.me.uk> <877f5nu9qn.fsf@topbug.net> <87fukavgks.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="SBtGWBmhgmdFjEWF2vJnlVBRvxHKQvij4" X-Trace: blaine.gmane.org 1485132687 8182 195.159.176.226 (23 Jan 2017 00:51:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 23 Jan 2017 00:51:27 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 Cc: matthew@woodcraft.me.uk, 22661@debbugs.gnu.org To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 23 01:51:19 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 1cVSqh-0000cC-1P for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Jan 2017 01:51:07 +0100 Original-Received: from localhost ([::1]:38347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVSqm-0006DO-80 for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Jan 2017 19:51:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVSqf-0006D6-By for bug-gnu-emacs@gnu.org; Sun, 22 Jan 2017 19:51:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVSqc-0003O2-9f for bug-gnu-emacs@gnu.org; Sun, 22 Jan 2017 19:51:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40379) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cVSqc-0003Nv-6R for bug-gnu-emacs@gnu.org; Sun, 22 Jan 2017 19:51:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cVSqb-0003a4-RG for bug-gnu-emacs@gnu.org; Sun, 22 Jan 2017 19:51: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: Mon, 23 Jan 2017 00:51: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.148513264513737 (code B ref 22661); Mon, 23 Jan 2017 00:51:01 +0000 Original-Received: (at 22661) by debbugs.gnu.org; 23 Jan 2017 00:50:45 +0000 Original-Received: from localhost ([127.0.0.1]:38578 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cVSqL-0003ZU-30 for submit@debbugs.gnu.org; Sun, 22 Jan 2017 19:50:45 -0500 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:21402) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cVSqJ-0003ZL-Eg for 22661@debbugs.gnu.org; Sun, 22 Jan 2017 19:50:43 -0500 Original-Received: from [192.168.88.88] (cpe-104-32-170-214.socal.res.rr.com [104.32.170.214]) by mx.zohomail.com with SMTPS id 148513262929281.81154260124549; Sun, 22 Jan 2017 16:50:29 -0800 (PST) In-Reply-To: <87fukavgks.fsf@users.sourceforge.net> 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:128318 Archived-At: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --SBtGWBmhgmdFjEWF2vJnlVBRvxHKQvij4 Content-Type: multipart/mixed; boundary="wPJUQhFhQ8Wlmux0b3Uh5FKm1wop4MRl4"; protected-headers="v1" From: Hong Xu To: npostavs@users.sourceforge.net Cc: matthew@woodcraft.me.uk, 22661@debbugs.gnu.org Message-ID: <3defc94b-3d38-95ec-1d18-e272a412f5fc@topbug.net> Subject: Re: bug#22661: 25.0.91; python.el electric-indent misbehaviour with 'else:' and nested 'if:' References: <878trky4d9.fsf@topbug.net> <87d1fgiaf2.fsf@golux.woodcraft.me.uk> <877f5nu9qn.fsf@topbug.net> <87fukavgks.fsf@users.sourceforge.net> In-Reply-To: <87fukavgks.fsf@users.sourceforge.net> --wPJUQhFhQ8Wlmux0b3Uh5FKm1wop4MRl4 Content-Type: multipart/mixed; boundary="------------8F85076FB666C68BCD6F59B4" This is a multi-part message in MIME format. --------------8F85076FB666C68BCD6F59B4 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01/22/2017 03:08 PM, npostavs@users.sourceforge.net wrote: >=20 > I think it's better to maximize the range of save-match-data, i.e., hav= e > it cover as much code as practical between the place that sets the matc= h > data and the place that uses the it, rather than minimizing the range s= o > that it only covers functions which modify match data (because the > default assumption in Emacs is that functions may modify match data > unless they say otherwise). In this case, I would put it around the > `and` in the line above. >=20 Thanks. I've attached a newer version with tests with all the issues fixe= d. --------------8F85076FB666C68BCD6F59B4 Content-Type: text/x-patch; name="0001-python-mode-Fix-detection-for-opening-blocks.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-python-mode-Fix-detection-for-opening-blocks.patch" =46rom 1f2108514c14339ff2db5fea2d1b35c3538b2efd 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. * python-tests.el (python-indent-electric-colon-4): Add an indent test case where there is one-more indented previous opening block. --- lisp/progmodes/python.el | 20 ++++++++++++++++++-- test/lisp/progmodes/python-tests.el | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d8262dd0a750..90b5e4e0dc67 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -4693,7 +4693,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"))) @@ -4709,7 +4710,22 @@ 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-ind= entations)))) + (< indentation (apply #'min collected-ind= entations))) + ;; 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)) + (save-match-data + (while (and (< (point) cur-line) + (setq no-back-indent + (or (> (current-inden= tation) indentation) + (python-info-curr= ent-line-empty-p)))) + (forward-line))) + no-back-indent))) (setq collected-indentations (cons indentation collected-indentations)) (when (member (match-string-no-properties 0) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/py= thon-tests.el index 2df1bbf50d81..158c52f080c4 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -1156,6 +1156,27 @@ python-tests-visible-string (python-tests-look-at "that)") (should (=3D (current-indentation) 6)))) =20 +(ert-deftest python-indent-electric-colon-4 () + "Test indentation case where there is one more-indented previous open = block." + (python-tests-with-temp-buffer + " +def f(): + if True: + a =3D 5 + + if True: + a =3D 10 + + b =3D 3 + +else +" + (python-tests-look-at "else") + (goto-char (line-end-position)) + (python-tests-self-insert ":") + (python-tests-look-at "else" -1) + (should (=3D (current-indentation) 4)))) + (ert-deftest python-indent-region-1 () "Test indentation case from Bug#18843." (let ((contents " --=20 2.1.4 --------------8F85076FB666C68BCD6F59B4-- --wPJUQhFhQ8Wlmux0b3Uh5FKm1wop4MRl4-- --SBtGWBmhgmdFjEWF2vJnlVBRvxHKQvij4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYhVNUAAoJECZsfTOCL4R4UWoP/1E/Ck/3SjwRHpZUgzdHJnu5 H6HlzjCIbhp965PrU1EOQn6+Jl2MIpt5Go0hbrB+3nmSYV51coxMKN/bGryxgdry ubCyTwJR6xDqsng4vkqCIAn9S3jpcn5dQdah8xAZr9+vlP+iELBVyANdA5zIdbSp WbP22r3RtFn76B3iaL4UwcnvG7HbRpQUPYJByDIfd+bYkPgqJWaEVErjFKTYQqet HnRn2b2LPXX1ss+xowb2H/YjS4YmFOHo3Xq26KDp+VPGVUmFrlkjH4r9x0Kfgq5Z dVKcpnAARrNXjvBb0z6P7m7BjCManOya9IAs+59LAE06wr3fyN3LZuU3DX5wLJ+q WNQNBnKBESeEcco02u369ZxJ9XarVuIZryysRRz0azLPDYM8YkPK0yJtazwa6QjQ dSXi+bCHfLPzD1js7Q9LLsyBkX6Oz2+gnZs+IaqF0a3LnHGNehkGHnJqVbV813SW nnDz5kquJ9DgNX8spMv9puHoh2IrndUkn0vI5ofjXwK7IQ4tkTaTe8sOyWl+5fea vNOeARaefBnRnS3qRWCBRGOa8qP0/SVvt520cIGs53JdFH2w/4b7G0+eEc/YnZkr KxtpiQt+VSMzU8PwUNG3e/iTacu87WRIon++XWCm8o2GBGquVdQrrSYs3OEf02VB NtjnWB1/Xr5qsUR2XY8V =QceS -----END PGP SIGNATURE----- --SBtGWBmhgmdFjEWF2vJnlVBRvxHKQvij4--