Subject: Re: bug#72561: 31.0.50; Scan error in ert--pp-with-indentation-and-newline

From: Stefan Monnier <[email-masked]>
Date: Wed, 21 Aug 2024 17:41:38 -0400

>    Error: scan-error ("Containing expression ends prematurely" 221 221)
>      forward-sexp-default-function(-1)
>      forward-sexp(-1)
>      calculate-lisp-indent((5 221 238 nil nil nil 4 nil nil (5 27 161 175
>      lisp-indent-calc-next(#s(lisp-indent-state :stack (50 16 6 5 nil) :p
>      indent-sexp()
>      ert--pp-with-indentation-and-newline((ert-test-failed ((should (equa

Hmm...

> --- a/lisp/emacs-lisp/ert.el
> +++ b/lisp/emacs-lisp/ert.el
> @@ -1323,7 +1323,8 @@ ert--pp-with-indentation-and-newline
>      (unless (bolp) (insert "\n"))
>      (save-excursion
>        (goto-char begin)
> -      (indent-sexp))))
> +      (with-syntax-table emacs-lisp-mode-syntax-table
> +        (indent-sexp)))))

Your patch makes sense: indeed, looking at the code of `indent-sexp`,
I see that it uses `lisp-indent*` functions in a way which presumes that
we're looking at Lisp code and would require a list-mode syntax-table.
I wonder why this has not bitten us earlier in other circumstances.

But I also wonder why `ert--pp-with-indentation-and-newline` calls
`indent-sexp`, since `pp` should have done that for us already, so I'd
be tempted to just remove that call.  Or maybe the purpose is to "shift"
the text when `begin` is not in column 0?
If so, maybe `indent-rigidly` is a better way to get the same result?

        Stefan