gpt4 book ai didi

linux - 如何在创建 Latex 文件时在同一目录中自动创建 makefile?

转载 作者:太空狗 更新时间:2023-10-29 11:48:01 25 4
gpt4 key购买 nike

当我使用 vim 创建一个 .tex 文件时,我得到了一个很好的模板

autocmd BufNewFile *.tex 0r $HOME/.vim/templates/skeleton.tex

在我的 .vimrc 中。我的主目录中也有一个 makefile 模板,但我必须手动将其复制到 .tex 文件所在的位置。在 Linux 环境中,如何在创建 .tex 文件的同时自动复制或自动生成 makefile?

最佳答案

可移植的答案不会使用 cp(它可能会覆盖先前存在的 makefile),而是使用 vim 函数 readfile() 和 writefile()。

要触发它,最好的办法是定义并执行一个函数来加载第一个骨架,并即时创建 Makefile:

" untested code
"
function! s:NewTeXPlusMakefile()
let where = expand('%:p:h')
" see mu-template's fork for a more advanced way to find template-files
let skeletons_path = globpath(&rtp, 'templates')

" the current .tex file
let lines = readfile(skeletons_path.'/skeleton.tex')
call setline(1, lines)

" the Makefile, that MUST not be overwritten when it already exists!
let makefile = where.'/Makefile'
if ! filereadable(makefile)
let lines = readfile(skeletons_path.'/skeleton.makefile')
call writefile(lines, makefile )
endif
endfunction

augroup LaTeXTemplates
au!
au BufNewFile *.tex call s:NewTeXPlusMakefile()
augroup END

关于linux - 如何在创建 Latex 文件时在同一目录中自动创建 makefile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2956406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com