diff options
| author | Noam Postavsky | 2019-08-16 07:26:40 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2019-08-17 09:42:34 -0400 |
| commit | bcd0115e4db49791a77566b80fabc4384d9ebf57 (patch) | |
| tree | eb5024d4e633eb5e21c83f3ca1e50a9dd46ac6f9 | |
| parent | 5f992d1990d9f351cf907dcf2066f573e0fe9407 (diff) | |
| download | emacs-bcd0115e4db49791a77566b80fabc4384d9ebf57.tar.gz emacs-bcd0115e4db49791a77566b80fabc4384d9ebf57.zip | |
Fix lisp indent infloop on unfinished strings (Bug#37045)
* lisp/emacs-lisp/lisp-mode.el (lisp-indent-calc-next): Stop trying to
skip over strings if we've hit the end of buffer.
* test/lisp/emacs-lisp/lisp-mode-tests.el
(lisp-indent-unfinished-string): New test.
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 15 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/lisp-mode-tests.el | 6 |
2 files changed, 15 insertions, 6 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 74bf0c87c53..bde0a4ea6d9 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -810,7 +810,7 @@ by more than one line to cross a string literal." | |||
| 810 | (setq last-sexp (nth 2 ppss))) | 810 | (setq last-sexp (nth 2 ppss))) |
| 811 | (setq depth (car ppss)) | 811 | (setq depth (car ppss)) |
| 812 | ;; Skip over newlines within strings. | 812 | ;; Skip over newlines within strings. |
| 813 | (nth 3 ppss)) | 813 | (and (not (eobp)) (nth 3 ppss))) |
| 814 | (let ((string-start (nth 8 ppss))) | 814 | (let ((string-start (nth 8 ppss))) |
| 815 | (setq ppss (parse-partial-sexp (point) (point-max) | 815 | (setq ppss (parse-partial-sexp (point) (point-max) |
| 816 | nil nil ppss 'syntax-table)) | 816 | nil nil ppss 'syntax-table)) |
| @@ -826,17 +826,22 @@ by more than one line to cross a string literal." | |||
| 826 | indent-stack))))) | 826 | indent-stack))))) |
| 827 | (prog1 | 827 | (prog1 |
| 828 | (let (indent) | 828 | (let (indent) |
| 829 | (cond ((= (forward-line 1) 1) nil) | 829 | (cond ((= (forward-line 1) 1) |
| 830 | ;; Negative depth, probably some kind of syntax error. | 830 | ;; Can't move to the next line, apparently end of buffer. |
| 831 | nil) | ||
| 831 | ((null indent-stack) | 832 | ((null indent-stack) |
| 832 | ;; Reset state. | 833 | ;; Negative depth, probably some kind of syntax |
| 834 | ;; error. Reset the state. | ||
| 833 | (setq ppss (parse-partial-sexp (point) (point)))) | 835 | (setq ppss (parse-partial-sexp (point) (point)))) |
| 834 | ((car indent-stack)) | 836 | ((car indent-stack)) |
| 835 | ((integerp (setq indent (calculate-lisp-indent ppss))) | 837 | ((integerp (setq indent (calculate-lisp-indent ppss))) |
| 836 | (setf (car indent-stack) indent)) | 838 | (setf (car indent-stack) indent)) |
| 837 | ((consp indent) ; (COLUMN CONTAINING-SEXP-START) | 839 | ((consp indent) ; (COLUMN CONTAINING-SEXP-START) |
| 838 | (car indent)) | 840 | (car indent)) |
| 839 | ;; This only happens if we're in a string. | 841 | ;; This only happens if we're in a string, but the |
| 842 | ;; loop should always skip over strings (unless we hit | ||
| 843 | ;; end of buffer, which is taken care of by the first | ||
| 844 | ;; clause). | ||
| 840 | (t (error "This shouldn't happen")))) | 845 | (t (error "This shouldn't happen")))) |
| 841 | (setf (lisp-indent-state-stack state) indent-stack) | 846 | (setf (lisp-indent-state-stack state) indent-stack) |
| 842 | (setf (lisp-indent-state-ppss-point state) ppss-point) | 847 | (setf (lisp-indent-state-ppss-point state) ppss-point) |
diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el index 63632449ca5..e4ba929ecbd 100644 --- a/test/lisp/emacs-lisp/lisp-mode-tests.el +++ b/test/lisp/emacs-lisp/lisp-mode-tests.el | |||
| @@ -284,7 +284,11 @@ Expected initialization file: `%s'\" | |||
| 284 | (lisp-indent-line) | 284 | (lisp-indent-line) |
| 285 | (should (equal (buffer-string) "prompt> foo")))) | 285 | (should (equal (buffer-string) "prompt> foo")))) |
| 286 | 286 | ||
| 287 | 287 | (ert-deftest lisp-indent-unfinished-string () | |
| 288 | "Don't infloop on unfinished string (Bug#37045)." | ||
| 289 | (with-temp-buffer | ||
| 290 | (insert "\"\n") | ||
| 291 | (lisp-indent-region (point-min) (point-max)))) | ||
| 288 | 292 | ||
| 289 | (provide 'lisp-mode-tests) | 293 | (provide 'lisp-mode-tests) |
| 290 | ;;; lisp-mode-tests.el ends here | 294 | ;;; lisp-mode-tests.el ends here |