如何打印clojure文件?
我希望能够格式化整个clojure文件,使其看起来美观。我发现的最好的东西是clojures。它在正确的位置进行缩进和换行。然而,它只能阅读clojure Literals。Clojure文件作为字符串读入<代码>读取字符串将只取字符串的第一个括号。在整个序列上映射读取字符串会遇到很多问题。有人知道一种让clojure文件看起来漂亮的自动方法吗?不仅仅是正确缩进?您可以使用: 检查它。您可以使用: 检查它。您可以使用它在源文件上运行库。如果您是引导用户,您可以使用bootfmt来处理您的文件,它也使用zprint zprint库将从零开始完全重新格式化您的源代码,使其尽可能漂亮。实际上,它在每一个层次上都会尝试一些事情,看看哪一个“更好”,并且内置了一些启发式方法,试图在垂直空间中产生尽可能多的信息,同时看起来“漂亮”。 它非常了解Clojure(和Clojurescript)源代码,知道哪些函数需要不同类型的处理以及处理新的Clojure.spec(cljs.spec)文件 它的可配置性近乎荒谬,因此只需稍加调整,您就可以按照您希望的方式输出代码。但是,即使没有任何配置,它通常也能很好地使代码看起来漂亮 将它与lein zprint一起使用非常简单。 将如何打印clojure文件?,clojure,formatting,pretty-print,Clojure,Formatting,Pretty Print,我希望能够格式化整个clojure文件,使其看起来美观。我发现的最好的东西是clojures。它在正确的位置进行缩进和换行。然而,它只能阅读clojure Literals。Clojure文件作为字符串读入读取字符串将只取字符串的第一个括号。在整个序列上映射读取字符串会遇到很多问题。有人知道一种让clojure文件看起来漂亮的自动方法吗?不仅仅是正确缩进?您可以使用: 检查它。您可以使用: 检查它。您可以使用它在源文件上运行库。如果您是引导用户,您可以使用bootfmt来处理您的文件,它也使用z
[lein zprint“0.1.16”]
放入项目的:plugins向量中。clj:
:插件[[lein zprint“0.1.16”]
然后,要格式化源文件,只需在该文件上调用lein zprint:
$lein zprint src/.clj
除非您另有说明(在project.clj中执行此操作很简单),否则它会将现有文件重命名为.clj.old
,以便您在尝试时对它们进行比较
下面是一个示例(显然格式不好):
使用$lein zprint 70 src/example/apply.clj格式化后
将其格式化为70列,以使其更适合此答案:
(defn apply-style-x
"Given an existing-map and a new-map, if the new-map specifies a
style, apply it if it exists. Otherwise do nothing. Return
[updated-map new-doc-map error-string]"
[doc-string doc-map existing-map new-map]
(let [style-name (get new-map :style :not-specified)]
(if (= style-name :not-specified)
[existing-map doc-map nil]
(let [style-map (if (= style-name :default)
(get-default-options)
(get-in existing-map
[:style-map style-name]))]
(cond
(nil? style-name) [existing-map doc-map
"Can't specify a style of nil!"]
style-map
[(merge-deep existing-map style-map)
(when doc-map
(diff-deep-doc
(str doc-string " specified :style " style-name)
doc-map
existing-map
style-map)) nil]
:else [existing-map doc-map
(str "Style '" style-name "' not found!")])))))
您可以使用将在源文件上运行库的。如果您是引导用户,您可以使用bootfmt来处理您的文件,它也使用zprint
zprint库将从零开始完全重新格式化您的源代码,使其尽可能漂亮。实际上,它在每一个层次上都会尝试一些事情,看看哪一个“更好”,并且内置了一些启发式方法,试图在垂直空间中产生尽可能多的信息,同时看起来“漂亮”。
它非常了解Clojure(和Clojurescript)源代码,知道哪些函数需要不同类型的处理以及处理新的Clojure.spec(cljs.spec)文件
它的可配置性近乎荒谬,因此只需稍加调整,您就可以按照您希望的方式输出代码。但是,即使没有任何配置,它通常也能很好地使代码看起来漂亮
将它与lein zprint一起使用非常简单。
将[lein zprint“0.1.16”]
放入项目的:plugins向量中。clj:
:插件[[lein zprint“0.1.16”]
然后,要格式化源文件,只需在该文件上调用lein zprint:
$lein zprint src/.clj
除非您另有说明(在project.clj中执行此操作很简单),否则它会将现有文件重命名为.clj.old
,以便您在尝试时对它们进行比较
下面是一个示例(显然格式不好):
使用$lein zprint 70 src/example/apply.clj格式化后
将其格式化为70列,以使其更适合此答案:
(defn apply-style-x
"Given an existing-map and a new-map, if the new-map specifies a
style, apply it if it exists. Otherwise do nothing. Return
[updated-map new-doc-map error-string]"
[doc-string doc-map existing-map new-map]
(let [style-name (get new-map :style :not-specified)]
(if (= style-name :not-specified)
[existing-map doc-map nil]
(let [style-map (if (= style-name :default)
(get-default-options)
(get-in existing-map
[:style-map style-name]))]
(cond
(nil? style-name) [existing-map doc-map
"Can't specify a style of nil!"]
style-map
[(merge-deep existing-map style-map)
(when doc-map
(diff-deep-doc
(str doc-string " specified :style " style-name)
doc-map
existing-map
style-map)) nil]
:else [existing-map doc-map
(str "Style '" style-name "' not found!")])))))
(defn apply-style-x
"Given an existing-map and a new-map, if the new-map specifies a
style, apply it if it exists. Otherwise do nothing. Return
[updated-map new-doc-map error-string]"
[doc-string doc-map existing-map new-map]
(let [style-name (get new-map :style :not-specified)]
(if (= style-name :not-specified)
[existing-map doc-map nil]
(let [style-map (if (= style-name :default)
(get-default-options)
(get-in existing-map
[:style-map style-name]))]
(cond
(nil? style-name) [existing-map doc-map
"Can't specify a style of nil!"]
style-map
[(merge-deep existing-map style-map)
(when doc-map
(diff-deep-doc
(str doc-string " specified :style " style-name)
doc-map
existing-map
style-map)) nil]
:else [existing-map doc-map
(str "Style '" style-name "' not found!")])))))