live-py-plugin icon indicating copy to clipboard operation
live-py-plugin copied to clipboard

Vim support

Open blayz3r opened this issue 4 years ago • 4 comments

Any plans to support Vim

blayz3r avatar Oct 06 '20 06:10 blayz3r

I've never been a regular user of Vim, so I don't plan to add support for it. If you or anyone else is interested in contributing support for Vim, there's a description of the process in the contributing file. It mostly involves launching a Python subprocess to call the tracer code, and then displaying the results in a side-by-side window.

I did a little searching for how to write a Vim plugin, and it looks like there's lots of documentation. One example is Learn Vimscript the Hard Way.

donkirkby avatar Oct 07 '20 01:10 donkirkby

So currently there is a plugin here that does something similar: https://github.com/metakirby5/codi.vim Basically is does this by:

  • Start a job that invokes script on the bin, which is python in this case
  • If asynchronous, grab stdout until the number of prompts received from stdout matches the number of lines in the main buffer; if synchronous, just run the job to conclusion and grab the output
  • Get the values associated with each line using the algorithm described here
  • Replace the Codi buffer contents

The difference ofcourse is that codi gets ouput put from the Repl and live-py-plugin does some extra manupualtion.

Is it possible to run the plugin as a script e.g run python live-py-plugin.py > output.txt

image

blayz3r avatar Oct 13 '20 19:10 blayz3r

Thanks for doing the research. Yes, the core analysis is done by a Python package called space_tracer, and you can run that as a command-line tool. See the contributing file for some hints, look at Space Tracer's getting started page, or look at its parse_args() method in the source code.

Let me know if you need any hints on how to make Space Tracer do what you need.

donkirkby avatar Oct 13 '20 20:10 donkirkby

Simple solution :

  1. make a shell script that runs space_tracer
  2. run that shell script in a vim terminal buffer

Here is my script (in zsh) (named space_tracer_loop):

#!/bin/zsh

fswatch -0 $1 | while read -d "" event
do
    clear
    space_tracer $1
done

It uses fswatch.

Here is the command to run it in a vim split terminal : :vert term space_tracer_loop %

And, each time you save your file, it will update ! It is not exactly live, since you have to save the file, but this is a very simple solution that basically does the job. I guess it is possible to use the contents of the vim buffer instead, but that would require far more work, and the usage of vimscript (or lua, or python, or any language to configure vim, because vimscript is not the only language you can use to configure vim).

OsKaR31415 avatar Jun 05 '22 17:06 OsKaR31415