]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix string end search in python-nav-end-of-statement
authorkobarity <kobarity@gmail.com>
Mon, 13 Jan 2025 13:38:42 +0000 (22:38 +0900)
committerEshel Yaron <me@eshelyaron.com>
Sat, 15 Feb 2025 19:31:57 +0000 (20:31 +0100)
* lisp/progmodes/python.el (python-nav-end-of-statement):
Change to look for string delimiter characters and check
syntax, instead of looking for string-delimiter syntax.
* test/lisp/progmodes/python-tests.el
(python-nav-end-of-statement-5): New test.  (Bug#75387)

(cherry picked from commit 6491fee366f58a831689c57aa31493dd70bc2245)

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

index 5f35dd40468dcaa4dd3b2c283bdc007000fff02f..221ef745ce1b6a10027a7a7fd802ca0dfa737371 100644 (file)
@@ -2322,8 +2322,11 @@ of the statement."
                            (setq
                             last-string-end
                             (or (if (eq t (nth 3 (syntax-ppss)))
-                                    (re-search-forward
-                                     (rx (syntax string-delimiter)) nil t)
+                                    (cl-loop
+                                     while (re-search-forward
+                                            (rx (or "\"\"\"" "'''")) nil t)
+                                     unless (python-syntax-context 'string)
+                                     return (point))
                                   (ignore-error scan-error
                                     (goto-char string-start)
                                     (python-nav--lisp-forward-sexp)
index 10bf7897039dea34492c0cf8c285a02e5d32802f..dead3ab7346fd769e60d27005afd727701c45b72 100644 (file)
@@ -3171,6 +3171,30 @@ d = '''d'''
                 (python-tests-look-at "c'")
                 (pos-eol))))))
 
+(ert-deftest python-nav-end-of-statement-5 ()
+  "Test long multi-line string (Bug#75387)."
+  (let* ((line (format "%s\n" (make-string 80 ?a)))
+         (lines (apply #'concat (make-list 50 line))))
+    (python-tests-with-temp-buffer
+     (concat
+      "
+s = '''
+"
+      lines
+      "\\'''"
+      lines
+      "'''
+a = 1
+")
+     (python-tests-look-at "s = '''")
+     (should (= (save-excursion
+                  (python-nav-end-of-statement)
+                  (point))
+                (save-excursion
+                  (python-tests-look-at "a = 1")
+                  (forward-line -1)
+                  (pos-eol)))))))
+
 (ert-deftest python-nav-forward-statement-1 ()
   (python-tests-with-temp-buffer
    "