Is there an online tool to auto-indent and format Clojure code like there are many for JSON?

后端 未结 4 676
别跟我提以往
别跟我提以往 2021-02-18 23:20

There are a lot of tools online that take a JSON text and show you formatted and well indented format of the same.

Some go even further and make a nice tree-like structu

4条回答
  •  悲&欢浪女
    2021-02-19 00:06

    There is now https://github.com/weavejester/cljfmt for that purpose

    Instructions

    Add it in your Leiningen plugins:

    :plugins [[lein-cljfmt "0.6.1"]]
    

    Then, to autoformat all code in your project:

    lein cljfmt fix
    

    Sample

    Your sample code will become:

    (defn prime? [n known] (loop [cnt (dec (count known)) acc []] (if (< cnt 0) (not (any? acc))
                                                                      (recur (dec cnt) (concat acc [(zero? (mod n (nth known cnt)))])))))
    

    After adding some linebreaks and reformatting again:

    (defn prime? [n known]
      (loop [cnt (dec (count known)) acc []]
        (if (< cnt 0) (not (any? acc))
            (recur (dec cnt) (concat acc [(zero? (mod n (nth known cnt)))])))))
    

提交回复
热议问题