打印Clojure数据时如何增加最大行长 [英] How to increase max line length when printing Clojure data
本文介绍了打印Clojure数据时如何增加最大行长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将内容写入 edn
文件,并且希望行的最大宽度大于当前的默认值:
I am writing content to an edn
file and would like the maximum width of the lines to be greater than the current default value:
(use 'clojure.pprint)
nil
user=> *print-right-margin*
72
这似乎与我的输出一致目前正在。但是如何增加默认值呢?
This seems to accord with the output I am currently getting. But how to increase the default value?
这是我用来写出 edn
文件的函数:
This is the function I'm using to write out the edn
file:
(defn pp-str [x] (-> x clojure.pprint/pprint with-out-str))
示例用法:
(spit "foo.edn" (u/pp-str foo))
在 foo
可能是打h或其他Clojure数据的地方。
Where foo
might be some hiccup, or other Clojure data.
推荐答案
尝试在 pp-str
函数之外重新绑定 * print-right-margin *
:
try rebinding *print-right-margin*
either outside the pp-str
function:
(binding [*print-right-margin* 1000]
(spit "foo.edn" (u/pp-str foo)))
或从内部:
(defn pp-str [x]
(binding [*print-right-margin* 1000]
(-> x clojure.pprint/pprint with-out-str))))
这将临时重新定义封闭块范围的值。这应该有帮助
this would temporarily redefine the value for the scope of the enclosed block. This should help
这篇关于打印Clojure数据时如何增加最大行长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文