donkirkby / live-py-plugin

Live coding in Python with PyCharm, Emacs, Sublime Text, or even a browser
https://donkirkby.github.io/live-py-plugin
MIT License
291 stars 57 forks source link

Editors with autosave #275

Closed upgradeQ closed 4 years ago

upgradeQ commented 4 years ago

As a workaround those editors that don't have plugin , but do support autosave, might try using this script. Run python watch.py in split , edit e.py while autosave is on

# watch.py
from subprocess import run
from time import sleep
from os import system

def main():
    saved = None
    switch = True
    while True:
        with open("e.py", "r") as f:
            content = f.read()
            if saved == content:
                if switch:
                    with open("out.txt", "r") as sp_trace:
                        print(sp_trace.read())
                    switch = False

                sleep(0.1)
            else:
                switch = True
                saved = content
                run("space_tracer e.py -r out.txt")
                # https://stackoverflow.com/a/51043407
                system("cls||clear")
try:
    main()
except KeyboardInterrupt:
    pass

So for vim there is plugin and for VSCode #218 it's built-in

donkirkby commented 4 years ago

Thanks for the suggestion, @HQupgradeHQ. I've done something similar in GNU/Linux, where it's even easier to use the watch command. If running your script is expensive for some reason, though, your version would avoid extra runs.

I didn't include that in the instructions, because I found it's not useful once you have more than a single screen of code. There's no way to synchronize the scrolling between the code and the display. You could add a --traced option, but that still seems too fiddly to be practical.

I'm going to close this issue for now, but please add a comment if you do find it practical to use some technique like this when you don't have real editor integration.

upgradeQ commented 4 years ago

Yes it is useful to evaluate something while continuous execution is going.