]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Python navigation problem with a line continuation using backslash
authorkobarity <kobarity@gmail.com>
Sat, 23 Jul 2022 08:26:33 +0000 (10:26 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 23 Jul 2022 08:26:33 +0000 (10:26 +0200)
* lisp/progmodes/python.el (python-nav--beginning-of-defun): Fix
line continuation using backslash in nested defun (bug#56615).

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

index f31832fec9c02da2c0e1fdf6f38f2cdebb8de057..ec7d65722009636a5ff99a350613a3b3ca617e8d 100644 (file)
@@ -1459,8 +1459,11 @@ With positive ARG search backwards, else search forwards."
                             (current-indentation)))
          (body-indentation
           (and (> arg 0)
-               (or (and (python-info-looking-at-beginning-of-defun)
-                        (+ (current-indentation) python-indent-offset))
+               (or (and (python-info-looking-at-beginning-of-defun nil t)
+                        (+ (save-excursion
+                             (python-nav-beginning-of-statement)
+                             (current-indentation))
+                           python-indent-offset))
                    (save-excursion
                      (while
                          (and
index b2cccdd95694e5f7f683ab717ad8d67e0ce4b7c2..3b10bde23bc7efabd7ca1a1ac0becfb197d2b948 100644 (file)
@@ -1995,6 +1995,32 @@ def c():
                 (beginning-of-line)
                 (point))))))
 
+(ert-deftest python-nav-beginning-of-defun-5 ()
+  (python-tests-with-temp-buffer
+   "
+class C:
+
+    def \\
+            m(self):
+        pass
+"
+   (python-tests-look-at "m(self):")
+   (should (= (save-excursion
+                (python-nav-beginning-of-defun)
+                (point))
+              (save-excursion
+                (python-tests-look-at "def \\" -1)
+                (beginning-of-line)
+                (point))))
+   (python-tests-look-at "class C:" -1)
+   (should (= (save-excursion
+                (python-nav-beginning-of-defun -1)
+                (point))
+              (save-excursion
+                (python-tests-look-at "def \\")
+                (beginning-of-line)
+                (point))))))
+
 (ert-deftest python-nav-end-of-defun-1 ()
   (python-tests-with-temp-buffer
    "