Subject: Re: bug#19342: auto-fill scan-error in sh-mode

From: Lars Ingebrigtsen <[email-masked]>
Date: Thu, 19 Aug 2021 15:29:10 +0200

Glenn Morris <[email-masked]> writes:

> Type a long string with spaces, past fill-column; eg:
>
> foo="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaa
>
> Auto-fill results in:
>
> Error: (scan-error "Containing expression ends prematurely" 75 75)

This problem is still present in Emacs 28.  This is the backtrace:

Debugger entered--Lisp error: (scan-error "Containing expression ends prematurely" 95 95)
  signal(scan-error ("Containing expression ends prematurely" 95 95))
  (if (and (car res) (= pos (point)) (not (if forw (eobp) (bobp)))) (
  (let ((pos (point)) (res (if forw (smie-forward-sexp 'halfsexp) (sm
  (while (/= n 0) (setq n (- n (if forw 1 -1))) (let ((pos (point)) (
  (let ((forw (> n 0)) (forward-sexp-function nil)) (while (/= n 0) (
  smie-forward-sexp-command(1)
  forward-sexp(1)
  (cond ((< 0 (length tok)) (assoc tok smie-grammar)) ((looking-at "\
  (let ((tok (funcall smie-forward-token-function))) (cond ((< 0 (len
  smie-indent-forward-token()
  smie-indent-keyword()
  smie--funcall(smie-indent-keyword)
  run-hook-wrapped(smie--funcall smie-indent-keyword)
  smie-indent-calculate()
  smie-auto-fill(#f(compiled-function (&rest args) #<bytecode -0x1d0b7391ba5340b6>))

The code that errors out is:

(defun smie-indent-forward-token ()
[...]
     ((looking-at "\\s\"\\|\\s|")
      (forward-sexp 1)

That is, if we're auto-filling an unterminated string, it'll always bug
out, apparently?

I've added Stefan to the CCs.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no