Skip to content

Commit

Permalink
README: Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
n-eq committed Aug 22, 2017
2 parents 30b4136 + 506a15f commit 1bd239f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 44 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mbed-vim

[![version](https://img.shields.io/badge/version-v0.2-red.svg)](https://github.com/nelqatib/mbed-vim/releases)
[![version](https://img.shields.io/badge/version-v1.0-red.svg)](https://github.com/nelqatib/mbed-vim/releases)
[![Build Status](https://travis-ci.org/nelqatib/mbed-vim.svg?branch=master)](https://travis-ci.org/nelqatib/mbed-vim)
[![license](http://img.shields.io/badge/license-mit-blue.svg)](https://opensource.org/licenses/MIT)

Expand All @@ -15,7 +15,7 @@ $ git clone [email protected]:marrakchino/mbed-vim.git
$ cp mbed-vim/plugin/mbed.vim ~/.vim/plugin
```

* By downloading and saving the plugin file in your `plugin` directory
* By downloading the plugin file to your **plugin** directory using `wget`

```sh
$ wget https://raw.githubusercontent.com/nelqatib/mbed-vim/master/plugin/mbed.vim -O ~/.vim/plugin/mbed.vim
Expand Down Expand Up @@ -48,7 +48,7 @@ output when the compilation is unsuccessful.
<leader>d: Import missing dependencies.
<leader>a: Prompt for an mbed library to add.
<leader>r: Prompt for an mbed library to remove.
<leader>l: Display dependency tree
<leader>l: Display the dependency tree.
<F9>: Close the error buffer (when open).
<F12>: Set the current application's target and toolchain.
```
Expand Down
107 changes: 66 additions & 41 deletions plugin/mbed.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" mbed.vim
" author: marrakchino ([email protected])
" license: MIT (https://opensource.org/licenses/MIT)
" version: 0.2
" version: 1.0
"
" This file contains routines that may be used to execute mbed CLI commands
" from within VIM. It depends on mbed OS. Therefore,
Expand Down Expand Up @@ -34,9 +34,9 @@
" Additionally, you can specify the values of these variables in your vim
" configuration file, to suit this plugin to your needs (in case you always
" use the same mbed target/toolchain):
" g:mbed_target -- The name of your target. mbed CLI doesn't check that your
" w:mbed_target -- The name of your target. mbed CLI doesn't check that your
" target name is correct, so make sure you don't misspell it.
" g:mbed_toolchain -- The name of the used toolchain (ARM, GCC_ARM, IAR).
" w:mbed_toolchain -- The name of the used toolchain (ARM, GCC_ARM, IAR).
"
" Notes:
" When you execute an unsuccessful "compile" command an "error buffer" is open
Expand All @@ -47,45 +47,73 @@
" is opened. You can close this buffer with <F9>.
"

" Global variables
" XXX: variables should be local to the current window or global?
if !exists( "g:mbed_target" )
let g: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( "g:mbed_toolchain" )
let g: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 )
let l:mbed_tools_exist = system("which mbed")
if l:mbed_tools_exist == ""
call system("which mbed")
if v:shell_error
echoe "Couldn't find mbed CLI tools."
else
if g:mbed_target == "" || a:force != 0
" if has("win32") " TODO (one day)
let l:target = system('mbed target')
" no target set
if l:target == ""
let g:mbed_target = input("Please enter your mbed target name: ")
elseif match(l:target, "ERROR") != -1
return
endif
if w:mbed_target == "" || a:force != 0
let l:target_list = system("mbed target -S")
" if has("win32") " TODO (one day)
let l:target = system('mbed target')
if v:shell_error || match(l:target, "No") != -1
echo "There was a problem checking the current target."
let l:target = input("Please enter your mbed target name: ")
" see if we can find the target name in the list of supported targets
" FIXME: pitfall, when a single letter is given for example ("A"), match
" will assume it's OK, need to search for whole word...
if match(l:target_list, l:target) == -1
echo "\rThe target chosen isn't supported, please check
\ the spelling and your current version of mbed-OS then try again."
vnew | set buftype=nofile
let l:target_list = "\nSupported targets:\n\n" . l:target_list
put =l:target_list
normal ggj
return
else
let g:mbed_target = l:target
endif
endif
let w:mbed_target = substitute(substitute(l:target, '\[[^]]*\] ', '', 'g'), '\n', '', 'g')
endif

if g:mbed_toolchain == "" || a:force != 0
" if has("win32") " TODO (one day)
let l:toolchain = system('mbed toolchain')
if l:toolchain == "" " no toolchain set
let g:mbed_toolchain = input("Please choose a toolchain (ARM, GCC_ARM, IAR): ")
elseif match(l:toolchain, "ERROR") != -1
if w:mbed_toolchain == "" || a:force != 0
" if has("win32") " TODO (one day)
let l:toolchain = system('mbed toolchain')
if v:shell_error || match(l:toolchain, "No") != -1
echo "\rThere was a problem checking the current toolchain."
let l:toolchain = input("Please choose a toolchain (ARM, GCC_ARM, IAR): ")
if l:toolchain != "ARM" && l:toolchain != "GCC_ARM" && l:toolchain != "IAR"
echo "\rWrong toolchain, please try again."
return
else
let g:mbed_toolchain = l:toolchain
endif
endif
let w:mbed_toolchain = substitute(substitute(l:toolchain, '\[[^]]*\] ', '', 'g'), '\n', '', 'g')
endif
endfunction

Expand All @@ -109,6 +137,7 @@ function! PasteContentToErrorBuffer()
call CleanErrorBuffer()
else
execute "vert belowright sb " . g:error_buffer_number
set buftype=nofile
endif
else
vnew
Expand All @@ -122,11 +151,8 @@ function! PasteContentToErrorBuffer()
endif

call CleanErrorBuffer()

" paste register content to buffer
silent put=@o
" go to last line
normal G
normal ggddG
endfunction

" Clear the error buffer's content
Expand All @@ -145,11 +171,11 @@ function! CloseErrorBuffer()
endif
endfunction

" Compile the current program with the given flag (-f, -c, -v, -vv)
function! MbedCompile(flag)
call MbedGetTargetandToolchain ( 0 )
" Compile the current program with the given flag(s) (-f, -c, -v, -vv)
function! MbedCompile(flags)
call MbedGetTargetandToolchain(0)
execute 'wa'
let @o = system("mbed compile " . "-m" . g:mbed_target . " -t " . g:mbed_toolchain . " " . a:flag)
let @o = system("mbed compile" . " -m " . w:mbed_target . " -t " . w:mbed_toolchain . " " . a:flags)
if !empty(@o)
" <Image> pattern not found
if match(getreg("o"), "Image") == -1
Expand Down Expand Up @@ -192,10 +218,9 @@ endfunction

function! MbedList()
let @o = system("mbed ls")
" XXX: if @o == "" ??
if !empty(@o)
" no output
new
new | set buftype = nofile
silent put=@o
" Delete empty lines
execute "g/^$/d"
Expand Down Expand Up @@ -240,5 +265,5 @@ map <F12> :call MbedGetTargetandToolchain(1)<CR>
" commands
command! -nargs=? Add :call MbedAdd("<args>")
command! -nargs=? Remove :call MbedRemove("<args>")
command! -nargs=1 SetToolchain :let g:mbed_toolchain="<args>"
command! -nargs=1 SetTarget :let g:mbed_target="<args>"
command! -nargs=1 SetToolchain :let w:mbed_toolchain="<args>"
command! -nargs=1 SetTarget :let w:mbed_target="<args>"

0 comments on commit 1bd239f

Please sign in to comment.