-
Notifications
You must be signed in to change notification settings - Fork 41
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
Allow closing parens after indented comment lines #92
Comments
This is a good question. I've thought about it some, and I just think it is difficult to reconcile.
For example, given we have this: [:foo
;; :bar ;; This does bar things
] If I comment out the last line, indent-mode has to insert a close-paren somewhere, so it's forced to create a new line to include the indented comment: [:foo
;; :bar ;; This does bar things
]
;] Once you uncomment the last line, the |
I can't think of a solution for this, so I'll document it in a faq |
This came up again. This is the first I've heard Parinfer "breaking UX" for non-parinfer users, despite preserving the code. This means parinfer changed the code format in such a way that makes it easy for non-parinfer users to break the code. from: status-im/status-mobile@883b702#commitcomment-23648790 on the one hand, it’s a given that incorrect indentation is going to mislead you about implied structure. on the other hand, if users setup their code so that they can safely uncomment lines without thinking, then it is parinfer that threw a fork in their process and will take the blame for the broken code |
This Parinfer behavior has always bothered me. One partial workaround for now, at least in Clojure, is to use the discard syntax, In Common Lisp and Emacs Lisp, the user can use a dotted list with an explicit nil, like But on team projects, this would likely violate the style norms. |
Thanks for commenting, I've been thinking about how to fix this, which I think is worth doing now based on what I've heard. elevating priority. |
Paren trail lines will be created as a result of indented comments. When the comments are removed or indented differently, stale paren trail lines should be removed rather than emptied. This will help keep Parinfer from sprinkling too many padded line artifacts when comments shift around. (tracking at #133) |
I will again close this, but move it to a WIP |
New ideaRe-opening (again), because:
New Hygiene rule for cleaning up lines
New Indentation rules for comment tokens
Reversibility of rule 4 is enabled by rule 1Here, “reversibility” means that if you type something, Parinfer’s effect on your code can be undone by removing what you just typed. My original concern above was that if someone repeatedly adds and removes a semicolon, it would create a flood of new lines being added over and over again. The hygiene rule (# 1) prevents this. For example, if I comment out the last (foo
;; bar
;)
^ commenting out `)` …then a new one will be inserted on a new line: (foo
;; bar
;)
)
^ new `)` on new line And if I remove the semicolon that I just typed, the hygiene rule removes the line that Parinfer added: (foo
;; bar
)
^ uncommented (and subsequent line hygienically removed) Impact on DesignThese new rules seem to be systematic enough to allow comments to behave like normal expressions when participating in indentation rules— by just prefixing their paren trails with a newline and extra whitespace. And this is kept in check by a new hygiene rule which produces standard-looking formatted code in other cases as well. The properties of these new rules should propagate pretty predictably, but I’ll see how it affects existing test cases and report back any unforeseen effects here. Why did the original design include the constraint of not adding or removing lines?
Forgive me, I’m having trouble remembering. I think symmetry between input and output seemed nice or important in some contexts, but I can’t recall the reasons if I had them. |
How would the following be formatted according to your new idea, Shaun? ;; example 1
(foo bar ;; something
)
;; example 2
(foo
bar ;; something
) |
It‘s a good question— should inline comments and indented comments have their positions preserved in the AST, and if so, when? The current rules I stated above only relate to indented comments, and don’t change Parinfer’s behavior toward inline comments. So the closing parentheses are moved after bar in both cases: I opened an issue in the Clojure Style Guide and left my thoughts about inline comments there: |
One thing I noticed is that Parinfer already has logic for preserving the relative indentation of child comments when their parent expression moves, but it looks like the way it’s set up actually breaks the reversibility goal. The video below shows how dedented comments can be captured by sufficiently dedenting the parent expression. This means that implementing these new rules would actually improve the behavior there. dedented-comments-violate-reversibility.mp4 |
Sometimes comments are within a block for a reason, and keeping them within the block may be useful. For example, in indent mode, moving around
becomes
I think that the second form loses some obviousness in that it's no longer obvious on what the comment is relating to. Should parinfer be updated to include this?
The text was updated successfully, but these errors were encountered: