-
Notifications
You must be signed in to change notification settings - Fork 55
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
rewrite-clj does not preserve CRLF whitespaces #187
Comments
Thanks for raising such a clear and easy-to-digest issue @ikappaki, very much appreciated! This is currently as designed, but I think rewrite-clj docs should describe this behaviour clearly if this is not already the case. We use clojure tools.reader and I think it wants to normalize |
Hi @lread, and thank you for the prompt reply! May I please argue that there shouldn't be any exceptions in the design doc that suggest that all newlines seq should be treated as LF. I think the goal that wtitespaces should be preserved is quite powerful, since it guarantees compatibility across all architecture, which should be part of the design. This adversely affects window's users. Its native line ending format is CRLF. If a zipper pipeline is constructed on such a file, it is likely to convert the CRLF to LF even if there are no other changes, and the file stored on disk with incompatible line endings. Every To exaggerate a bit, imagine the trouble it would have caused on *nix if IMHO the tools reader issue is an incidental complexity that should be either prioritised upstream (the issue looks stale?) or a workaround should be devised in |
The JIRA issue doesn't yet have a patch. Maybe it would help if someone wrote that patch and brought the issue to the attention of the core team either on Slack, ask.clojure, etc. |
I haven't looked inside rewrite-clj where this could be patched temporarily, but some looking into this might also help the process of contemplating if a workaround in rewrite-clj is feasible and desired. |
My understanding: I think the clojure tools.reader does not intend to preserve Before my tools.reader work-around in rewrite-clj, files with mixed At this point not normalizing to For now I'm willing to document the behaviour (if I haven't already done so). |
So @ikappaki, I don't disagree with your sentiment at all here, but Clojure is not entirely Windows-friendly. We, unfortunately, inherit that Windows unfriendly-ness. |
Related: #93 |
Sure @lread we are both I think on the same page here and we are just having a friendly discussion from our personal perspectives :) I have been using Clojure primarily on MS-Windows for a long time now, and I have not noticed anything at the language level that I would consider brought me to a disadvantage compared to working on other operating systems. The tooling perhaps is an exception where the user has to go via PowerShell and calling conventions and arguments passing do not match between unix and windows, but I think this area is not relevant to this case. I believe there is a large user base who are primarily developing on windows, that should not be discounted as second class citizens, since this hinders Clojure's wider adaptation. Thanks :) |
I'm not in disagreement, and very much appreciate this issue and discussion. My guess: Clojure Windows support is not first-class because there are fewer Clojure Windows users, and there are fewer Clojure Windows users because Windows support is not first-class. I'll document this rewrite-clj behaviour but leave this issue open for a bit to potentially capture thoughts/ideas from others. |
Just for my understanding: rewrite-clj has a temporary workaround (normalizing \r\n to \n) for an issue in tools.reader, but tools.reader maintainers haven't responded in the issue, but word has it that they will never fix this? Why does the workaround in rewrite-clj normalize and does not preserve the Windows newline? |
The current intent of clojure tools.reader is to normalize newlines to I was willing to work around a bug, but was not interested in changing the intended behaviour. I do not know if the Clojure core team will address the issue I raised, or if they will change the newline normalization behaviour. There was interest on Slack when I raised the issue, but have not heard back since. |
Thanks @ikappaki for raising clj-commons#187 I'll leave the issue open for a bit to gather more feedback but at least we've documented the behaviour for now.
Added a question to Ask Clojure. |
Note: user=> (read-string "\"foo\r\nbar\"")
"foo\r\nbar"
user=> (require '[clojure.tools.reader :as rdr])
nil
user=> (rdr/read-string "\"foo\r\nbar\"")
"foo\r\nbar" I.e. the clojure reader(s) do not mess with newlines within literal strings, but rewrite-clj currently does. But I don't see why rewrite-clj would not preserve newlines as they are written: it's a rewriting tool with preservation for whitespace after all. |
Yeah, it took me a while, but I finally agree. The fact that the Clojure readers normalize newlines is an internal detail of the readers. One detail that we might want to remember is that:
Will always (appropriately) return |
I'm starting to think about this one a bit again. New NewlinesWhen inserting a new newline, we have to decide the variant of that newline (CR or CRLF). Ideally we'd just use whatever variant the source is already using but:
It would be nice if the newline variant selection could be automatic for new newlines, but I'm not sure if it can be. Mixed NewlinesIf a source has mixed newlines we'd preserve that oddity. I remember mixed newlines causing the author of zprint some grief but that might have been due do issues with rewrite-clj and not anything else. |
Version
1.1.45
Platform
Operating System: any
Clojure version: any
JDK vendor and version: any
Symptom
crewrite-clj
does not preserve CRLF whitespace when converted from zipper back to string,Reproduction
On the REPL:
The
\r\n
line endings have been converted to\n
.Actual behavior
The zipper converts CRLF line endings to LF.
Expected behavior
As per documentation whitespaces should be preserved:
Diagnosis
The CRLF to LF conversion was an intentional workaround as per f78856e:
Action
I'm not familiar with the codebase, but I might try to have a look at it at some point.
The text was updated successfully, but these errors were encountered: