]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix blank/comment line handling in python-nav-beginning-of-block
authorkobarity <kobarity@gmail.com>
Sun, 7 Aug 2022 14:10:26 +0000 (16:10 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 7 Aug 2022 14:10:58 +0000 (16:10 +0200)
* lisp/progmodes/python.el (python-nav-beginning-of-block): Fix
handling of blank/comment line right after block start (bug#57038).

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

index 27bdbae311321cb83e6fd962cc38e9b1b27f8d9b..88b19c88cd91e5a7007f7075f416d652a5ebfa9c 100644 (file)
@@ -1761,16 +1761,16 @@ backward to previous statement."
   "Move to start of current block."
   (interactive "^")
   (let ((starting-pos (point)))
+    ;; Go to first line beginning a statement
+    (while (and (not (bobp))
+                (or (and (python-nav-beginning-of-statement) nil)
+                    (python-info-current-line-comment-p)
+                    (python-info-current-line-empty-p)))
+      (forward-line -1))
     (if (progn
           (python-nav-beginning-of-statement)
           (looking-at (python-rx block-start)))
         (point-marker)
-      ;; Go to first line beginning a statement
-      (while (and (not (bobp))
-                  (or (and (python-nav-beginning-of-statement) nil)
-                      (python-info-current-line-comment-p)
-                      (python-info-current-line-empty-p)))
-        (forward-line -1))
       (let ((block-matching-indent
              (- (current-indentation) python-indent-offset)))
         (while
index 07f2c4f09a33516aa5e5a3a61c0af2444de50b1f..eb5712269092bded8c27bdd81485fe400efd749b 100644 (file)
@@ -2734,6 +2734,28 @@ def decoratorFunctionWithArguments(arg1, arg2, arg3):
                 (point))
               (python-tests-look-at "def wwrap(f):" -1)))))
 
+(ert-deftest python-nav-beginning-of-block-2 ()
+  (python-tests-with-temp-buffer
+   "
+if True:
+
+    pass
+if False:
+    # comment
+    pass
+"
+   (python-tests-look-at "if True:")
+   (forward-line)
+   (should (= (save-excursion
+                (python-nav-beginning-of-block)
+                (point))
+              (python-tests-look-at "if True:" -1)))
+   (python-tests-look-at "# comment")
+   (should (= (save-excursion
+                (python-nav-beginning-of-block)
+                (point))
+              (python-tests-look-at "if False:" -1)))))
+
 (ert-deftest python-nav-end-of-block-1 ()
   (python-tests-with-temp-buffer
    "