Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug fixes and support for function signatures

 * Bug fix for xolox#lua#dofile(): Unless I'm severely misunderstanding
   Vim I've probably found a bug in the Lua Interface for Vim: When you
   print() a very long line and try to intercept the output with :redir
   commands, the long line is repeated once more after the initial (and
   expected) output. This makes it impossible to send large blobs of
   serialized data from Lua to Vim. The workaround is simple though:
   Simply print() each matching entry individually and join the printed
   lines in Vim script before evaluating the expression.

 * The dynamic completion sometimes wouldn't use omni completion even
   when it was enabled and the best choice. This is now fixed.

 * The new xolox#lua#getsignature() function returns the signatures of
   standard library functions and is used to show signatures in tool
   tips and completion menus.

 * The standard library signatures in autoload/xolox/lua_data.vim were
   generated using a simple Lua script which I'm also committing.
  • Loading branch information...
commit 79a547656edf1803a8f13435cb85814206bf66ff 1 parent 3aafd93
@xolox authored
View
71 autoload/xolox/lua.vim
@@ -250,22 +250,45 @@ function! xolox#lua#completefunc(init, base) " {{{1
endif
let items = []
if xolox#lua#getopt('lua_complete_keywords', 1)
- call extend(items, g:xolox#lua_complete#keywords)
+ call extend(items, g:xolox#lua_data#keywords)
endif
if xolox#lua#getopt('lua_complete_globals', 1)
- call extend(items, g:xolox#lua_complete#globals)
+ call extend(items, g:xolox#lua_data#globals)
endif
if xolox#lua#getopt('lua_complete_library', 1)
- call extend(items, g:xolox#lua_complete#library)
+ call extend(items, g:xolox#lua_data#library)
endif
let pattern = xolox#misc#escape#pattern(a:base)
- return filter(items, 'v:val.word =~ pattern')
+ call filter(items, 'v:val.word =~ pattern')
+ return s:addsignatures(items)
endfunction
function! s:get_completion_prefix()
return match(strpart(getline('.'), 0, col('.') - 2), '\w\+\.\?\w*$')
endfunction
+function! s:addsignatures(entries)
+ for entry in a:entries
+ let signature = xolox#lua#getsignature(entry.word)
+ if !empty(signature)
+ let entry.menu = signature
+ endif
+ endfor
+ return a:entries
+endfunction
+
+function! xolox#lua#getsignature(identifier) " {{{1
+ let identifier = substitute(a:identifier, '()$', '', '')
+ let signature = get(g:xolox#lua_data#signatures, identifier, '')
+ if empty(signature)
+ let signature = get(g:xolox#lua_data#signatures, 'string.' . identifier, '')
+ endif
+ if empty(signature)
+ let signature = get(g:xolox#lua_data#signatures, 'file:' . identifier, '')
+ endif
+ return signature
+endfunction
+
function! xolox#lua#omnifunc(init, base) " {{{1
if a:init
return s:get_completion_prefix()
@@ -277,6 +300,7 @@ function! xolox#lua#omnifunc(init, base) " {{{1
endif
if !exists('s:omnifunc_variables')
let s:omnifunc_variables = xolox#lua#getomnivariables(s:omnifunc_modules)
+ call s:addsignatures(s:omnifunc_variables)
endif
" FIXME When you type "require'" without a space in between
" the getline('.') call below returns an empty string?!
@@ -287,7 +311,7 @@ function! xolox#lua#omnifunc(init, base) " {{{1
return s:omnifunc_variables
else
let pattern = xolox#misc#escape#pattern(a:base)
- return filter(copy(s:omnifunc_variables), 'v:val =~ pattern')
+ return filter(copy(s:omnifunc_variables), 'v:val.word =~ pattern')
endif
endfunction
@@ -346,8 +370,7 @@ endfunction
function! xolox#lua#getomnivariables(modules) " {{{1
let starttime = xolox#misc#timer#start()
let output = xolox#lua#dofile(s:omnicomplete_script, a:modules)
- let variables = split(output, "\n")
- call sort(variables, 1)
+ let variables = eval('[' . substitute(output, '\_s\+', ',', 'g') . ']')
let msg = "%s: Collected %i variables for omni completion in %s"
call xolox#misc#timer#stop(msg, s:script, len(variables), starttime)
return variables
@@ -369,7 +392,11 @@ function! xolox#lua#completedynamic(type) " {{{1
" are available, which is kind of annoying. But I don't know of an
" alternative to :silent that can be used inside of <expr>
" mappings?!
- return a:type . "\<C-x>\<C-u>"
+ if xolox#lua#getopt('lua_complete_omni', 0)
+ return a:type . "\<C-x>\<C-o>"
+ else
+ return a:type . "\<C-x>\<C-u>"
+ endif
endif
endif
endif
@@ -377,29 +404,21 @@ function! xolox#lua#completedynamic(type) " {{{1
endfunction
function! xolox#lua#dofile(pathname, arguments) " {{{1
- " First try to use the Lua Interface for Vim.
- try
- call xolox#misc#msg#debug("%s: Trying Lua Interface for Vim ..", s:script)
+ if has('lua')
+ " Use the Lua Interface for Vim.
redir => output
lua arg = vim.eval('a:arguments')
execute 'silent luafile' fnameescape(a:pathname)
redir END
- if !empty(output)
- return output
- endif
- catch
- redir END
- call xolox#misc#msg#warn("%s: %s (at %s)", s:script, v:exception, v:throwpoint)
- endtry
- " Fall back to the command line Lua interpreter.
- call xolox#misc#msg#debug("Falling back to external Lua interpreter ..")
- let output = system(join(['lua', a:pathname] + a:arguments))
- if v:shell_error
- let msg = "%s: Failed to retrieve omni completion candidates (output: '%s')"
- call xolox#misc#msg#warn(msg, s:script, output)
- return ''
else
- return output
+ " Use the command line Lua interpreter.
+ let output = xolox#misc#str#trim(system(join(['lua', a:pathname] + a:arguments)))
+ if v:shell_error
+ let msg = "%s: Failed to retrieve omni completion candidates (output: '%s')"
+ call xolox#misc#msg#warn(msg, s:script, output)
+ endif
+ endif
+ return xolox#misc#str#trim(output)
endfunction
" vim: ts=2 sw=2 et
View
194 autoload/xolox/lua_complete.vim
@@ -1,194 +0,0 @@
-" Vim auto-load script
-" Author: Peter Odding <peter@peterodding.com>
-" Last Change: June 14, 2011
-" URL: http://peterodding.com/code/vim/lua-ftplugin
-
-" This script contains static user completion data.
-
-" Enable line continuation.
-let s:cpo_save = &cpo
-set cpoptions-=C
-
-let g:xolox#lua_complete#keywords = [
- \ { 'word': "and", 'kind': 'k' },
- \ { 'word': "break", 'kind': 'k' },
- \ { 'word': "do", 'kind': 'k' },
- \ { 'word': "else", 'kind': 'k' },
- \ { 'word': "elseif", 'kind': 'k' },
- \ { 'word': "end", 'kind': 'k' },
- \ { 'word': "false", 'kind': 'k' },
- \ { 'word': "for", 'kind': 'k' },
- \ { 'word': "function", 'kind': 'k' },
- \ { 'word': "if", 'kind': 'k' },
- \ { 'word': "in", 'kind': 'k' },
- \ { 'word': "local", 'kind': 'k' },
- \ { 'word': "nil", 'kind': 'k' },
- \ { 'word': "not", 'kind': 'k' },
- \ { 'word': "or", 'kind': 'k' },
- \ { 'word': "repeat", 'kind': 'k' },
- \ { 'word': "return", 'kind': 'k' },
- \ { 'word': "then", 'kind': 'k' },
- \ { 'word': "true", 'kind': 'k' },
- \ { 'word': "until", 'kind': 'k' },
- \ { 'word': "while", 'kind': 'k' }]
-
-let g:xolox#lua_complete#globals = [
- \ { 'word': "_G", 'kind': 'v' },
- \ { 'word': "_VERSION", 'kind': 'v' },
- \ { 'word': "arg", 'kind': 'v' },
- \ { 'word': "assert()", 'kind': 'f' },
- \ { 'word': "collectgarbage()", 'kind': 'f' },
- \ { 'word': "coroutine", 'kind': 'v' },
- \ { 'word': "debug", 'kind': 'v' },
- \ { 'word': "dofile()", 'kind': 'f' },
- \ { 'word': "error()", 'kind': 'f' },
- \ { 'word': "gcinfo()", 'kind': 'f' },
- \ { 'word': "getfenv()", 'kind': 'f' },
- \ { 'word': "getmetatable()", 'kind': 'f' },
- \ { 'word': "io", 'kind': 'v' },
- \ { 'word': "ipairs()", 'kind': 'f' },
- \ { 'word': "load()", 'kind': 'f' },
- \ { 'word': "loadfile()", 'kind': 'f' },
- \ { 'word': "loadstring()", 'kind': 'f' },
- \ { 'word': "math", 'kind': 'v' },
- \ { 'word': "module()", 'kind': 'f' },
- \ { 'word': "newproxy()", 'kind': 'f' },
- \ { 'word': "next()", 'kind': 'f' },
- \ { 'word': "os", 'kind': 'v' },
- \ { 'word': "package", 'kind': 'v' },
- \ { 'word': "pairs()", 'kind': 'f' },
- \ { 'word': "pcall()", 'kind': 'f' },
- \ { 'word': "prettyprint()", 'kind': 'f' },
- \ { 'word': "print()", 'kind': 'f' },
- \ { 'word': "rawequal()", 'kind': 'f' },
- \ { 'word': "rawget()", 'kind': 'f' },
- \ { 'word': "rawset()", 'kind': 'f' },
- \ { 'word': "require()", 'kind': 'f' },
- \ { 'word': "select()", 'kind': 'f' },
- \ { 'word': "setfenv()", 'kind': 'f' },
- \ { 'word': "setmetatable()", 'kind': 'f' },
- \ { 'word': "string", 'kind': 'v' },
- \ { 'word': "table", 'kind': 'v' },
- \ { 'word': "tonumber()", 'kind': 'f' },
- \ { 'word': "tostring()", 'kind': 'f' },
- \ { 'word': "type()", 'kind': 'f' },
- \ { 'word': "unpack()", 'kind': 'f' },
- \ { 'word': "xpcall()", 'kind': 'f' }]
-
-let g:xolox#lua_complete#library = [
- \ { 'word': "coroutine.create()", 'kind': 'f' },
- \ { 'word': "coroutine.resume()", 'kind': 'f' },
- \ { 'word': "coroutine.running()", 'kind': 'f' },
- \ { 'word': "coroutine.status()", 'kind': 'f' },
- \ { 'word': "coroutine.wrap()", 'kind': 'f' },
- \ { 'word': "coroutine.yield()", 'kind': 'f' },
- \ { 'word': "debug.debug()", 'kind': 'f' },
- \ { 'word': "debug.getfenv()", 'kind': 'f' },
- \ { 'word': "debug.gethook()", 'kind': 'f' },
- \ { 'word': "debug.getinfo()", 'kind': 'f' },
- \ { 'word': "debug.getlocal()", 'kind': 'f' },
- \ { 'word': "debug.getmetatable()", 'kind': 'f' },
- \ { 'word': "debug.getregistry()", 'kind': 'f' },
- \ { 'word': "debug.getupvalue()", 'kind': 'f' },
- \ { 'word': "debug.setfenv()", 'kind': 'f' },
- \ { 'word': "debug.sethook()", 'kind': 'f' },
- \ { 'word': "debug.setlocal()", 'kind': 'f' },
- \ { 'word': "debug.setmetatable()", 'kind': 'f' },
- \ { 'word': "debug.setupvalue()", 'kind': 'f' },
- \ { 'word': "debug.traceback()", 'kind': 'f' },
- \ { 'word': "io.close()", 'kind': 'f' },
- \ { 'word': "io.flush()", 'kind': 'f' },
- \ { 'word': "io.input()", 'kind': 'f' },
- \ { 'word': "io.lines()", 'kind': 'f' },
- \ { 'word': "io.open()", 'kind': 'f' },
- \ { 'word': "io.output()", 'kind': 'f' },
- \ { 'word': "io.popen()", 'kind': 'f' },
- \ { 'word': "io.read()", 'kind': 'f' },
- \ { 'word': "io.size()", 'kind': 'f' },
- \ { 'word': "io.stderr", 'kind': 'm' },
- \ { 'word': "io.stdin", 'kind': 'm' },
- \ { 'word': "io.stdout", 'kind': 'm' },
- \ { 'word': "io.tmpfile()", 'kind': 'f' },
- \ { 'word': "io.type()", 'kind': 'f' },
- \ { 'word': "io.write()", 'kind': 'f' },
- \ { 'word': "math.abs()", 'kind': 'f' },
- \ { 'word': "math.acos()", 'kind': 'f' },
- \ { 'word': "math.asin()", 'kind': 'f' },
- \ { 'word': "math.atan()", 'kind': 'f' },
- \ { 'word': "math.atan2()", 'kind': 'f' },
- \ { 'word': "math.ceil()", 'kind': 'f' },
- \ { 'word': "math.cos()", 'kind': 'f' },
- \ { 'word': "math.cosh()", 'kind': 'f' },
- \ { 'word': "math.deg()", 'kind': 'f' },
- \ { 'word': "math.exp()", 'kind': 'f' },
- \ { 'word': "math.floor()", 'kind': 'f' },
- \ { 'word': "math.fmod()", 'kind': 'f' },
- \ { 'word': "math.frexp()", 'kind': 'f' },
- \ { 'word': "math.huge", 'kind': 'm' },
- \ { 'word': "math.ldexp()", 'kind': 'f' },
- \ { 'word': "math.log()", 'kind': 'f' },
- \ { 'word': "math.log10()", 'kind': 'f' },
- \ { 'word': "math.max()", 'kind': 'f' },
- \ { 'word': "math.min()", 'kind': 'f' },
- \ { 'word': "math.mod()", 'kind': 'f' },
- \ { 'word': "math.modf()", 'kind': 'f' },
- \ { 'word': "math.pi", 'kind': 'm' },
- \ { 'word': "math.pow()", 'kind': 'f' },
- \ { 'word': "math.rad()", 'kind': 'f' },
- \ { 'word': "math.random()", 'kind': 'f' },
- \ { 'word': "math.randomseed()", 'kind': 'f' },
- \ { 'word': "math.sin()", 'kind': 'f' },
- \ { 'word': "math.sinh()", 'kind': 'f' },
- \ { 'word': "math.sqrt()", 'kind': 'f' },
- \ { 'word': "math.tan()", 'kind': 'f' },
- \ { 'word': "math.tanh()", 'kind': 'f' },
- \ { 'word': "os.clock()", 'kind': 'f' },
- \ { 'word': "os.date()", 'kind': 'f' },
- \ { 'word': "os.difftime()", 'kind': 'f' },
- \ { 'word': "os.execute()", 'kind': 'f' },
- \ { 'word': "os.exit()", 'kind': 'f' },
- \ { 'word': "os.getenv()", 'kind': 'f' },
- \ { 'word': "os.remove()", 'kind': 'f' },
- \ { 'word': "os.rename()", 'kind': 'f' },
- \ { 'word': "os.setlocale()", 'kind': 'f' },
- \ { 'word': "os.time()", 'kind': 'f' },
- \ { 'word': "os.tmpname()", 'kind': 'f' },
- \ { 'word': "package.config", 'kind': 'm' },
- \ { 'word': "package.cpath", 'kind': 'm' },
- \ { 'word': "package.loaded", 'kind': 'm' },
- \ { 'word': "package.loaders", 'kind': 'm' },
- \ { 'word': "package.loadlib()", 'kind': 'f' },
- \ { 'word': "package.path", 'kind': 'm' },
- \ { 'word': "package.preload", 'kind': 'm' },
- \ { 'word': "package.seeall()", 'kind': 'f' },
- \ { 'word': "string.byte()", 'kind': 'f' },
- \ { 'word': "string.char()", 'kind': 'f' },
- \ { 'word': "string.dump()", 'kind': 'f' },
- \ { 'word': "string.find()", 'kind': 'f' },
- \ { 'word': "string.format()", 'kind': 'f' },
- \ { 'word': "string.gfind()", 'kind': 'f' },
- \ { 'word': "string.gmatch()", 'kind': 'f' },
- \ { 'word': "string.gsplit()", 'kind': 'f' },
- \ { 'word': "string.gsub()", 'kind': 'f' },
- \ { 'word': "string.len()", 'kind': 'f' },
- \ { 'word': "string.lower()", 'kind': 'f' },
- \ { 'word': "string.match()", 'kind': 'f' },
- \ { 'word': "string.rep()", 'kind': 'f' },
- \ { 'word': "string.reverse()", 'kind': 'f' },
- \ { 'word': "string.sub()", 'kind': 'f' },
- \ { 'word': "string.upper()", 'kind': 'f' },
- \ { 'word': "table.concat()", 'kind': 'f' },
- \ { 'word': "table.foreach()", 'kind': 'f' },
- \ { 'word': "table.foreachi()", 'kind': 'f' },
- \ { 'word': "table.getn()", 'kind': 'f' },
- \ { 'word': "table.insert()", 'kind': 'f' },
- \ { 'word': "table.maxn()", 'kind': 'f' },
- \ { 'word': "table.remove()", 'kind': 'f' },
- \ { 'word': "table.setn()", 'kind': 'f' },
- \ { 'word': "table.sort()", 'kind': 'f' }]
-
-" Restore compatibility options.
-let &cpo = s:cpo_save
-unlet s:cpo_save
-
-" vim: ts=2 sw=2 et
View
329 autoload/xolox/lua_data.vim
@@ -0,0 +1,329 @@
+" Vim auto-load script
+" Author: Peter Odding <peter@peterodding.com>
+" Last Change: June 14, 2011
+" URL: http://peterodding.com/code/vim/lua-ftplugin
+
+" This script contains static user completion data based
+" on the Lua 5.1 reference manual and implementation.
+
+" Enable line continuation.
+let s:cpo_save = &cpo
+set cpoptions-=C
+
+" Keywords. {{{1
+let g:xolox#lua_data#keywords = [
+ \ { 'word': 'and', 'kind': 'k' },
+ \ { 'word': 'break', 'kind': 'k' },
+ \ { 'word': 'do', 'kind': 'k' },
+ \ { 'word': 'else', 'kind': 'k' },
+ \ { 'word': 'elseif', 'kind': 'k' },
+ \ { 'word': 'end', 'kind': 'k' },
+ \ { 'word': 'false', 'kind': 'k' },
+ \ { 'word': 'for', 'kind': 'k' },
+ \ { 'word': 'function', 'kind': 'k' },
+ \ { 'word': 'if', 'kind': 'k' },
+ \ { 'word': 'in', 'kind': 'k' },
+ \ { 'word': 'local', 'kind': 'k' },
+ \ { 'word': 'nil', 'kind': 'k' },
+ \ { 'word': 'not', 'kind': 'k' },
+ \ { 'word': 'or', 'kind': 'k' },
+ \ { 'word': 'repeat', 'kind': 'k' },
+ \ { 'word': 'return', 'kind': 'k' },
+ \ { 'word': 'then', 'kind': 'k' },
+ \ { 'word': 'true', 'kind': 'k' },
+ \ { 'word': 'until', 'kind': 'k' },
+ \ { 'word': 'while', 'kind': 'k' } ]
+
+" Global variables. {{{1
+let g:xolox#lua_data#globals = [
+ \ { 'word': '_G', 'kind': 'v' },
+ \ { 'word': '_VERSION', 'kind': 'v' },
+ \ { 'word': 'arg', 'kind': 'v' },
+ \ { 'word': 'assert()', 'kind': 'f' },
+ \ { 'word': 'collectgarbage()', 'kind': 'f' },
+ \ { 'word': 'coroutine', 'kind': 'v' },
+ \ { 'word': 'debug', 'kind': 'v' },
+ \ { 'word': 'dofile()', 'kind': 'f' },
+ \ { 'word': 'error()', 'kind': 'f' },
+ \ { 'word': 'gcinfo()', 'kind': 'f' },
+ \ { 'word': 'getfenv()', 'kind': 'f' },
+ \ { 'word': 'getmetatable()', 'kind': 'f' },
+ \ { 'word': 'io', 'kind': 'v' },
+ \ { 'word': 'ipairs()', 'kind': 'f' },
+ \ { 'word': 'load()', 'kind': 'f' },
+ \ { 'word': 'loadfile()', 'kind': 'f' },
+ \ { 'word': 'loadstring()', 'kind': 'f' },
+ \ { 'word': 'math', 'kind': 'v' },
+ \ { 'word': 'module()', 'kind': 'f' },
+ \ { 'word': 'newproxy()', 'kind': 'f' },
+ \ { 'word': 'next()', 'kind': 'f' },
+ \ { 'word': 'os', 'kind': 'v' },
+ \ { 'word': 'package', 'kind': 'v' },
+ \ { 'word': 'pairs()', 'kind': 'f' },
+ \ { 'word': 'pcall()', 'kind': 'f' },
+ \ { 'word': 'prettyprint()', 'kind': 'f' },
+ \ { 'word': 'print()', 'kind': 'f' },
+ \ { 'word': 'rawequal()', 'kind': 'f' },
+ \ { 'word': 'rawget()', 'kind': 'f' },
+ \ { 'word': 'rawset()', 'kind': 'f' },
+ \ { 'word': 'require()', 'kind': 'f' },
+ \ { 'word': 'select()', 'kind': 'f' },
+ \ { 'word': 'setfenv()', 'kind': 'f' },
+ \ { 'word': 'setmetatable()', 'kind': 'f' },
+ \ { 'word': 'string', 'kind': 'v' },
+ \ { 'word': 'table', 'kind': 'v' },
+ \ { 'word': 'tonumber()', 'kind': 'f' },
+ \ { 'word': 'tostring()', 'kind': 'f' },
+ \ { 'word': 'type()', 'kind': 'f' },
+ \ { 'word': 'unpack()', 'kind': 'f' },
+ \ { 'word': 'xpcall()', 'kind': 'f' } ]
+
+" Standard library identifiers. {{{1
+let g:xolox#lua_data#library = [
+ \ { 'word': 'coroutine.create()', 'kind': 'f' },
+ \ { 'word': 'coroutine.resume()', 'kind': 'f' },
+ \ { 'word': 'coroutine.running()', 'kind': 'f' },
+ \ { 'word': 'coroutine.status()', 'kind': 'f' },
+ \ { 'word': 'coroutine.wrap()', 'kind': 'f' },
+ \ { 'word': 'coroutine.yield()', 'kind': 'f' },
+ \ { 'word': 'debug.debug()', 'kind': 'f' },
+ \ { 'word': 'debug.getfenv()', 'kind': 'f' },
+ \ { 'word': 'debug.gethook()', 'kind': 'f' },
+ \ { 'word': 'debug.getinfo()', 'kind': 'f' },
+ \ { 'word': 'debug.getlocal()', 'kind': 'f' },
+ \ { 'word': 'debug.getmetatable()', 'kind': 'f' },
+ \ { 'word': 'debug.getregistry()', 'kind': 'f' },
+ \ { 'word': 'debug.getupvalue()', 'kind': 'f' },
+ \ { 'word': 'debug.setfenv()', 'kind': 'f' },
+ \ { 'word': 'debug.sethook()', 'kind': 'f' },
+ \ { 'word': 'debug.setlocal()', 'kind': 'f' },
+ \ { 'word': 'debug.setmetatable()', 'kind': 'f' },
+ \ { 'word': 'debug.setupvalue()', 'kind': 'f' },
+ \ { 'word': 'debug.traceback()', 'kind': 'f' },
+ \ { 'word': 'io.close()', 'kind': 'f' },
+ \ { 'word': 'io.flush()', 'kind': 'f' },
+ \ { 'word': 'io.input()', 'kind': 'f' },
+ \ { 'word': 'io.lines()', 'kind': 'f' },
+ \ { 'word': 'io.open()', 'kind': 'f' },
+ \ { 'word': 'io.output()', 'kind': 'f' },
+ \ { 'word': 'io.popen()', 'kind': 'f' },
+ \ { 'word': 'io.read()', 'kind': 'f' },
+ \ { 'word': 'io.size()', 'kind': 'f' },
+ \ { 'word': 'io.stderr', 'kind': 'm' },
+ \ { 'word': 'io.stdin', 'kind': 'm' },
+ \ { 'word': 'io.stdout', 'kind': 'm' },
+ \ { 'word': 'io.tmpfile()', 'kind': 'f' },
+ \ { 'word': 'io.type()', 'kind': 'f' },
+ \ { 'word': 'io.write()', 'kind': 'f' },
+ \ { 'word': 'math.abs()', 'kind': 'f' },
+ \ { 'word': 'math.acos()', 'kind': 'f' },
+ \ { 'word': 'math.asin()', 'kind': 'f' },
+ \ { 'word': 'math.atan()', 'kind': 'f' },
+ \ { 'word': 'math.atan2()', 'kind': 'f' },
+ \ { 'word': 'math.ceil()', 'kind': 'f' },
+ \ { 'word': 'math.cos()', 'kind': 'f' },
+ \ { 'word': 'math.cosh()', 'kind': 'f' },
+ \ { 'word': 'math.deg()', 'kind': 'f' },
+ \ { 'word': 'math.exp()', 'kind': 'f' },
+ \ { 'word': 'math.floor()', 'kind': 'f' },
+ \ { 'word': 'math.fmod()', 'kind': 'f' },
+ \ { 'word': 'math.frexp()', 'kind': 'f' },
+ \ { 'word': 'math.huge', 'kind': 'm' },
+ \ { 'word': 'math.ldexp()', 'kind': 'f' },
+ \ { 'word': 'math.log()', 'kind': 'f' },
+ \ { 'word': 'math.log10()', 'kind': 'f' },
+ \ { 'word': 'math.max()', 'kind': 'f' },
+ \ { 'word': 'math.min()', 'kind': 'f' },
+ \ { 'word': 'math.mod()', 'kind': 'f' },
+ \ { 'word': 'math.modf()', 'kind': 'f' },
+ \ { 'word': 'math.pi', 'kind': 'm' },
+ \ { 'word': 'math.pow()', 'kind': 'f' },
+ \ { 'word': 'math.rad()', 'kind': 'f' },
+ \ { 'word': 'math.random()', 'kind': 'f' },
+ \ { 'word': 'math.randomseed()', 'kind': 'f' },
+ \ { 'word': 'math.sin()', 'kind': 'f' },
+ \ { 'word': 'math.sinh()', 'kind': 'f' },
+ \ { 'word': 'math.sqrt()', 'kind': 'f' },
+ \ { 'word': 'math.tan()', 'kind': 'f' },
+ \ { 'word': 'math.tanh()', 'kind': 'f' },
+ \ { 'word': 'os.clock()', 'kind': 'f' },
+ \ { 'word': 'os.date()', 'kind': 'f' },
+ \ { 'word': 'os.difftime()', 'kind': 'f' },
+ \ { 'word': 'os.execute()', 'kind': 'f' },
+ \ { 'word': 'os.exit()', 'kind': 'f' },
+ \ { 'word': 'os.getenv()', 'kind': 'f' },
+ \ { 'word': 'os.remove()', 'kind': 'f' },
+ \ { 'word': 'os.rename()', 'kind': 'f' },
+ \ { 'word': 'os.setlocale()', 'kind': 'f' },
+ \ { 'word': 'os.time()', 'kind': 'f' },
+ \ { 'word': 'os.tmpname()', 'kind': 'f' },
+ \ { 'word': 'package.config', 'kind': 'm' },
+ \ { 'word': 'package.cpath', 'kind': 'm' },
+ \ { 'word': 'package.loaded', 'kind': 'm' },
+ \ { 'word': 'package.loaders', 'kind': 'm' },
+ \ { 'word': 'package.loadlib()', 'kind': 'f' },
+ \ { 'word': 'package.path', 'kind': 'm' },
+ \ { 'word': 'package.preload', 'kind': 'm' },
+ \ { 'word': 'package.seeall()', 'kind': 'f' },
+ \ { 'word': 'string.byte()', 'kind': 'f' },
+ \ { 'word': 'string.char()', 'kind': 'f' },
+ \ { 'word': 'string.dump()', 'kind': 'f' },
+ \ { 'word': 'string.find()', 'kind': 'f' },
+ \ { 'word': 'string.format()', 'kind': 'f' },
+ \ { 'word': 'string.gfind()', 'kind': 'f' },
+ \ { 'word': 'string.gmatch()', 'kind': 'f' },
+ \ { 'word': 'string.gsplit()', 'kind': 'f' },
+ \ { 'word': 'string.gsub()', 'kind': 'f' },
+ \ { 'word': 'string.len()', 'kind': 'f' },
+ \ { 'word': 'string.lower()', 'kind': 'f' },
+ \ { 'word': 'string.match()', 'kind': 'f' },
+ \ { 'word': 'string.rep()', 'kind': 'f' },
+ \ { 'word': 'string.reverse()', 'kind': 'f' },
+ \ { 'word': 'string.sub()', 'kind': 'f' },
+ \ { 'word': 'string.upper()', 'kind': 'f' },
+ \ { 'word': 'table.concat()', 'kind': 'f' },
+ \ { 'word': 'table.foreach()', 'kind': 'f' },
+ \ { 'word': 'table.foreachi()', 'kind': 'f' },
+ \ { 'word': 'table.getn()', 'kind': 'f' },
+ \ { 'word': 'table.insert()', 'kind': 'f' },
+ \ { 'word': 'table.maxn()', 'kind': 'f' },
+ \ { 'word': 'table.remove()', 'kind': 'f' },
+ \ { 'word': 'table.setn()', 'kind': 'f' },
+ \ { 'word': 'table.sort()', 'kind': 'f' } ]
+
+" Function signatures. {{{1
+
+let g:xolox#lua_data#signatures = {
+ \ 'assert': 'assert(v [, message])',
+ \ 'collectgarbage': 'collectgarbage(opt [, arg])',
+ \ 'dofile': 'dofile(filename)',
+ \ 'error': 'error(message [, level])',
+ \ 'getfenv': 'getfenv([f])',
+ \ 'getmetatable': 'getmetatable(object)',
+ \ 'ipairs': 'ipairs(t)',
+ \ 'load': 'load(func [, chunkname])',
+ \ 'loadfile': 'loadfile([filename])',
+ \ 'loadstring': 'loadstring(string [, chunkname])',
+ \ 'next': 'next(table [, index])',
+ \ 'pairs': 'pairs(t)',
+ \ 'pcall': 'pcall(f, arg1, ...)',
+ \ 'print': 'print(...)',
+ \ 'rawequal': 'rawequal(v1, v2)',
+ \ 'rawget': 'rawget(table, index)',
+ \ 'rawset': 'rawset(table, index, value)',
+ \ 'select': 'select(index, ...)',
+ \ 'setfenv': 'setfenv(f, table)',
+ \ 'setmetatable': 'setmetatable(table, metatable)',
+ \ 'tonumber': 'tonumber(e [, base])',
+ \ 'tostring': 'tostring(e)',
+ \ 'type': 'type(v)',
+ \ 'unpack': 'unpack(list [, i [, j]])',
+ \ 'xpcall': 'xpcall(f, err)',
+ \ 'coroutine.create': 'coroutine.create(f)',
+ \ 'coroutine.resume': 'coroutine.resume(co [, val1, ...])',
+ \ 'coroutine.running': 'coroutine.running()',
+ \ 'coroutine.status': 'coroutine.status(co)',
+ \ 'coroutine.wrap': 'coroutine.wrap(f)',
+ \ 'coroutine.yield': 'coroutine.yield(...)',
+ \ 'module': 'module(name [, ...])',
+ \ 'require': 'require(modname)',
+ \ 'package.loadlib': 'package.loadlib(libname, funcname)',
+ \ 'package.seeall': 'package.seeall(module)',
+ \ 'string.byte': 'string.byte(s [, i [, j]])',
+ \ 'string.char': 'string.char(...)',
+ \ 'string.dump': 'string.dump(function)',
+ \ 'string.find': 'string.find(s, pattern [, init [, plain]])',
+ \ 'string.format': 'string.format(formatstring, ...)',
+ \ 'string.gmatch': 'string.gmatch(s, pattern)',
+ \ 'string.gsub': 'string.gsub(s, pattern, repl [, n])',
+ \ 'string.len': 'string.len(s)',
+ \ 'string.lower': 'string.lower(s)',
+ \ 'string.match': 'string.match(s, pattern [, init])',
+ \ 'string.rep': 'string.rep(s, n)',
+ \ 'string.reverse': 'string.reverse(s)',
+ \ 'string.sub': 'string.sub(s, i [, j])',
+ \ 'string.upper': 'string.upper(s)',
+ \ 'table.concat': 'table.concat(table [, sep [, i [, j]]])',
+ \ 'table.insert': 'table.insert(table, [pos,] value)',
+ \ 'table.maxn': 'table.maxn(table)',
+ \ 'table.remove': 'table.remove(table [, pos])',
+ \ 'table.sort': 'table.sort(table [, comp])',
+ \ 'math.abs': 'math.abs(x)',
+ \ 'math.acos': 'math.acos(x)',
+ \ 'math.asin': 'math.asin(x)',
+ \ 'math.atan': 'math.atan(x)',
+ \ 'math.atan2': 'math.atan2(y, x)',
+ \ 'math.ceil': 'math.ceil(x)',
+ \ 'math.cos': 'math.cos(x)',
+ \ 'math.cosh': 'math.cosh(x)',
+ \ 'math.deg': 'math.deg(x)',
+ \ 'math.exp': 'math.exp(x)',
+ \ 'math.floor': 'math.floor(x)',
+ \ 'math.fmod': 'math.fmod(x, y)',
+ \ 'math.frexp': 'math.frexp(x)',
+ \ 'math.ldexp': 'math.ldexp(m, e)',
+ \ 'math.log': 'math.log(x)',
+ \ 'math.log10': 'math.log10(x)',
+ \ 'math.max': 'math.max(x, ...)',
+ \ 'math.min': 'math.min(x, ...)',
+ \ 'math.modf': 'math.modf(x)',
+ \ 'math.pow': 'math.pow(x, y)',
+ \ 'math.rad': 'math.rad(x)',
+ \ 'math.random': 'math.random([m [, n]])',
+ \ 'math.randomseed': 'math.randomseed(x)',
+ \ 'math.sin': 'math.sin(x)',
+ \ 'math.sinh': 'math.sinh(x)',
+ \ 'math.sqrt': 'math.sqrt(x)',
+ \ 'math.tan': 'math.tan(x)',
+ \ 'math.tanh': 'math.tanh(x)',
+ \ 'io.close': 'io.close([file])',
+ \ 'io.flush': 'io.flush()',
+ \ 'io.input': 'io.input([file])',
+ \ 'io.lines': 'io.lines([filename])',
+ \ 'io.open': 'io.open(filename [, mode])',
+ \ 'io.output': 'io.output([file])',
+ \ 'io.popen': 'io.popen(prog [, mode])',
+ \ 'io.read': 'io.read(...)',
+ \ 'io.tmpfile': 'io.tmpfile()',
+ \ 'io.type': 'io.type(obj)',
+ \ 'io.write': 'io.write(...)',
+ \ 'file:close': 'file:close()',
+ \ 'file:flush': 'file:flush()',
+ \ 'file:lines': 'file:lines()',
+ \ 'file:read': 'file:read(...)',
+ \ 'file:seek': 'file:seek([whence] [, offset])',
+ \ 'file:setvbuf': 'file:setvbuf(mode [, size])',
+ \ 'file:write': 'file:write(...)',
+ \ 'os.clock': 'os.clock()',
+ \ 'os.date': 'os.date([format [, time]])',
+ \ 'os.difftime': 'os.difftime(t2, t1)',
+ \ 'os.execute': 'os.execute([command])',
+ \ 'os.exit': 'os.exit([code])',
+ \ 'os.getenv': 'os.getenv(varname)',
+ \ 'os.remove': 'os.remove(filename)',
+ \ 'os.rename': 'os.rename(oldname, newname)',
+ \ 'os.setlocale': 'os.setlocale(locale [, category])',
+ \ 'os.time': 'os.time([table])',
+ \ 'os.tmpname': 'os.tmpname()',
+ \ 'debug.debug': 'debug.debug()',
+ \ 'debug.getfenv': 'debug.getfenv(o)',
+ \ 'debug.gethook': 'debug.gethook([thread])',
+ \ 'debug.getinfo': 'debug.getinfo([thread,] function [, what])',
+ \ 'debug.getlocal': 'debug.getlocal([thread,] level, local)',
+ \ 'debug.getmetatable': 'debug.getmetatable(object)',
+ \ 'debug.getregistry': 'debug.getregistry()',
+ \ 'debug.getupvalue': 'debug.getupvalue(func, up)',
+ \ 'debug.setfenv': 'debug.setfenv(object, table)',
+ \ 'debug.sethook': 'debug.sethook([thread,] hook, mask [, count])',
+ \ 'debug.setlocal': 'debug.setlocal([thread,] level, local, value)',
+ \ 'debug.setmetatable': 'debug.setmetatable(object, table)',
+ \ 'debug.setupvalue': 'debug.setupvalue(func, up, value)',
+ \ 'debug.traceback': 'debug.traceback([thread,] [message] [, level])' }
+
+" }}}
+
+" Restore compatibility options.
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
+" vim: ts=2 sw=2 et
View
8 ftplugin/lua.vim
@@ -3,7 +3,7 @@
" Author: Peter Odding <peter@peterodding.com>
" Last Change: June 14, 2011
" URL: http://peterodding.com/code/vim/lua-ftplugin
-" Version: 0.6.3
+" Version: 0.6.4
" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3625 1 :AutoInstall: lua.zip
@@ -82,6 +82,12 @@ call add(s:undo_ftplugin, "iunmap <buffer> '")
inoremap <buffer> <silent> <expr> " xolox#lua#completedynamic('"')
call add(s:undo_ftplugin, 'iunmap <buffer> "')
+" Enable tool tips with function signatures? {{{1
+if has('balloon_eval')
+ setlocal ballooneval balloonexpr=xolox#lua#getsignature(v:beval_text)
+ call add(s:undo_ftplugin, 'setlocal ballooneval< balloonexpr<')
+endif
+
" }}}1
" Let Vim know how to disable the plug-in.
View
14 misc/lua-ftplugin/getsignatures.lua
@@ -0,0 +1,14 @@
+#!/usr/bin/env lua
+
+local http = require 'socket.http'
+local webpage = http.request 'http://www.lua.org/manual/5.1/manual.html'
+local matches = {}
+for anchor, signature in webpage:gmatch '<h3>%s*<a%s+name="pdf%-(.-)">%s*<code>%s*(.-)%s*</code>%s*</a>%s*</h3>' do
+ if anchor ~= signature then
+ signature = signature:gsub('&middot;', '.')
+ signature = signature:gsub('%s+%(', '(')
+ table.insert(matches, string.format("'%s': '%s'", anchor, signature))
+ end
+end
+local newline = '\n \\ '
+print(string.format('let g:xolox#lua_data#signatures = {%s%s }', newline, table.concat(matches, ',' .. newline)))
View
21 misc/lua-ftplugin/omnicomplete.lua
@@ -25,7 +25,11 @@ local function isident(s)
return type(s) == 'string' and s:find('^[A-Za-z_][A-Za-z_0-9]*$') and not keywords[s]
end
-local function dump(table, path, cache)
+local function addmatch(output, word, kind, desc)
+ print(string.format("{'word':'%s','kind':'%s','menu':'%s'}", word, kind, desc))
+end
+
+local function dump(table, path, cache, output)
local printed = false
for key, value in pairs(table) do
if isident(key) then
@@ -33,17 +37,17 @@ local function dump(table, path, cache)
local vtype = type(value)
if vtype == 'function' then
printed = true
- print(path .. "()")
+ addmatch(output, path, 'f', path .. '()')
elseif vtype ~= 'table' then
printed = true
- print(path)
+ addmatch(output, path, 'v', path)
else
if vtype == 'table' and not cache[value] then
cache[value] = true
- if dump(value, path, cache) then
+ if dump(value, path, cache, output) then
printed = true
else
- print(path .. "[]")
+ addmatch(output, path, 'm', path .. '[]')
end
end
end
@@ -59,7 +63,6 @@ for _, modulename in ipairs(arg) do
end
-- Generate completion candidates from global state.
-local cache = {}
-cache[_G] = true
-cache[package.loaded] = true
-dump(_G, nil, cache)
+local cache = { [_G] = true, [package.loaded] = true }
+local output = {}
+dump(_G, nil, cache, output)
Please sign in to comment.
Something went wrong with that request. Please try again.