unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55690: 29.0.50; hs-hide-all hangs if backslash escaped newline is used in Python class/function definition
@ 2022-05-28 14:56 kobarity
  2022-05-28 15:03 ` kobarity
  0 siblings, 1 reply; 3+ messages in thread
From: kobarity @ 2022-05-28 14:56 UTC (permalink / raw)
  To: 55690

When the following steps are performed, Emacs hangs.

1. emacs -Q
2. Load the following Python file using M-x find-file
   (Please note that the first blank line is mandatory.)

#+begin_src python

def \
        foo():
    pass
#+end_src

3. M-x hs-minor-mode
4. M-x hs-hide-all

It is possible to quit using C-g.

In GNU Emacs 29.0.50 (build 4, x86_64-pc-linux-gnu)
 of 2022-05-21 built on ubuntu
Repository revision: 208102fa470e3417320062cdb48a9967d80bf092
Repository branch: master
System Description: Ubuntu 22.04 LTS

Configured using:
 'configure --without-x --with-gnutls=ifavailable'

Configured features:
ACL LIBXML2 MODULES NOTIFY INOTIFY PDUMPER SECCOMP SOUND SQLITE3 THREADS
XIM ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow regexp-opt sort mail-extr face-remap help-mode tool-bar emacsbug
message mailcap yank-media rmc puny dired dired-loaddefs rfc822 mml
mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util
text-property-search time-date seq mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
term/screen term/xterm xterm gv subr-x byte-opt bytecomp byte-compile
cconv iso-transl tooltip eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice simple cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop
case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads inotify
multi-tty make-network-process emacs)

Memory information:
((conses 16 48401 6401)
 (symbols 48 5803 1)
 (strings 32 16090 1890)
 (string-bytes 1 510153)
 (vectors 16 9643)
 (vector-slots 8 112266 9121)
 (floats 8 25 264)
 (intervals 56 385 66)
 (buffers 992 12))





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#55690: 29.0.50; hs-hide-all hangs if backslash escaped newline is used in Python class/function definition
  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
  2022-05-28 16:51   ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: kobarity @ 2022-05-28 15:03 UTC (permalink / raw)
  To: 55690

[-- 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
    "

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#55690: 29.0.50; hs-hide-all hangs if backslash escaped newline is used in Python class/function definition
  2022-05-28 15:03 ` kobarity
@ 2022-05-28 16:51   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-28 16:51 UTC (permalink / raw)
  To: kobarity; +Cc: 55690

kobarity <kobarity@gmail.com> writes:

> 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.

Thanks; pushed to Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-28 16:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2022-05-28 16:51   ` Lars Ingebrigtsen

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).