skywind3000 / asyncrun.vim

:rocket: Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
https://www.vim.org/scripts/script.php?script_id=5431
MIT License
1.84k stars 109 forks source link

indentation error #215

Open pinggit opened 3 years ago

pinggit commented 3 years ago

in markdown document I prefer to indent the code, like this:

"Iet's look at these code:

    def log(func):
        def wrapper(*args, **kw):
            print('call %s():' % func.__name__)
            return func(*args, **kw)
        return wrapper

    @log
    def now():
        print('2016-07-05')

this is just an example."

with Asyncrun, I'd like to visual select the code and run it:

:'<,'>AsyncRun python3

which throw an error

|| [python3]
||   File "<stdin>", line 1
||     def log(func):
||     ^
|| IndentationError: unexpected indent
|| [Finished in 1 seconds with code 1]

I know this is because Asyncrun literally copied the visual block and throw it to python3, which report an error. My question is, is there any workaround to "ignore" the leading indentations (for markdown only) when passing to python? that will be super useful!

skywind3000 commented 3 years ago

This is a python only problem, should not be fixed in asyncrun.

What you need is a text filter which will preprocess your source code, take care of the indentation before passing it to python:

:'<,'>AsyncRun your_text_filter | python3