Skip to content
  • Sponsor clojure-emacs/clojure-mode

  • Notifications You must be signed in to change notification settings
  • Fork 247

Fix alignment issue involving margin comments. #609

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

Merged
merged 2 commits into from
Feb 22, 2022

Conversation

samwagg
Copy link
Contributor

@samwagg samwagg commented Jan 23, 2022

Alignment wasn't working properly when nested, multi-line sexps were followed by margin comments.

  • The commits are consistent with our contribution guidelines.
  • You've added tests (if possible) to cover your change(s). Bugfix, indentation, and font-lock tests are extremely important!
  • You've run M-x checkdoc and fixed any warnings in the code you've written.
  • You've updated the changelog (if adding/changing user-visible functionality).
  • You've updated the readme (if adding/changing user-visible functionality).

Thanks!

samwagg added a commit to samwagg/clojure-mode that referenced this pull request Jan 23, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Alignment wasn't working properly when nested, multi-line sexps were followed by margin comments.
@samwagg samwagg force-pushed the #608-margin-comment-alignment branch 2 times, most recently from 0ed7ba2 to 51d6b48 Compare January 23, 2022 23:12
@@ -705,6 +705,11 @@ x
"#?@(:clj [2]
:cljs [2])")

(when-aligning-it "should work correctly when margin comments appear after multi-line, non-terminal sexps"
"(let [:x (+ 2 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems an odd example, I really don't recall ever seeing an aligned function invocation.

Hashmaps, cases, etc are more frequent targets.

Also, this piece of code would look exactly the same for the aligned and not aligned cases, so one can't really tell if you're affecting alignment at all with the proposed changes.

I'd suggest choosing a variety of examples, and also, add ; comments at different positions, to get really good coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think alignment of let bindings is common. I made the strange decision to use keywords for the left-hand side of the bindings, which I will definitely update.

I will update to add examples for hashmap and case. I plan to still use a single test with a single form, but I will add all three cases within the form. I think that's what you have in mind.

I will also update so that the alignment isn't trivial; I can see how that might be confusing, but I also what to make clear that it is besides the point. The point is that when you align code that is already aligned correctly, it is getting mangled (see the attached issue). This test does fail if you undo the regexp change I made.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Appreciated.

Simply for record, I still don't see a particular alignment in the example, neither for the let itself or the function invocations:

image

I'm aware that let alignment is a thing but it's better shown e.g. here:

image

...Just in case, indentation != alignment.

btw, this initial newline I added in both of my examples would make the tests more readable. I think it would be welcome if you can update all examples to include it.

(I haven't tried running the tests like that, might require removing the initial newline programatically if present)

@samwagg
Copy link
Contributor Author

samwagg commented Feb 4, 2022

Alright, updated. A couple notes:

  • I left the commits unsquashed for now in case it helps with reviewing. But I understand they need to be squashed before merge.
  • I had interpreted your request to "update all examples" to include the initial newline as a request to update all the existing indentation tests. But now I'm wondering if you just meant for me to do it for my multiple examples. It seems right to be consistent, but I can easily drop that commit if desired.

@vemv
Copy link
Member

vemv commented Feb 4, 2022

Looks all good to me! Great work.

As one last suggestion, you could add examples with ;; comments for greater coverage.


I cannot further review these days for personal reasons, someone else will have to approve/merge

@bbatsov
Copy link
Member

bbatsov commented Feb 5, 2022

I'll take it from here.

@samwagg
Copy link
Contributor Author

samwagg commented Feb 5, 2022

I wasn't sure if I was meant to test margin comments that begin ;; or comments on their own line, so I added coverage for both. The latter is distinct from the issue I was testing, imo, so I added a separate test for it. I checked, and it didn't look like there were any existing tests for alignment of sexps with interleaved line comments.

@samwagg
Copy link
Contributor Author

samwagg commented Feb 5, 2022

I wasn't sure if I was meant to test margin comments that begin ;; or comments on their own line, so I added coverage for both. The latter is distinct from the issue I was testing, imo, so I added a separate test for it. I checked, and it didn't look like there were any existing tests for alignment of sexps with interleaved line comments.

Actually, I suppose having one test with a variety of different comment examples makes sense. I guess I just have tunnel vision for the specific bug I am fixing. I can combine the two tests into one that covers all examples if that style is preferred.

@bbatsov
Copy link
Member

bbatsov commented Feb 6, 2022

More test coverage is usually a good thing, plus some conventions are not as strong with Clojure as with older Lisps - e.g. a lot of people use ;; comments everywhere, although historically ;; was a line comment and ; was a margin comment.

Alignment wasn't working properly when nested, multi-line sexps were followed by margin comments.
Begin multi-line example strings with a newline so that the indentation of the
first line in relation to the rest of the string is plain to see.
@samwagg samwagg force-pushed the #608-margin-comment-alignment branch from 453a7ba to baa5469 Compare February 6, 2022 17:48
@samwagg
Copy link
Contributor Author

samwagg commented Feb 6, 2022

Alright, I think I'm done then. I squashed my commits.

@samwagg
Copy link
Contributor Author

samwagg commented Feb 22, 2022

Hi, just dropping a reminder that I am finished making changes with this PR and I think it's ready. Please let me know if there are any further changes desired.

@bbatsov bbatsov merged commit 4a0b598 into clojure-emacs:master Feb 22, 2022
@bbatsov
Copy link
Member

bbatsov commented Feb 22, 2022

Thanks!

@vemv
Copy link
Member

vemv commented Mar 8, 2022

Released as 5.14.0

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

Successfully merging this pull request may close these issues.

None yet

3 participants