]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix syntax check in python-info-looking-at-beginning-of-defun
authorkobarity <kobarity@gmail.com>
Fri, 23 Sep 2022 15:39:53 +0000 (17:39 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 23 Sep 2022 15:39:53 +0000 (17:39 +0200)
* lisp/progmodes/python.el
(python-info-looking-at-beginning-of-defun): Check syntax after moving
to the beginning of line.
* test/lisp/progmodes/python-tests.el (python-nav-beginning-of-defun-6)
(python-end-of-defun-1, python-info-looking-at-beginning-of-defun-3):
New tests (bug#58023).

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

index d5ff059cc8ee2ab5b06c15c6341c129a57b42073..80c5b31b6eaba9c88b5291be2c020f285ee169ea 100644 (file)
@@ -5505,11 +5505,11 @@ operator."
   "Check if point is at `beginning-of-defun' using SYNTAX-PPSS.
 When CHECK-STATEMENT is non-nil, the current statement is checked
 instead of the current physical line."
-  (and (not (python-syntax-context-type (or syntax-ppss (syntax-ppss))))
-       (save-excursion
-         (when check-statement
-           (python-nav-beginning-of-statement))
-         (beginning-of-line 1)
+  (save-excursion
+    (when check-statement
+      (python-nav-beginning-of-statement))
+    (beginning-of-line 1)
+    (and (not (python-syntax-context-type (or syntax-ppss (syntax-ppss))))
          (looking-at python-nav-beginning-of-defun-regexp))))
 
 (defun python-info-looking-at-beginning-of-block ()
index 20a7a0132a8659112f30dc7ef07e79e853e590c2..fdaedb5fd7ab0cf32f1f5d5159a01b6f38f8c771 100644 (file)
@@ -2342,6 +2342,21 @@ class C:
                 (beginning-of-line)
                 (point))))))
 
+(ert-deftest python-nav-beginning-of-defun-6 ()
+  (python-tests-with-temp-buffer
+   "
+class C:
+    def foo(self):
+        pass
+"
+   (python-tests-look-at "self")
+   (should (= (save-excursion
+                (python-nav-beginning-of-defun)
+                (point))
+              (save-excursion
+                (beginning-of-line)
+                (point))))))
+
 (ert-deftest python-nav-end-of-defun-1 ()
   (python-tests-with-temp-buffer
    "
@@ -2472,6 +2487,26 @@ def \\
               (save-excursion
                 (point-max))))))
 
+(ert-deftest python-end-of-defun-1 ()
+  (python-tests-with-temp-buffer
+   "
+class C:
+    def a(self
+          ):
+        pass
+
+    def b(self):
+        pass
+"
+   (should (= (save-excursion
+                (python-tests-look-at "def a")
+                (end-of-defun)
+                (point))
+              (save-excursion
+                (python-tests-look-at "def b")
+                (forward-line -1)
+                (point))))))
+
 (ert-deftest python-nav-backward-defun-1 ()
   (python-tests-with-temp-buffer
    "
@@ -5734,6 +5769,19 @@ def \\
    (should (not (python-info-looking-at-beginning-of-defun)))
    (should (not (python-info-looking-at-beginning-of-defun nil t)))))
 
+(ert-deftest python-info-looking-at-beginning-of-defun-3 ()
+  (python-tests-with-temp-buffer
+   "
+def foo(arg=\"default\"):  # Comment
+    pass
+"
+   (python-tests-look-at "arg")
+   (should (python-info-looking-at-beginning-of-defun))
+   (python-tests-look-at "default")
+   (should (python-info-looking-at-beginning-of-defun))
+   (python-tests-look-at "Comment")
+   (should (python-info-looking-at-beginning-of-defun))))
+
 (ert-deftest python-info-looking-at-beginning-of-block-1 ()
   (python-tests-with-temp-buffer
    "