aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkobarity2022-05-28 18:51:01 +0200
committerLars Ingebrigtsen2022-05-28 18:51:01 +0200
commit1e66c8af402176e9f1b5f3fbdbf5f796fec79079 (patch)
tree9395a9e2a1e75c48be809b8f084f8f0f0716d47c
parent5d8b6ba89efdcddfd0189da77dd4099283466a05 (diff)
downloademacs-1e66c8af402176e9f1b5f3fbdbf5f796fec79079.tar.gz
emacs-1e66c8af402176e9f1b5f3fbdbf5f796fec79079.zip
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).
-rw-r--r--lisp/progmodes/python.el5
-rw-r--r--test/lisp/progmodes/python-tests.el54
2 files changed, 57 insertions, 2 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 9adbb82abf4..c2483436fe9 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -359,7 +359,8 @@
359(defmacro python-rx (&rest regexps) 359(defmacro python-rx (&rest regexps)
360 "Python mode specialized rx macro. 360 "Python mode specialized rx macro.
361This variant of `rx' supports common Python named REGEXPS." 361This variant of `rx' supports common Python named REGEXPS."
362 `(rx-let ((block-start (seq symbol-start 362 `(rx-let ((sp-bsnl (or space (and ?\\ ?\n)))
363 (block-start (seq symbol-start
363 (or "def" "class" "if" "elif" "else" "try" 364 (or "def" "class" "if" "elif" "else" "try"
364 "except" "finally" "for" "while" "with" 365 "except" "finally" "for" "while" "with"
365 ;; Python 3.10+ PEP634 366 ;; Python 3.10+ PEP634
@@ -1439,7 +1440,7 @@ marks the next defun after the ones already marked."
1439 function)) 1440 function))
1440 1441
1441(defvar python-nav-beginning-of-defun-regexp 1442(defvar python-nav-beginning-of-defun-regexp
1442 (python-rx line-start (* space) defun (+ space) (group symbol-name)) 1443 (python-rx line-start (* space) defun (+ sp-bsnl) (group symbol-name))
1443 "Regexp matching class or function definition. 1444 "Regexp matching class or function definition.
1444The name of the defun should be grouped so it can be retrieved 1445The name of the defun should be grouped so it can be retrieved
1445via `match-string'.") 1446via `match-string'.")
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 479d68a0623..8db0a07170d 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -1861,6 +1861,22 @@ class C(object):
1861 (beginning-of-line) 1861 (beginning-of-line)
1862 (point)))))) 1862 (point))))))
1863 1863
1864(ert-deftest python-nav-beginning-of-defun-4 ()
1865 (python-tests-with-temp-buffer
1866 "
1867def \\
1868 a():
1869 return 0
1870"
1871 (python-tests-look-at "return 0")
1872 (should (= (save-excursion
1873 (python-nav-beginning-of-defun)
1874 (point))
1875 (save-excursion
1876 (python-tests-look-at "def \\" -1)
1877 (beginning-of-line)
1878 (point))))))
1879
1864(ert-deftest python-nav-end-of-defun-1 () 1880(ert-deftest python-nav-end-of-defun-1 ()
1865 (python-tests-with-temp-buffer 1881 (python-tests-with-temp-buffer
1866 " 1882 "
@@ -1964,6 +1980,20 @@ def decoratorFunctionWithArguments(arg1, arg2, arg3):
1964 (python-tests-look-at "return wrapped_f") 1980 (python-tests-look-at "return wrapped_f")
1965 (line-beginning-position)))))) 1981 (line-beginning-position))))))
1966 1982
1983(ert-deftest python-nav-end-of-defun-3 ()
1984 (python-tests-with-temp-buffer
1985 "
1986def \\
1987 a():
1988 return 0
1989"
1990 (should (= (save-excursion
1991 (python-tests-look-at "def \\")
1992 (python-nav-end-of-defun)
1993 (point))
1994 (save-excursion
1995 (point-max))))))
1996
1967(ert-deftest python-nav-backward-defun-1 () 1997(ert-deftest python-nav-backward-defun-1 ()
1968 (python-tests-with-temp-buffer 1998 (python-tests-with-temp-buffer
1969 " 1999 "
@@ -2062,6 +2092,18 @@ class A(object):
2062 (should (not (python-nav-backward-defun))) 2092 (should (not (python-nav-backward-defun)))
2063 (should (= point (point)))))) 2093 (should (= point (point))))))
2064 2094
2095(ert-deftest python-nav-backward-defun-4 ()
2096 (python-tests-with-temp-buffer
2097 "
2098def \\
2099 a():
2100 return 0
2101"
2102 (goto-char (point-max))
2103 (should (= (save-excursion (python-nav-backward-defun))
2104 (python-tests-look-at "def \\" -1)))
2105 (should (not (python-nav-backward-defun)))))
2106
2065(ert-deftest python-nav-forward-defun-1 () 2107(ert-deftest python-nav-forward-defun-1 ()
2066 (python-tests-with-temp-buffer 2108 (python-tests-with-temp-buffer
2067 " 2109 "
@@ -2160,6 +2202,18 @@ class A(object):
2160 (should (not (python-nav-forward-defun))) 2202 (should (not (python-nav-forward-defun)))
2161 (should (= point (point)))))) 2203 (should (= point (point))))))
2162 2204
2205(ert-deftest python-nav-forward-defun-4 ()
2206 (python-tests-with-temp-buffer
2207 "
2208def \\
2209 a():
2210 return 0
2211"
2212 (goto-char (point-min))
2213 (should (= (save-excursion (python-nav-forward-defun))
2214 (python-tests-look-at "():")))
2215 (should (not (python-nav-forward-defun)))))
2216
2163(ert-deftest python-nav-beginning-of-statement-1 () 2217(ert-deftest python-nav-beginning-of-statement-1 ()
2164 (python-tests-with-temp-buffer 2218 (python-tests-with-temp-buffer
2165 " 2219 "