[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 419b873f39: Fix syntax check in python-info-looking-at-beginning-
From: |
Lars Ingebrigtsen |
Subject: |
master 419b873f39: Fix syntax check in python-info-looking-at-beginning-of-defun |
Date: |
Fri, 23 Sep 2022 11:40:42 -0400 (EDT) |
branch: master
commit 419b873f3998c32493e8ec8d18571868613e6315
Author: kobarity <kobarity@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Fix syntax check in python-info-looking-at-beginning-of-defun
* 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 | 10 ++++----
test/lisp/progmodes/python-tests.el | 48 +++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index d5ff059cc8..80c5b31b6e 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -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 ()
diff --git a/test/lisp/progmodes/python-tests.el
b/test/lisp/progmodes/python-tests.el
index 20a7a0132a..fdaedb5fd7 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -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
"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 419b873f39: Fix syntax check in python-info-looking-at-beginning-of-defun,
Lars Ingebrigtsen <=