4

I'd like to insert the result of an evaluated Clojure expression directly in my Emacs buffer, in pretty-printed form.

For example, with something like:

    ;; [emacs lisp]
    (insert (nrepl-dict-get (nrepl-sync-request:eval "(range 30)") "value"))

I get, in the buffer of interest,

    ;;=>
    (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29)

In the past, I've let Clojure pretty-print things for me, as so:

(nrepl-dict-get
  (nrepl-sync-request:eval
    (format "(clojure.core/let [x %s] (with-out-str (clojure.pprint/pprint x)))"
            "(range 30)"))
  "value")
;;=>
"(0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n 10\n 11\n 12\n 13\n 14\n 15\n 16\n 17\n 18\n 19\n 20\n 21\n 22\n 23\n 24\n 25\n 26\n 27\n 28\n 29)\n"

However, the " and \n are being inserted escaped; I want them to be inserted unescaped. In other words, I want the pretty-printed result to be inserted directly without escaping quotes or newlines. This used to work in earlier versions of Cider and cider-nrepl.

4

2 回答 2

2

包装:

(nrepl-dict-get
  (nrepl-sync-request:eval
    (format "(clojure.core/let [x %s] (with-out-str (clojure.pprint/pprint x)))"
            "(range 30)"))
  "value")

read应该解决这个问题。

于 2014-11-25T05:35:34.727 回答
1

我刚刚在lispy中添加了这个功能(它是一个 Paredit 风格的包,使用 Cider 进行 Clojure eval ): 2E将添加到漂亮打印的 eval-and-insert,而 E将继续做一个简单的。

这是一个例子(|代表点):

|(for [x (range 8)] (range x))

之后E

|(for [x (range 8)] (range x))
(() (0) (0 1) (0 1 2) (0 1 2 3) (0 1 2 3 4) (0 1 2 3 4 5) (0 1 2 3 4 5 6))

之后2E

|(for [x (range 8)] (range x))
(()
 (0)
 (0 1)
 (0 1 2)
 (0 1 2 3)
 (0 1 2 3 4)
 (0 1 2 3 4 5)
 (0 1 2 3 4 5 6))

当然你仍然可以做EjM同样的事情:

(for [x (range 8)] (range x))
|(()
 (0)
 (0 1)
 (0 1 2)
 (0 1 2 3)
 (0 1 2 3 4)
 (0 1 2 3 4 5)
 (0 1 2 3 4 5 6))
于 2014-11-25T11:47:57.867 回答