-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from nelqatib/v1.0
First major version * `w:mbed_[target|toolchain]` variables are window-scoped, this enables multiple simultaneous sessions with different targets or toolchains. * Strenghten mbed target/toolchain checks: If the `w:mbed_target` is not read from a configuration file, it is verified that it is supported by the currently used version of **mbed-os**. Similarly, when the `w:mbed_toolchain` variable is read from user input, it is verified to be equal to **ARM**, **IAR**, or **GCC_ARM**. * The open buffer resulting from a `MbedList()` call is a **nofile** type: it can be directly closed with `:q`. * `w:mbed_[target|toolchain]` variables are set by default to values read in **~/.mbed** file and eventually overwritten using the local **.mbed** file. Fixes #12 , fixes #15 , fixes #14 , closes #16
- Loading branch information
Showing
2 changed files
with
80 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
@@ -15,14 +15,25 @@ $ 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 | ||
``` | ||
|
||
## Features | ||
|
||
* Compiling the current application with different options (clean, verbose mode, etc.) and displaying the | ||
output when the compilation is unseccessful. | ||
|
||
* Adding/Removing a library. | ||
|
||
* Setting the application's target/toolchain. | ||
|
||
* Synchronizing the different dependencies. | ||
|
||
* Running tests. | ||
|
||
### Default key mappings | ||
|
||
```vim | ||
|
@@ -37,7 +48,7 @@ $ wget https://raw.githubusercontent.com/nelqatib/mbed-vim/master/plugin/mbed.vi | |
<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. | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
||
|
@@ -109,6 +137,7 @@ function! PasteContentToErrorBuffer() | |
call CleanErrorBuffer() | ||
else | ||
execute "vert belowright sb " . g:error_buffer_number | ||
set buftype=nofile | ||
endif | ||
else | ||
vnew | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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" | ||
|
@@ -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>" |