unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55033: [PATCH] Define indentation behavior for a few more special Scheme forms
@ 2022-04-20  7:20 Jean Abou Samra
  2022-04-20  7:47 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Jean Abou Samra @ 2022-04-20  7:20 UTC (permalink / raw)
  To: 55033

[-- Attachment #1: Type: text/plain, Size: 337 bytes --]

Hi,

The attached patch defines special indentation for a few more special Scheme
forms: and-let*, with-syntax, eval-when, and the pattern matching family
(match, match-lambda, match-let, etc.).

I didn't do copyright assignment, assuming that the patch is trivial enough,
but let me know if this would be desirable.

Best regards,
Jean

[-- Attachment #2: 0001-Define-indentation-behavior-for-a-few-more-special-S.patch --]
[-- Type: text/x-patch, Size: 1941 bytes --]

From 1c6f0aca088896b7e07f7251bc860daeda0916fe Mon Sep 17 00:00:00 2001
From: Jean Abou Samra <jean@abou-samra.fr>
Date: Tue, 19 Apr 2022 23:40:29 +0200
Subject: [PATCH] Define indentation behavior for a few more special Scheme
 forms

* lisp/progmodes/scheme.el: define 'scheme-indent-function for
  and-let*, with-syntax, eval-when, and pattern matching macros.
---
 lisp/progmodes/scheme.el | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lisp/progmodes/scheme.el b/lisp/progmodes/scheme.el
index 592e2d5057..9b98c4e6dd 100644
--- a/lisp/progmodes/scheme.el
+++ b/lisp/progmodes/scheme.el
@@ -576,12 +576,16 @@ indentation."
 (put 'letrec 'scheme-indent-function 1)
 (put 'let-values 'scheme-indent-function 1) ; SRFI 11
 (put 'let*-values 'scheme-indent-function 1) ; SRFI 11
+(put 'and-let* 'scheme-indent-function 1) ; SRFI 2
 (put 'sequence 'scheme-indent-function 0) ; SICP, not r4rs
 (put 'let-syntax 'scheme-indent-function 1)
 (put 'letrec-syntax 'scheme-indent-function 1)
 (put 'syntax-rules 'scheme-indent-function 1)
 (put 'syntax-case 'scheme-indent-function 2) ; not r5rs
+(put 'with-syntax 'scheme-indent-function 1)
 (put 'library 'scheme-indent-function 1) ; R6RS
+;; Part of at least Guile, Chez Scheme, Chicken
+(put 'eval-when 'scheme-indent-function 1)
 
 (put 'call-with-input-file 'scheme-indent-function 1)
 (put 'call-with-port 'scheme-indent-function 1)
@@ -605,6 +609,14 @@ indentation."
 ;; SRFI-8
 (put 'receive 'scheme-indent-function 2)
 \f
+;; SRFI-204 (withdrawn, but provided in many implementations, see the SRFI text)
+(put 'match 'scheme-indent-function 1)
+(put 'match-lambda 'scheme-indent-function 0)
+(put 'match-lambda* 'scheme-indent-function 0)
+(put 'match-let 'scheme-indent-function 'scheme-let-indent)
+(put 'match-let* 'scheme-indent-function 1)
+(put 'match-letrec 'scheme-indent-function 1)
+\f
 ;;;; MIT Scheme specific indentation.
 
 (if scheme-mit-dialect
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#55033: [PATCH] Define indentation behavior for a few more special Scheme forms
  2022-04-20  7:20 bug#55033: [PATCH] Define indentation behavior for a few more special Scheme forms Jean Abou Samra
@ 2022-04-20  7:47 ` Eli Zaretskii
  2022-04-20  9:31   ` Jean Abou Samra
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2022-04-20  7:47 UTC (permalink / raw)
  To: Jean Abou Samra; +Cc: 55033

> Date: Wed, 20 Apr 2022 09:20:45 +0200
> From: Jean Abou Samra <jean@abou-samra.fr>
> 
> The attached patch defines special indentation for a few more special Scheme
> forms: and-let*, with-syntax, eval-when, and the pattern matching family
> (match, match-lambda, match-let, etc.).

Thanks, but could you perhaps explain the rationale for each change,
so that they could be independently verified?  I find the comment
above this part of code, viz.:

  ;; (put 'begin 'scheme-indent-function 0), say, causes begin to be indented
  ;; like defun if the first form is placed on the next line, otherwise
  ;; it is indented like any other form (i.e. forms line up under first).

too obfuscated to understand the numbers used as the values of this
property; in particular, the interpretation of the numerical value
(zero in the above example) doesn't seem to be explained, at least not
explicitly enough for me to understand it.  I'd love to have that
explained better if possible.

Also, when you say "SRFI 2" in a comment, where in the SRFI 2 document
should one look for the information relevant to the indentation?

> I didn't do copyright assignment, assuming that the patch is trivial enough,
> but let me know if this would be desirable.

This patch can be accepted without a copyright assignment, but if you
intend to contribute to Emacs in the future, I'd encourage you to
start your legal paperwork rolling, so that we could accept your
contributions without any limitations.  If you agree, I will send you
the form to fill and the instructions to email it.

Thanks.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#55033: [PATCH] Define indentation behavior for a few more special Scheme forms
  2022-04-20  7:47 ` Eli Zaretskii
@ 2022-04-20  9:31   ` Jean Abou Samra
  2022-04-20  9:59     ` Eli Zaretskii
  2022-04-20 16:38     ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: Jean Abou Samra @ 2022-04-20  9:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 55033

Le 20/04/2022 à 09:47, Eli Zaretskii a écrit :
>> Date: Wed, 20 Apr 2022 09:20:45 +0200
>> From: Jean Abou Samra <jean@abou-samra.fr>
>>
>> The attached patch defines special indentation for a few more special Scheme
>> forms: and-let*, with-syntax, eval-when, and the pattern matching family
>> (match, match-lambda, match-let, etc.).
> Thanks, but could you perhaps explain the rationale for each change,
> so that they could be independently verified?  I find the comment
> above this part of code, viz.:
>
>    ;; (put 'begin 'scheme-indent-function 0), say, causes begin to be indented
>    ;; like defun if the first form is placed on the next line, otherwise
>    ;; it is indented like any other form (i.e. forms line up under first).
>
> too obfuscated to understand the numbers used as the values of this
> property; in particular, the interpretation of the numerical value
> (zero in the above example) doesn't seem to be explained, at least not
> explicitly enough for me to understand it.  I'd love to have that
> explained better if possible.



Yeah, I didn't take my understanding from code comments, but from

http://community.schemewiki.org/?emacs-indentation

I could easily improve the comments.

Basically, the two important cases are (put 'xx 'scheme-indent-function 0),
which indents with two spaces rather than one in case the first form is
on a separate line, as is traditional for begin, let, etc.; and
(put 'xx 'scheme-indent-function 1), which is used for let-like and
lambda-like constructs where you first have one form more to the right
(if you really want to put it on a different line, but normally you'd put
it on the same line as "lambda" or start it on the same line as "let"),
and then a sequence of forms indented with two spaces within the let/lambda
body.

(begin
   expr ; note extra space
   expr2
   expr3)

(lambda
     (x y z) ; if you really want to
   expr
   expr2
   expr3)

(lambda (x y z) ; more common
   expr
   expr2
   expr3)



> Also, when you say "SRFI 2" in a comment, where in the SRFI 2 document
> should one look for the information relevant to the indentation?


Good question. I didn't even think of looking ;-)
It seemed obvious to me that you would indent it
like a let*, since it is a variant of the let* construct.
But ... looking at the SRFI text
<https://srfi.schemers.org/srfi-2/srfi-2.html>
I see that it is inconsistent. It has three different
possibilities in the examples:

(and-let* (...)
     ...)

(and-let* (...)
   ...)

(and-let* (...)
          ...)

The second one is in a 'mixed' example where the indentation
is not even consistent within the body of one and-let*, which
I find very weird.

At any rate, I looked at these:

https://www.gnu.org/software/guile/manual/html_node/SRFI_002d2.html
(Guile)

https://www.gnu.org/software/mit-scheme/documentation/stable/mit-scheme-ref/and_002dlet_002a-_0028SRFI-2_0029.html
(MIT/GNU Scheme)

https://practical-scheme.net/gauche/man/gauche-refe/Binding-constructs.html
(Gauche)

All of them have indentation as I would expect, namely

(and-let* (...)
   ...)



>> I didn't do copyright assignment, assuming that the patch is trivial enough,
>> but let me know if this would be desirable.
> This patch can be accepted without a copyright assignment, but if you
> intend to contribute to Emacs in the future, I'd encourage you to
> start your legal paperwork rolling, so that we could accept your
> contributions without any limitations.  If you agree, I will send you
> the form to fill and the instructions to email it.


That would be appreciated.

Best,
Jean






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#55033: [PATCH] Define indentation behavior for a few more special Scheme forms
  2022-04-20  9:31   ` Jean Abou Samra
@ 2022-04-20  9:59     ` Eli Zaretskii
  2022-04-20 16:38     ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2022-04-20  9:59 UTC (permalink / raw)
  To: Jean Abou Samra; +Cc: 55033

> Date: Wed, 20 Apr 2022 11:31:01 +0200
> Cc: 55033@debbugs.gnu.org
> From: Jean Abou Samra <jean@abou-samra.fr>
> 
> >> I didn't do copyright assignment, assuming that the patch is trivial enough,
> >> but let me know if this would be desirable.
> > This patch can be accepted without a copyright assignment, but if you
> > intend to contribute to Emacs in the future, I'd encourage you to
> > start your legal paperwork rolling, so that we could accept your
> > contributions without any limitations.  If you agree, I will send you
> > the form to fill and the instructions to email it.
> 
> 
> That would be appreciated.

Form sent off-list.

I will study carefully the rest of your message a bit later.  Thanks.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#55033: [PATCH] Define indentation behavior for a few more special Scheme forms
  2022-04-20  9:31   ` Jean Abou Samra
  2022-04-20  9:59     ` Eli Zaretskii
@ 2022-04-20 16:38     ` Eli Zaretskii
  2022-04-20 16:47       ` Jean Abou Samra
  1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2022-04-20 16:38 UTC (permalink / raw)
  To: Jean Abou Samra; +Cc: 55033-done

> Date: Wed, 20 Apr 2022 11:31:01 +0200
> Cc: 55033@debbugs.gnu.org
> From: Jean Abou Samra <jean@abou-samra.fr>
> 
> > Thanks, but could you perhaps explain the rationale for each change,
> > so that they could be independently verified?  I find the comment
> > above this part of code, viz.:
> >
> >    ;; (put 'begin 'scheme-indent-function 0), say, causes begin to be indented
> >    ;; like defun if the first form is placed on the next line, otherwise
> >    ;; it is indented like any other form (i.e. forms line up under first).
> >
> > too obfuscated to understand the numbers used as the values of this
> > property; in particular, the interpretation of the numerical value
> > (zero in the above example) doesn't seem to be explained, at least not
> > explicitly enough for me to understand it.  I'd love to have that
> > explained better if possible.
> 
> 
> 
> Yeah, I didn't take my understanding from code comments, but from
> 
> http://community.schemewiki.org/?emacs-indentation
> 
> I could easily improve the comments.

Thanks, I used this to expand the commentary there, and installed as a
followup after your changes.

And with that, I'm closing this bug report.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#55033: [PATCH] Define indentation behavior for a few more special Scheme forms
  2022-04-20 16:38     ` Eli Zaretskii
@ 2022-04-20 16:47       ` Jean Abou Samra
  0 siblings, 0 replies; 6+ messages in thread
From: Jean Abou Samra @ 2022-04-20 16:47 UTC (permalink / raw)
  To: Eli Zaretskii, 55033

Thank you for applying the patch and expanding the comment!





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-20 16:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20  7:20 bug#55033: [PATCH] Define indentation behavior for a few more special Scheme forms Jean Abou Samra
2022-04-20  7:47 ` Eli Zaretskii
2022-04-20  9:31   ` Jean Abou Samra
2022-04-20  9:59     ` Eli Zaretskii
2022-04-20 16:38     ` Eli Zaretskii
2022-04-20 16:47       ` Jean Abou Samra

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).