From 7dc2fb6a1e28a58c19b0ee0a5463e00ca7e8f6fb Mon Sep 17 00:00:00 2001 From: kobarity Date: Mon, 13 Jan 2025 22:38:42 +0900 Subject: [PATCH] Fix string end search in python-nav-end-of-statement * 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 | 7 +++++-- test/lisp/progmodes/python-tests.el | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 5f35dd40468..221ef745ce1 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -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) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 10bf7897039..dead3ab7346 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -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 " -- 2.39.5