make menu - an example for the "confirm" function

2 Points

marco marco

8 years ago

This function shows a menu and runs make with the selected target. Selecting nothing just runs make.

My personal make targets which I have in every makefile are

bld to build, tst to run the tests, cln to clean, rel to copy/install the software, tag to run ctags, and so on …

Adapt the names to your make targets. (twice, in list and in confirm function) Replace <yourkeys> by your desired key sequence to call the function.

Of course I could have given the same keystroke sequences as mappings to every make target, but this way I have a menu which appears and this technique can be used for many other things. So this post is more about showing what can be done with the "confirm" function.

Note! make sure your CWD is correct.

function! MakeMenu()
   let l:myMakeTargets = ["quit", "", "tag", "cln", "bld", "tst", "rel", "all", "doc"]
   let l:c=0
   let l:c = confirm("Make Menu","&make\nta&g\n&cln\n&bld\n&tst\n&rel\n&all\n&doc")
   if l:c != 0
         exe "make " . l:myMakeTargets[l:c]

nnoremap <yourkeys> :call MakeMenu()<CR>