diff options
| author | Daniel Colascione | 2016-11-08 15:26:43 -0800 |
|---|---|---|
| committer | Daniel Colascione | 2016-11-08 15:28:49 -0800 |
| commit | 3ef4ee84fa3f658c2df802569dc89023d98e9947 (patch) | |
| tree | 6c8490fbfd02d796f21e43c33f83f702c1f5f461 | |
| parent | 8da810f91b11a258a7ed0f5315292143072881d8 (diff) | |
| download | emacs-3ef4ee84fa3f658c2df802569dc89023d98e9947.tar.gz emacs-3ef4ee84fa3f658c2df802569dc89023d98e9947.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.el | 11 | ||||
| -rw-r--r-- | test/automated/python-tests.el | 7 |
2 files changed, 16 insertions, 2 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 9091289b62e..d0d4a7f766e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -4865,12 +4865,19 @@ point's current `syntax-ppss'." | |||
| 4865 | ;; Allow up to two consecutive docstrings only. | 4865 | ;; Allow up to two consecutive docstrings only. |
| 4866 | (>= | 4866 | (>= |
| 4867 | 2 | 4867 | 2 |
| 4868 | (progn | 4868 | (let (last-backward-sexp-point) |
| 4869 | (while (save-excursion | 4869 | (while (save-excursion |
| 4870 | (python-nav-backward-sexp) | 4870 | (python-nav-backward-sexp) |
| 4871 | (setq backward-sexp-point (point)) | 4871 | (setq backward-sexp-point (point)) |
| 4872 | (and (= indentation (current-indentation)) | 4872 | (and (= indentation (current-indentation)) |
| 4873 | (not (bobp)) ; Prevent infloop. | 4873 | ;; Make sure we're always moving point. |
| 4874 | ;; If we get stuck in the same position | ||
| 4875 | ;; on consecutive loop iterations, | ||
| 4876 | ;; bail out. | ||
| 4877 | (prog1 (not (eql last-backward-sexp-point | ||
| 4878 | backward-sexp-point)) | ||
| 4879 | (setq last-backward-sexp-point | ||
| 4880 | backward-sexp-point)) | ||
| 4874 | (looking-at-p | 4881 | (looking-at-p |
| 4875 | (concat "[uU]?[rR]?" | 4882 | (concat "[uU]?[rR]?" |
| 4876 | (python-rx string-delimiter))))) | 4883 | (python-rx string-delimiter))))) |
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index 54ed92212b8..f6564dd58cc 100644 --- a/test/automated/python-tests.el +++ b/test/automated/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 | ||