1

I have this function to compile my tex files:

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

The first conditional is there because when creating figures I want to compile the current buffer even if there is a main file. However when I call the function in a path that contains "figures" I get

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

and the mainfile variable is set to the main tex file and not to the current buffer as I want.

4

1 回答 1

1

按照错误消息的提示尝试,并将“lcd %:h”更改为“lcd %:p:h”。

此外,您不需要 :exec。直接写就行了,就是ex命令:

function! CompileTex()
    silent write!
    call setqflist([])
    echon "compiling with arara ..."
    lcd %:p:h
    ...
    etc.
于 2013-10-23T14:59:53.203 回答