1
1
" mbed.vim
2
2
" author: marrakchino ([email protected] )
3
- " version: 0.1
3
+ " license: MIT (https://opensource.org/licenses/MIT)
4
+ " version: 0.2
4
5
"
5
6
" This file contains routines that may be used to execute mbed CLI commands
6
7
" from within VIM. It depends on mbed OS. Therefore,
19
20
" <leader>d: Import missing dependencies
20
21
" <leader>a: Prompt for an mbed library to add
21
22
" <leader>r: Prompt for an mbed library to remove
23
+ " <leader>l: Display the dependency tree
22
24
" <F9>: Close the error buffer (when open)
23
- " <F11 >: Set the current application's target and toolchain
25
+ " <F12 >: Set the current application's target and toolchain
24
26
"
25
27
" Add <library_name> -- Add the specified library. When no argument is given,
26
28
" you are prompted for the name of the library
45
47
" is opened. You can close this buffer with <F9>.
46
48
"
47
49
48
-
49
- " TODO: transform MbedAdd* and MbedRemove* functions to take a variable number
50
- " of arguments (libraries to add/remove), see vim varags
51
- " (http://learnvimscriptthehardway.stevelosh.com/chapters/24.html)
52
-
53
-
54
50
" Global variables
55
51
" XXX: variables should be local to the current window or global?
56
52
if ! exists ( " g:mbed_target" )
@@ -153,7 +149,7 @@ endfunction
153
149
function ! MbedCompile (flag)
154
150
call MbedGetTargetandToolchain ( 0 )
155
151
execute ' wa'
156
- let @o = system (" ! mbed compile" . a: flag )
152
+ let @o = system (" mbed compile " . " -m " . g: mbed_target . " -t " . g: mbed_toolchain . " " . a: flag )
157
153
if ! empty (@o )
158
154
" <Image> pattern not found
159
155
if match (getreg (" o" ), " Image" ) == -1
@@ -164,30 +160,34 @@ function! MbedCompile(flag)
164
160
endif
165
161
endfunction
166
162
167
- function ! MbedAddLibary (libraryName )
168
- if a: libraryName == " "
163
+ function ! MbedAdd ( ... )
164
+ if a: 0 == 0
169
165
call PromptForLibraryToAdd ()
170
166
else
171
- execute ' !mbed add ' . a: libraryName
167
+ for library in a: 000
168
+ execute ' !mbed add ' . library
169
+ endfor
172
170
endif
173
171
endfunction
174
172
175
173
function ! PromptForLibraryToAdd ()
176
174
let l: library_name = input (" Please enter the name/URL of the library to add: " )
177
- call MbedAddLibary (l: library_name )
175
+ call MbedAdd (l: library_name )
178
176
endfunction
179
177
180
- function ! MbedRemoveLibary (libraryName )
181
- if a: libraryName == " "
178
+ function ! MbedRemove ( ... )
179
+ if a: 0 == 0
182
180
call PromptForLibraryToRemove ()
183
181
else
184
- execute ' !mbed remove ' . a: libraryName
182
+ for library in a: 000
183
+ execute ' !mbed remove ' . library
184
+ endfor
185
185
endif
186
186
endfunction
187
187
188
188
function ! PromptForLibraryToRemove ()
189
189
let l: library_name = input (" Please enter the name/URL of the library to remove: " )
190
- call MbedRemoveLibary (l: library_name )
190
+ call MbedRemove (l: library_name )
191
191
endfunction
192
192
193
193
function ! MbedList ()
@@ -206,18 +206,14 @@ function! MbedList()
206
206
if l: newheight < winheight (0 )
207
207
execute " resize " . l: newheight
208
208
endif
209
- else
210
- echo " @o is empty.."
211
209
endif
212
210
endfunction
213
211
214
- " TODO
215
212
function ! MbedTest ()
216
213
execute ' wa'
217
- let @t = system (" ! mbed test" )
214
+ let @t = system (" mbed test" )
218
215
if ! empty (@t )
219
- " TODO: find a pattern in the output to notify that the tests were
220
- " successful
216
+ " TODO: find a pattern in the output to notify that the tests were successful
221
217
vnew
222
218
set buftype = nofile
223
219
silent put = @t
@@ -235,13 +231,14 @@ map <leader>n :call MbedNew()<CR>
235
231
map <leader> s :call MbedSync()<CR>
236
232
map <leader> t :call MbedTest()<CR>
237
233
map <leader> d :call MbedDeploy()<CR>
238
- map <leader> a :call MbedAddLibary("")<CR>
239
- map <leader> r :call MbedRemoveLibary("")<CR>
234
+ map <leader> a :call MbedAdd("")<CR>
235
+ map <leader> r :call MbedRemove("")<CR>
236
+ map <leader> l :call MbedList()<CR>
240
237
map <F9> :call CloseErrorBuffer()<CR>
241
- map <F11 > :call MbedGetTargetandToolchain(1)<CR>
238
+ map <F12 > :call MbedGetTargetandToolchain(1)<CR>
242
239
243
240
" commands
244
- command ! -nargs =? Add :call MbedAddLibary (" <args>" )
245
- command ! -nargs =? Remove :call MbedRemoveLibary (" <args>" )
241
+ command ! -nargs =? Add :call MbedAdd (" <args>" )
242
+ command ! -nargs =? Remove :call MbedRemove (" <args>" )
246
243
command ! -nargs =1 SetToolchain :let g: mbed_toolchain= " <args>"
247
244
command ! -nargs =1 SetTarget :let g: mbed_target= " <args>"
0 commit comments