Skip to content

Commit 39ce940

Browse files
committed
feat: Enable compiler functionality out of the box in SIL files
1 parent cb3bf29 commit 39ce940

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

autoload/sile.vim

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
" SPDX-FileCopyrightText: © 2015 Caleb Maclennan <[email protected]>
2+
" SPDX-License-Identifier: GPL-2.0-or-later
3+
4+
scriptencoding utf-8
5+
6+
if exists('g:loaded_sile')
7+
finish
8+
endif
9+
10+
let g:loaded_sile = 1
11+
12+
if exists('g:sile_no_bin') && g:sile_no_bin
13+
unlet! g:sile_bin
14+
elseif !exists('g:sile_bin') || empty(g:sile_bin)
15+
if executable('sile')
16+
let g:sile_bin = 'sile'
17+
else
18+
unlet! g:sile_bin
19+
echohl WarningMsg
20+
echomsg 'No sile command detected, set g:sile_bin to enable more vim-sile features.'
21+
echohl None
22+
endif
23+
elseif !executable(g:sile_bin)
24+
unlet! g:sile_bin
25+
echohl WarningMsg
26+
echomsg 'Command set in g:sile_bin is not executable, fix to to enable more vim-sile features.'
27+
echohl None
28+
endif
29+
30+
if !exists('g:sile_main')
31+
let g:sile_main = '%:p'
32+
endif
33+
34+
function! sile#init() abort
35+
if !exists('b:sile_bin')
36+
let b:sile_bin = get(g:, 'sile_bin', 0)
37+
endif
38+
let settings = [
39+
\ 'sile_main',
40+
\ ]
41+
for setting in settings
42+
if !has_key(b:, setting)
43+
let b:{setting} = get(g:, setting)
44+
endif
45+
endfor
46+
endfunction

compiler/sile.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
" SPDX-FileCopyrightText: © 2015 Caleb Maclennan <[email protected]>
2+
" SPDX-License-Identifier: GPL-2.0-or-later
3+
4+
scriptencoding utf-8
5+
6+
if exists('b:current_compiler')
7+
finish
8+
endif
9+
10+
call sile#init()
11+
12+
let b:current_compiler = b:sile_bin
13+
14+
if exists(':CompilerSet') != 2
15+
command -nargs=* CompilerSet setlocal <args>
16+
endif
17+
18+
let s:escaped_bin = substitute(b:sile_bin, ' ', '\\ ', 'g')
19+
let s:escaped_main = substitute(shellescape(expand(b:sile_main)), ' ', '\\ ', 'g')
20+
21+
execute 'CompilerSet makeprg=' . s:escaped_bin . '\ ' . s:escaped_main

ftplugin/sile.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ let b:did_ftplugin = 1
1313

1414
setlocal comments=:%
1515
setlocal commentstring=%\ %s
16+
17+
if !exists('current_compiler')
18+
compiler sile
19+
endif

0 commit comments

Comments
 (0)