From: akater <nuclearspace@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
"Mattias Engdegård" <mattiase@acm.org>,
9622@debbugs.gnu.org, "Diogo F. S. Ramos" <diogofsr@gmail.com>
Subject: bug#9622: [PATCH] Re: bug#9622: 23.3; flet indentation
Date: Thu, 28 Oct 2021 19:23:45 +0000 [thread overview]
Message-ID: <87k0hxj6m6.fsf@gmail.com> (raw)
In-Reply-To: <87v926o303.fsf@gnus.org>
[-- Attachment #1.1: Type: text/plain, Size: 132 bytes --]
New patch supports incomplete sexps and adds tests for them.
“test-identation” ert test in elisp-mode-tests.el does pass.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 865 bytes --]
[-- Attachment #2: Support incomplete sexps when indenting cl-flet-like forms --]
[-- Type: text/x-diff, Size: 8078 bytes --]
From c3edf97a4f39044885a8bc544a31762ba9a28695 Mon Sep 17 00:00:00 2001
From: akater <nuclearspace@gmail.com>
Date: Mon, 18 Oct 2021 03:08:06 +0000
Subject: [PATCH] Indent cl-flet-like forms correctly in incomplete expressions
* lisp/emacs-lisp/lisp-mode.el
(lisp--local-defform-body-p): Support incomplete sexps
* test/lisp/progmodes/elisp-mode-resources/flet.erts:
Add tests for incomplete sexps
---
lisp/emacs-lisp/lisp-mode.el | 74 +++++------
.../progmodes/elisp-mode-resources/flet.erts | 121 ++++++++++++++++++
2 files changed, 153 insertions(+), 42 deletions(-)
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 5dfb1fae356..15afdef0252 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1114,56 +1114,46 @@ defun lisp--local-defform-body-p (state)
STATE is the `parse-partial-sexp' state for current position."
(when-let ((start-of-innermost-containing-list (nth 1 state)))
(let* ((parents (nth 9 state))
- (second-cons-after (cddr parents))
- second-order-parent)
+ (first-cons-after (cdr parents))
+ (second-cons-after (cdr first-cons-after))
+ first-order-parent second-order-parent)
(while second-cons-after
(when (= start-of-innermost-containing-list
(car second-cons-after))
- (setq second-order-parent (car parents)
+ (setq second-order-parent (pop parents)
+ first-order-parent (pop parents)
;; Leave the loop.
second-cons-after nil))
(pop second-cons-after)
(pop parents))
(when second-order-parent
- (save-excursion
- (goto-char (1+ second-order-parent))
- (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
- ;; relative positions of subsexps in supersexps
- ;; but it doesn't so we check manually.
- ;;
- ;; First, we must be looking at list now.
- (ignore-errors (when (= (scan-lists (point) 1 0)
- (scan-sexps (point) 1))
- ;; Looking at list; descend into it:
- (down-list 1)
- t))
- ;; In Wishful Lisp, the following form would be
- ;; (cl-member start-of-innermost-containing-list
- ;; (points-at-beginning-of-lists-at-this-level)
- ;; :test #'=)
- (cl-loop
- with pos = (ignore-errors
- ;; The first local definition may be indented
- ;; with whitespace following open paren.
- (goto-char (scan-lists (point) 1 0))
- (goto-char (scan-lists (point) -1 0))
- (point))
- while pos
- do (if (= start-of-innermost-containing-list pos)
- (cl-return t)
- (setq pos (ignore-errors
- (goto-char (scan-lists (point) 2 0))
- (goto-char (scan-lists (point) -1 0))
- (point)))))))))))
+ (let (local-definitions-starting-point)
+ (and (save-excursion
+ (goto-char (1+ second-order-parent))
+ (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)))))
+ (when (memq head '( cl-flet cl-labels cl-macrolet cl-flet*
+ cl-symbol-macrolet))
+ ;; In what follows, we rely on (point) returning non-nil.
+ (setq local-definitions-starting-point
+ (progn
+ (parse-partial-sexp
+ (point) first-order-parent nil
+ ;; From docstring of `parse-partial-sexp':
+ ;; Fourth arg non-nil means stop
+ ;; when we come to any character
+ ;; 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))))))))
(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 447cf08cc25..7c4a0f304e9 100644
--- a/test/lisp/progmodes/elisp-mode-resources/flet.erts
+++ b/test/lisp/progmodes/elisp-mode-resources/flet.erts
@@ -220,3 +220,124 @@ Name: flet15
h
i)))
=-=-=
+
+Name: flet-indentation-incomplete-sexp-no-side-effects-1
+Code: (lambda () (emacs-lisp-mode) (setq indent-tabs-mode nil) (newline nil t))
+Point-Char: |
+
+=-=
+(let ((x (and y|
+=-=
+(let ((x (and y
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-no-side-effects-2
+
+=-=
+(let ((x|
+=-=
+(let ((x
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-whitespace-1
+Point-Char: |
+
+=-=
+(cl-flet((f (x)|
+=-=
+(cl-flet((f (x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-whitespace-2
+Point-Char: |
+
+=-=
+(cl-flet((f(x)|
+=-=
+(cl-flet((f(x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-whitespace-3
+
+=-=
+(cl-flet ((f(x)|
+=-=
+(cl-flet ((f(x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-whitespace-4
+
+=-=
+(cl-flet( (f (x)|
+=-=
+(cl-flet( (f (x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-whitespace-5
+
+=-=
+(cl-flet( (f(x)|
+=-=
+(cl-flet( (f(x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-1
+
+=-=
+(cl-flet((f (x)|
+=-=
+(cl-flet((f (x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-2
+
+=-=
+(cl-flet ((f(x)|
+=-=
+(cl-flet ((f(x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-3
+
+=-=
+(cl-flet( (f (x)|
+=-=
+(cl-flet( (f (x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-4
+
+=-=
+(cl-flet( (f (x)|
+=-=
+(cl-flet( (f (x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-5
+
+=-=
+(cl-flet( (f (x)|
+=-=
+(cl-flet( (f (x)
+ |
+=-=-=
+
+Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-6
+
+=-=
+(cl-flet( (f(x)|
+=-=
+(cl-flet( (f(x)
+ |
+=-=-=
--
2.32.0
next prev parent reply other threads:[~2021-10-28 19:23 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <504153FB-8633-4755-A91A-DF5DD64E6FAA@acm.org>
2021-09-28 3:01 ` bug#9622: 23.3; flet indentation akater
2021-09-28 5:23 ` Lars Ingebrigtsen
2021-09-28 10:11 ` Mattias Engdegård
2021-09-28 10:35 ` Mattias Engdegård
2021-09-28 16:39 ` akater
2021-09-29 18:12 ` bug#9622: [PATCH] " akater
2021-09-30 6:37 ` Lars Ingebrigtsen
2021-09-30 8:05 ` Mattias Engdegård
2021-09-30 13:06 ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-30 13:41 ` Lars Ingebrigtsen
2021-09-30 13:57 ` akater
2021-10-01 11:27 ` Lars Ingebrigtsen
2021-10-09 7:26 ` akater
2021-10-09 11:23 ` Lars Ingebrigtsen
2021-10-28 19:23 ` akater [this message]
2021-10-28 21:53 ` Lars Ingebrigtsen
2021-09-30 14:52 ` Mattias Engdegård
2021-09-30 15:11 ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-30 15:23 ` Thierry Volpiatto
2021-09-30 15:33 ` akater
2021-09-30 16:04 ` Thierry Volpiatto
2021-09-30 15:25 ` Mattias Engdegård
2021-09-30 15:56 ` akater
2021-09-30 19:28 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-30 23:23 ` akater
2021-11-08 1:13 ` Michael Heerdegen
2021-11-08 6:18 ` bug#9622: [PATCH] " akater
2021-11-08 6:38 ` Lars Ingebrigtsen
2021-11-08 6:38 ` akater
2021-11-08 6:53 ` Lars Ingebrigtsen
2021-11-08 9:36 ` akater
2021-11-09 3:25 ` Lars Ingebrigtsen
2021-11-08 16:30 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k0hxj6m6.fsf@gmail.com \
--to=nuclearspace@gmail.com \
--cc=9622@debbugs.gnu.org \
--cc=contovob@tcd.ie \
--cc=diogofsr@gmail.com \
--cc=larsi@gnus.org \
--cc=mattiase@acm.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.