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

Remove , (comm) from edn #130

Closed
leandropincini opened this issue Apr 20, 2023 · 12 comments
Closed

Remove , (comm) from edn #130

leandropincini opened this issue Apr 20, 2023 · 12 comments

Comments

@leandropincini
Copy link

I'm wondering if maybe we could have a feature that removes the , (comm) while parsing to edn.
Like parse a json -> edn without commas.

Clojurian's slack thread: https://clojurians.slack.com/archives/CM5HRADAA/p1682017322255449

@borkdude
Copy link
Owner

borkdude commented Apr 20, 2023

I've written a script once to remove commas:

borkdude@m1 ~/dev/babashka (master*) $ echo '{:a 1 :b 2}' | jet
{:a 1, :b 2}
borkdude@m1 ~/dev/babashka (master*) $ echo '{:a 1 :b 2}' | jet | /tmp/strip_commas.bb
{:a 1 :b 2}
borkdude@m1 ~/dev/babashka (master*) $ cat /tmp/strip_commas.bb
#!/usr/bin/env bb

(require '[rewrite-clj.zip :as z])

(-> (let [loc (z/of-string (slurp *in*))]
       (loop [loc loc]
         (let [next (z/next* loc)]
           (if (z/end? loc) (z/root loc)
               (if (= :comma (z/tag loc))
                 (recur (z/remove* loc))
                 (recur next))))))
    str
    (print))

(flush)

We could integrate this into jet, but I'll wait for more upvotes first.

@ericdallo
Copy link
Contributor

Looks like a good code to be behind a flag to --remove-commas or something, we could even in the future consider doing it by default

@borkdude
Copy link
Owner

Why would you do this by default?

@borkdude
Copy link
Owner

Wow, where do all these upvotes come from, was there a campaign within nubank? :) Please explain more why this feature is considered important.

@ericdallo
Copy link
Contributor

All the time I'd prefer to see a edn without commas, I suppose most people as well, but we could gather more feedback about that.

@borkdude we usually code edn without commas, like:

{:a 1
 :b 2
 :c 3}

And we use jet/jet.el to parse json<->edn to paste on code, and it's kind of inconvenient the need to keep removing commas after parsing it as we don't write:

{:a 1,
 :b 2,
 :c 3}

@borkdude
Copy link
Owner

Alright. I'll hopefully get to it this week! :)

@borkdude
Copy link
Owner

@ericdallo @leandropincini Is this mostly about commas between map entries? The library I'm using to colorize (puget) only allows stripping the comma between map entries, not generally. So what I could do:

If --no-commas is provided, I provide puget with the :map-delimiter "".
In other cases I can strip all commas myself manually.

@ericdallo
Copy link
Contributor

IMO stripping all commas is a better choice, what we want most if not all the time, otherwise would be --no-commas-between-map-entries 😅

@borkdude
Copy link
Owner

borkdude commented Apr 26, 2023

I know that's better but it's not possible in combination with colorization at the moment, unless I implement my own colorization.

@borkdude
Copy link
Owner

Anyway, in emacs when calling jet, it won't produce colorized output anyway and then all commas would be removed.

@leandropincini
Copy link
Author

I was wondering if it worths to add a know issue (breaks the color) for that and some ways to avoid it.

@borkdude
Copy link
Owner

Published as 0.5.25 and the option is called --no-commas. It fully works with uncolored output, and only works inside maps with colored output, but in the future we can maybe improve this.

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

3 participants