Subject: Re: bug#38255: 27.0.50; Indentation error-out in css-mode

From: Stefan Monnier <[email-masked]>
Date: Thu, 21 Nov 2019 18:29:14 -0500

>> foo {
>> }
>> }
>>
>> The following backtrace is triggered.
>>
>> Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
>>   smie-next-sexp(#f(compiled-function () #<bytecode 0x155d7de91a0d>)
>> #f(compiled-function (n) #<bytecode 0x155d7f00a465>) #<subr car>
>> #f(compiled-function (x) "Return the car of the cdr of X." #<bytecode
>> 0x1ffc61806017>) "}")
>>   smie-backward-sexp("}")
>>   smie-indent-keyword()
>>   run-hook-with-args-until-success(smie-indent-keyword)

Thanks for the great recipe.  I pushed the fix below to Emacs's master.

        Stefan

diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index f2163b243e..2c2898ae71 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -702,7 +702,11 @@ smie-next-sexp
   (catch 'return
     (let ((levels
            (if (stringp halfsexp)
-               (prog1 (list (cdr (assoc halfsexp smie-grammar)))
+               (prog1 (list (or (cdr (assoc halfsexp smie-grammar))
+                                (when (string-match "\\`\\s(\\|\\s)\\(\\)\\'"
+                                                    halfsexp)
+                                  (if (match-end 1) '(0 nil) '(nil 0)))
+                                (error "Unknown token: %S" halfsexp)))
                  (setq halfsexp nil)))))
       (while
           (let* ((pos (point))