OK, seancorfield's videos have convinced me that maybe this is the first time in a very long time that I should at least try out another editor/IDE, Atom.
I installed latest Atom, and Chlorine, and ran a clj
process with the socket REPL options mentioned on the Chlorine getting started instructions, and was able to connect to it and have a REPL tab/frame seen in Atom, next to my .clj source file.
I may be doing something odd, and was curious what might be going on under the covers a little bit. I was in a source file for namespace foo.bar, and in a comment block at the end I have (require '[foo.bar :as f]) followed by some other forms to evaluate that use the alias f/fn-name-inside-foo.bar
That works fine if you just copy and paste it to a terminal REPL, but may be causing me difficulties when I use Chorine's evaluate-block command.
Is there magicalness in Chlorine's evaluate-block that always tries to evaluate code sent via evaluate-block
in the same namespace as the source code editor frame?
Correct.
Block evaluation is done in the context of the namespace.
thanks, that makes sense. I had been using Emacs inf-clojure with lein and/or clj, and I believe its 'evaluate in REPL' capability doesn't have that behavior, so threw me off.
Yeah, it's a small piece of "magic" but it makes the behavior in general much more intuitive.
So Chlorine's evaluate-block
is probably sending (in-ns 'foo.bar)
forms at appropriate times over the socket REPL?
Correct.
If you're curious about also using REBL with Chlorine, https://github.com/seancorfield/atom-chlorine-setup has more REBL-specific commands and modified keymaps.
I tried out Atom's vim-mode-plus
package due to my extensive vim muscle memory, and found that makes doing evaluate-block
for a form that ends with )
as the last character on a line not possible from normal mode. You have to go into insert mode to get the cursor after the )
, or have extra whitespace after the )
. I can live with it -- it just made me chuckle when I saw what was happening.
I pretty much carried my ProtoREPL bindings over to Chlorine because that's what I'd used for years before.
It appears that Chlorine does not cause new menu items to be created within Atom when it is installed?
So one must create key bindings to take advantage of things like evaluate-block
?
Or use the command-palette. Yeah.
Strange that behavior of )
. I never had this problem and I do use Chlorine with vim-mode-plus
. But yeah, if you put a cursor on the end of the line it'll not evaluate in normal-mode
I think that's because I never evaluate something pointing the cursor at the end of the line. For example, if I have a form:
(+ 1 2 (* 3 4))
If I want to evaluate the outer form, I use evaluate-top-block
, or my cursor will probably be over 2
, 1
, +
...
Actually, I may have confused myself that it doesn't work. It is doing it now.
Also, a little bit more information, Chlorine's evaluation commands indeed detects the first ns
form and send it to REPL. Once I saw a library that uses multiple ns
entries in the same file, and it was not working with Chlorine - I'm working on a feature that'll send the correct ns (will scan top-level forms and pick up the previous namespace declaration)
@andy.fingerhut, it only fails if the line ends with two parenthesis ))
OK, more experimentation results. If I have this on a line by itself (def x (+ 5 5))
with no white space at the end, and I am in normal, not insert, mode, then evaluate-block
while the cursor is over the last )
evaluates (+ 5 5)
only. If I insert a space between the two right parens like this: (def x (+ 5 5) )
then normal mode evaluate-block
evaluates the whole def
if the cursor is on the last )
.
Yeah, kinda makes sense why it would do that.
When you're in normal-mode, if you have 1234
, for example, and point the cursor to 3
, it doesn't really knows where you are: if you press i
, your cursor is between 2 and 3. If you press a
, you're between 3 and 4. Schrödinger's Selection? 🐱
Yeah, I've actually used Emacs viper-mode more than vim for a few years, and whoever implemented that actually lets you move the cursor one step to the right after the last character on the line, unlike vim. Not saying that is what Atom vim-mode-plus ought to do, since it is a little weird for vim users.