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: Wed, 29 Sep 2021 18:12:10 +0000 Message-ID: <87lf3fntdx.fsf@gmail.com> References: <504153FB-8633-4755-A91A-DF5DD64E6FAA@acm.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="13613"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , 9622@debbugs.gnu.org, "Diogo F. S. Ramos" To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 29 20:24:11 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 1mVeFW-0003KY-Ns for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 20:24:10 +0200 Original-Received: from localhost ([::1]:41994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVeFU-0004aG-Va for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 14:24:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVeFN-0004ZG-TO for bug-gnu-emacs@gnu.org; Wed, 29 Sep 2021 14:24:01 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38657) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVeFN-00085U-Ll for bug-gnu-emacs@gnu.org; Wed, 29 Sep 2021 14:24:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mVeFN-0000eX-IV for bug-gnu-emacs@gnu.org; Wed, 29 Sep 2021 14:24:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: akater Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 Sep 2021 18:24: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.16329398332492 (code B ref 9622); Wed, 29 Sep 2021 18:24:01 +0000 Original-Received: (at 9622) by debbugs.gnu.org; 29 Sep 2021 18:23:53 +0000 Original-Received: from localhost ([127.0.0.1]:50203 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVeFD-0000e5-UT for submit@debbugs.gnu.org; Wed, 29 Sep 2021 14:23:53 -0400 Original-Received: from mail-qk1-f181.google.com ([209.85.222.181]:40530) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVeF7-0000dm-R8 for 9622@debbugs.gnu.org; Wed, 29 Sep 2021 14:23:51 -0400 Original-Received: by mail-qk1-f181.google.com with SMTP id 72so3244249qkk.7 for <9622@debbugs.gnu.org>; Wed, 29 Sep 2021 11:23:45 -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=ArSH97DPjmZnAq1eLMR9yaW6d7+wbt7HWhfhVvQTbkw=; b=TqeJt/ksD+PpPEpRKrB77DaWDRWFAR01HjZHIoAeBL2G5DBT3a88jmj1Bq3nUVe1bx acSSVJL7hW7IHZn8VaZKkLA13UbUU+pbmDGfuJMImj+7R/0crLZI5ODlZYW1mIoy/qXT Xi1/1Q88I4y4Y6HCLhkmMUZplgL68Ut7xNTco7Js86hxkswP4kVlVGaivwJoly/PyY2I 0oz+oFZQEhrPJra/sU8s77jCL2dzCYcwcpCd76jvEqubwtV/HoukWUPWXgVGjYIpcxEZ PP1Vbp/ZAngTvlhZdZ6OluXfELr7yqUjm4Ly0ev2608IAO8uc2die6Bz4V+R96E1CONv YRFg== 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=ArSH97DPjmZnAq1eLMR9yaW6d7+wbt7HWhfhVvQTbkw=; b=Zba3yINq5uOZSZwzPdmeral3vgRplaLb6WAUMSyjSRuK+dJkfOLTFH7VvW2eNIjgeF 2W05m6SKMNsIFSukuRqk6LcHmOZS0JE2cwYNseS3qkF2EPKmIk0bryuqh+61pH8h0qGx HmcaHiQ9IGT4jC/7pCxAhlH89PqzistaBvfnTc9BE2oE5T0SAauJy7yeDIQmdhR/rAjy DioiKzQyH4GHMFB0mnQAP31nQSBSNQN7+d4B/tKVzncuJ1VrJBBJ7mz+EydtkxBSOBiO SOjyKQet2IZupQKPDQOtrrmfCrHFOR6e0Gq+ll4kP54t5YOMZ8FA3J/4T7HtiHRQLKvB BCYw== X-Gm-Message-State: AOAM531Gv7XcPJfXtI9N/cLOjwNobtBFf1eY2Gj5jfepjLo/Lh6Ck0JS RCVHNc47yjr15QEX1hZBSyw= X-Google-Smtp-Source: ABdhPJyqLtT56BSSnXaGAfk1AR5w+h52H/k9tSj7JaYOE2i6Ja8ipjt277/vehh1xsDtlN1D37IQ3A== X-Received: by 2002:a37:6547:: with SMTP id z68mr1179509qkb.303.1632939820331; Wed, 29 Sep 2021 11:23:40 -0700 (PDT) Original-Received: from localhost (wholesomeserver.media.mit.edu. [18.27.197.252]) by smtp.googlemail.com with ESMTPSA id k19sm360371qko.115.2021.09.29.11.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 11:23:39 -0700 (PDT) In-Reply-To: <504153FB-8633-4755-A91A-DF5DD64E6FAA@acm.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:215896 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 Several fixes: =2D We now check whether we're in the relevant subexpression of flet and friends. =2D Added -p to the predicate's name. =2D Added cl-macrolet cl-flet* cl-symbol-macrolet to the list of local definers. I added cl-symbol-macrolet too because this is how SLIME indents symbol-macrolet. Technical notes: =2D I attached flet-tests.sexp which only contains cl-flet forms written the way they are meant to be indented. I think writing them in strings in deftest forms would be quite ugly and unreliable. If appropriate, I could add test(s) that would try to indent individual forms in the file; no change indicates test(s) passed. Only I'm not sure what would be the best way to define an individual ert test per form but I guess I'll figure it out. OK? =2D parse-partial-sexp does not keep any record of relative position of subexpressions in superexpressions which I found surprising. Things would be easier if it did. Other things might become easier too. But I did not dare to patch it. I also have stylistic notes. First, the less important ones. =2D You changed =E2=80=9Ciff=E2=80=9D to =E2=80=9Cif=E2=80=9D; I meant =E2= =80=9Ciff=E2=80=9D, i.e. =E2=80=9Cif and only if=E2=80=9D; I now changed it to =E2=80=9Cwhen=E2=80=9D simply because the semantics cor= responds directly to that of lisp's own lingo and is thus in my opinion easier to read. =2D Lines > In Wishful Lisp, the following form would be > ... are supposed to convey the intent of what the form in quistion does, in a concise way. Feel free to remove this if you feel it doesn't help. The more involved stylistic note is =2D a line split issue that I wanted to discuss for some time. See the diff when it comes to second-order-parent and (pop parents). TL;DR: it's entirely up to you but I wanted to point out that this was done deliberately. Note that if pop (or a hypothetical cdrf) accepted multiple arguments, most people would agree it's fine to keep these two on a single line; if you have time, see the discussion I started in emacs-devel: https://lists.gnu.org/archive/html/emacs-devel/2021-09/msg02189.html --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJLBAEBCgA1FiEEgu5SJRdnQOF34djNsr6xYbHsf0QFAmFUrHoXHG51Y2xlYXJz cGFjZUBnbWFpbC5jb20ACgkQsr6xYbHsf0S2qQ/+K9AIm82i0sov8jkZfe0OSVns 6Dp29UG4vHMNV9GF/reAPVy72ewQW4QZo7dP0EyItZHNllHPgOnAXPApnZdpYBqL gk067/B4MN6Erctep5gjys/0xGn0bHzJjAAzg/MrdsXDKkynNhSPP83qqEN4Kl/F VvZWKz2HVxYjtaW+OKDnP8CsA1bj0I4+d4ZNbVVABH0ghwysuY+UZVkno2/66xot 0+7aShJYmhJU/53q4gxXw6R6N76Q+Jj5cQiTISWZJA2a//LcwA/NwgaBz5fIoi4o 9CX/luTdUdjj26lOd1EOFkGaGg9B8qXznzo+E1+G5s8U22NxC6Dm2IuLy1Ev/Qik TWBQv92yW5TSwSaGd9XcQZ0lEERZqU6quvw7h+7sNbJNssqzue8M8YZrnNI928qM bwJNy+80eY/N8slHGuougVm/6y068wQZ2d5OfqJDxdenQC07XLv7dLaUlv1Y4X4E 3xfrdhCBWVV2H3Jytqu2L1SNE25LfKyT1xE1qrTQimPGQ0Lg7m2vsdut9wTg7N0L KQ6ABhCQQwH8vAMQpy75LTFEYxszUSviZXnTclaBuIKd98aKbDHItvIJ4ikV7c8T DfCLqM3+s1ncrcstHgoWCD7+zCvse1gksAFLgqUrjNRtPIh+vKZAbAyaSRoNhxr0 DDZKyXV2YPigxr5NBss= =0wRN -----END PGP SIGNATURE----- --==-=-=-- --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fixup-cl-flet-indentation.patch Content-Description: Fix cl-flet indentation >From 688ec23060f89a75d7356bba576bc8d31f32174f Mon Sep 17 00:00:00 2001 From: akater Date: Wed, 29 Sep 2021 15:45:32 +0000 Subject: [PATCH] ; Fixup: cl-flet indentation Addresses several deficiencies in bugfix 38037e04cb05cb1f2b604f0b1602d36b0bcf6985 - Check whether we're in the relevant subexpression of flet and friends. - Add -p to the predicate's name. - Add cl-macrolet cl-flet* cl-symbol-macrolet to the list of local definers. cl-symbol-macrolet added because this is how SLIME indents symbol-macrolet. --- lisp/emacs-lisp/lisp-mode.el | 55 ++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 7ce857e990..d2d63606da 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -1106,26 +1106,55 @@ defun calculate-lisp-indent (&optional parse-start) (t normal-indent)))))) -(defun lisp--local-defform-body (state) - "Return non-nil if at local definition body according to STATE. +(defun lisp--local-defform-body-p (state) + "Return non-nil when at local definition body according to 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) + (let* ((parents (nth 9 state)) second-order-parent + (second-cons-after (cddr parents))) (while second-cons-after (when (= start-of-innermost-containing-list (car second-cons-after)) (setq second-order-parent (car parents) ;; Leave the loop. second-cons-after nil)) - (pop second-cons-after) - (pop parents)) + (pop second-cons-after) (pop parents)) (and second-order-parent (save-excursion (goto-char (1+ second-order-parent)) - (memq (read (current-buffer)) - '(cl-flet cl-labels))))))) + (and (memq (read (current-buffer)) + '( 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))))))))))) (defun lisp-indent-function (indent-point state) "This function is the normal value of the variable `lisp-indent-function'. @@ -1160,7 +1189,9 @@ defun lisp-indent-function (indent-point state) (if (and (elt state 2) (not (looking-at "\\sw\\|\\s_"))) ;; car of form doesn't seem to be a symbol - (if (lisp--local-defform-body state) + (if (lisp--local-defform-body-p state) + ;; We nevertheless check whether we are in flet-like form + ;; as we presume local function names could be non-symbols. (lisp-indent-defform state indent-point) (if (not (> (save-excursion (forward-line 1) (point)) calculate-lisp-indent-last-sexp)) @@ -1184,8 +1215,8 @@ defun lisp-indent-function (indent-point state) (and (null method) (> (length function) 3) (string-match "\\`def" function)) - ;; Check whether we are in flet or labels. - (lisp--local-defform-body state)) + ;; Check whether we are in flet-like form. + (lisp--local-defform-body-p state)) (lisp-indent-defform state indent-point)) ((integerp method) (lisp-indent-specform method state -- 2.32.0 --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=flet-tests.sexp Content-Description: Test cases (cl-flet () (a (dangerous-position b))) (cl-flet wrong-syntax-but-should-not-obstruct-indentation (a (dangerous-position b))) (cl-flet ((a (arg-of-flet-a) b c))) (cl-flet ((a (arg-of-flet-a) b c (if d e f)) (irregular-local-def (form returning lambda)) (g (arg-of--flet-g) h i)) (let ((j k)) (if dangerous-position l m))) (cl-flet ((a (arg-of-flet-a) b c (if d e f)) (irregular-local-def (form returning lambda)) (g (arg-of--flet-g) h i)) (let ((j k)) (if dangerous-position l m))) (cl-flet ((a (arg-of-flet-a) b c (if d e f)) (irregular-local-def (form returning lambda)) (irregular-local-def (form returning lambda)) wrong-syntax-but-should-not-osbtruct-indentation (g (arg-of--flet-g) h i)) (let ((j k)) (if dangerous-position l m))) (cl-flet ((a (arg-of-flet-a) b c (if d e f)) (irregular-local-def (form returning lambda)) wrong-syntax-but-should-not-osbtruct-indentation (g (arg-of--flet-g) h i)) (let ((j k)) (if dangerous-position l m))) (cl-flet (wrong-syntax-but-should-not-obstruct-indentation (g (arg-of--flet-g) h i)) (let ((j k)) (if dangerous-position l m))) ;; (setf _) not yet supported but looks like it will be (cl-flet (((setf a) (new value) stuff) wrong-syntax-but-should-not-obstruct-indentation (g (arg-of--flet-g) h i)) (let ((j k)) (if dangerous-position l m))) (cl-flet ( (a (arg-of-flet-a) b c (if d e f)) (irregular-local-def (form returning lambda)) (g (arg-of--flet-g) h i)) (let ((j k)) (if dangerous-position l m))) (cl-flet ( wrong-syntax-but-should-not-obstruct-indentation (g (arg-of--flet-g) h i)) (let ((j k)) (if dangerous-position l m))) (cl-flet ( wrong-syntax-but-should-not-obstruct-indentation (g (arg-of--flet-g) h i)) (let ((j k)) (if dangerous-position l m))) (cl-flet (wrong-syntax-but-should-not-obstruct-indentation (g (arg-of--flet-g) h i) wrong-syntax-but-should-not-obstruct-indentation (g (arg-of--flet-g) h i))) (cl-flet (wrong-syntax-but-should-not-obstruct-indentation wrong-syntax-but-should-not-obstruct-indentation (g (arg-of--flet-g) h i) wrong-syntax-but-should-not-obstruct-indentation)) (cl-flet (wrong-syntax-but-should-not-obstruct-indentation wrong-syntax-but-should-not-obstruct-indentation wrong-syntax-but-should-not-obstruct-indentation (g (arg-of--flet-g) h i))) --=-=-=--