Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IF form is misindented #45

Closed
luismbo opened this issue Dec 31, 2018 · 17 comments
Closed

IF form is misindented #45

luismbo opened this issue Dec 31, 2018 · 17 comments

Comments

@luismbo
Copy link
Member

luismbo commented Dec 31, 2018

image

The then and else branches should be aligned.

@ninejaguar
Copy link

image

The then and else branches should be aligned.

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

image

@arbv
Copy link
Member

arbv commented Dec 31, 2018

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.

@arbv arbv closed this as completed Dec 31, 2018
@phoe
Copy link

phoe commented Dec 31, 2018

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

@arbv
Copy link
Member

arbv commented Dec 31, 2018

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

@ninejaguar
Copy link

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
Copy link

phoe commented Dec 31, 2018

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
Copy link
Member

arbv commented Dec 31, 2018

@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
Copy link
Member

arbv commented Dec 31, 2018

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.

@arbv arbv reopened this Dec 31, 2018
@ninejaguar
Copy link

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
Copy link
Member

arbv commented Jan 1, 2019

@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
Copy link

ninejaguar commented Jan 1, 2019

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
Copy link
Member

arbv commented Jan 1, 2019

@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
Copy link

olopierpa commented Jan 1, 2019 via email

@ninejaguar
Copy link

ninejaguar commented Jan 1, 2019

@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
Copy link

@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
Copy link
Member

arbv commented Jan 2, 2019

Fixed.

@arbv
Copy link
Member

arbv commented Jan 2, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants