From 5da4f196fc3c8b411936551568477d70a9046421 Mon Sep 17 00:00:00 2001 From: Noam Postavsky 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