sharplispers / cormanlisp

Corman Lisp
MIT License
571 stars 77 forks source link

IF form is misindented #45

Closed luismbo closed 5 years ago

luismbo commented 5 years ago

image

The then and else branches should be aligned.

ninejaguar commented 5 years ago

image

The then and else branches should be aligned.

You're right, they're aligned in Portacle...

image

arbv commented 5 years ago

It is not misindented. Dorai Sitaram's lispindent uses old-school formatting for IF form which I kind-of like. The same formatting is used by default for Emacs Lisp, for example.

phoe commented 5 years ago

If anything, indentation behavior should be configurable as soon as swank indentation is available on Corman CL. (See #43)

arbv commented 5 years ago

Lispindent's behaviour can be customised as described here https://github.com/ds26gte/scmindent/blob/master/README.adoc.

ninejaguar commented 5 years ago

Lispindent's behaviour can be customised as described here https://github.com/ds26gte/scmindent/blob/master/README.adoc.

Thank you for that clarifying link. I knew I'd seen that type of indentation before in Emacs but didn't have a vanilla install handy. Portacle's approach is non-standard. After comparing the two, along with the explanation in the link you'd provided, the default Emacs way makes more sense. Portacle may disappear as Lispbox and others have, but there will always be good old Emacs to show the way and compare with :-)

phoe commented 5 years ago

Portacle may disappear as Lispbox and others have

AFAIK, both Portacle and Lispbox depend on the Swank indentation contrib that makes it possible for the Lisp image itself to provide indentation hints to the editor. See https://github.com/slime/slime/blob/master/contrib/swank-indentation.lisp

arbv commented 5 years ago

@ninejaguar @phoe Portacle uses the indentation support provided by SLIME/SWANK.

To be fair, the different indentation of the IF form is a matter of taste, nothing more. And it is configurable. I should add some more information into the manual.

arbv commented 5 years ago

I will consider changing default 'lispindent' behaviour it turns out to be a big deal for many users, although I would rather avoid supporting forked, specialised version of 'lispindent' solely because of this feature.

ninejaguar commented 5 years ago

I will consider changing default 'lispindent' behaviour it turns out to be a big deal for many users, although I would rather avoid supporting forked, specialised version of 'lispindent' solely because of this feature.

I don't know if you'll get the necessary user feedback, but a search on expected indentation for Common Lisp suggests that there's a strong preference to follow whatever Slime/Swank is doing on top of the default Emacs Lisp way of indentation.

According to the "Google Common Lisp Style Guide"...

"Ideally, use the default indentation settings provided by slime-indentation."

https://google.github.io/styleguide/lispguide.xml#Indentation

According to the "Lisp-Lang Style Guide"...

In the if special form, both branches must be on the same line:

(if (> x 5)
    (format t "Greater than five")
    (format t "Less than or equal to five"))

https://lisp-lang.org/style-guide/

According to Robert Strandh's "Symbolic programming using Common Lisp: Indenting Common Lisp"...

Each special form has its own indentation rule. Here, we give a list of the most common ones.

Indenting the if special form

The if special form in Common Lisp takes exactly three subexpressions. The subexpressions should be lined up, like this:

  (if (= (f x) 4)
      (top-level x)
      (g x))

This indentation is accomplished by the following Emacs expression that you can put in your .emacs file:

(put 'if 'lisp-indent-function nil)

http://dept-info.labri.fr/~idurand/enseignement/lst-info/PFS/Common/Strandh-Tutorial/indentation.html

arbv commented 5 years ago

@ninejaguar @luismbo

I don't know if you'll get the necessary user feedback, but a search on expected indentation for Common Lisp suggests that there's a strong preference to follow whatever Slime/Swank is doing on top of the default Emacs Lisp way of indentation.

It seems I have got enough user feedback regarding this matter.

OK then, let's try to not deviate from the more common way of indenting IF.

Does indenting IF-forms works as expected after executing the following snippet?

(setf (cdr (assoc "IF" ide::*lisp-keywords* :test #'string-equal)) -1)

P.S.

I could not imagine doing this stuff literally 3-hours after the New Year in my timezone.

ninejaguar commented 5 years ago

OK then, let's try to not deviate from the more common way of indenting IF.

Does indenting IF-forms works as expected after executing the following snippet?

(setf (cdr (assoc "IF" ide::*lisp-keywords* :test #'string-equal)) -1)

P.S.

I could not imagine doing this stuff literally 3-hours after the New Year in my timezone.

Happy New Year! May you and your loved ones enjoy great health and happiness in 2019!

It appears that executing the suggested snippet works on the first example below, but the second example may have an issue in the body of the THEN branch as seen in the prog1 form...

image

But, using progn or prog2 instead seems to work...

image

image

arbv commented 5 years ago

@ninejaguar

It seems that 'lispindent' has some specific rules about indenting PROG1. Actually, I believe, this indentation makes sense.

BTW, SLIME/SWANK seems to indent PROG1 and PROG2 forms in exactly the same way. It has nothing to do with indenting IF-form.

Anyway, I am not sure that making current indenting engine to work exactly the same way as SLIME/SWANK is what should be done.

olopierpa commented 5 years ago

On Tue, Jan 1, 2019 at 4:04 AM ninejaguar notifications@github.com wrote:

OK then, let's try to not deviate from the more common way of indenting IF.

Does indenting IF-forms works as expected after executing the following snippet?

(setf (cdr (assoc "IF" ide::lisp-keywords :test #'string-equal)) -1)

P.S.

I could not imagine doing this stuff literally 3-hours after the New Year in my timezone.

Happy New Year! May you and your loved ones enjoy great health and happiness in 2019!

It appears that executing the suggested snippet works on the first example below, but the second example may have an issue in the body of the THEN branch as seen in the prog1 form...

The PROG1 is indented correctly. The first form should be on the same line as the PROG1 itself.

The IF indentation which started this thread is not 'old-school'. Only Elisp has ever been indented that way, and Lisp code indented by a misconfigured Emacs.

Reply to this email directly, view it on GitHub https://github.com/sharplispers/cormanlisp/issues/45#issuecomment-450706871, or mute the thread https://github.com/notifications/unsubscribe-auth/ADTJ4bUA-chuVZ5hODixbgf5KpwVvJnoks5u-tBIgaJpZM4Zlf-t .

ninejaguar commented 5 years ago

@arbv

It seems that 'lispindent' has some specific rules about indenting PROG1. Actually, I believe, this indentation makes sense.

BTW, SLIME/SWANK seems to indent PROG1 and PROG2 forms in exactly the same way. It has nothing to do with indenting IF-form.

You're right. It looks like Portacle is indenting similarly based on the following snippet...

image

ninejaguar commented 5 years ago

@olopierpa

The PROG1 is indented correctly. The first form should be on the same line as the PROG1 itself.

Good to know! Thank you for clarifying.

arbv commented 5 years ago

Fixed.

arbv commented 5 years ago

I have updated the 3.1 release to include the fix for this issue.