From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net 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 18:08:03 -0500 Message-ID: <87fukavgks.fsf@users.sourceforge.net> References: <878trky4d9.fsf@topbug.net> <87d1fgiaf2.fsf@golux.woodcraft.me.uk> <877f5nu9qn.fsf@topbug.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1485126510 12344 195.159.176.226 (22 Jan 2017 23:08:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 22 Jan 2017 23:08:30 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: Matthew Woodcraft , 22661@debbugs.gnu.org To: Hong Xu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 23 00:08:24 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 1cVRFF-0002U9-CK for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Jan 2017 00:08:21 +0100 Original-Received: from localhost ([::1]:38092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVRFK-0007Dt-Jw for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Jan 2017 18:08:26 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVRF1-00077p-Fb for bug-gnu-emacs@gnu.org; Sun, 22 Jan 2017 18:08:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVREw-0004Av-EI for bug-gnu-emacs@gnu.org; Sun, 22 Jan 2017 18:08:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40364) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cVREw-0004Ar-Al for bug-gnu-emacs@gnu.org; Sun, 22 Jan 2017 18:08:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cVREw-00014n-3C for bug-gnu-emacs@gnu.org; Sun, 22 Jan 2017 18:08:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 22 Jan 2017 23:08:02 +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.14851264254070 (code B ref 22661); Sun, 22 Jan 2017 23:08:02 +0000 Original-Received: (at 22661) by debbugs.gnu.org; 22 Jan 2017 23:07:05 +0000 Original-Received: from localhost ([127.0.0.1]:38563 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cVRE0-00013a-QN for submit@debbugs.gnu.org; Sun, 22 Jan 2017 18:07:04 -0500 Original-Received: from mail-it0-f42.google.com ([209.85.214.42]:34811) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cVRDz-000134-6A for 22661@debbugs.gnu.org; Sun, 22 Jan 2017 18:07:03 -0500 Original-Received: by mail-it0-f42.google.com with SMTP id k200so20448410itb.1 for <22661@debbugs.gnu.org>; Sun, 22 Jan 2017 15:07:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=yc891PlfibALPijXTzv5JLscyq1n8A+nbTDQh3hXUBE=; b=HsfdeGvhprIy+zorrmA3lUVIeSLmho6Y9MufDTEnDD388VTW5wdI8JfYKwygDszaMZ 8kYfJifegqKOw4112rmCmlnLQDGI3LBUywdhdOYqUG1pLojnUq1xuZYD6yfvYP1kM+FK /6P8nrVcwFRvy73mickFqeW0HKMDexkkVTRtg4evMvawjg+pfKEMKniGyu2TSxCagCsk a0+zjIZOTY9lg4EfHJjOdKI7SiSy3gv4T2HsmdYMjPuKLiwA+2u17gI4WIEPfRP/tJDr 2q1ZYTPtVcQrYUe9zOOw/bp4LcacjSwFc0m3lwFR2s5BbWHvtogJR7c48+G7AfQ39uKB qCYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=yc891PlfibALPijXTzv5JLscyq1n8A+nbTDQh3hXUBE=; b=lCbMU56tWHe42/fVfBeZXYvNlylyQmMquHCPLsAkMhLMyqHy+abT/Aze1CfQkEBvSl 3s7VUwy59ejeMk7qUJnCAaJWgFFoQnoTD6o45aFrhFF6gjDsqqU5M2bwdLJgITEzUESL WI9aYpvwMK06jyuY+oCicf2i9P1DLfUCRdvOgHG3b9vfCqPrXIIeXgdygT1lp9nAkOGr IgGgNrhxfm4+LGCpevrc7rIbKJDzPnyZttekUmqg5ru3LZz9GIjMzgDnFwv+bZdhwN4m vyDFGDIH1YmBdB9fMZIWl0zKPc+5/OmzQi29KMEthOCMEMVGT/F5rNPmVAZzBkroLsws R/GA== X-Gm-Message-State: AIkVDXIAla8+yEDoZuzN9XqTEjMzEYc9iUBTvWZm/Sfm3UKxpCwjNlcEZv+cdpY9lfxLUw== X-Received: by 10.36.17.7 with SMTP id 7mr12952278itf.113.1485126417544; Sun, 22 Jan 2017 15:06:57 -0800 (PST) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id 184sm7652361itx.0.2017.01.22.15.06.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Jan 2017 15:06:56 -0800 (PST) In-Reply-To: <877f5nu9qn.fsf@topbug.net> (Hong Xu's message of "Sat, 21 Jan 2017 18:08:48 -0800") 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:128317 Archived-At: Hong Xu writes: > 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. Looks good, with a minor adjustment I suggested below. Adding a test would be nice too. > --- > 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 > --- 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) > - (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)) I think it's better to maximize the range of save-match-data, i.e., have it cover as much code as practical between the place that sets the match data and the place that uses the it, rather than minimizing the range so 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. > (or (not collected-indentations) > - (< indentation (apply #'min collected-indentations)))) > + (< indentation (apply #'min collected-indentations))) > + ;; 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-indentation) indentation) > + (save-match-data > + (python-info-current-line-empty-p))))) > + (forward-line)) > + no-back-indent))) > (setq collected-indentations > (cons indentation collected-indentations)) > (when (member (match-string-no-properties 0)