1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
let s:base = expand("<sfile>:h:h")
let Filter = { _, v -> stridx(v, s:base) == -1 && stridx(v, $VIMRUNTIME) == -1 && v !~ "after" }
let files = filter(globpath(&rtp, 'ftplugin/crystal.vim', 1, 1), Filter)
if len(files) > 0
exec 'source ' . files[0]
finish
endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
if exists('b:did_ftplugin')
finish
endif
let b:did_ftplugin = 1
setlocal comments=:#
setlocal commentstring=#\ %s
setlocal suffixesadd=.cr
" Set format for quickfix window
setlocal errorformat=
\%ESyntax\ error\ in\ line\ %l:\ %m,
\%ESyntax\ error\ in\ %f:%l:\ %m,
\%EError\ in\ %f:%l:\ %m,
\%C%p^,
\%-C%.%#
let g:crystal_compiler_command = get(g:, 'crystal_compiler_command', 'crystal')
let g:crystal_auto_format = get(g:, 'crystal_auto_format', 0)
command! -buffer -nargs=* CrystalImpl echo crystal_lang#impl(expand('%'), getpos('.'), <q-args>).output
command! -buffer -nargs=0 CrystalDef call crystal_lang#jump_to_definition(expand('%'), getpos('.'))
command! -buffer -nargs=* CrystalContext echo crystal_lang#context(expand('%'), getpos('.'), <q-args>).output
command! -buffer -nargs=* CrystalHierarchy echo crystal_lang#type_hierarchy(expand('%'), <q-args>)
command! -buffer -nargs=? CrystalSpecSwitch call crystal_lang#switch_spec_file(<f-args>)
command! -buffer -nargs=? CrystalSpecRunAll call crystal_lang#run_all_spec(<f-args>)
command! -buffer -nargs=? CrystalSpecRunCurrent call crystal_lang#run_current_spec(<f-args>)
command! -buffer -nargs=* -bar CrystalFormat call crystal_lang#format(<q-args>, 0)
command! -buffer -nargs=* CrystalExpand echo crystal_lang#expand(expand('%'), getpos('.'), <q-args>).output
nnoremap <buffer><Plug>(crystal-jump-to-definition) :<C-u>CrystalDef<CR>
nnoremap <buffer><Plug>(crystal-show-context) :<C-u>CrystalContext<CR>
nnoremap <buffer><Plug>(crystal-spec-switch) :<C-u>CrystalSpecSwitch<CR>
nnoremap <buffer><Plug>(crystal-spec-run-all) :<C-u>CrystalSpecRunAll<CR>
nnoremap <buffer><Plug>(crystal-spec-run-current) :<C-u>CrystalSpecRunCurrent<CR>
nnoremap <buffer><Plug>(crystal-format) :<C-u>CrystalFormat<CR>
" autocmd is setup per buffer. Please do not use :autocmd!. It refreshes
" augroup hence removes autocmds for other buffers (#105)
augroup plugin-ft-crystal
autocmd BufWritePre <buffer> if g:crystal_auto_format && &filetype ==# 'crystal' | call crystal_lang#format('', 1) | endif
augroup END
if get(g:, 'crystal_define_mappings', 1)
nmap <buffer>gd <Plug>(crystal-jump-to-definition)
nmap <buffer>gc <Plug>(crystal-show-context)
nmap <buffer>gss <Plug>(crystal-spec-switch)
nmap <buffer>gsa <Plug>(crystal-spec-run-all)
nmap <buffer>gsc <Plug>(crystal-spec-run-current)
endif
if &l:ofu ==# ''
setlocal omnifunc=crystal_lang#complete
endif
" Options for vim-matchit
if exists('g:loaded_matchit') && !exists('b:match_words')
let b:match_ignorecase = 0
let b:match_words =
\ '\<\%(if\|unless\|case\|while\|until\|for\|do\|class\|module\|struct\|lib\|macro\|ifdef\|def\|begin\|enum\|annotation\)\>=\@!' .
\ ':' .
\ '\<\%(else\|elsif\|ensure\|when\|in\|rescue\|break\|next\)\>' .
\ ':' .
\ '\<end\>' .
\ ',{:},\[:\],(:)'
let b:match_skip =
\ 'synIDattr(synID(line("."), col("."), 0), "name") =~# ''' .
\ '\<crystal\%(String\|StringDelimiter\|ASCIICode\|Escape\|' .
\ 'Interpolation\|NoInterpolation\|Comment\|Documentation\|' .
\ 'ConditionalModifier\|' .
\ 'Function\|BlockArgument\|KeywordAsMethod\|ClassVariable\|' .
\ 'InstanceVariable\|GlobalVariable\|Symbol\)\>'''
endif
" Options for jiangmiao/auto-pairs
if exists('g:AutoPairsLoaded')
let b:AutoPairs = { '{%': '%}' }
call extend(b:AutoPairs, g:AutoPairs, 'force')
endif
" vim: sw=2 sts=2 et:
endif
|