Get Pretty Printed Result in a Cider Expression in Emacs

I would like to paste the result of the evaluated Clojure expression directly into the Emacs buffer in 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 allowed Clojure pretty-printed things for me:

(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, "and \nshielded are inserted; I want them to be inserted without saving. In other words, I want the printed result to be inserted directly without escaping quotes or newlines. This was used for earlier versions of Cider and cider-nrepl.

+4
source share
2 answers

Packaging:

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

in read .

+2

lispy ( Paredit , Cider Clojure eval): 2E - eval--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))
+1

All Articles