Skip to content

Commit

Permalink
Read w:mbed_[target|toolchain] from config files
Browse files Browse the repository at this point in the history
By default set theses variables to the values read from ~/.mbed
and eventually overriden by the local .mbed content.

This simplifies the compilation flow when the user opens a buffer in a
project in which the target and toolchain were already set.

Closes #16
  • Loading branch information
n-eq committed Aug 22, 2017
1 parent da90f2b commit 02b3118
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions plugin/mbed.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,32 @@
" is opened. You can close this buffer with <F9>.
"

if !exists( "w:mbed_target" )
function! ReadTargetandToolchainFromConfigFile(file)
if filereadable(a:file)
if match(readfile(a:file), "TARGET")
let w:mbed_target = system("grep 'TARGET' " . a:file . " | cut -f2 -d=")
elseif match(readfile(a:file), "TOOLCHAIN")
let w:mbed_toolchain = system("grep 'TOOLCHAIN' " . a:file . " | cut -f2 -d=")
endif
endif
endfunction

if !exists("w:mbed_target")
let w:mbed_target = ""
endif

if !exists( "w:mbed_toolchain" )
if !exists("w:mbed_toolchain")
let w:mbed_toolchain = ""
endif

" read from ~/.mbed if found
call ReadTargetandToolchainFromConfigFile("~/.mbed")
" eventually override the global configuration with the local .mbed file content
call ReadTargetandToolchainFromConfigFile(".mbed")

" sometimes a line break remains...
let w:mbed_target = substitute(w:mbed_target, '\n', '', 'g')

function! MbedGetTargetandToolchain( force )
call system("which mbed")
if v:shell_error
Expand Down Expand Up @@ -200,7 +218,6 @@ endfunction

function! MbedList()
let @o = system("mbed ls")
" XXX: if @o == "" ??
if !empty(@o)
" no output
new | set buftype = nofile
Expand Down

0 comments on commit 02b3118

Please sign in to comment.