0

如果我的代码如下所示:

(apply + 0
   [1 2 3 4])

我把它通过阅读器,它变成了

(apply + 0 [1 2 3 4])并且格式(回车和空格)丢失

是否有在读取代码时保存代码的格式?


例如:

(fact [{:type :section
        :title "Normal Operation"
        :tag "normal-operation"}]

  "The most straightforward code is one where no issues raised. This
   can be seen in Example {{ribol-normal-eq}} below:"

  [{:type :image :href "ribol-normal.png"}]

  [[{:tag "ribol-normal-eq"}]]
  (manage                          ;; L2
   [1 2 (manage 3)])               ;; L1 and L0
  => [1 2 3]

转换为:

1 - 正常运行

最直接的代码是没有问题的代码。这可以在下面的示例 1.1 中看到:

[[ribol-normal.png]]

1.1

(manage                          ;; L2
   [1 2 (manage 3)])             ;; L1 and L0

=> [1 2 3]
4

2 回答 2

1

clojure.pprint/write与 一起使用code-dispatch

(clojure.pprint/write
  '(apply + 0 [1 2 3 4])
  :dispatch clojure.pprint/code-dispatch)

它不会给你你想要的缩进,因为应用形式太短,而且你的换行符只对最后一个参数是相当随意的。但是,如果您想打印 Clojure 代码,这是正确的做法。它将正确打印 let- 和其他各种表格。

这是一个较长形式的示例

(clojure.pprint/write
  '(defn plugin
     "A leiningen plugin project template."
     [name]
     (let [render (renderer "plugin")
           unprefixed (if (.startsWith name "lein-")
                        (subs name 5)
                        name)
           data {:name name,
                 :unprefixed-name unprefixed,
                 :sanitized (sanitize unprefixed),
                 :year (year)}]
       (main/info
         (str "Generating a fresh Leiningen plugin called " name "."))
       (->files
         data
         ["project.clj" (render "project.clj" data)]
         ["README.md" (render "README.md" data)]
         [".gitignore" (render "gitignore" data)]
         ["src/leiningen/{{sanitized}}.clj" (render "name.clj" data)]
         ["LICENSE" (render "LICENSE" data)])))
  :dispatch
  clojure.pprint/code-dispatch)

=>

(defn plugin
  "A leiningen plugin project template."
  [name]
  (let [render (renderer "plugin")
        unprefixed (if (.startsWith name "lein-") (subs name 5) name)
        data {:name name,
              :unprefixed-name unprefixed,
              :sanitized (sanitize unprefixed),
              :year (year)}]
    (main/info
      (str "Generating a fresh Leiningen plugin called " name "."))
    (->files
      data
      ["project.clj" (render "project.clj" data)]
      ["README.md" (render "README.md" data)]
      [".gitignore" (render "gitignore" data)]
      ["src/leiningen/{{sanitized}}.clj" (render "name.clj" data)]
      ["LICENSE" (render "LICENSE" data)])))
于 2013-08-12T11:16:57.297 回答
0

sjacket是朝着这个方向迈出的第一步。但它仍处于发展的早期阶段。

于 2013-08-12T10:38:54.093 回答