GNU bug report logs -
#24856
25.1.50; Emacs stucks when using C-k to kill lines in python-mode if the next line is a beginning of a docstring
Previous Next
Reported by: raynewang(王磊) <raynewang <at> tencent.com>
Date: Wed, 2 Nov 2016 06:33:02 UTC
Severity: normal
Tags: confirmed, fixed, patch
Merged with 21628,
21629,
21646,
21657,
21671,
24839,
24905,
26041
Found in versions 25.0.50, 25.1, 25.1.50, 26.0.50
Fixed in version 25.2
Done: Daniel Colascione <dancol <at> dancol.org>
Bug is archived. No further changes may be made.
Full log
Message #11 received at 24856 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
merge 24856 24839
tags 24856 patch
quit
Clément Pit--Claudel <clement.pit <at> gmail.com> writes:
> emacs -Q test.py --eval '(insert " \"")'
>
> In other words, a mis-indented string on the first line is enough to
> reproduce the bug.
>
Yes, seems to be the same as 24839.
> It seems to be an infinite loop in fontification:
>
> Debugger entered--Lisp error: (quit)
> python-info-beginning-of-statement-p()
> python-nav--forward-sexp(-1 nil nil)
> python-nav-forward-sexp(-1 nil nil)
> python-nav-backward-sexp()
> python-info-docstring-p((0 nil nil t nil nil 0 nil 5 nil nil))
Here is a patch:
[v1-0001-Fix-infloop-in-python-docstring-detection.patch (text/plain, inline)]
From 5da4f196fc3c8b411936551568477d70a9046421 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Wed, 2 Nov 2016 21:59:10 -0400
Subject: [PATCH v1] Fix infloop in python docstring detection
The function `python-info-docstring-p' (introduced in 2015-04-05
"python.el: Enhance docstring detection following PEP-257[...]") could
get stuck when called with point before the first expression in the
buffer. The attempted fix in 2015-04-06 "Fix previous commit to prevent
infloop" did not handle the case where there is only whitespace between
the first expression and the beginning of buffer (Bug#24856, Bug#24839).
* lisp/progmodes/python.el (python-info-docstring-p): Stop looping when
`python-nav-backward-sexp' fails to move point.
---
lisp/progmodes/python.el | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e5efc2b..de06efb 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4867,13 +4867,14 @@ python-info-docstring-p
2
(progn
(while (save-excursion
- (python-nav-backward-sexp)
- (setq backward-sexp-point (point))
- (and (= indentation (current-indentation))
- (not (bobp)) ; Prevent infloop.
- (looking-at-p
- (concat "[uU]?[rR]?"
- (python-rx string-delimiter)))))
+ (let ((cur-point (point)))
+ (python-nav-backward-sexp)
+ (setq backward-sexp-point (point))
+ (and (= indentation (current-indentation))
+ (/= cur-point (point)) ; Prevent infloop.
+ (looking-at-p
+ (concat "[uU]?[rR]?"
+ (python-rx string-delimiter))))))
;; Previous sexp was a string, restore point.
(goto-char backward-sexp-point)
(cl-incf counter))
--
2.9.3
This bug report was last modified 8 years and 72 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.