From: kobarity <kobarity@gmail.com>
To: 55690@debbugs.gnu.org
Subject: bug#55690: 29.0.50; hs-hide-all hangs if backslash escaped newline is used in Python class/function definition
Date: Sun, 29 May 2022 00:03:53 +0900 [thread overview]
Message-ID: <CAMQkrSp=o2e4KLx_fakY9hee5yscee6BZNbHMJg+MJdwYtbh=w@mail.gmail.com> (raw)
In-Reply-To: <CAMQkrSow_wNr3tTC9R7-jvgQ2yj1gJPnG8JzygEsHZYuwu+9qg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 202 bytes --]
The problem is that python-nav-end-of-defun used in
python-hideshow-forward-sexp-function can not handle backslash escaped
newline in class/function definitions. Attached is a patch to fix the
problem.
[-- Attachment #2: fix-55690.patch --]
[-- Type: application/octet-stream, Size: 3976 bytes --]
commit 8c2eacc6038da9a9a5b3b6dc3c76823fe1f0e7f1
Author: kobarity <kobarity@gmail.com>
Date: Sat May 28 23:59:06 2022 +0900
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).
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 9adbb82abf..c2483436fe 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -359,7 +359,8 @@ python-mode-map
(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 @@ python-forward-sexp-function
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'.")
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 479d68a062..8db0a07170 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -1861,6 +1861,22 @@ python-nav-beginning-of-defun-3
(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 @@ python-nav-end-of-defun-2
(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 @@ python-nav-backward-defun-3
(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 @@ python-nav-forward-defun-3
(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
"
next prev parent reply other threads:[~2022-05-28 15:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-28 14:56 bug#55690: 29.0.50; hs-hide-all hangs if backslash escaped newline is used in Python class/function definition kobarity
2022-05-28 15:03 ` kobarity [this message]
2022-05-28 16:51 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMQkrSp=o2e4KLx_fakY9hee5yscee6BZNbHMJg+MJdwYtbh=w@mail.gmail.com' \
--to=kobarity@gmail.com \
--cc=55690@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).