]> git.lizzy.rs Git - rust.git/blob - src/etc/vim/ftplugin/rust.vim
Add commands :RustEmitIr and :RustEmitAsm
[rust.git] / src / etc / vim / ftplugin / rust.vim
1 " Language:     Rust
2 " Description:  Vim syntax file for Rust
3 " Maintainer:   Chris Morgan <me@chrismorgan.info>
4 " Maintainer:   Kevin Ballard <kevin@sb.org>
5 " Last Change:  May 27, 2014
6
7 if exists("b:did_ftplugin")
8         finish
9 endif
10 let b:did_ftplugin = 1
11
12 let s:save_cpo = &cpo
13 set cpo&vim
14
15 " Variables {{{1
16
17 " The rust source code at present seems to typically omit a leader on /*!
18 " comments, so we'll use that as our default, but make it easy to switch.
19 " This does not affect indentation at all (I tested it with and without
20 " leader), merely whether a leader is inserted by default or not.
21 if exists("g:rust_bang_comment_leader") && g:rust_bang_comment_leader == 1
22         " Why is the `,s0:/*,mb:\ ,ex:*/` there, you ask? I don't understand why,
23         " but without it, */ gets indented one space even if there were no
24         " leaders. I'm fairly sure that's a Vim bug.
25         setlocal comments=s1:/*,mb:*,ex:*/,s0:/*,mb:\ ,ex:*/,:///,://!,://
26 else
27         setlocal comments=s0:/*!,m:\ ,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,://
28 endif
29 setlocal commentstring=//%s
30 setlocal formatoptions-=t formatoptions+=croqnl
31 " j was only added in 7.3.541, so stop complaints about its nonexistence
32 silent! setlocal formatoptions+=j
33
34 " This includeexpr isn't perfect, but it's a good start
35 setlocal includeexpr=substitute(v:fname,'::','/','g')
36
37 " NOT adding .rc as it's being phased out (0.7)
38 setlocal suffixesadd=.rs
39
40 if exists("g:ftplugin_rust_source_path")
41     let &l:path=g:ftplugin_rust_source_path . ',' . &l:path
42 endif
43
44 if exists("g:loaded_delimitMate")
45         if exists("b:delimitMate_excluded_regions")
46                 let b:rust_original_delimitMate_excluded_regions = b:delimitMate_excluded_regions
47         endif
48         let b:delimitMate_excluded_regions = delimitMate#Get("excluded_regions") . ',rustLifetimeCandidate,rustGenericLifetimeCandidate'
49 endif
50
51 " Motion Commands {{{1
52
53 " Bind motion commands to support hanging indents
54 nnoremap <silent> <buffer> [[ :call rust#Jump('n', 'Back')<CR>
55 nnoremap <silent> <buffer> ]] :call rust#Jump('n', 'Forward')<CR>
56 xnoremap <silent> <buffer> [[ :call rust#Jump('v', 'Back')<CR>
57 xnoremap <silent> <buffer> ]] :call rust#Jump('v', 'Forward')<CR>
58 onoremap <silent> <buffer> [[ :call rust#Jump('o', 'Back')<CR>
59 onoremap <silent> <buffer> ]] :call rust#Jump('o', 'Forward')<CR>
60
61 " Commands {{{1
62
63 " See |:RustRun| for docs
64 command! -nargs=* -complete=file -bang -bar -buffer RustRun call rust#Run(<bang>0, [<f-args>])
65
66 " See |:RustExpand| for docs
67 command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -bar -buffer RustExpand call rust#Expand(<bang>0, [<f-args>])
68
69 " See |:RustEmitIr| for docs
70 command! -nargs=* -bar -buffer RustEmitIr call rust#Emit("ir", [<f-args>])
71
72 " See |:RustEmitAsm| for docs
73 command! -nargs=* -bar -buffer RustEmitAsm call rust#Emit("asm", [<f-args>])
74
75 " Mappings {{{1
76
77 " Bind ⌘R in MacVim to :RustRun
78 nnoremap <silent> <buffer> <D-r> :RustRun<CR>
79 " Bind ⌘⇧R in MacVim to :RustRun! pre-filled with the last args
80 nnoremap <buffer> <D-R> :RustRun! <C-r>=join(b:rust_last_rustc_args)<CR><C-\>erust#AppendCmdLine(' -- ' . join(b:rust_last_args))<CR>
81
82 if !exists("b:rust_last_rustc_args") || !exists("b:rust_last_args")
83         let b:rust_last_rustc_args = []
84         let b:rust_last_args = []
85 endif
86
87 " Cleanup {{{1
88
89 let b:undo_ftplugin = "
90                 \setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
91                 \|if exists('b:rust_original_delimitMate_excluded_regions')
92                   \|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions
93                   \|unlet b:rust_original_delimitMate_excluded_regions
94                 \|else
95                   \|unlet! b:delimitMate_excluded_regions
96                 \|endif
97                 \|unlet! b:rust_last_rustc_args b:rust_last_args
98                 \|delcommand RustRun
99                 \|delcommand RustExpand
100                 \|delcommand RustEmitIr
101                 \|delcommand RustEmitAsm
102                 \|nunmap <buffer> <D-r>
103                 \|nunmap <buffer> <D-R>
104                 \|nunmap <buffer> [[
105                 \|nunmap <buffer> ]]
106                 \|xunmap <buffer> [[
107                 \|xunmap <buffer> ]]
108                 \|ounmap <buffer> [[
109                 \|ounmap <buffer> ]]
110                 \"
111
112 " }}}1
113
114 let &cpo = s:save_cpo
115 unlet s:save_cpo
116
117 " vim: set noet sw=4 ts=4: