Fork me on GitHub
#vim
<
2017-11-16
>
jebberjeb14:11:07

" Support for Lisp REPL Terminal Interaction
augroup Terminal
  au!
  au TermOpen * let g:term_jid = b:terminal_job_id
augroup END

" Check if the character under the cursor is the start
" (or end) of something we'd want to send to the REPL.
function! REPLSendSafe()
    " Hack to get character under the cursor.
    norm "ayl
    if index(["(", ")", "[", "]", "{", "}"], @a) >= 0
        " Hack to get text using % motion.
        norm v%"ay
        call REPLSend(@a)
    endif
endfunction

function! REPLSend(cmd)
    call jobsend(g:term_jid, a:cmd."\n")
endfunction

" If no visual selection, send safely
nnoremap <leader>ef :call REPLSendSafe()<cr>
" If there's a visual selection, just send it
vnoremap <leader>ef "ay:call REPLSend(@a)<cr>
" Send the entire buffer
nnoremap <leader>eb :call REPLSend("(load-file \"".expand('%:p')."\")")<cr>
nnoremap <leader>doc :call REPLSend("(clojure.repl/doc ".expand("<cword>").")")<cr>

jebberjeb14:11:42

FWIW, I quit using the SocketREPL plugin a few days ago and have just been doing this. I like it.

jebberjeb14:11:33

Pretty spartan setup, no gf, only one REPL connection here, and you have to start it up yourself. But I’ve enjoyed working with it.

jebberjeb14:11:13

Obviously, this requires you to have a REPL running in a :term

dominicm14:11:35

That's so spartan 😂 I don't know how I'd live with it.

dominicm14:11:37

Any reason why?

snoe17:11:45

I tried that when nvim first came out, but IIRC evaling whole files or large chunks of code would get truncated.

jebberjeb18:11:18

@dominicm hmm, good question 🙂 That’s all I ever did w/ Fireplace really.

jebberjeb18:11:46

@snoe Yeah I guess it will work ok w/ Clojure using load-file, but maybe it will have that problem w/ ClojureScript now.

dominicm18:11:22

@jebberjeb no jump to source?

jebberjeb18:11:34

I still have vim-clojure-static, and paredit, of course 🙂

jebberjeb18:11:12

Um, honestly, I used to use jump to source when I had it. But not a lot.

jebberjeb18:11:09

Not enough to make me want to give up the simplicity of text -> REPL.

jebberjeb21:11:43

I think it was possible because I’d already given up jump to source and other niceties when I left Fireplace. The latest change was brought on by the fact that, as much as I love being able to author plugins in Clojure, and as well as it has worked for me, firing up a JVM process and having a bunch of code just so I can send text over a socket never sat well with me.

jebberjeb21:11:49

So I was looking at tslime.vim the other day when I came across the SO post that shows how jobsend() can be used with Neovim terminal.

jebberjeb21:11:33

That’s when I knew I could have my SocketREPL cake and eat it simply too.

dominicm22:11:29

Do you find them only niceties? I find them flow conducive. I never have to think to do what I need, I keep moving forward.

dominicm22:11:59

The false positives trip me up with tools which are approximate. It breaks my concentration.

jebberjeb22:11:02

Either I’m not frequently working on things that require that degree of concentration, or I’ve found a way, maybe subconsciously, to use those pauses constructively.

jebberjeb22:11:10

I do find the occasional ack-grep does break my flow a bit. In the early stages of working with a codebase, I feel it enough to be frustrated.

dominicm22:11:28

How big are the codebases you work on?

jebberjeb22:11:57

They vary quite a bit from project to project. Even with bigger codebases, I usually only interact with a portion of it that is manageable without jump to source.

jebberjeb22:11:30

I know that not using jump to source does slow me down some.

snoe22:11:57

I think what I’d miss most is a way to jump into jars, for whatever reason i’m doing that almost every day. And @dominicm the approximate problem is why I’m using cursive now, IIRC find-usages didn’t work on keywords and is so much slower through the repl.

jebberjeb22:11:14

@snoe I almost said that. I miss being able to jump into jars. That’s one place I can’t get to easily with ack.

dominicm22:11:42

@jebberjeb I don't get the benefit of isolation, I think I'm running all over 50k loc clojure currently. I wouldn't be surprised if it's more now.

dominicm22:11:55

I wonder if that's why I need that more.

dominicm22:11:06

@snoe interesting that's a limitation, I can't imagine it's a hard one. Refactor needs a little improving I think.

jebberjeb22:11:11

50k LOC Clojure is large. I might be tempted to resurrect Fireplace at that point.

jebberjeb22:11:27

Most of my work the last couple of years has been ClojureScript heavy. My experience has been that jump to source is a little fickle when working with ClojureScript. At least as far as Fireplace is concerned. But I’ve seen similar complaints from other tools.

jebberjeb22:11:26

Early difficulties using gf on ClojureScript codebases probably helped me rationalize letting it go, or building the alternative skills.

dominicm22:11:22

I know I personally fixed some upstream bugs with gf and cljs for boot.

dominicm22:11:53

When we moved the project to boot, I felt it would be held against me, so fixed it.

dominicm22:11:38

I still don't really trust fireplace and cljs though, it usually fails. Or launches rhino without my consent.

jebberjeb22:11:28

Feels like that should just be a library, no? (defn get-source-file-and-line [some-symbol] …)

dominicm23:11:36

Yep, it's not too complex a feature to implement tbh. I implemented it in replant.