2013-10-23 33 views
1

我有這個功能編譯我TEX文件:VIM:問題與函數編譯當前緩衝區

function! CompileTex() 
    silent write! 
    call setqflist([]) 
    echon "compiling with arara ..." 
    exec 'lcd %:h' 

    if expand("%:p") =~# '\(figuras\|figures\)' 
     let mainfile = fnameescape(expand("%:p")) 
    else 
     let mainfile = fnameescape(Tex_GetMainFileName()) 
    endif 
    let &l:makeprg = 'arara -v ' . mainfile 
    silent make! 

    if !empty(getqflist()) 
     copen 
     wincmd J 
    else 
     cclose 
     redraw 
     echon "successfully compiled" 
    endif 

endfunction 

的第一個條件是存在的,因爲在創建人物時,我想編譯當前緩衝區,即使是有主文件。然而,當我打電話,它包含一個路徑功能「人物」我得到

Error detected while processing function CompileTex: 
line 4: 
E499: Empty file name for '%' or '#', only works with ":p:h": lcd %:h 

mainfile變量被設置到主TEX文件,而不是因爲我想當前緩衝區。

回答

1

請嘗試按照錯誤消息的建議,並將「lcd%:h」更改爲「lcd%:p:h」。

此外,你不需要:exec。直接寫它,它是一個ex命令:

function! CompileTex() 
    silent write! 
    call setqflist([]) 
    echon "compiling with arara ..." 
    lcd %:p:h 
    ... 
    etc. 
+0

確實修復了錯誤消息,但主tex文件仍然編譯,而不是我想要的當前緩衝區。 – petobens

+0

也許這是我的設置問題。檢查路徑中「圖」的條件是否正確?或者我應該修改它? – petobens

+0

這個條件看起來對我來說很合適。不過,我不確定Tex_GetMainFileName()是做什麼的。您是否驗證過該功能正在做您想要的功能? – Ben