clojure-vim / acid.nvim

Asynchronous Clojure Interactive Development
161 stars 12 forks source link

Feature request: a more flexible AcidMotion #39

Closed daveyarwood closed 5 years ago

daveyarwood commented 5 years ago

Wishlist:

  1. Make cpaw (evaluate around word) work.

    • Let's say I type (def x 2), put my cursor on one of the parens, and type cpp to evaluate the form, defining x in the current namespace.
    • I do some more editing, maybe I delete the line where I defined x, and I forget what the value of x is.
    • Now I want to evaluate x and see its value.
    • How do I do this? It seems like cpp only works at the level of a form, but doesn't work on a symbol. I tried cpaw and cpiw (eval "inside word," "around word" and neither of those did the trick.
    • It would be great if acid provided a keybinding for "evaluate the element under the cursor."
  2. Provide a visual mode binding that sends the current selection to the REPL.

    • As I was trying to figure out what keys to press to send just x to the REPL, one thing I kept wanting to work was to highlight x in visual mode and press some keybindng to send to the REPL.
    • vlime has this feature and it's super handy!
    • Open question about where the result should be displayed... I guess in virtualtext in the buffer, in the same place where it would be displayed with cpp? It's sort of ambiguous though, because you could visually select more than one form... Maybe displaying it in the command area would be acceptable?
hkupty commented 5 years ago

PR is merged. I believe this one is fixed, but feel free to request more out of this.

I'll close for now, but you can reopen if you will.

daveyarwood commented 5 years ago

Things are definitely getting nicer -- thanks for looking into this.

Worth noting that when you implemented #38 (cqp to get a REPL prompt in the same namespace, that gave me a good workaround for evaluating the form under the cursor. For example, I can evaluate (def foo 42) using cpp and then see the value of foo by typing cqpfoo<CR>

Unless I missed it, I think we're still lacking the "evaluate form under cursor" functionality. I'd like to be able to put my cursor over foo and call some function provided by acid.nvim to send foo to the REPL and show the result.

I tried cpiw and cpaw (i.e. evaluate inside word / evaluate around word), and both produced this error:

Error detected while processing function AcidMotion:                                                                                                                  
line    1:
E5105: Error while calling lua chunk: /home/dave/.vim/bundle/acid.nvim//lua/acid/forms.lua:48: bad argument #1 to 'sub' (string expected, got nil)

No entries in /tmp/acid-log-handler.log when I do that.

I also noticed that visual select + cp only seems to work when I select an S-expression. If I select (inc foo) and press cp, it evaluates and displays ;; => 43 in virtualtext. But if I do this with foo or [foo], I get the same error as above (bad argument #1 to 'sub' (string expected, got nil)).

(Worth noting I also get the same error when I put my cursor over the [ in [foo] and press cpp, so it's probably unrelated to visual select.)

hkupty commented 5 years ago

Something's weird there.. I couldn't find the sub fn call on line 48, so I'm assuming the lua code is pointing to the old version while the viml version is newer.

Maybe there's an easier way of doing that, but if you run:

:lua << EOF
package.loaded['acid.features'] = nil
package.loaded['acid.forms'] = nil
EOF

That should force-refresh the code to the newer version.

daveyarwood commented 5 years ago

I tried running that in normal mode, as well as putting it in my vimrc and restarting vim, and it made no difference.

I also tried running :UpdateRemotePlugins (even though I have vim-plug configured to do this automatically when updating acid.nvim) and restarting vim, and that made no difference.

hkupty commented 5 years ago

I'll investigate this further. Nonetheless, try cps instead. It should work as that is a fn call to expand('<cword>').

daveyarwood commented 5 years ago

cps is awesome, works like a charm!

It looks like the issues I described above have actually gone away after I updated just now. I am able to highlight foo and press cp and see ;; => 42. And I can highlight [foo] and press cp and see ;; => [42]. And cpaw and cpiw are working as I expect. Nice work! :100:

I did run into an edge case where if I highlight an entire line (including the line break at the end) by pressing V, and then I run cp, the evaluation result in the virtualtext is a RuntimeException with ANSI escape codes:

[foo] ;; =>              ^[[1;31mjava.lang.RuntimeException^[[m: ^[[3mEOF while reading, starting at line 1^[[m\n^[[1;31mclojure.lang.LispReader$ReaderException^[[m: ^[

From /tmp/acid-log-handler.log:

2019-03-27 12:07:44,266 - [acid.nvim :DEBUG] - fpath is None
2019-03-27 12:07:44,270 - [acid.nvim :DEBUG] - Hitting cache for ns 'ezzmq.context'
2019-03-27 12:07:44,276 - [acid.session :INFO] - sending data -> {'code': '[', 'op': 'eval', 'id': '7c9c7b865d9f4988a056cad91e78b917', 'ns': 'ezzmq.context'}
2019-03-27 12:07:44,346 - [acid :INFO] - {'root-ex': 'class java.lang.RuntimeException', 'status': ['eval-error'], 'session': 'cb875d90-d030-4c36-a7ba-1046da7fd2be', 'ex': 'class clojure.lang.ExceptionInfo', 'id': '7c9c7b865d9f4988a056cad91e78b917'}
2019-03-27 12:07:44,351 - [acid.session :INFO] - stopped watching key 7c9c7b865d9f4988a056cad91e78b917-e0934127bc244785be682cca9e160d74-watcher
2019-03-27 12:07:44,352 - [acid :INFO] - {'session': 'cb875d90-d030-4c36-a7ba-1046da7fd2be', 'id': '7c9c7b865d9f4988a056cad91e78b917', 'out': '             \x1b[1;31mjava.lang.RuntimeException\x1b[m: \x1b[3mEOF while reading, starting at line 1\x1b[m\n\x1b[1;31mclojure.lang.LispReader$ReaderException\x1b[m: \x1b[3mjava.lang.RuntimeException: EOF while reading, starting at line 1\x1b[m\n             \x1b[1;31mclojure.lang.ExceptionInfo\x1b[m: \x1b[3m\x1b[m\n'}
2019-03-27 12:07:44,353 - [acid :INFO] - {'status': ['done'], 'session': 'cb875d90-d030-4c36-a7ba-1046da7fd2be', 'id': '7c9c7b865d9f4988a056cad91e78b917'}

If I leave off the line break by doing v$cp instead, it works correctly.

daveyarwood commented 5 years ago

Interestingly, it seems to be sending [ instead of [foo] or [foo]\n or whatever. :thinking:

hkupty commented 5 years ago

This is an issue with searchpairpos's filters + off-by-one somewhere I'd say. I'll take a look at it later.

Thanks!

hkupty commented 5 years ago

I've added also cpt, for evaluation of the top level form. At first I had outsourced that to vim-sexp, but then I realised it has the same off-by-one issue when on a ), so I used vim api instead.

The correct and much better approach will probably involve neovim/neovim#9219.

I'll close this issue for now, to focus on the others, but please reopen if I forgot something or if you still miss any feature on this one.

Cheers