summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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."
(setq endpos (copy-marker
(if endpos endpos
;; Get error now if we don't have a complete sexp
- ;; after point. We actually look for a sexp which
- ;; ends after the current line so that we properly
- ;; indent things like #s(...). This might not be
- ;; needed if Bug#15998 is fixed.
- (let ((eol (line-end-position)))
- (save-excursion (while (and (< (point) eol) (not (eobp)))
- (forward-sexp 1))
- (point))))))
+ ;; after point.
+ (save-excursion
+ (let ((eol (line-end-position)))
+ (forward-sexp 1)
+ ;; We actually look for a sexp which ends
+ ;; after the current line so that we properly
+ ;; indent things like #s(...). This might not
+ ;; be needed if Bug#15998 is fixed.
+ (condition-case ()
+ (while (and (< (point) eol) (not (eobp)))
+ (forward-sexp 1))
+ ;; But don't signal an error for incomplete
+ ;; sexps following the first complete sexp
+ ;; after point.
+ (scan-error nil)))
+ (point)))))
(save-excursion
(while (let ((indent (lisp-indent-calc-next parse-state))
(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
#s(foo
bar)\n"))))
+(ert-deftest indent-sexp-cant-go ()
+ "`indent-sexp' shouldn't error before a sexp."
+ ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=31984#32.
+ (with-temp-buffer
+ (emacs-lisp-mode)
+ (insert "(())")
+ (goto-char (1+ (point-min)))
+ ;; Paredit calls `indent-sexp' from this position.
+ (indent-sexp)
+ (should (equal (buffer-string) "(())"))))
+
(ert-deftest lisp-indent-region ()
"Test basics of `lisp-indent-region'."
(with-temp-buffer