]> git.eshelyaron.com Git - emacs.git/commitdiff
python-info-dedenter-opening-block-positions: Fix to support "bare" match
authorDmitry Gutov <dgutov@yandex.ru>
Thu, 9 Mar 2023 15:24:54 +0000 (17:24 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Thu, 9 Mar 2023 15:31:21 +0000 (17:31 +0200)
* lisp/progmodes/python.el
(python-info-dedenter-opening-block-positions): Make the check
stricter.  Require that block starts only at indentation.

* test/lisp/progmodes/python-tests.el
(python-indent-after-bare-match): Another test (bug#62031).

lisp/progmodes/python.el
test/lisp/progmodes/python-tests.el

index 5b11d204de11c3a382914eeb6614a7462db64d26..1980815bae95e9576ae63419db38578840abe47a 100644 (file)
@@ -5792,7 +5792,9 @@ likely an invalid python file."
             (while (python-nav--syntactically
                     (lambda ()
                       (cl-loop while (re-search-backward (python-rx block-start) nil t)
-                               if (memq (char-before) '(nil ?\s ?\t ?\n))
+                               if (save-match-data
+                                    (looking-back (rx line-start (* whitespace))
+                                                  (line-beginning-position)))
                                return t))
                     #'<)
               (let ((indentation (current-indentation)))
index 7e2f66e9095d8411d20747e5d938cfd005eaf3a4..2568299bb665c6c34f1114970a5469fa5f9a4a1c 100644 (file)
@@ -1994,6 +1994,20 @@ def test_re(string):
    (python-tests-look-at "else:")
    (should (= (python-indent-calculate-indentation) 4))))
 
+(ert-deftest python-indent-after-bare-match ()
+  "Test BUG 62031 regression."
+  (python-tests-with-temp-buffer
+   "
+from re import match
+
+def test_re(string):
+    if match('^[a-c]+$', string):
+        print('yes')
+    else:
+    "
+   (python-tests-look-at "else:")
+   (should (= (python-indent-calculate-indentation) 4))))
+
 \f
 ;;; Filling