aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Colascione2016-11-08 15:26:43 -0800
committerDaniel Colascione2016-11-08 15:26:43 -0800
commit112111c4e489aae5cbe241ffa458d97b6a133d3a (patch)
tree3de7ef225d0b2bd30eb475067851aacf89fd7fd0
parent06cfaa3dfa1888b55df437a16ced6f718678bc56 (diff)
downloademacs-112111c4e489aae5cbe241ffa458d97b6a133d3a.tar.gz
emacs-112111c4e489aae5cbe241ffa458d97b6a133d3a.zip
Avoid infloop in python
Fix bug#24905 * lisp/progmodes/python.el (python-info-docstring-p): Improve infloop avoidance: replace (bobp) with generic test for forward progress. * test/lisp/progmodes/python-tests.el (python-bob-infloop-avoid): Add test for bug#24905
-rw-r--r--lisp/progmodes/python.el11
-rw-r--r--test/lisp/progmodes/python-tests.el7
2 files changed, 16 insertions, 2 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 290cdc8120d..f9b28c322c8 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4892,12 +4892,19 @@ point's current `syntax-ppss'."
4892 ;; Allow up to two consecutive docstrings only. 4892 ;; Allow up to two consecutive docstrings only.
4893 (>= 4893 (>=
4894 2 4894 2
4895 (progn 4895 (let (last-backward-sexp-point)
4896 (while (save-excursion 4896 (while (save-excursion
4897 (python-nav-backward-sexp) 4897 (python-nav-backward-sexp)
4898 (setq backward-sexp-point (point)) 4898 (setq backward-sexp-point (point))
4899 (and (= indentation (current-indentation)) 4899 (and (= indentation (current-indentation))
4900 (not (bobp)) ; Prevent infloop. 4900 ;; Make sure we're always moving point.
4901 ;; If we get stuck in the same position
4902 ;; on consecutive loop iterations,
4903 ;; bail out.
4904 (prog1 (not (eql last-backward-sexp-point
4905 backward-sexp-point))
4906 (setq last-backward-sexp-point
4907 backward-sexp-point))
4901 (looking-at-p 4908 (looking-at-p
4902 (concat "[uU]?[rR]?" 4909 (concat "[uU]?[rR]?"
4903 (python-rx string-delimiter))))) 4910 (python-rx string-delimiter)))))
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 54ed92212b8..f6564dd58cc 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -2452,6 +2452,13 @@ if x:
2452 (line-beginning-position) (line-end-position)) 2452 (line-beginning-position) (line-end-position))
2453 "abcdef"))))) 2453 "abcdef")))))
2454 2454
2455(ert-deftest python-bob-infloop-avoid ()
2456 "Test that strings at BOB don't confuse syntax analysis. Bug#24905"
2457 (python-tests-with-temp-buffer
2458 " \"\n"
2459 (goto-char (point-min))
2460 (font-lock-fontify-buffer)))
2461
2455 2462
2456;;; Shell integration 2463;;; Shell integration
2457 2464