Subject: bug#9622: [PATCH] Re: bug#9622: 23.3; flet indentation

From: akater <[email-masked]>
Date: Thu, 30 Sep 2021 13:57:04 +0000

Lars Ingebrigtsen <[email-masked]> writes:

> Perhaps we should consider backing out these changed in Emacs 28 and
> continuing to work on them on the trunk?

I don't think so.  The first attempt was written in a hurry, and merged
without extensive testing; in the second I did exhaustive tests, it just
never crossed my mind to test on unbalanced expressions.  This very much
looks like the last ignore-errors of them:

>From 2e5f87b345d349dc6657f8034102a842d0685232 Mon Sep 17 00:00:00 2001
From: akater <[email-masked]>
Date: Thu, 30 Sep 2021 13:37:59 +0000
Subject: [PATCH] Fix other regressions in cl-flet indentation

* lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p):
Fix indentation regression
introduced by 38037e04cb05cb1f2b604f0b1602d36b0bcf6985
(bug#9622), namely don't fail in unreadable (incl. unbalanced) sexps.
---
 lisp/emacs-lisp/lisp-mode.el | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index cd054801bc..57196dfec4 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1124,9 +1124,13 @@ defun lisp--local-defform-body-p (state)
       (when second-order-parent
         (save-excursion
           (goto-char (1+ second-order-parent))
-          (and (memq (read (current-buffer))
-                     '( cl-flet cl-labels cl-macrolet cl-flet*
-                        cl-symbol-macrolet))
+          (and (when-let ((head (ignore-errors
+                                  ;; FIXME: This does not distinguish
+                                  ;; between reading nil and a read error.
+                                  ;; We don't care but still, better fix this.
+                                  (read (current-buffer)))))
+                 (memq head '( cl-flet cl-labels cl-macrolet cl-flet*
+                               cl-symbol-macrolet)))
                ;; Now we must check that we are
                ;; in the second element of the flet-like form.
                ;; It would be easier if `parse-partial-sexp' also recorded
-- 
2.32.0