From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: akater Newsgroups: gmane.emacs.bugs Subject: bug#9622: [PATCH] Re: bug#9622: 23.3; flet indentation Date: Thu, 28 Oct 2021 19:23:45 +0000 Message-ID: <87k0hxj6m6.fsf@gmail.com> References: <504153FB-8633-4755-A91A-DF5DD64E6FAA@acm.org> <87lf3fntdx.fsf@gmail.com> <87tui26027.fsf@gnus.org> <87r1d62owt.fsf@tcd.ie> <8735pm2nai.fsf@gnus.org> <87a6junp3j.fsf@gmail.com> <87ilyhx9wb.fsf@gnus.org> <871r4ud5gz.fsf@gmail.com> <87v926o303.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26302"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "Basil L. Contovounesios" , Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 9622@debbugs.gnu.org, "Diogo F. S. Ramos" To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 28 21:36:32 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgBCQ-0006bX-FH for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 28 Oct 2021 21:36:30 +0200 Original-Received: from localhost ([::1]:47738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgBCO-0006yg-9f for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 28 Oct 2021 15:36:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgBBz-0006ux-LI for bug-gnu-emacs@gnu.org; Thu, 28 Oct 2021 15:36:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41736) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgBBz-0000no-Bs for bug-gnu-emacs@gnu.org; Thu, 28 Oct 2021 15:36:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mgBBx-00026a-Uk for bug-gnu-emacs@gnu.org; Thu, 28 Oct 2021 15:36:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: akater Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Oct 2021 19:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9622 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 9622-submit@debbugs.gnu.org id=B9622.16354497378064 (code B ref 9622); Thu, 28 Oct 2021 19:36:01 +0000 Original-Received: (at 9622) by debbugs.gnu.org; 28 Oct 2021 19:35:37 +0000 Original-Received: from localhost ([127.0.0.1]:53282 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgBBZ-00025x-5o for submit@debbugs.gnu.org; Thu, 28 Oct 2021 15:35:37 -0400 Original-Received: from mail-lf1-f54.google.com ([209.85.167.54]:43716) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgBBX-00025k-1P for 9622@debbugs.gnu.org; Thu, 28 Oct 2021 15:35:35 -0400 Original-Received: by mail-lf1-f54.google.com with SMTP id bq11so15832804lfb.10 for <9622@debbugs.gnu.org>; Thu, 28 Oct 2021 12:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=vNWYMRU+MaiG1nR8IJs6ZgwJga3fYRAJ6UmXsKV0Dtw=; b=J2uxCJouj6H0+2mrXcoPI3XBoXGv1QrYCXgOTd2I/yTKTf3cU50F3g7rXLGd7FrGwe TRlAgrK77HJLaydL5llh8y+6z5C+wvNRNoDeQMyryaiRBGcLIb75jv5zv3BGG5OK7SlO Bc7foa50bvS7tKfNdvewT1/2ht92TOT41gMmgcbqpuEYjQPXzRZR3fEoU3rG3DO8iSra TFWzNVYC6MPXkU9J5jE4sxjL0mjSi0+Z1KAAfJqVs0C9s25rVK2BnlF+J3+q/jxEtn2i KIueYGxuUNlW1HJ0j/DdTPai0UL9LvxXTA0v0igJ/OuqVZ4aeL9kYOByN1NsI/dZNYJM FlHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=vNWYMRU+MaiG1nR8IJs6ZgwJga3fYRAJ6UmXsKV0Dtw=; b=mtO5WzuL2XigrARyf0SjWFdBf7a3WVeA3JSfMaIuh+XjhyVPPgpBJF5poCeDIwcvRz QGQaYGJa84BFn2lGCbdaaRYioG/8/6CuIe+7/g+vAtsz1mIKq1MhXsd2gE4yxH+EAh+I SIG/ezOIJ8KQQLwTlPFkw/iv1juaTU38cVizIwPAoJjixUZwQGHxvyDKDBEqktbuIAfw GGJ0i1aa37HdjzwBO85OaOUWrcJl6saS1mLJ9E3JiFs5fsS+UkJj/liGrNV2Xo6FJb5X 2rOM7C8bYyNntNpbJxKzwCVWHLiTpM0Xsp2OtH7vqzzt//8iRjdl1/91pUqG0nXmhOip h4BA== X-Gm-Message-State: AOAM532YimtHt+CvnbfPTXUgXwpEbpo1ecFVuveXYFKF+jmg/5PlgWDD sIu5IHg1cy1HQJcK5I95JMg= X-Google-Smtp-Source: ABdhPJxbXGfd9mck2tDFbNmLqkoxQjsat5/6JjDnBP3Kc8XcoFYgDY0fKvhBdGU7xgOjpxlNBG8WvQ== X-Received: by 2002:ac2:4e6b:: with SMTP id y11mr6200117lfs.439.1635449728830; Thu, 28 Oct 2021 12:35:28 -0700 (PDT) Original-Received: from localhost ([89.248.168.244]) by smtp.googlemail.com with ESMTPSA id o21sm402037lfu.77.2021.10.28.12.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 12:35:28 -0700 (PDT) In-Reply-To: <87v926o303.fsf@gnus.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:218516 Archived-At: --=-=-= Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" --==-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable New patch supports incomplete sexps and adds tests for them. =E2=80=9Ctest-identation=E2=80=9D ert test in elisp-mode-tests.el does pass. --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJLBAEBCgA1FiEEgu5SJRdnQOF34djNsr6xYbHsf0QFAmF6+MQXHG51Y2xlYXJz cGFjZUBnbWFpbC5jb20ACgkQsr6xYbHsf0Q25A//TI7+fuHJSs9jD7znH9R7I05j Hox1JP02hcUxNnGYQYEoSMAGvqICMs1p+ZLiWdypcr6ywEqmNs2lYtyIHqBaRSlW a5SagalEMfeOA3OwbOzoK5oFLz0CzvieM86kUlV2HEfE4LEXtr487KJiWuN0omv+ bDKgRB6Y9DgcwO3c4cv7ug+ABDPtPtdsPKlA/tUOSsIWGpqzS/T7rVZP3Iv1FObU PhHMNMwKFoofsl5qEenEhTV8CbXKxPRyM0bYpxsMI2yXE9wj97tXrSaiihPnMjhZ u5orP2hznlLJSwRZeQXIJOM4pOU+LzJnyrFYyTzLV1OLY7ysMoxjjymyduE/lBBE w5/FvAc+sJOX78sfe7fe7My5s2jNp3ZRfiqBhANDtjUSe9LmxTMV2rrofR1I0Apf 7swTnJzdnEZn3/6El67kl3z2CpiQQvEZuXs9xSb8XrJiu+ECA8l75hH+fsi3swt5 nXyN9rIv3Lhjryxv9m2EGras9FiA22z7iVRXJUyoju8mv1Ja86CUlQKaq3tDMzIp 45GTa2O7KqdY6tvCH63Z4usb+a7zE1K7pqYMSgLIGfXuaOFg/7vFAT8m+5k54kSU dizPu++BoUPc12WL3lUTkeUE3YDE5zAgSA2oDLuZGJQOICBQfhsYPJ4J4SEyMrlV x600BeuYFvsxwnVz1L8= =obX0 -----END PGP SIGNATURE----- --==-=-=-- --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Indent-cl-flet-like-forms-correctly-in-incomplete-ex.patch Content-Transfer-Encoding: quoted-printable Content-Description: Support incomplete sexps when indenting cl-flet-like forms >From c3edf97a4f39044885a8bc544a31762ba9a28695 Mon Sep 17 00:00:00 2001 From: akater Date: Mon, 18 Oct 2021 03:08:06 +0000 Subject: [PATCH] Indent cl-flet-like forms correctly in incomplete expressi= ons * 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 (=3D 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 t= his. - (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 (=3D (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 #'=3D) - (cl-loop - with pos =3D (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 (=3D 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 erro= r. + ;; We don't care but still, better fix= this. + (read (current-buffer))))) + (when (memq head '( cl-flet cl-labels cl-macrolet cl-fl= et* + 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 =E2=80=9Cto the right=E2= =80=9D. + (backward-up-list 2) + t) + (=3D local-definitions-starting-point (point)))))))) =20 (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))) =3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-no-side-effects-1 +Code: (lambda () (emacs-lisp-mode) (setq indent-tabs-mode nil) (newline ni= l t)) +Point-Char: | + +=3D-=3D +(let ((x (and y| +=3D-=3D +(let ((x (and y + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-no-side-effects-2 + +=3D-=3D +(let ((x| +=3D-=3D +(let ((x + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-whitespace-1 +Point-Char: | + +=3D-=3D +(cl-flet((f (x)| +=3D-=3D +(cl-flet((f (x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-whitespace-2 +Point-Char: | + +=3D-=3D +(cl-flet((f(x)| +=3D-=3D +(cl-flet((f(x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-whitespace-3 + +=3D-=3D +(cl-flet ((f(x)| +=3D-=3D +(cl-flet ((f(x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-whitespace-4 + +=3D-=3D +(cl-flet( (f (x)| +=3D-=3D +(cl-flet( (f (x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-whitespace-5 + +=3D-=3D +(cl-flet( (f(x)| +=3D-=3D +(cl-flet( (f(x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-1 + +=3D-=3D +(cl-flet((f (x)| +=3D-=3D +(cl-flet((f (x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-2 + +=3D-=3D +(cl-flet ((f(x)| +=3D-=3D +(cl-flet ((f(x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-3 + +=3D-=3D +(cl-flet( (f (x)| +=3D-=3D +(cl-flet( (f (x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-4 + +=3D-=3D +(cl-flet( (f (x)| +=3D-=3D +(cl-flet( (f (x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-5 + +=3D-=3D +(cl-flet( (f (x)| +=3D-=3D +(cl-flet( (f (x) + | +=3D-=3D-=3D + +Name: flet-indentation-incomplete-sexp-missing-and-excessive-whitespace-6 + +=3D-=3D +(cl-flet( (f(x)| +=3D-=3D +(cl-flet( (f(x) + | +=3D-=3D-=3D --=20 2.32.0 --=-=-=--