From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#62031: 29.0.60; python-mode indentation after re.match Date: Wed, 8 Mar 2023 19:57:36 +0200 Message-ID: <69793abf-3d2f-2dbe-698b-877ededfc56b@yandex.ru> References: <5ea3a37a-4e43-4ede-9f96-7159f54272e8@yandex.ru> <87bkl4y5gw.fsf@metapensiero.it> <87wn3rk7bk.fsf@metapensiero.it> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27059"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Cc: Rob Moss To: Lele Gaifax , 62031@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 08 18:58:26 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZy3W-0006uG-2e for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Mar 2023 18:58:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZy3C-0003yj-5o; Wed, 08 Mar 2023 12:58:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZy38-0003xR-RE for bug-gnu-emacs@gnu.org; Wed, 08 Mar 2023 12:58:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZy38-00041v-ED for bug-gnu-emacs@gnu.org; Wed, 08 Mar 2023 12:58:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pZy38-0003Jk-0e for bug-gnu-emacs@gnu.org; Wed, 08 Mar 2023 12:58:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 08 Mar 2023 17:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62031 X-GNU-PR-Package: emacs Original-Received: via spool by 62031-submit@debbugs.gnu.org id=B62031.167829826612727 (code B ref 62031); Wed, 08 Mar 2023 17:58:01 +0000 Original-Received: (at 62031) by debbugs.gnu.org; 8 Mar 2023 17:57:46 +0000 Original-Received: from localhost ([127.0.0.1]:50157 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pZy2r-0003JC-N2 for submit@debbugs.gnu.org; Wed, 08 Mar 2023 12:57:46 -0500 Original-Received: from mail-ed1-f44.google.com ([209.85.208.44]:35500) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pZy2q-0003It-3X for 62031@debbugs.gnu.org; Wed, 08 Mar 2023 12:57:44 -0500 Original-Received: by mail-ed1-f44.google.com with SMTP id u9so69188586edd.2 for <62031@debbugs.gnu.org>; Wed, 08 Mar 2023 09:57:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678298258; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=s2llRNQ/S0HS6Jfc7QU7StYjfaCgLitUoaBZkQ2lfwM=; b=KDpAcxiKUmGbBl/8AtmhwvH3ePb23GpXxya/d85BDQkelsldZQcNJ/8tGqMTfAziGT VhxrmeM5cuRD+0xJ9zMDiCCAnVAnijn530Mgzob4Q3sLTwNXtdPcIQtlUD+HedrqiyTX F3OohMFP1fvAgby329Riv1v63I6EXlnPZaVtIbYzfB3P8m/9XWlGMTopY608Y9yKG0yp 14B9FXLIEKn8S8adn3ssTbR7xij+5viLE5kFDBYGIev8M1UGYrrOuaNg0vDaNDtOQodv bzMPnqfMnKy8aZzwhGWQU+aFT35v5LmWpnmtUN3UxJuA2kiYf4qrJhbF2wA39DrhAuuj L0hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678298258; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=s2llRNQ/S0HS6Jfc7QU7StYjfaCgLitUoaBZkQ2lfwM=; b=pkv0arQkY4paEIeUkvE21UupgfdDI3fqEkVyl2btht0srFJk7UInwpGkDLK+FcbFG2 c+cLIHD6CXqfCTkFSP8sXDHML23/NBywXNpYr9kHvoCI6zPIzjyvBoRD5bzya5rLfuG4 oVHwNy4hSToXx2gTQh+idH+fW+wO2nf6Lt5qRbk1QdOD28eA6i84pijxqKEUV0gD/cnf J74Nr8HMpUKkHHJCkR7EEIwvVqPHhAU8RS0I0V2blPoBwzyLMEVo6D/ItBG/qwPdT08K irTDog3GnB8JtstyifguMNNpZuGPDWzGKeLxuQvwHZ9XwfQY62CMdAWswUGV9UXLEOO7 f1hA== X-Gm-Message-State: AO0yUKXymJpgHLSd3wJKT53HI6zmIFjczUYIAGL3r2IyfSX+SLj645lh K6wimGKZ5Jm37ldnEqlu3kk= X-Google-Smtp-Source: AK7set9x797WjicTR0T7ZRROz6YLEQVoYnm498Z7VcY8/zfHLEMLDrJfzSEqZUjLmtY7EsuI6yFGtQ== X-Received: by 2002:aa7:d6d8:0:b0:4a0:af87:b3ab with SMTP id x24-20020aa7d6d8000000b004a0af87b3abmr14981953edr.36.1678298258224; Wed, 08 Mar 2023 09:57:38 -0800 (PST) Original-Received: from [192.168.0.2] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id b31-20020a509f22000000b004eb16b75b93sm3648909edf.49.2023.03.08.09.57.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Mar 2023 09:57:37 -0800 (PST) Content-Language: en-US In-Reply-To: <87wn3rk7bk.fsf@metapensiero.it> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:257555 Archived-At: On 08/03/2023 09:53, Lele Gaifax wrote: > I had a quick glance at this, and while I can confirm the problem with > the following test > > diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el > index 4f24c042c6a..9926c4b002f 100644 > --- a/test/lisp/progmodes/python-tests.el > +++ b/test/lisp/progmodes/python-tests.el > @@ -1982,6 +1982,17 @@ python-virt-bin > (should (eq (car (python-indent-context)) :after-block-start)) > (should (= (python-indent-calculate-indentation) 8)))) > > +(ert-deftest python-indent-after-re-match () > + "Test BUG 62031 regression." > + (python-tests-with-temp-buffer > + " > +def test_re(string): > + if re.match('^[a-c]+$', string): > + print('yes') > + else: > +" > + (python-tests-look-at "else:") > + (should (= (python-indent-calculate-indentation) 4)))) > > I could not figure out how this can be fixed, with my current knowledge > on python.el. > > There are several places where the regexp produced by `(python-rx > block-start)' is used, many within a `(looking-at ...)' form and several > others in a `(re-search-forward ...)': given that block starting > "keywords" are required to be at the beginning of a line, possibly > preceded by whitespace, I think that the problem may arise from those > usages which do not explicitly enforce the constraint, but unfortunately > all my attempts to do that a) didn't make the test above green and b) > broke one or more of the other tests. Right, the problem is that we need some post-check for block-start searches. python-rx (like rx in general) is just a syntax for Emacs regexp, and it doesn't support lookbehind or etc. After some edebug-ing, the patch below seems to fix this case. Maybe other uses of (python-rx block-start) need this treatment as well, but I'd like to leave that to someone who comes later. And a lot of them happen after a (back-to-indentation) call, so those seem covered too. diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 1f970633bfc..aff8dc206b4 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5792,7 +5792,9 @@ python-info-dedenter-opening-block-positions (catch 'exit (while (python-nav--syntactically (lambda () - (re-search-backward (python-rx block-start) nil t)) + (cl-loop do (re-search-backward (python-rx block-start) nil t) + until (memq (char-before) '(nil ?\s ?\t ?\n)) + finally return (point))) #'<) (let ((indentation (current-indentation))) (when (and (not (memq indentation collected-indentations))