atom-slime
atom-slime copied to clipboard
end of file on #
If I type
(defun sqr (x)
Followed by enter to move down to the next line and finish my expression
(* x x))
The enter triggers completion on an unbalanced expression resulting in the mentioned error.
The root problem is that, at the moment, the REPL only supports single-line input. Instead of noticing that you've typed an unbalanced s-expression and waiting for you to balance it on the next end, it tries to execute the unbalanced expression (resulting in an error).
Completely agree that it would be cool to add multi-line REPL support - but unfortunately don't have the cycles at the moment. If you're interested, I could always use some more help on this project; feel free to dive into the code and submit a pull request!
@sjlevine I'd be interested in doing this. I was wondering if simply counting the left and right parens would do the trick? If the parens are balanced, it means we can hand the expression off to swank, otherwise we can just carry on on the next line.
Becomes subtly more complex when parentheses are included in quotes, strings, etc. Not sure if the editor even handles those cases correctly though...
Good point :) Ok, I will try to put something together during Christmas, it's an interesting one, and I think it would be a nice one to have.
Alternatively some key combination like Shift+Enter could be used to allow the user to continue on the next line. This way there's no need (for now) to do some involved paren matching. Thoughts?
@jarecsni I like the shift-enter idea.
@sjlevine, would that step on the toes of any other planned functionality you can think of?
Hi all,
Thanks @jarecsni and @haz for your comments, bug reports, and help with this package!
I think the shift-enter idea could work, but I like the parenthesis matching strategy better. In particular, I'd recommend using the paredit-js
library -- which is already used extensively by atom-slime
-- for doing that parenthesis counting and handling the case where they might be nested, in strings, etc. This library parses s-expressions in Lisp into an abstract-syntax tree (AST), basically a nice datastructure that our code can use. I bet it can detect unbalanced expressions.
Also, the only other complications I see, is that I believe there are some tricky cases in atom-slime
about handing key presses in the text editor, dealing with the case where the REPL keeps printing stuff (like from another thread) but the user types things at the same time, etc. -- that would all need to be taken into account to make sure this works.