Fix Python Hideshow problem with backslash escaped newlines

* lisp/progmodes/python.el (python-rx)
(python-nav-beginning-of-defun-regexp): Allow
python-nav-*-defun to handle backslash escaped newlines
(bug#55690).
This commit is contained in:
kobarity 2022-05-28 18:51:01 +02:00 committed by Lars Ingebrigtsen
parent 5d8b6ba89e
commit 1e66c8af40
2 changed files with 57 additions and 2 deletions

View file

@ -359,7 +359,8 @@
(defmacro python-rx (&rest regexps)
"Python mode specialized rx macro.
This variant of `rx' supports common Python named REGEXPS."
`(rx-let ((block-start (seq symbol-start
`(rx-let ((sp-bsnl (or space (and ?\\ ?\n)))
(block-start (seq symbol-start
(or "def" "class" "if" "elif" "else" "try"
"except" "finally" "for" "while" "with"
;; Python 3.10+ PEP634
@ -1439,7 +1440,7 @@ marks the next defun after the ones already marked."
function))
(defvar python-nav-beginning-of-defun-regexp
(python-rx line-start (* space) defun (+ space) (group symbol-name))
(python-rx line-start (* space) defun (+ sp-bsnl) (group symbol-name))
"Regexp matching class or function definition.
The name of the defun should be grouped so it can be retrieved
via `match-string'.")

View file

@ -1861,6 +1861,22 @@ class C(object):
(beginning-of-line)
(point))))))
(ert-deftest python-nav-beginning-of-defun-4 ()
(python-tests-with-temp-buffer
"
def \\
a():
return 0
"
(python-tests-look-at "return 0")
(should (= (save-excursion
(python-nav-beginning-of-defun)
(point))
(save-excursion
(python-tests-look-at "def \\" -1)
(beginning-of-line)
(point))))))
(ert-deftest python-nav-end-of-defun-1 ()
(python-tests-with-temp-buffer
"
@ -1964,6 +1980,20 @@ def decoratorFunctionWithArguments(arg1, arg2, arg3):
(python-tests-look-at "return wrapped_f")
(line-beginning-position))))))
(ert-deftest python-nav-end-of-defun-3 ()
(python-tests-with-temp-buffer
"
def \\
a():
return 0
"
(should (= (save-excursion
(python-tests-look-at "def \\")
(python-nav-end-of-defun)
(point))
(save-excursion
(point-max))))))
(ert-deftest python-nav-backward-defun-1 ()
(python-tests-with-temp-buffer
"
@ -2062,6 +2092,18 @@ class A(object):
(should (not (python-nav-backward-defun)))
(should (= point (point))))))
(ert-deftest python-nav-backward-defun-4 ()
(python-tests-with-temp-buffer
"
def \\
a():
return 0
"
(goto-char (point-max))
(should (= (save-excursion (python-nav-backward-defun))
(python-tests-look-at "def \\" -1)))
(should (not (python-nav-backward-defun)))))
(ert-deftest python-nav-forward-defun-1 ()
(python-tests-with-temp-buffer
"
@ -2160,6 +2202,18 @@ class A(object):
(should (not (python-nav-forward-defun)))
(should (= point (point))))))
(ert-deftest python-nav-forward-defun-4 ()
(python-tests-with-temp-buffer
"
def \\
a():
return 0
"
(goto-char (point-min))
(should (= (save-excursion (python-nav-forward-defun))
(python-tests-look-at "():")))
(should (not (python-nav-forward-defun)))))
(ert-deftest python-nav-beginning-of-statement-1 ()
(python-tests-with-temp-buffer
"