성공적인 출력 구문 표시

4911 단어 vim-dispatch

묘사

python 스크립트를 실행하는 함수는 오류가 발생하면 quickfix 창에 표시됩니다.
function! PythonDispatch()
    let l:save_pwd = getcwd()
    let old_efm = &l:efm
    lcd %:p:h
    let current_file = expand('%:p:t')
    let compiler = 'python '
    let &l:makeprg = compiler . current_file

    setlocal errorformat=
        \%A\ \ File\ \"%f\"\\\,\ line\ %l\\\,%m,
        \%C\ \ \ \ %.%#,
        \%+Z%.%#Error\:\ %.%#,
        \%A\ \ File\ \"%f\"\\\,\ line\ %l,
        \%+C\ \ %.%#,
        \%-C%p^,
        \%Z%m,
        \%-G%.%#,
        \%-G%.%#

    execute 'silent Make'

    let &l:efm = old_efm
    execute 'lcd ' . l:save_pwd
endfunction
그러나 구축에 성공했을 때 (즉 오류가 없음) 내가 얻은 유일한 정보는

Finished: python {python file}


미리 보기 창 (또는quickfix 창 자체) 에서 성공적으로 만들어진 출력을 보고 싶습니다.execute 'silent Make' 이후에 다음 행을 추가하여 이러한 함수를 수정하려고 합니다.
    au QuickfixCmdPost cgetfile exe "silent! call " ShowPyOutput(current_file)
어느 곳, 어디
function! ShowPyOutput(file)
    if empty(getqflist())
        let output = split(system('python ' . a:file), "\n")
        let height = len(output)
        if empty(output)
            pclose
            echo 'No python output.'
            return
        endif
        pclose
        if height < 12
            execute "botright " . height . "new python_output"
        else
            execute "botright 12new python_output"
        endif
        setlocal buftype=nofile bufhidden=delete noswapfile nowrap previewwindow
        redraw
        call append(line('$'), output)
        normal dd
        wincmd p
    endif
endfunction
그러나 이것은 작용하지 않는다. (나는 내 QuickfixCmdPost 자동 명령이 확장 current_file 을 시도할 때 문제가 있다고 생각한다.)설령 내가 그것을 일하게 하더라도 (특정한 파일 이름으로 바꾸기 current_file, 예를 들어 foo.py)), 주요 문제는 내가 system() 에서python 파일을 다시 실행해서 출력을 포획하는 것이다.
그래서 나의 문제는 :Make (또는 유사) 한 번만 실행해서 성공적인 구축 출력을 포착하고 미리 보기 창에 출력을 표시할 수 있느냐는 것이다.
이렇게 오랫동안 물어 주셔서 죄송합니다. 미리 도와 주셔서 감사합니다!

토론 #1

오류 형식에서 삭제%-G%.%#하면 모든 출력이 포착됩니다.

토론 #2

@t 감사합니다.내가 쓴 잘못된 형식은 다음과 같습니다.
setlocal errorformat=
    \%A\ \ File\ \"%f\"\\\,\ line\ %l\\\,%m,
    \%C\ \ \ \ %.%#,
    \%+Z%.%#Error\:\ %.%#,
    \%A\ \ File\ \"%f\"\\\,\ line\ %l,
    \%+C\ \ %.%#,
    \%-C%p^,
    \%Z%m,
    \%-GTraceback%.%#
그리고 출력을 확실히 잡았지만 구축이 완료되면 수동으로 실행해야 한다:copen.quickfix 창을 자동으로 열 수 있는 방법이 있습니까?

토론 #셋

명확하게 포함%+G%.%#.다시 한 번 감사 드립니다.질문
print('foo')
x
나는 그것을 실행한 후에 '빠른 복구' 창에서
|| foo
foo.py|2| in <module> NameError: name 'x' is not defined
이런 상황에서 나는 단지 잘못을 얻고 싶을 뿐이다.
 foo.py|2| in <module> NameError: name 'x' is not defined

토론 #4

출력이 아닙니다.%+G%.%#@t 마지막 질문에 대답해 주세요. 질문fix에서 인쇄할 오류 형식 foo.py을 수정하는 방법|| foo이 아니라

토론 #5

입니다. 즉, 삭제하고 싶습니다foo.이렇게 번거롭게 해서 미안하지만, 당신의 큰 도움에 감사 드립니다!|| foo너 못해||그래.다시 한 번 감사합니다

토론 #6

@t특정 기능 하나만 사용하면

토론 #7

자동 명령을 터치할 수 있습니까?예를 들어

토론 #8

또는 QuickFixCmdPost를 호출할 때 아래의 최소vimrc를 사용하면 자동 명령을 터치합니다.나는 단지 호출 RunPython() 할 때 자동 명령을 터치하고 싶을 뿐이다.제가 할 수 있을까요?미리 당신의 도움에 감사 드립니다.
set nocompatible

let $ONEDRIVE_HOME = expand('C:/OD/Users/Pedro')
let $DOTVIM = expand('$ONEDRIVE_HOME/vimfiles')

set runtimepath+=$DOTVIM/bundle/dispatch/
filetype plugin indent on

function! RunPython()
    let l:save_pwd = getcwd()
    lcd %:p:h
    let current_file = expand('%:p:t')
    let compiler = 'python '
    let &l:makeprg = compiler . current_file
    execute 'silent Make'
    execute 'lcd ' . l:save_pwd
endfunction

function! OpenBuffer()
    execute "silent botright new py_output"
    call append(line('$'), "This should only show up when running RunPython()")
    normal dd
endfunction

function! MyFlake8()
    let l:save_pwd = getcwd()
    lcd %:p:h
    let current_file = expand('%:p:t')
    let compiler = 'flake8 '
    let &l:makeprg = compiler . current_file
    execute 'silent Make'
    execute 'lcd ' . l:save_pwd
endfunction

augroup test_au
    au!
    au QuickFixCmdPost cgetfile call OpenBuffer()
augroup END
너는 조건부로 리셋 함수를 검사할 수 있다.MyFlake8()@tpope.감사합니다!!!

좋은 웹페이지 즐겨찾기