Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clojure REPL and escape characters in strings #291

Closed
DjebbZ opened this issue Nov 13, 2013 · 9 comments
Closed

Clojure REPL and escape characters in strings #291

DjebbZ opened this issue Nov 13, 2013 · 9 comments

Comments

@DjebbZ
Copy link

DjebbZ commented Nov 13, 2013

Hi,

First thanks for the plugin. Learning Clojure with it is a delightful experience.

I'm encountering a strange behaviour when I evaluate characters and regexps from my code. When I type #{\a \b} in the REPL, it returns itself normally. When I send this same code from my editor to the REPL, it fails with :

user=> (load-string "#{\a \b}")

RuntimeException Unsupported escape character: \a  clojure.lang.Util.runtimeException (Util.java:219)
RuntimeException Unmatched delimiter: }  clojure.lang.Util.runtimeException (Util.java:219)
RuntimeException EOF while reading string  clojure.lang.Util.runtimeException (Util.java:219)

So I have to double-escape every single characters, as well as special chars from regexps like so #{\\a \\b} so I can send them to the REPL from my code.

Is this behaviour normal ? To be expected ? A bug ? As I started to learn Clojure (my first Lisp ever) I may not know several things about how code and REPL differ. Any explanations very welcome.

@mason-stewart
Copy link
Contributor

Hi @DjebbZ,
The load-string functionality has been discussed (among many other things) in #212, particularly here: #212 (comment)

Just for reference, the code in question is at https://github.com/wuub/SublimeREPL/blob/master/text_transfer.py#L80 and the commit that introduced it is here 71d0092

I believe @lionandoil added that to allow syntax errors to be thrown immediately, rather than trying to accidentally evaluate a single, incomplete line or selection, i.e. (foo bar and then having the REPL hang as it waits for the form to be closed.

@lionandoil should the sender automatically double-escape the string? In Emacs, Paredit-mode will convert (- 42 (int \A)) into "(- 42 (int \\A))" when Shift' is pressed while a form is selected, but not when " is manually typed at the beginning and end of a form. I supposed the Clojure sender could convert single backslashes into doubles before eval?

Would implementing that cause other issues? Thanks!

@lionandoil
Copy link
Contributor

Heyho, yes I just tried and squeezing a

.replace('\\', r'\\')

between the strip() and the other replace() should indeed do the trick. I'm quite busy at the moment so if someone else could make that pull request that'd be grand!

@mason-stewart
Copy link
Contributor

Yep, I'll take care of it today. Thanks dude!

@wuub wuub closed this as completed in 47e424e Nov 15, 2013
wuub added a commit that referenced this issue Nov 15, 2013
Clojure sender now escapes backslashes. Fixes #291
@DjebbZ
Copy link
Author

DjebbZ commented Nov 15, 2013

Thanks !
I relaunched ST (3) but no update yet... Any idea when will it be published on Package Control ?

@wuub
Copy link
Owner

wuub commented Nov 15, 2013

Probably this Sunday. Sorry. :(

I'm trying to find time to do a release for two weeks now, it takes a LOT
of time (ST2 stable, ST2 dev, St3 beta, ST3 dev on Win/Linux/Mac) and I
haven't been able to squeeze it into my schedule recently.

@DjebbZ
Copy link
Author

DjebbZ commented Nov 16, 2013

No problem, SublimeREPL is already super nice like this for a beginner like me. 2 weeks is quick enough :)

@wuub
Copy link
Owner

wuub commented Nov 17, 2013

@DjebbZ I'll need one or two more days :) Unfortunately I was not able to do it today :(

@DjebbZ
Copy link
Author

DjebbZ commented Nov 18, 2013

No problem ! You take your contribution very seriously, I really appreciate. I'm not using Clojure nor SublimeREPL in production, so take it easy :)

@eeng
Copy link

eeng commented Aug 22, 2015

Hi, this plugin has been of great help to me, so thank you very much!
Just one problem though, I'm experiencing this bug too. Is there a possibility that the fix has not been published yet on the Package Control?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants