|
1 | 1 | " Vim compiler file |
2 | 2 | " Compiler: Pandoc |
3 | 3 | " Maintainer: Konfekt |
4 | | -" Last Change: 2024 Aug 20 |
| 4 | +" Last Change: 2024 Sep 8 |
5 | 5 | " |
6 | 6 | " Expects output file extension, say `:make html` or `:make pdf`. |
7 | 7 | " Passes additional arguments to pandoc, say `:make html --self-contained`. |
| 8 | +" Adjust command-line flags by buffer-local/global variable |
| 9 | +" b/g:pandoc_compiler_args which defaults to empty. |
8 | 10 |
|
9 | 11 | if exists("current_compiler") |
10 | 12 | finish |
@@ -40,18 +42,21 @@ silent! function s:PandocFiletype(filetype) abort |
40 | 42 | endif |
41 | 43 | endfunction |
42 | 44 |
|
43 | | -let b:pandoc_compiler_from = get(b:, 'pandoc_compiler_from', s:PandocFiletype(&filetype)) |
44 | | -let b:pandoc_compiler_lang = get(b:, 'pandoc_compiler_lang', &spell ? matchstr(&spelllang, '^\a\a') : '') |
| 45 | +silent! function s:PandocLang() |
| 46 | + let lang = get(b:, 'pandoc_compiler_lang', |
| 47 | + \ &spell ? matchstr(&spelllang, '^\a\a') : '') |
| 48 | + if lang ==# 'en' | let lang = '' | endif |
| 49 | + return empty(lang) ? '' : '--metadata lang='..lang |
| 50 | +endfunction |
45 | 51 |
|
46 | 52 | execute 'CompilerSet makeprg=pandoc'..escape( |
47 | | - \ ' --standalone' . |
48 | | - \ (b:pandoc_compiler_from ==# 'markdown' && (getline(1) =~# '^%\s\+\S\+' || (search('^title:\s+\S+', 'cnw') > 0)) ? |
49 | | - \ '' : ' --metadata title=%:t:r:S') . |
50 | | - \ (empty(b:pandoc_compiler_lang) ? |
51 | | - \ '' : ' --metadata lang='..b:pandoc_compiler_lang) . |
52 | | - \ ' --from='..b:pandoc_compiler_from . |
53 | | - \ ' '..get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', '')) . |
54 | | - \ ' --output %:r:S.$* -- %:S', ' ') |
| 53 | + \ ' --standalone'.. |
| 54 | + \ (s:PandocFiletype(&filetype) ==# 'markdown' && (getline(1) =~# '^%\s\+\S\+' || (search('^title:\s+\S+', 'cnw') > 0)) ? |
| 55 | + \ '' : ' --metadata title=%:t:r:S').. |
| 56 | + \ ' '..s:PandocLang().. |
| 57 | + \ ' --from='..s:PandocFiletype(&filetype).. |
| 58 | + \ ' '..get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', '')).. |
| 59 | + \ ' --output %:r:S.$* -- %:S', ' ') |
55 | 60 | CompilerSet errorformat=\"%f\",\ line\ %l:\ %m |
56 | 61 |
|
57 | 62 | let &cpo = s:keepcpo |
|
0 commit comments