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

From: akater <[email-masked]>
Date: Mon, 08 Nov 2021 06:18:11 +0000

Michael Heerdegen <[email-masked]> writes:

> #+begin_src emacs-lisp
> (cl-flet* ((cont-w/expr (f) (g-w/extended-expr cont f))
>            (cont-prepend (&rest exps)
>              (cont-w/expr (lambda (p) (apply #'g--and (append exps (list p)))))))
>   (pcase expr
>     ((and (let transformed (g--trivial-transformation-p expr)) (guard transformed))
>     (cont-prepend transformed))))
> #+end_src
>
> and the last line gets indented wrongly (one space too less).  When I
> remove the wrapping `cl-flet*' indentation behavior gets back to the
> expected.

Indeed, I forgot one save-excursion.

To Lars: tests involving complete sexps do pass, the rest I couldn't
run, as described in bug#51680

>From 367ec048e7fbf6d7f3453a64e953079575444f4d Mon Sep 17 00:00:00 2001
From: akater <[email-masked]>
Date: Mon, 8 Nov 2021 04:48:13 +0000
Subject: [PATCH] ; * lisp/emacs-lisp/lisp-mode.el: Fix parser state
 corruption.

* lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p): Preserve
the point
* test/lisp/progmodes/elisp-mode-resources/flet.erts: Add corresponding
test example
---
 lisp/emacs-lisp/lisp-mode.el                       | 13 +++++++------
 test/lisp/progmodes/elisp-mode-resources/flet.erts | 10 ++++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 15afdef0252..a5613e70e0a 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1148,12 +1148,13 @@ defun lisp--local-defform-body-p (state)
                               ;; that starts a sexp.
                               t)
                              (point))))))
-               (ignore-errors
-                 ;; We rely on `backward-up-list' working
-                 ;; even when sexp is incomplete “to the right”.
-                 (backward-up-list 2)
-                 t)
-               (= local-definitions-starting-point (point))))))))
+               (save-excursion
+                 (ignore-errors
+                   ;; We rely on `backward-up-list' working
+                   ;; even when sexp is incomplete “to the right”.
+                   (backward-up-list 2)
+                   t)
+                 (= local-definitions-starting-point (point)))))))))
 
 (defun lisp-indent-function (indent-point state)
   "This function is the normal value of the variable `lisp-indent-function'.
diff --git a/test/lisp/progmodes/elisp-mode-resources/flet.erts b/test/lisp/progmodes/elisp-mode-resources/flet.erts
index 7c4a0f304e9..da3dcb6ec3e 100644
--- a/test/lisp/progmodes/elisp-mode-resources/flet.erts
+++ b/test/lisp/progmodes/elisp-mode-resources/flet.erts
@@ -221,6 +221,16 @@ Name: flet15
             i)))
 =-=-=
 
+Name: flet16
+
+=-=
+(cl-flet ((f (x)
+            (g x)))
+  (pcase e
+    ((dangerous-expression)
+     (form))))
+=-=-=
+
 Name: flet-indentation-incomplete-sexp-no-side-effects-1
 Code: (lambda () (emacs-lisp-mode) (setq indent-tabs-mode nil) (newline nil t))
 Point-Char: |
-- 
2.32.0