-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathdoge.vim
230 lines (200 loc) · 6.78 KB
/
doge.vim
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
let s:save_cpo = &cpoptions
set cpoptions&vim
let g:doge_prefix = '[vim-doge]'
let s:unsupported_msg = g:doge_prefix . ' Unsupported version. %s is required.'
if !has('nvim') && (v:version < 700 || !has('patch-7.4.2119'))
echohl WarningMsg
echo printf(s:unsupported_msg, 'Vim v7.4.2119+')
echohl None
finish
endif
if has('nvim') && !has('nvim-0.3.2')
echohl WarningMsg
echo printf(s:unsupported_msg, 'NeoVim v0.3.2+')
echohl None
finish
endif
if has('win32') && &shellslash
set noshellslash
let g:doge_dir = resolve(expand('<sfile>:p:h:h'))
set shellslash
else
let g:doge_dir = resolve(expand('<sfile>:p:h:h'))
endif
" section Introduction, intro {{{
""
" @section Introduction, intro
" We all love documentation because it makes our codebases easier to understand,
" yet no one has time to write it in a good and proper way.
"
" Vim-doge is a (Do)cumentation (Ge)nerator which will generate a proper
" documentation skeleton based on certain expressions (mainly functions).
" Simply put your cursor on a function, press `<Leader>d`, jump quickly through
" TODO items using `<Tab>` and `<S-Tab>` to quickly add descriptions and go on
" coding!
" }}}
" section Preprocessors, preprocessors {{{
""
" @section Preprocessors, preprocessors
" @parentsection functions
" Preprocess functions are called for specific filetypes when @plugin(name) is
" generating a comment. The following preprocess functions are available:
"
" doge#preprocessors#<language>#alter_parser_args(parser_args)
" }}}
if exists('g:loaded_doge')
finish
endif
let g:loaded_doge = 1
if !exists('g:doge_install_path')
""
" (Default: /path/to/vim-doge)
"
" The path where the bin/ directory will be installed and loaded from.
let g:doge_install_path = g:doge_dir
endif
if !exists('g:doge_enable_mappings')
""
" (Default: 1)
"
" Whether to enable built-in mappings.
let g:doge_enable_mappings = 1
endif
if !exists('g:doge_mapping')
""
" (Default: '<Leader>d')
"
" The mapping to trigger vim-doge. The mapping accepts a count, to select a
" specific doc standard, if more than one is defined.
let g:doge_mapping = '<Leader>d'
endif
""
" (Default: {
" 'javascript': [
" 'javascript.jsx',
" 'javascriptreact',
" 'javascript.tsx',
" 'typescriptreact',
" 'typescript',
" ],
" 'html': ['svelte', 'vue'],
" 'java': ['groovy'],
" })
" Set filetypes as an alias for other filetypes.
" The key should be the filetype that is defined in ftplugin/<key>.vim.
" The value must be a list of 1 or more filetypes that will be aliases.
"
" Example:
" let g:doge_filetype_aliases = {
" \ 'javascript': ['typescript']
" \}
"
" If you use the above settings and you open `myfile.ts` then it will behave
" like you're opening a javascript filetype.
let g:doge_filetype_aliases = doge#utils#deepextend({
\ 'javascript': [
\ 'javascript.jsx',
\ 'javascriptreact',
\ 'javascript.tsx',
\ 'typescriptreact',
\ 'typescript',
\ 'typescript.tsx',
\ ],
\ 'html': ['svelte', 'vue'],
\ 'java': ['groovy'],
\}, get(g:, 'doge_filetype_aliases', {}), 1)
if !exists('g:doge_buffer_mappings')
""
" (Default: 1)
"
" Mappings to jump forward/backward are applied as buffer mappings when
" interactive mode starts and removed when it ends.
let g:doge_buffer_mappings = 1
endif
if !exists('g:doge_mapping_comment_jump_forward')
""
" (Default: '<Tab>')
"
" The mapping to jump forward to the next TODO item in a comment.
" Requires @setting(g:doge_comment_interactive) to be enabled.
let g:doge_mapping_comment_jump_forward = '<Tab>'
endif
if !exists('g:doge_mapping_comment_jump_backward')
""
" (Default: '<S-Tab>')
"
" The mapping to jump backward to the previous TODO item in a comment.
" Requires @setting(g:doge_comment_interactive) to be enabled.
let g:doge_mapping_comment_jump_backward = '<S-Tab>'
endif
if !exists('g:doge_comment_interactive')
""
" (Default: 1)
"
" Jumps interactively through all TODO items in the generated comment.
let g:doge_comment_interactive = 1
endif
if !exists('g:doge_comment_jump_wrap')
""
" (Default: 1)
"
" Continue to cycle among placeholders when reaching the start or end.
let g:doge_comment_jump_wrap = 1
endif
if !exists('g:doge_comment_jump_modes')
""
" (Default: ['n', 'i', 's'])
"
" Defines the modes in which doge will jump forward and backward when
" interactive mode is active. For example: removing 'i' would allow you to use
" <Tab> for autocompletion in insert mode.
let g:doge_comment_jump_modes = ['n', 'i', 's']
endif
" Doxygen settings that will be used for all C-family languages.
if !exists('g:doge_doxygen_settings')
let g:doge_doxygen_settings = {
\ 'char': '@',
\}
else
let s:doxygen_settings = get(g:, 'doge_doxygen_settings', {})
if has_key(s:doxygen_settings, 'char') && !(s:doxygen_settings['char'] ==# '@' || s:doxygen_settings['char'] ==# '\')
echoerr g:doge_prefix . ' "' . s:doxygen_settings['char'] . '" is not a valid character. Accepted characters are @ or \'
endif
endif
" Register all the <Plug> mappings.
nnoremap <Plug>(doge-generate) :<C-u>call doge#generate(v:count)<CR>
for s:mode in g:doge_comment_jump_modes
call execute(printf('%snoremap <expr> <Plug>(doge-comment-jump-forward) doge#comment#jump("forward")', s:mode), 'silent!')
call execute(printf('%snoremap <expr> <Plug>(doge-comment-jump-backward) doge#comment#jump("backward")', s:mode), 'silent!')
endfor
if g:doge_enable_mappings == v:true
call execute(printf('nmap <silent> %s <Plug>(doge-generate)', g:doge_mapping), 'silent!')
if g:doge_buffer_mappings == v:false
for s:mode in g:doge_comment_jump_modes
call execute(printf('%smap <silent> %s <Plug>(doge-comment-jump-forward)', s:mode, g:doge_mapping_comment_jump_forward), 'silent!')
call execute(printf('%smap <silent> %s <Plug>(doge-comment-jump-backward)', s:mode, g:doge_mapping_comment_jump_backward), 'silent!')
endfor
endif
endif
unlet s:mode
""
" @command DogeGenerate {doc_standard}
" Command to generate documentation. The `{doc_standard}` accepts a count or a
" string as argument, and it can complete the available doc standards for the
" current buffer.
"
" The numeric value should point to an index key from the
" `b:doge_supported_doc_standards` variable.
"
" The string value should point to a doc standard name listed in the
" `b:doge_supported_doc_standards` variable.
command! -count -nargs=? -complete=customlist,doge#command_complete DogeGenerate call doge#generate(<count> ? <count> : <q-args>)
augroup doge
autocmd!
autocmd TextChangedI * call doge#comment#update_interactive_comment_info()
autocmd InsertLeave * call doge#comment#deactivate_when_done()
autocmd TextChanged * call doge#comment#deactivate_when_done()
autocmd FileType * call doge#on_filetype_change()
augroup END
let &cpoptions = s:save_cpo
unlet s:save_cpo