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.
This commit is contained in:
parent
d24c5f26bf
commit
8579105393
2 changed files with 27 additions and 8 deletions
|
@ -1199,14 +1199,22 @@ ENDPOS is encountered."
|
||||||
(setq endpos (copy-marker
|
(setq endpos (copy-marker
|
||||||
(if endpos endpos
|
(if endpos endpos
|
||||||
;; Get error now if we don't have a complete sexp
|
;; Get error now if we don't have a complete sexp
|
||||||
;; after point. We actually look for a sexp which
|
;; after point.
|
||||||
;; ends after the current line so that we properly
|
(save-excursion
|
||||||
;; indent things like #s(...). This might not be
|
|
||||||
;; needed if Bug#15998 is fixed.
|
|
||||||
(let ((eol (line-end-position)))
|
(let ((eol (line-end-position)))
|
||||||
(save-excursion (while (and (< (point) eol) (not (eobp)))
|
(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))
|
(forward-sexp 1))
|
||||||
(point))))))
|
;; But don't signal an error for incomplete
|
||||||
|
;; sexps following the first complete sexp
|
||||||
|
;; after point.
|
||||||
|
(scan-error nil)))
|
||||||
|
(point)))))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(while (let ((indent (lisp-indent-calc-next parse-state))
|
(while (let ((indent (lisp-indent-calc-next parse-state))
|
||||||
(ppss (lisp-indent-state-ppss parse-state)))
|
(ppss (lisp-indent-state-ppss parse-state)))
|
||||||
|
|
|
@ -125,6 +125,17 @@ noindent\" 3
|
||||||
#s(foo
|
#s(foo
|
||||||
bar)\n"))))
|
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 ()
|
(ert-deftest lisp-indent-region ()
|
||||||
"Test basics of `lisp-indent-region'."
|
"Test basics of `lisp-indent-region'."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue