psc-ide-vim icon indicating copy to clipboard operation
psc-ide-vim copied to clipboard

Evaluate expression and insert result in code view

Open andreasthoelke opened this issue 8 years ago • 2 comments

This maybe be a feature request or just something that I overlooked:

I would like to evaluate an expression or top level symbol and then get the result in vimscript, so I can insert it below the symbol name in the code view - similar to how PSCIDEaddTypeAnnotation inserts the type. This mostly saves me switching back and forth between a psci window and the code, but has other nice properties as well. It seems there is no related feature in the psc-ide protocol, so I'll probably have to ask there, but I wanted to ask here first, to hear if I'm missing a psc-ide-vim feature and if others think this may be a useful feature.

andreasthoelke avatar Nov 30 '17 20:11 andreasthoelke

I don't think there is support for that in psc-ide protocol.

coot avatar Mar 11 '18 13:03 coot

Right, it's not in the psc-ide protocol and I'm not sure if others think this would be a useful feature.

I'm now simply using nvim terminal mode to insert pulp repl results into the code:

function! OnEvent(job_id, data, event) dict
  if a:event == 'stdout'
    if a:data[0] =~ 'Error'
      call append(line('.'), a:data)
    else
      call append(line('.'), a:data)
    endif
  elseif a:event == 'stderr'
    call append(line('.'), a:data)
  else
    call append(line('.'), "Unknown event?!")
  endif
endfunction

function! PursEval(expr)
  call jobsend(g:PursReplID, a:expr . "\n")
endfun

let Cbs = {
\ 'on_stdout': function('OnEvent'),
\ 'on_stderr': function('OnEvent'),
\ 'on_exit': function('OnEvent')
\ }

command! PursRepl :let PursReplID = jobstart("pulp repl", Cbs)

It would need filtering in the event handler to not clutter your code with all outputs. Not a very elegant approach, so not sure how others are doing this.

andreasthoelke avatar Mar 12 '18 14:03 andreasthoelke