Skip to content

Instantly share code, notes, and snippets.

@marcotrosi
Created July 6, 2015 07:21
Show Gist options
  • Save marcotrosi/c41b08945a162642c6ee to your computer and use it in GitHub Desktop.
Save marcotrosi/c41b08945a162642c6ee to your computer and use it in GitHub Desktop.
Vim/Lua - exporting balloon info as Lua data and running external script to create the balloon text
set balloonexpr=Balloon()
let g:BalloonScript="<scriptname>"
set ballooneval
function! Balloon()
let balloondata = ['return', '{']
call add(balloondata, " ['cwd'] = [[" . getcwd() . "]],")
call add(balloondata, " ['fileabspath'] = [[" . expand('%:p') . "]],")
call add(balloondata, " ['filerelpath'] = [[" . expand('%:.') . "]],")
call add(balloondata, " ['fileabsdir'] = [[" . expand('%:p:h') . "]],")
call add(balloondata, " ['filereldir'] = [[" . expand('%:.:h') . "]],")
call add(balloondata, " ['file'] = [[" . expand('%:t') . "]],")
call add(balloondata, " ['filename'] = [[" . expand('%:t:r') . "]],")
call add(balloondata, " ['fileext'] = [[" . expand('%:e') . "]],")
call add(balloondata, " ['line'] = [[" . v:beval_lnum . "]],")
call add(balloondata, " ['column'] = [[" . v:beval_col . "]],")
call add(balloondata, " ['text'] = [[" . v:beval_text . "]],")
call add(balloondata, "}")
call writefile(balloondata, "/path/to/.vimballooninfo")
call system(g:BalloonScript)
return join(readfile("/path/to/.vimballoontext"), "\n")
endfunction
" to load the data into a Lua script run
" t = dofile("/path/to/.vimballooninfo")
" the Lua script shall write the balloon text into the file "/path/to/.vimballoontext".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment