aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoam Postavsky2018-07-27 19:41:39 -0400
committerNoam Postavsky2018-07-27 19:41:39 -0400
commit857910539313c0f2d89fe5626a41f1abe6c33ca7 (patch)
tree7c4a9b8184cd09d842962fe9dcbec07651611766
parentd24c5f26bf6c12bda614f90ba3345d710482005a (diff)
downloademacs-857910539313c0f2d89fe5626a41f1abe6c33ca7.tar.gz
emacs-857910539313c0f2d89fe5626a41f1abe6c33ca7.zip
Don't fail to indent-sexp before a full sexp (Bug#31984)
* lisp/emacs-lisp/lisp-mode.el (indent-sexp): Only signal error if the initial forward-sexp fails. Suppress scan-error forn any of the forward-sexp calls after that. * test/lisp/emacs-lisp/lisp-mode-tests.el (indent-sexp-cant-go): New test.
-rw-r--r--lisp/emacs-lisp/lisp-mode.el24
-rw-r--r--test/lisp/emacs-lisp/lisp-mode-tests.el11
2 files changed, 27 insertions, 8 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 44b27236a9c..205c810b978 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1199,14 +1199,22 @@ ENDPOS is encountered."
1199 (setq endpos (copy-marker 1199 (setq endpos (copy-marker
1200 (if endpos endpos 1200 (if endpos endpos
1201 ;; Get error now if we don't have a complete sexp 1201 ;; Get error now if we don't have a complete sexp
1202 ;; after point. We actually look for a sexp which 1202 ;; after point.
1203 ;; ends after the current line so that we properly 1203 (save-excursion
1204 ;; indent things like #s(...). This might not be 1204 (let ((eol (line-end-position)))
1205 ;; needed if Bug#15998 is fixed. 1205 (forward-sexp 1)
1206 (let ((eol (line-end-position))) 1206 ;; We actually look for a sexp which ends
1207 (save-excursion (while (and (< (point) eol) (not (eobp))) 1207 ;; after the current line so that we properly
1208 (forward-sexp 1)) 1208 ;; indent things like #s(...). This might not
1209 (point)))))) 1209 ;; be needed if Bug#15998 is fixed.
1210 (condition-case ()
1211 (while (and (< (point) eol) (not (eobp)))
1212 (forward-sexp 1))
1213 ;; But don't signal an error for incomplete
1214 ;; sexps following the first complete sexp
1215 ;; after point.
1216 (scan-error nil)))
1217 (point)))))
1210 (save-excursion 1218 (save-excursion
1211 (while (let ((indent (lisp-indent-calc-next parse-state)) 1219 (while (let ((indent (lisp-indent-calc-next parse-state))
1212 (ppss (lisp-indent-state-ppss parse-state))) 1220 (ppss (lisp-indent-state-ppss parse-state)))
diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el
index 0b052e9fc30..30f606d3816 100644
--- a/test/lisp/emacs-lisp/lisp-mode-tests.el
+++ b/test/lisp/emacs-lisp/lisp-mode-tests.el
@@ -125,6 +125,17 @@ noindent\" 3
125#s(foo 125#s(foo
126 bar)\n")))) 126 bar)\n"))))
127 127
128(ert-deftest indent-sexp-cant-go ()
129 "`indent-sexp' shouldn't error before a sexp."
130 ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=31984#32.
131 (with-temp-buffer
132 (emacs-lisp-mode)
133 (insert "(())")
134 (goto-char (1+ (point-min)))
135 ;; Paredit calls `indent-sexp' from this position.
136 (indent-sexp)
137 (should (equal (buffer-string) "(())"))))
138
128(ert-deftest lisp-indent-region () 139(ert-deftest lisp-indent-region ()
129 "Test basics of `lisp-indent-region'." 140 "Test basics of `lisp-indent-region'."
130 (with-temp-buffer 141 (with-temp-buffer