From a59dc01d86914987fd5d95954e136e8617593dea Mon Sep 17 00:00:00 2001 From: marrakchino Date: Fri, 18 Aug 2017 22:23:32 +0200 Subject: [PATCH 01/10] Strenghten target/toolchain checks * Target and toolchain variables are now window-scoped, in fact many windows may be simultaneously be open and there is no reason that they all have the same target/toolchain * Target name is verified by comparing to `mbed target -S` output. This check is weak as it can be produce wrong results (matching "A" is almost always true for example). We need to search for the whole word, not the pattern. * Similarly, toolchain name is checked, it obviously must match ARM, GCC_ARM or IAR. --- plugin/mbed.vim | 68 +++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/plugin/mbed.vim b/plugin/mbed.vim index 26a16cc..baceb53 100644 --- a/plugin/mbed.vim +++ b/plugin/mbed.vim @@ -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 @@ -49,43 +49,55 @@ " Global variables " XXX: variables should be local to the current window or global? -if !exists( "g:mbed_target" ) - let g:mbed_target = "" +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 function! MbedGetTargetandToolchain( force ) let l:mbed_tools_exist = system("which mbed") - if l:mbed_tools_exist == "" + if v:shell_error != 0 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 != 0 || 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 = l:target + 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 != 0 || 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 = l:toolchain endif endfunction @@ -149,7 +161,7 @@ endfunction function! MbedCompile(flag) 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:flag) if !empty(@o) " pattern not found if match(getreg("o"), "Image") == -1 @@ -240,5 +252,5 @@ map :call MbedGetTargetandToolchain(1) " commands command! -nargs=? Add :call MbedAdd("") command! -nargs=? Remove :call MbedRemove("") -command! -nargs=1 SetToolchain :let g:mbed_toolchain="" -command! -nargs=1 SetTarget :let g:mbed_target="" +command! -nargs=1 SetToolchain :let w:mbed_toolchain="" +command! -nargs=1 SetTarget :let w:mbed_target="" From 6052faef7db727c508b28f8c5098927d0e9f5948 Mon Sep 17 00:00:00 2001 From: marrakchino Date: Fri, 18 Aug 2017 22:34:16 +0200 Subject: [PATCH 02/10] Remove no more used l:mbed_tools_exist variable --- plugin/mbed.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugin/mbed.vim b/plugin/mbed.vim index baceb53..4819a65 100644 --- a/plugin/mbed.vim +++ b/plugin/mbed.vim @@ -47,8 +47,6 @@ " is opened. You can close this buffer with . " -" Global variables -" XXX: variables should be local to the current window or global? if !exists( "w:mbed_target" ) let w:mbed_target = "" endif @@ -58,7 +56,7 @@ if !exists( "w:mbed_toolchain" ) endif function! MbedGetTargetandToolchain( force ) - let l:mbed_tools_exist = system("which mbed") + call system("which mbed") if v:shell_error != 0 echoe "Couldn't find mbed CLI tools." return From 8c301948d645acc120e325490913cb6564bc0e00 Mon Sep 17 00:00:00 2001 From: marrakchino Date: Sat, 19 Aug 2017 19:42:20 +0200 Subject: [PATCH 03/10] Update README --- README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d292780..20884a4 100644 --- a/README.md +++ b/README.md @@ -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,7 +15,7 @@ $ git clone git@github.com: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 and saving the plugin file in your `plugin` directory using `wget` ```sh $ wget https://raw.githubusercontent.com/nelqatib/mbed-vim/master/plugin/mbed.vim -O ~/.vim/plugin/mbed.vim @@ -23,6 +23,17 @@ $ wget https://raw.githubusercontent.com/nelqatib/mbed-vim/master/plugin/mbed.vi ## 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 + +* Synchronize the dependencies. + +* Run tests. + ### Default key mappings ```vim @@ -37,7 +48,7 @@ $ wget https://raw.githubusercontent.com/nelqatib/mbed-vim/master/plugin/mbed.vi d: Import missing dependencies. a: Prompt for an mbed library to add. r: Prompt for an mbed library to remove. -l: Display dependency tree +l: Display the dependency tree. : Close the error buffer (when open). : Set the current application's target and toolchain. ``` From b805f7b726a9d86e48dce46973cd8b64599e740f Mon Sep 17 00:00:00 2001 From: marrakchino Date: Sat, 19 Aug 2017 19:44:06 +0200 Subject: [PATCH 04/10] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 20884a4..90e8f10 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,13 @@ $ wget https://raw.githubusercontent.com/nelqatib/mbed-vim/master/plugin/mbed.vi * Compiling the current application with different options (clean, verbose mode, etc.) and displaying the output when the compilation is unseccessful. -* Adding/Removing a library +* Adding/Removing a library. -* Setting the application's target/toolchain +* Setting the application's target/toolchain. -* Synchronize the dependencies. +* Synchronizing the different dependencies. -* Run tests. +* Running tests. ### Default key mappings From 909e1747187646a90996b723cb6bc911f3345a59 Mon Sep 17 00:00:00 2001 From: marrakchino Date: Sat, 19 Aug 2017 19:45:48 +0200 Subject: [PATCH 05/10] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 90e8f10..25c5cc8 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ $ git clone git@github.com:marrakchino/mbed-vim.git $ cp mbed-vim/plugin/mbed.vim ~/.vim/plugin ``` -* By downloading and saving the plugin file in your `plugin` directory using `wget` +* 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 From 50214dffd078831f572b7e7d9bcc27696391e1cd Mon Sep 17 00:00:00 2001 From: marrakchino Date: Sun, 20 Aug 2017 19:02:45 +0200 Subject: [PATCH 06/10] Minor fixes, change version number --- plugin/mbed.vim | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/plugin/mbed.vim b/plugin/mbed.vim index 4819a65..0ba0a76 100644 --- a/plugin/mbed.vim +++ b/plugin/mbed.vim @@ -1,7 +1,7 @@ " mbed.vim " author: marrakchino (nabilelqatib@gmail.com) " 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, @@ -57,7 +57,7 @@ endif function! MbedGetTargetandToolchain( force ) call system("which mbed") - if v:shell_error != 0 + if v:shell_error echoe "Couldn't find mbed CLI tools." return endif @@ -65,7 +65,7 @@ function! MbedGetTargetandToolchain( force ) let l:target_list = system("mbed target -S") " if has("win32") " TODO (one day) let l:target = system('mbed target') - if v:shell_error != 0 || match(l:target, "No") != -1 + 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 @@ -87,7 +87,7 @@ function! MbedGetTargetandToolchain( force ) if w:mbed_toolchain == "" || a:force != 0 " if has("win32") " TODO (one day) let l:toolchain = system('mbed toolchain') - if v:shell_error != 0 || match(l:toolchain, "No") != -1 + 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" @@ -119,6 +119,7 @@ function! PasteContentToErrorBuffer() call CleanErrorBuffer() else execute "vert belowright sb " . g:error_buffer_number + set buftype=nofile endif else vnew @@ -132,11 +133,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 @@ -155,11 +153,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" . w:mbed_target . " -t " . w:mbed_toolchain . " " . a:flag) + let @o = system("mbed compile" . " -m " . w:mbed_target . " -t " . w:mbed_toolchain . " " . a:flags) if !empty(@o) " pattern not found if match(getreg("o"), "Image") == -1 From 587959814fcc8491e2ec589f5c97e13011936f7e Mon Sep 17 00:00:00 2001 From: marrakchino Date: Mon, 21 Aug 2017 20:35:58 +0200 Subject: [PATCH 07/10] Resolve #15 --- plugin/mbed.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/mbed.vim b/plugin/mbed.vim index 0ba0a76..fa1804d 100644 --- a/plugin/mbed.vim +++ b/plugin/mbed.vim @@ -81,7 +81,7 @@ function! MbedGetTargetandToolchain( force ) return endif endif - let w:mbed_target = l:target + let w:mbed_target = substitute(substitute(l:target, '\[[^]]*\] ', '', 'g'), '\n', '', 'g') endif if w:mbed_toolchain == "" || a:force != 0 @@ -95,7 +95,7 @@ function! MbedGetTargetandToolchain( force ) return endif endif - let w:mbed_toolchain = l:toolchain + let w:mbed_toolchain = substitute(substitute(l:target, '\[[^]]*\] ', '', 'g'), '\n', '', 'g') endif endfunction From db22fb92bc594d50694a5b8915b684107c0f7e65 Mon Sep 17 00:00:00 2001 From: marrakchino Date: Mon, 21 Aug 2017 20:38:25 +0200 Subject: [PATCH 08/10] Fix typo --- plugin/mbed.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/mbed.vim b/plugin/mbed.vim index fa1804d..8d74255 100644 --- a/plugin/mbed.vim +++ b/plugin/mbed.vim @@ -95,7 +95,7 @@ function! MbedGetTargetandToolchain( force ) return endif endif - let w:mbed_toolchain = substitute(substitute(l:target, '\[[^]]*\] ', '', 'g'), '\n', '', 'g') + let w:mbed_toolchain = substitute(substitute(l:toolchain, '\[[^]]*\] ', '', 'g'), '\n', '', 'g') endif endfunction From da90f2bcacb5069df2e23c1b9a65007263524464 Mon Sep 17 00:00:00 2001 From: marrakchino Date: Mon, 21 Aug 2017 20:43:08 +0200 Subject: [PATCH 09/10] Resolve #14 --- plugin/mbed.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/mbed.vim b/plugin/mbed.vim index 8d74255..6ad140e 100644 --- a/plugin/mbed.vim +++ b/plugin/mbed.vim @@ -203,7 +203,7 @@ function! MbedList() " XXX: if @o == "" ?? if !empty(@o) " no output - new + new | set buftype = nofile silent put=@o " Delete empty lines execute "g/^$/d" From 02b31182c57ef3d86cb4d46ee3c32cc6c9c67269 Mon Sep 17 00:00:00 2001 From: marrakchino Date: Tue, 22 Aug 2017 20:57:31 +0200 Subject: [PATCH 10/10] Read w:mbed_[target|toolchain] from config files 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 --- plugin/mbed.vim | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/plugin/mbed.vim b/plugin/mbed.vim index 6ad140e..e6676c3 100644 --- a/plugin/mbed.vim +++ b/plugin/mbed.vim @@ -47,14 +47,32 @@ " is opened. You can close this buffer with . " -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 @@ -200,7 +218,6 @@ endfunction function! MbedList() let @o = system("mbed ls") - " XXX: if @o == "" ?? if !empty(@o) " no output new | set buftype = nofile