Fix searching for end of string in python-nav-end-of-statement
* lisp/progmodes/python.el (python-nav-end-of-statement): Add searching for corresponding string-quote. * test/lisp/progmodes/python-tests.el (python-nav-end-of-statement-3) (python-nav-end-of-statement-4, python-info-current-defun-4): New tests. (Bug#58780)
This commit is contained in:
parent
7e1012765c
commit
f175141aea
2 changed files with 54 additions and 4 deletions
|
@ -2076,9 +2076,15 @@ of the statement."
|
||||||
(goto-char (+ (point)
|
(goto-char (+ (point)
|
||||||
(python-syntax-count-quotes
|
(python-syntax-count-quotes
|
||||||
(char-after (point)) (point))))
|
(char-after (point)) (point))))
|
||||||
(setq last-string-end
|
(setq
|
||||||
(or (re-search-forward
|
last-string-end
|
||||||
|
(or (if (eq t (nth 3 (syntax-ppss)))
|
||||||
|
(re-search-forward
|
||||||
(rx (syntax string-delimiter)) nil t)
|
(rx (syntax string-delimiter)) nil t)
|
||||||
|
(ignore-error scan-error
|
||||||
|
(goto-char string-start)
|
||||||
|
(python-nav--lisp-forward-sexp)
|
||||||
|
(point)))
|
||||||
(goto-char (point-max)))))))
|
(goto-char (point-max)))))))
|
||||||
((python-syntax-context 'paren)
|
((python-syntax-context 'paren)
|
||||||
;; The statement won't end before we've escaped
|
;; The statement won't end before we've escaped
|
||||||
|
|
|
@ -2955,6 +2955,36 @@ string
|
||||||
"'\n''\n"
|
"'\n''\n"
|
||||||
(python-nav-end-of-statement)))
|
(python-nav-end-of-statement)))
|
||||||
|
|
||||||
|
(ert-deftest python-nav-end-of-statement-3 ()
|
||||||
|
"Test unmatched quotes (Bug#58780)."
|
||||||
|
(python-tests-with-temp-buffer
|
||||||
|
"
|
||||||
|
' \"\"\"
|
||||||
|
v = 1
|
||||||
|
"
|
||||||
|
(python-tests-look-at "v =")
|
||||||
|
(should (= (save-excursion
|
||||||
|
(python-nav-end-of-statement)
|
||||||
|
(point))
|
||||||
|
(save-excursion
|
||||||
|
(point-max))))))
|
||||||
|
|
||||||
|
(ert-deftest python-nav-end-of-statement-4 ()
|
||||||
|
(python-tests-with-temp-buffer
|
||||||
|
"
|
||||||
|
abc = 'a\\
|
||||||
|
b\\
|
||||||
|
c'
|
||||||
|
d = '''d'''
|
||||||
|
"
|
||||||
|
(python-tests-look-at "b\\")
|
||||||
|
(should (= (save-excursion
|
||||||
|
(python-nav-end-of-statement)
|
||||||
|
(point))
|
||||||
|
(save-excursion
|
||||||
|
(python-tests-look-at "c'")
|
||||||
|
(pos-eol))))))
|
||||||
|
|
||||||
(ert-deftest python-nav-forward-statement-1 ()
|
(ert-deftest python-nav-forward-statement-1 ()
|
||||||
(python-tests-with-temp-buffer
|
(python-tests-with-temp-buffer
|
||||||
"
|
"
|
||||||
|
@ -5221,6 +5251,20 @@ def decoratorFunctionWithArguments(arg1, arg2, arg3):
|
||||||
(should (string= (python-info-current-defun t)
|
(should (string= (python-info-current-defun t)
|
||||||
"def decoratorFunctionWithArguments"))))
|
"def decoratorFunctionWithArguments"))))
|
||||||
|
|
||||||
|
(ert-deftest python-info-current-defun-4 ()
|
||||||
|
"Ensure unmatched quotes do not cause hang (Bug#58780)."
|
||||||
|
(python-tests-with-temp-buffer
|
||||||
|
"
|
||||||
|
def func():
|
||||||
|
' \"\"\"
|
||||||
|
v = 1
|
||||||
|
"
|
||||||
|
(python-tests-look-at "v = 1")
|
||||||
|
(should (string= (python-info-current-defun)
|
||||||
|
"func"))
|
||||||
|
(should (string= (python-info-current-defun t)
|
||||||
|
"def func"))))
|
||||||
|
|
||||||
(ert-deftest python-info-current-symbol-1 ()
|
(ert-deftest python-info-current-symbol-1 ()
|
||||||
(python-tests-with-temp-buffer
|
(python-tests-with-temp-buffer
|
||||||
"
|
"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue