clojure-emacs / clomacs

Simplifies Emacs Lisp interaction with Clojure and vice versa.
200 stars 21 forks source link

Passing escaped substrings #10

Closed nicholsonscn closed 7 years ago

nicholsonscn commented 7 years ago

Great tool. Makes a nice bridge.

I ran into one issue so far though where if the string you are passing through has substrings. These get processed by the clojure reader and break compilation.

For example- the clomacs demo will break if the selection you highlight is:

This is "a" test

instead of

This is a test

or if you call (cm-test-md-to-html-wrapper "# This is \"a\" test")

Clojure will throw a runtime exception complaining that it cannot resolve the symbol: a in this context. because the request passed to the repl will actually be "This is "a" test" (inner quotes not escaped).

Workaround: in clomacs.el in the method: clomacs-add-quotes I replaced (concat "\"" str "\"") with (format "%S" str)

With the capital S directive it still generates the string representation but uses prin1 for the formatting which attempts to escape things so that read will reproduce the string properly.

This seems to work for my testing so far (I haven't played with super nested substrings) but I'm not sure if there's some other reason the system manually created the string the original way (new to this entire framework).

Versions: Windows: Windows 10 Pro Version: 1703 Build: 15063.413 Emacs: GNU Emacs 25.2.1 (x86_64-w64-mingw32) of 2017-04-24 Clomacs: installed from MELPA Clojure: 1.8.0

kostafey commented 7 years ago

Thank you. Fixed ;).