Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Peter Odding authored June 14, 2011
71  autoload/xolox/lua.vim
@@ -250,22 +250,45 @@ function! xolox#lua#completefunc(init, base) " {{{1
250 250
   endif
251 251
   let items = []
252 252
   if xolox#lua#getopt('lua_complete_keywords', 1)
253  
-    call extend(items, g:xolox#lua_complete#keywords)
  253
+    call extend(items, g:xolox#lua_data#keywords)
254 254
   endif
255 255
   if xolox#lua#getopt('lua_complete_globals', 1)
256  
-    call extend(items, g:xolox#lua_complete#globals)
  256
+    call extend(items, g:xolox#lua_data#globals)
257 257
   endif
258 258
   if xolox#lua#getopt('lua_complete_library', 1)
259  
-    call extend(items, g:xolox#lua_complete#library)
  259
+    call extend(items, g:xolox#lua_data#library)
260 260
   endif
261 261
   let pattern = xolox#misc#escape#pattern(a:base)
262  
-  return filter(items, 'v:val.word =~ pattern')
  262
+  call filter(items, 'v:val.word =~ pattern')
  263
+  return s:addsignatures(items)
263 264
 endfunction
264 265
 
265 266
 function! s:get_completion_prefix()
266 267
   return match(strpart(getline('.'), 0, col('.') - 2), '\w\+\.\?\w*$')
267 268
 endfunction
268 269
 
  270
+function! s:addsignatures(entries)
  271
+  for entry in a:entries
  272
+    let signature = xolox#lua#getsignature(entry.word)
  273
+    if !empty(signature)
  274
+      let entry.menu = signature
  275
+    endif
  276
+  endfor
  277
+  return a:entries
  278
+endfunction
  279
+
  280
+function! xolox#lua#getsignature(identifier) " {{{1
  281
+  let identifier = substitute(a:identifier, '()$', '', '')
  282
+  let signature = get(g:xolox#lua_data#signatures, identifier, '')
  283
+  if empty(signature)
  284
+    let signature = get(g:xolox#lua_data#signatures, 'string.' . identifier, '')
  285
+  endif
  286
+  if empty(signature)
  287
+    let signature = get(g:xolox#lua_data#signatures, 'file:' . identifier, '')
  288
+  endif
  289
+  return signature
  290
+endfunction
  291
+
269 292
 function! xolox#lua#omnifunc(init, base) " {{{1
270 293
   if a:init
271 294
     return s:get_completion_prefix()
@@ -277,6 +300,7 @@ function! xolox#lua#omnifunc(init, base) " {{{1
277 300
   endif
278 301
   if !exists('s:omnifunc_variables')
279 302
     let s:omnifunc_variables = xolox#lua#getomnivariables(s:omnifunc_modules)
  303
+    call s:addsignatures(s:omnifunc_variables)
280 304
   endif
281 305
   " FIXME When you type "require'" without a space in between
282 306
   " the getline('.') call below returns an empty string?!
@@ -287,7 +311,7 @@ function! xolox#lua#omnifunc(init, base) " {{{1
287 311
     return s:omnifunc_variables
288 312
   else
289 313
     let pattern = xolox#misc#escape#pattern(a:base)
290  
-    return filter(copy(s:omnifunc_variables), 'v:val =~ pattern')
  314
+    return filter(copy(s:omnifunc_variables), 'v:val.word =~ pattern')
291 315
   endif
292 316
 endfunction
293 317
 
@@ -346,8 +370,7 @@ endfunction
346 370
 function! xolox#lua#getomnivariables(modules) " {{{1
347 371
   let starttime = xolox#misc#timer#start()
348 372
   let output = xolox#lua#dofile(s:omnicomplete_script, a:modules)
349  
-  let variables = split(output, "\n")
350  
-  call sort(variables, 1)
  373
+  let variables = eval('[' . substitute(output, '\_s\+', ',', 'g') . ']')
351 374
   let msg = "%s: Collected %i variables for omni completion in %s"
352 375
   call xolox#misc#timer#stop(msg, s:script, len(variables), starttime)
353 376
   return variables
@@ -369,7 +392,11 @@ function! xolox#lua#completedynamic(type) " {{{1
369 392
         " are available, which is kind of annoying. But I don't know of an
370 393
         " alternative to :silent that can be used inside of <expr>
371 394
         " mappings?!
372  
-        return a:type . "\<C-x>\<C-u>"
  395
+        if xolox#lua#getopt('lua_complete_omni', 0)
  396
+          return a:type . "\<C-x>\<C-o>"
  397
+        else
  398
+          return a:type . "\<C-x>\<C-u>"
  399
+        endif
373 400
       endif
374 401
     endif
375 402
   endif
@@ -377,29 +404,21 @@ function! xolox#lua#completedynamic(type) " {{{1
377 404
 endfunction
378 405
 
379 406
 function! xolox#lua#dofile(pathname, arguments) " {{{1
380  
-  " First try to use the Lua Interface for Vim.
381  
-  try
382  
-    call xolox#misc#msg#debug("%s: Trying Lua Interface for Vim ..", s:script)
  407
+  if has('lua')
  408
+    " Use the Lua Interface for Vim.
383 409
     redir => output
384 410
     lua arg = vim.eval('a:arguments')
385 411
     execute 'silent luafile' fnameescape(a:pathname)
386 412
     redir END
387  
-    if !empty(output)
388  
-      return output
389  
-    endif
390  
-  catch
391  
-    redir END
392  
-    call xolox#misc#msg#warn("%s: %s (at %s)", s:script, v:exception, v:throwpoint)
393  
-  endtry
394  
-  " Fall back to the command line Lua interpreter.
395  
-  call xolox#misc#msg#debug("Falling back to external Lua interpreter ..")
396  
-  let output = system(join(['lua', a:pathname] + a:arguments))
397  
-  if v:shell_error
398  
-    let msg = "%s: Failed to retrieve omni completion candidates (output: '%s')"
399  
-    call xolox#misc#msg#warn(msg, s:script, output)
400  
-    return ''
401 413
   else
402  
-  return output
  414
+    " Use the command line Lua interpreter.
  415
+    let output = xolox#misc#str#trim(system(join(['lua', a:pathname] + a:arguments)))
  416
+    if v:shell_error
  417
+      let msg = "%s: Failed to retrieve omni completion candidates (output: '%s')"
  418
+      call xolox#misc#msg#warn(msg, s:script, output)
  419
+    endif
  420
+  endif
  421
+  return xolox#misc#str#trim(output)
403 422
 endfunction
404 423
 
405 424
 " vim: ts=2 sw=2 et
194  autoload/xolox/lua_complete.vim
... ...
@@ -1,194 +0,0 @@
1  
-" Vim auto-load script
2  
-" Author: Peter Odding <peter@peterodding.com>
3  
-" Last Change: June 14, 2011
4  
-" URL: http://peterodding.com/code/vim/lua-ftplugin
5  
-
6  
-" This script contains static user completion data.
7  
-
8  
-" Enable line continuation.
9  
-let s:cpo_save = &cpo
10  
-set cpoptions-=C
11  
-
12  
-let g:xolox#lua_complete#keywords = [
13  
-      \ { 'word': "and", 'kind': 'k' },
14  
-      \ { 'word': "break", 'kind': 'k' },
15  
-      \ { 'word': "do", 'kind': 'k' },
16  
-      \ { 'word': "else", 'kind': 'k' },
17  
-      \ { 'word': "elseif", 'kind': 'k' },
18  
-      \ { 'word': "end", 'kind': 'k' },
19  
-      \ { 'word': "false", 'kind': 'k' },
20  
-      \ { 'word': "for", 'kind': 'k' },
21  
-      \ { 'word': "function", 'kind': 'k' },
22  
-      \ { 'word': "if", 'kind': 'k' },
23  
-      \ { 'word': "in", 'kind': 'k' },
24  
-      \ { 'word': "local", 'kind': 'k' },
25  
-      \ { 'word': "nil", 'kind': 'k' },
26  
-      \ { 'word': "not", 'kind': 'k' },
27  
-      \ { 'word': "or", 'kind': 'k' },
28  
-      \ { 'word': "repeat", 'kind': 'k' },
29  
-      \ { 'word': "return", 'kind': 'k' },
30  
-      \ { 'word': "then", 'kind': 'k' },
31  
-      \ { 'word': "true", 'kind': 'k' },
32  
-      \ { 'word': "until", 'kind': 'k' },
33  
-      \ { 'word': "while", 'kind': 'k' }]
34  
-
35  
-let g:xolox#lua_complete#globals = [
36  
-      \ { 'word': "_G", 'kind': 'v' },
37  
-      \ { 'word': "_VERSION", 'kind': 'v' },
38  
-      \ { 'word': "arg", 'kind': 'v' },
39  
-      \ { 'word': "assert()", 'kind': 'f' },
40  
-      \ { 'word': "collectgarbage()", 'kind': 'f' },
41  
-      \ { 'word': "coroutine", 'kind': 'v' },
42  
-      \ { 'word': "debug", 'kind': 'v' },
43  
-      \ { 'word': "dofile()", 'kind': 'f' },
44  
-      \ { 'word': "error()", 'kind': 'f' },
45  
-      \ { 'word': "gcinfo()", 'kind': 'f' },
46  
-      \ { 'word': "getfenv()", 'kind': 'f' },
47  
-      \ { 'word': "getmetatable()", 'kind': 'f' },
48  
-      \ { 'word': "io", 'kind': 'v' },
49  
-      \ { 'word': "ipairs()", 'kind': 'f' },
50  
-      \ { 'word': "load()", 'kind': 'f' },
51  
-      \ { 'word': "loadfile()", 'kind': 'f' },
52  
-      \ { 'word': "loadstring()", 'kind': 'f' },
53  
-      \ { 'word': "math", 'kind': 'v' },
54  
-      \ { 'word': "module()", 'kind': 'f' },
55  
-      \ { 'word': "newproxy()", 'kind': 'f' },
56  
-      \ { 'word': "next()", 'kind': 'f' },
57  
-      \ { 'word': "os", 'kind': 'v' },
58  
-      \ { 'word': "package", 'kind': 'v' },
59  
-      \ { 'word': "pairs()", 'kind': 'f' },
60  
-      \ { 'word': "pcall()", 'kind': 'f' },
61  
-      \ { 'word': "prettyprint()", 'kind': 'f' },
62  
-      \ { 'word': "print()", 'kind': 'f' },
63  
-      \ { 'word': "rawequal()", 'kind': 'f' },
64  
-      \ { 'word': "rawget()", 'kind': 'f' },
65  
-      \ { 'word': "rawset()", 'kind': 'f' },
66  
-      \ { 'word': "require()", 'kind': 'f' },
67  
-      \ { 'word': "select()", 'kind': 'f' },
68  
-      \ { 'word': "setfenv()", 'kind': 'f' },
69  
-      \ { 'word': "setmetatable()", 'kind': 'f' },
70  
-      \ { 'word': "string", 'kind': 'v' },
71  
-      \ { 'word': "table", 'kind': 'v' },
72  
-      \ { 'word': "tonumber()", 'kind': 'f' },
73  
-      \ { 'word': "tostring()", 'kind': 'f' },
74  
-      \ { 'word': "type()", 'kind': 'f' },
75  
-      \ { 'word': "unpack()", 'kind': 'f' },
76  
-      \ { 'word': "xpcall()", 'kind': 'f' }]
77  
-
78  
-let g:xolox#lua_complete#library = [
79  
-      \ { 'word': "coroutine.create()", 'kind': 'f' },
80  
-      \ { 'word': "coroutine.resume()", 'kind': 'f' },
81  
-      \ { 'word': "coroutine.running()", 'kind': 'f' },
82  
-      \ { 'word': "coroutine.status()", 'kind': 'f' },
83  
-      \ { 'word': "coroutine.wrap()", 'kind': 'f' },
84  
-      \ { 'word': "coroutine.yield()", 'kind': 'f' },
85  
-      \ { 'word': "debug.debug()", 'kind': 'f' },
86  
-      \ { 'word': "debug.getfenv()", 'kind': 'f' },
87  
-      \ { 'word': "debug.gethook()", 'kind': 'f' },
88  
-      \ { 'word': "debug.getinfo()", 'kind': 'f' },
89  
-      \ { 'word': "debug.getlocal()", 'kind': 'f' },
90  
-      \ { 'word': "debug.getmetatable()", 'kind': 'f' },
91  
-      \ { 'word': "debug.getregistry()", 'kind': 'f' },
92  
-      \ { 'word': "debug.getupvalue()", 'kind': 'f' },
93  
-      \ { 'word': "debug.setfenv()", 'kind': 'f' },
94  
-      \ { 'word': "debug.sethook()", 'kind': 'f' },
95  
-      \ { 'word': "debug.setlocal()", 'kind': 'f' },
96  
-      \ { 'word': "debug.setmetatable()", 'kind': 'f' },
97  
-      \ { 'word': "debug.setupvalue()", 'kind': 'f' },
98  
-      \ { 'word': "debug.traceback()", 'kind': 'f' },
99  
-      \ { 'word': "io.close()", 'kind': 'f' },
100  
-      \ { 'word': "io.flush()", 'kind': 'f' },
101  
-      \ { 'word': "io.input()", 'kind': 'f' },
102  
-      \ { 'word': "io.lines()", 'kind': 'f' },
103  
-      \ { 'word': "io.open()", 'kind': 'f' },
104  
-      \ { 'word': "io.output()", 'kind': 'f' },
105  
-      \ { 'word': "io.popen()", 'kind': 'f' },
106  
-      \ { 'word': "io.read()", 'kind': 'f' },
107  
-      \ { 'word': "io.size()", 'kind': 'f' },
108  
-      \ { 'word': "io.stderr", 'kind': 'm' },
109  
-      \ { 'word': "io.stdin", 'kind': 'm' },
110  
-      \ { 'word': "io.stdout", 'kind': 'm' },
111  
-      \ { 'word': "io.tmpfile()", 'kind': 'f' },
112  
-      \ { 'word': "io.type()", 'kind': 'f' },
113  
-      \ { 'word': "io.write()", 'kind': 'f' },
114  
-      \ { 'word': "math.abs()", 'kind': 'f' },
115  
-      \ { 'word': "math.acos()", 'kind': 'f' },
116  
-      \ { 'word': "math.asin()", 'kind': 'f' },
117  
-      \ { 'word': "math.atan()", 'kind': 'f' },
118  
-      \ { 'word': "math.atan2()", 'kind': 'f' },
119  
-      \ { 'word': "math.ceil()", 'kind': 'f' },
120  
-      \ { 'word': "math.cos()", 'kind': 'f' },
121  
-      \ { 'word': "math.cosh()", 'kind': 'f' },
122  
-      \ { 'word': "math.deg()", 'kind': 'f' },
123  
-      \ { 'word': "math.exp()", 'kind': 'f' },
124  
-      \ { 'word': "math.floor()", 'kind': 'f' },
125  
-      \ { 'word': "math.fmod()", 'kind': 'f' },
126  
-      \ { 'word': "math.frexp()", 'kind': 'f' },
127  
-      \ { 'word': "math.huge", 'kind': 'm' },
128  
-      \ { 'word': "math.ldexp()", 'kind': 'f' },
129  
-      \ { 'word': "math.log()", 'kind': 'f' },
130  
-      \ { 'word': "math.log10()", 'kind': 'f' },
131  
-      \ { 'word': "math.max()", 'kind': 'f' },
132  
-      \ { 'word': "math.min()", 'kind': 'f' },
133  
-      \ { 'word': "math.mod()", 'kind': 'f' },
134  
-      \ { 'word': "math.modf()", 'kind': 'f' },
135  
-      \ { 'word': "math.pi", 'kind': 'm' },
136  
-      \ { 'word': "math.pow()", 'kind': 'f' },
137  
-      \ { 'word': "math.rad()", 'kind': 'f' },
138  
-      \ { 'word': "math.random()", 'kind': 'f' },
139  
-      \ { 'word': "math.randomseed()", 'kind': 'f' },
140  
-      \ { 'word': "math.sin()", 'kind': 'f' },
141  
-      \ { 'word': "math.sinh()", 'kind': 'f' },
142  
-      \ { 'word': "math.sqrt()", 'kind': 'f' },
143  
-      \ { 'word': "math.tan()", 'kind': 'f' },
144  
-      \ { 'word': "math.tanh()", 'kind': 'f' },
145  
-      \ { 'word': "os.clock()", 'kind': 'f' },
146  
-      \ { 'word': "os.date()", 'kind': 'f' },
147  
-      \ { 'word': "os.difftime()", 'kind': 'f' },
148  
-      \ { 'word': "os.execute()", 'kind': 'f' },
149  
-      \ { 'word': "os.exit()", 'kind': 'f' },
150  
-      \ { 'word': "os.getenv()", 'kind': 'f' },
151  
-      \ { 'word': "os.remove()", 'kind': 'f' },
152  
-      \ { 'word': "os.rename()", 'kind': 'f' },
153  
-      \ { 'word': "os.setlocale()", 'kind': 'f' },
154  
-      \ { 'word': "os.time()", 'kind': 'f' },
155  
-      \ { 'word': "os.tmpname()", 'kind': 'f' },
156  
-      \ { 'word': "package.config", 'kind': 'm' },
157  
-      \ { 'word': "package.cpath", 'kind': 'm' },
158  
-      \ { 'word': "package.loaded", 'kind': 'm' },
159  
-      \ { 'word': "package.loaders", 'kind': 'm' },
160  
-      \ { 'word': "package.loadlib()", 'kind': 'f' },
161  
-      \ { 'word': "package.path", 'kind': 'm' },
162  
-      \ { 'word': "package.preload", 'kind': 'm' },
163  
-      \ { 'word': "package.seeall()", 'kind': 'f' },
164  
-      \ { 'word': "string.byte()", 'kind': 'f' },
165  
-      \ { 'word': "string.char()", 'kind': 'f' },
166  
-      \ { 'word': "string.dump()", 'kind': 'f' },
167  
-      \ { 'word': "string.find()", 'kind': 'f' },
168  
-      \ { 'word': "string.format()", 'kind': 'f' },
169  
-      \ { 'word': "string.gfind()", 'kind': 'f' },
170  
-      \ { 'word': "string.gmatch()", 'kind': 'f' },
171  
-      \ { 'word': "string.gsplit()", 'kind': 'f' },
172  
-      \ { 'word': "string.gsub()", 'kind': 'f' },
173  
-      \ { 'word': "string.len()", 'kind': 'f' },
174  
-      \ { 'word': "string.lower()", 'kind': 'f' },
175  
-      \ { 'word': "string.match()", 'kind': 'f' },
176  
-      \ { 'word': "string.rep()", 'kind': 'f' },
177  
-      \ { 'word': "string.reverse()", 'kind': 'f' },
178  
-      \ { 'word': "string.sub()", 'kind': 'f' },
179  
-      \ { 'word': "string.upper()", 'kind': 'f' },
180  
-      \ { 'word': "table.concat()", 'kind': 'f' },
181  
-      \ { 'word': "table.foreach()", 'kind': 'f' },
182  
-      \ { 'word': "table.foreachi()", 'kind': 'f' },
183  
-      \ { 'word': "table.getn()", 'kind': 'f' },
184  
-      \ { 'word': "table.insert()", 'kind': 'f' },
185  
-      \ { 'word': "table.maxn()", 'kind': 'f' },
186  
-      \ { 'word': "table.remove()", 'kind': 'f' },
187  
-      \ { 'word': "table.setn()", 'kind': 'f' },
188  
-      \ { 'word': "table.sort()", 'kind': 'f' }]
189  
-
190  
-" Restore compatibility options.
191  
-let &cpo = s:cpo_save
192  
-unlet s:cpo_save
193  
-
194  
-" vim: ts=2 sw=2 et
329  autoload/xolox/lua_data.vim
... ...
@@ -0,0 +1,329 @@
  1
+" Vim auto-load script
  2
+" Author: Peter Odding <peter@peterodding.com>
  3
+" Last Change: June 14, 2011
  4
+" URL: http://peterodding.com/code/vim/lua-ftplugin
  5
+
  6
+" This script contains static user completion data based
  7
+" on the Lua 5.1 reference manual and implementation.
  8
+
  9
+" Enable line continuation.
  10
+let s:cpo_save = &cpo
  11
+set cpoptions-=C
  12
+
  13
+" Keywords. {{{1
  14
+let g:xolox#lua_data#keywords = [
  15
+      \ { 'word': 'and', 'kind': 'k' },
  16
+      \ { 'word': 'break', 'kind': 'k' },
  17
+      \ { 'word': 'do', 'kind': 'k' },
  18
+      \ { 'word': 'else', 'kind': 'k' },
  19
+      \ { 'word': 'elseif', 'kind': 'k' },
  20
+      \ { 'word': 'end', 'kind': 'k' },
  21
+      \ { 'word': 'false', 'kind': 'k' },
  22
+      \ { 'word': 'for', 'kind': 'k' },
  23
+      \ { 'word': 'function', 'kind': 'k' },
  24
+      \ { 'word': 'if', 'kind': 'k' },
  25
+      \ { 'word': 'in', 'kind': 'k' },
  26
+      \ { 'word': 'local', 'kind': 'k' },
  27
+      \ { 'word': 'nil', 'kind': 'k' },
  28
+      \ { 'word': 'not', 'kind': 'k' },
  29
+      \ { 'word': 'or', 'kind': 'k' },
  30
+      \ { 'word': 'repeat', 'kind': 'k' },
  31
+      \ { 'word': 'return', 'kind': 'k' },
  32
+      \ { 'word': 'then', 'kind': 'k' },
  33
+      \ { 'word': 'true', 'kind': 'k' },
  34
+      \ { 'word': 'until', 'kind': 'k' },
  35
+      \ { 'word': 'while', 'kind': 'k' } ]
  36
+
  37
+" Global variables. {{{1
  38
+let g:xolox#lua_data#globals = [
  39
+      \ { 'word': '_G', 'kind': 'v' },
  40
+      \ { 'word': '_VERSION', 'kind': 'v' },
  41
+      \ { 'word': 'arg', 'kind': 'v' },
  42
+      \ { 'word': 'assert()', 'kind': 'f' },
  43
+      \ { 'word': 'collectgarbage()', 'kind': 'f' },
  44
+      \ { 'word': 'coroutine', 'kind': 'v' },
  45
+      \ { 'word': 'debug', 'kind': 'v' },
  46
+      \ { 'word': 'dofile()', 'kind': 'f' },
  47
+      \ { 'word': 'error()', 'kind': 'f' },
  48
+      \ { 'word': 'gcinfo()', 'kind': 'f' },
  49
+      \ { 'word': 'getfenv()', 'kind': 'f' },
  50
+      \ { 'word': 'getmetatable()', 'kind': 'f' },
  51
+      \ { 'word': 'io', 'kind': 'v' },
  52
+      \ { 'word': 'ipairs()', 'kind': 'f' },
  53
+      \ { 'word': 'load()', 'kind': 'f' },
  54
+      \ { 'word': 'loadfile()', 'kind': 'f' },
  55
+      \ { 'word': 'loadstring()', 'kind': 'f' },
  56
+      \ { 'word': 'math', 'kind': 'v' },
  57
+      \ { 'word': 'module()', 'kind': 'f' },
  58
+      \ { 'word': 'newproxy()', 'kind': 'f' },
  59
+      \ { 'word': 'next()', 'kind': 'f' },
  60
+      \ { 'word': 'os', 'kind': 'v' },
  61
+      \ { 'word': 'package', 'kind': 'v' },
  62
+      \ { 'word': 'pairs()', 'kind': 'f' },
  63
+      \ { 'word': 'pcall()', 'kind': 'f' },
  64
+      \ { 'word': 'prettyprint()', 'kind': 'f' },
  65
+      \ { 'word': 'print()', 'kind': 'f' },
  66
+      \ { 'word': 'rawequal()', 'kind': 'f' },
  67
+      \ { 'word': 'rawget()', 'kind': 'f' },
  68
+      \ { 'word': 'rawset()', 'kind': 'f' },
  69
+      \ { 'word': 'require()', 'kind': 'f' },
  70
+      \ { 'word': 'select()', 'kind': 'f' },
  71
+      \ { 'word': 'setfenv()', 'kind': 'f' },
  72
+      \ { 'word': 'setmetatable()', 'kind': 'f' },
  73
+      \ { 'word': 'string', 'kind': 'v' },
  74
+      \ { 'word': 'table', 'kind': 'v' },
  75
+      \ { 'word': 'tonumber()', 'kind': 'f' },
  76
+      \ { 'word': 'tostring()', 'kind': 'f' },
  77
+      \ { 'word': 'type()', 'kind': 'f' },
  78
+      \ { 'word': 'unpack()', 'kind': 'f' },
  79
+      \ { 'word': 'xpcall()', 'kind': 'f' } ]
  80
+
  81
+" Standard library identifiers. {{{1
  82
+let g:xolox#lua_data#library = [
  83
+      \ { 'word': 'coroutine.create()', 'kind': 'f' },
  84
+      \ { 'word': 'coroutine.resume()', 'kind': 'f' },
  85
+      \ { 'word': 'coroutine.running()', 'kind': 'f' },
  86
+      \ { 'word': 'coroutine.status()', 'kind': 'f' },
  87
+      \ { 'word': 'coroutine.wrap()', 'kind': 'f' },
  88
+      \ { 'word': 'coroutine.yield()', 'kind': 'f' },
  89
+      \ { 'word': 'debug.debug()', 'kind': 'f' },
  90
+      \ { 'word': 'debug.getfenv()', 'kind': 'f' },
  91
+      \ { 'word': 'debug.gethook()', 'kind': 'f' },
  92
+      \ { 'word': 'debug.getinfo()', 'kind': 'f' },
  93
+      \ { 'word': 'debug.getlocal()', 'kind': 'f' },
  94
+      \ { 'word': 'debug.getmetatable()', 'kind': 'f' },
  95
+      \ { 'word': 'debug.getregistry()', 'kind': 'f' },
  96
+      \ { 'word': 'debug.getupvalue()', 'kind': 'f' },
  97
+      \ { 'word': 'debug.setfenv()', 'kind': 'f' },
  98
+      \ { 'word': 'debug.sethook()', 'kind': 'f' },
  99
+      \ { 'word': 'debug.setlocal()', 'kind': 'f' },
  100
+      \ { 'word': 'debug.setmetatable()', 'kind': 'f' },
  101
+      \ { 'word': 'debug.setupvalue()', 'kind': 'f' },
  102
+      \ { 'word': 'debug.traceback()', 'kind': 'f' },
  103
+      \ { 'word': 'io.close()', 'kind': 'f' },
  104
+      \ { 'word': 'io.flush()', 'kind': 'f' },
  105
+      \ { 'word': 'io.input()', 'kind': 'f' },
  106
+      \ { 'word': 'io.lines()', 'kind': 'f' },
  107
+      \ { 'word': 'io.open()', 'kind': 'f' },
  108
+      \ { 'word': 'io.output()', 'kind': 'f' },
  109
+      \ { 'word': 'io.popen()', 'kind': 'f' },
  110
+      \ { 'word': 'io.read()', 'kind': 'f' },
  111
+      \ { 'word': 'io.size()', 'kind': 'f' },
  112
+      \ { 'word': 'io.stderr', 'kind': 'm' },
  113
+      \ { 'word': 'io.stdin', 'kind': 'm' },
  114
+      \ { 'word': 'io.stdout', 'kind': 'm' },
  115
+      \ { 'word': 'io.tmpfile()', 'kind': 'f' },
  116
+      \ { 'word': 'io.type()', 'kind': 'f' },
  117
+      \ { 'word': 'io.write()', 'kind': 'f' },
  118
+      \ { 'word': 'math.abs()', 'kind': 'f' },
  119
+      \ { 'word': 'math.acos()', 'kind': 'f' },
  120
+      \ { 'word': 'math.asin()', 'kind': 'f' },
  121
+      \ { 'word': 'math.atan()', 'kind': 'f' },
  122
+      \ { 'word': 'math.atan2()', 'kind': 'f' },
  123
+      \ { 'word': 'math.ceil()', 'kind': 'f' },
  124
+      \ { 'word': 'math.cos()', 'kind': 'f' },
  125
+      \ { 'word': 'math.cosh()', 'kind': 'f' },
  126
+      \ { 'word': 'math.deg()', 'kind': 'f' },
  127
+      \ { 'word': 'math.exp()', 'kind': 'f' },
  128
+      \ { 'word': 'math.floor()', 'kind': 'f' },
  129
+      \ { 'word': 'math.fmod()', 'kind': 'f' },
  130
+      \ { 'word': 'math.frexp()', 'kind': 'f' },
  131
+      \ { 'word': 'math.huge', 'kind': 'm' },
  132
+      \ { 'word': 'math.ldexp()', 'kind': 'f' },
  133
+      \ { 'word': 'math.log()', 'kind': 'f' },
  134
+      \ { 'word': 'math.log10()', 'kind': 'f' },
  135
+      \ { 'word': 'math.max()', 'kind': 'f' },
  136
+      \ { 'word': 'math.min()', 'kind': 'f' },
  137
+      \ { 'word': 'math.mod()', 'kind': 'f' },
  138
+      \ { 'word': 'math.modf()', 'kind': 'f' },
  139
+      \ { 'word': 'math.pi', 'kind': 'm' },
  140
+      \ { 'word': 'math.pow()', 'kind': 'f' },
  141
+      \ { 'word': 'math.rad()', 'kind': 'f' },
  142
+      \ { 'word': 'math.random()', 'kind': 'f' },
  143
+      \ { 'word': 'math.randomseed()', 'kind': 'f' },
  144
+      \ { 'word': 'math.sin()', 'kind': 'f' },
  145
+      \ { 'word': 'math.sinh()', 'kind': 'f' },
  146
+      \ { 'word': 'math.sqrt()', 'kind': 'f' },
  147
+      \ { 'word': 'math.tan()', 'kind': 'f' },
  148
+      \ { 'word': 'math.tanh()', 'kind': 'f' },
  149
+      \ { 'word': 'os.clock()', 'kind': 'f' },
  150
+      \ { 'word': 'os.date()', 'kind': 'f' },
  151
+      \ { 'word': 'os.difftime()', 'kind': 'f' },
  152
+      \ { 'word': 'os.execute()', 'kind': 'f' },
  153
+      \ { 'word': 'os.exit()', 'kind': 'f' },
  154
+      \ { 'word': 'os.getenv()', 'kind': 'f' },
  155
+      \ { 'word': 'os.remove()', 'kind': 'f' },
  156
+      \ { 'word': 'os.rename()', 'kind': 'f' },
  157
+      \ { 'word': 'os.setlocale()', 'kind': 'f' },
  158
+      \ { 'word': 'os.time()', 'kind': 'f' },
  159
+      \ { 'word': 'os.tmpname()', 'kind': 'f' },
  160
+      \ { 'word': 'package.config', 'kind': 'm' },
  161
+      \ { 'word': 'package.cpath', 'kind': 'm' },
  162
+      \ { 'word': 'package.loaded', 'kind': 'm' },
  163
+      \ { 'word': 'package.loaders', 'kind': 'm' },
  164
+      \ { 'word': 'package.loadlib()', 'kind': 'f' },
  165
+      \ { 'word': 'package.path', 'kind': 'm' },
  166
+      \ { 'word': 'package.preload', 'kind': 'm' },
  167
+      \ { 'word': 'package.seeall()', 'kind': 'f' },
  168
+      \ { 'word': 'string.byte()', 'kind': 'f' },
  169
+      \ { 'word': 'string.char()', 'kind': 'f' },
  170
+      \ { 'word': 'string.dump()', 'kind': 'f' },
  171
+      \ { 'word': 'string.find()', 'kind': 'f' },
  172
+      \ { 'word': 'string.format()', 'kind': 'f' },
  173
+      \ { 'word': 'string.gfind()', 'kind': 'f' },
  174
+      \ { 'word': 'string.gmatch()', 'kind': 'f' },
  175
+      \ { 'word': 'string.gsplit()', 'kind': 'f' },
  176
+      \ { 'word': 'string.gsub()', 'kind': 'f' },
  177
+      \ { 'word': 'string.len()', 'kind': 'f' },
  178
+      \ { 'word': 'string.lower()', 'kind': 'f' },
  179
+      \ { 'word': 'string.match()', 'kind': 'f' },
  180
+      \ { 'word': 'string.rep()', 'kind': 'f' },
  181
+      \ { 'word': 'string.reverse()', 'kind': 'f' },
  182
+      \ { 'word': 'string.sub()', 'kind': 'f' },
  183
+      \ { 'word': 'string.upper()', 'kind': 'f' },
  184
+      \ { 'word': 'table.concat()', 'kind': 'f' },
  185
+      \ { 'word': 'table.foreach()', 'kind': 'f' },
  186
+      \ { 'word': 'table.foreachi()', 'kind': 'f' },
  187
+      \ { 'word': 'table.getn()', 'kind': 'f' },
  188
+      \ { 'word': 'table.insert()', 'kind': 'f' },
  189
+      \ { 'word': 'table.maxn()', 'kind': 'f' },
  190
+      \ { 'word': 'table.remove()', 'kind': 'f' },
  191
+      \ { 'word': 'table.setn()', 'kind': 'f' },
  192
+      \ { 'word': 'table.sort()', 'kind': 'f' } ]
  193
+
  194
+" Function signatures. {{{1
  195
+
  196
+let g:xolox#lua_data#signatures = {
  197
+      \ 'assert': 'assert(v [, message])',
  198
+      \ 'collectgarbage': 'collectgarbage(opt [, arg])',
  199
+      \ 'dofile': 'dofile(filename)',
  200
+      \ 'error': 'error(message [, level])',
  201
+      \ 'getfenv': 'getfenv([f])',
  202
+      \ 'getmetatable': 'getmetatable(object)',
  203
+      \ 'ipairs': 'ipairs(t)',
  204
+      \ 'load': 'load(func [, chunkname])',
  205
+      \ 'loadfile': 'loadfile([filename])',
  206
+      \ 'loadstring': 'loadstring(string [, chunkname])',
  207
+      \ 'next': 'next(table [, index])',
  208
+      \ 'pairs': 'pairs(t)',
  209
+      \ 'pcall': 'pcall(f, arg1, ...)',
  210
+      \ 'print': 'print(...)',
  211
+      \ 'rawequal': 'rawequal(v1, v2)',
  212
+      \ 'rawget': 'rawget(table, index)',
  213
+      \ 'rawset': 'rawset(table, index, value)',
  214
+      \ 'select': 'select(index, ...)',
  215
+      \ 'setfenv': 'setfenv(f, table)',
  216
+      \ 'setmetatable': 'setmetatable(table, metatable)',
  217
+      \ 'tonumber': 'tonumber(e [, base])',
  218
+      \ 'tostring': 'tostring(e)',
  219
+      \ 'type': 'type(v)',
  220
+      \ 'unpack': 'unpack(list [, i [, j]])',
  221
+      \ 'xpcall': 'xpcall(f, err)',
  222
+      \ 'coroutine.create': 'coroutine.create(f)',
  223
+      \ 'coroutine.resume': 'coroutine.resume(co [, val1, ...])',
  224
+      \ 'coroutine.running': 'coroutine.running()',
  225
+      \ 'coroutine.status': 'coroutine.status(co)',
  226
+      \ 'coroutine.wrap': 'coroutine.wrap(f)',
  227
+      \ 'coroutine.yield': 'coroutine.yield(...)',
  228
+      \ 'module': 'module(name [, ...])',
  229
+      \ 'require': 'require(modname)',
  230
+      \ 'package.loadlib': 'package.loadlib(libname, funcname)',
  231
+      \ 'package.seeall': 'package.seeall(module)',
  232
+      \ 'string.byte': 'string.byte(s [, i [, j]])',
  233
+      \ 'string.char': 'string.char(...)',
  234
+      \ 'string.dump': 'string.dump(function)',
  235
+      \ 'string.find': 'string.find(s, pattern [, init [, plain]])',
  236
+      \ 'string.format': 'string.format(formatstring, ...)',
  237
+      \ 'string.gmatch': 'string.gmatch(s, pattern)',
  238
+      \ 'string.gsub': 'string.gsub(s, pattern, repl [, n])',
  239
+      \ 'string.len': 'string.len(s)',
  240
+      \ 'string.lower': 'string.lower(s)',
  241
+      \ 'string.match': 'string.match(s, pattern [, init])',
  242
+      \ 'string.rep': 'string.rep(s, n)',
  243
+      \ 'string.reverse': 'string.reverse(s)',
  244
+      \ 'string.sub': 'string.sub(s, i [, j])',
  245
+      \ 'string.upper': 'string.upper(s)',
  246
+      \ 'table.concat': 'table.concat(table [, sep [, i [, j]]])',
  247
+      \ 'table.insert': 'table.insert(table, [pos,] value)',
  248
+      \ 'table.maxn': 'table.maxn(table)',
  249
+      \ 'table.remove': 'table.remove(table [, pos])',
  250
+      \ 'table.sort': 'table.sort(table [, comp])',
  251
+      \ 'math.abs': 'math.abs(x)',
  252
+      \ 'math.acos': 'math.acos(x)',
  253
+      \ 'math.asin': 'math.asin(x)',
  254
+      \ 'math.atan': 'math.atan(x)',
  255
+      \ 'math.atan2': 'math.atan2(y, x)',
  256
+      \ 'math.ceil': 'math.ceil(x)',
  257
+      \ 'math.cos': 'math.cos(x)',
  258
+      \ 'math.cosh': 'math.cosh(x)',
  259
+      \ 'math.deg': 'math.deg(x)',
  260
+      \ 'math.exp': 'math.exp(x)',
  261
+      \ 'math.floor': 'math.floor(x)',
  262
+      \ 'math.fmod': 'math.fmod(x, y)',
  263
+      \ 'math.frexp': 'math.frexp(x)',
  264
+      \ 'math.ldexp': 'math.ldexp(m, e)',
  265
+      \ 'math.log': 'math.log(x)',
  266
+      \ 'math.log10': 'math.log10(x)',
  267
+      \ 'math.max': 'math.max(x, ...)',
  268
+      \ 'math.min': 'math.min(x, ...)',
  269
+      \ 'math.modf': 'math.modf(x)',
  270
+      \ 'math.pow': 'math.pow(x, y)',
  271
+      \ 'math.rad': 'math.rad(x)',
  272
+      \ 'math.random': 'math.random([m [, n]])',
  273
+      \ 'math.randomseed': 'math.randomseed(x)',
  274
+      \ 'math.sin': 'math.sin(x)',
  275
+      \ 'math.sinh': 'math.sinh(x)',
  276
+      \ 'math.sqrt': 'math.sqrt(x)',
  277
+      \ 'math.tan': 'math.tan(x)',
  278
+      \ 'math.tanh': 'math.tanh(x)',
  279
+      \ 'io.close': 'io.close([file])',
  280
+      \ 'io.flush': 'io.flush()',
  281
+      \ 'io.input': 'io.input([file])',
  282
+      \ 'io.lines': 'io.lines([filename])',
  283
+      \ 'io.open': 'io.open(filename [, mode])',
  284
+      \ 'io.output': 'io.output([file])',
  285
+      \ 'io.popen': 'io.popen(prog [, mode])',
  286
+      \ 'io.read': 'io.read(...)',
  287
+      \ 'io.tmpfile': 'io.tmpfile()',
  288
+      \ 'io.type': 'io.type(obj)',
  289
+      \ 'io.write': 'io.write(...)',
  290
+      \ 'file:close': 'file:close()',
  291
+      \ 'file:flush': 'file:flush()',
  292
+      \ 'file:lines': 'file:lines()',
  293
+      \ 'file:read': 'file:read(...)',
  294
+      \ 'file:seek': 'file:seek([whence] [, offset])',
  295
+      \ 'file:setvbuf': 'file:setvbuf(mode [, size])',
  296
+      \ 'file:write': 'file:write(...)',
  297
+      \ 'os.clock': 'os.clock()',
  298
+      \ 'os.date': 'os.date([format [, time]])',
  299
+      \ 'os.difftime': 'os.difftime(t2, t1)',
  300
+      \ 'os.execute': 'os.execute([command])',
  301
+      \ 'os.exit': 'os.exit([code])',
  302
+      \ 'os.getenv': 'os.getenv(varname)',
  303
+      \ 'os.remove': 'os.remove(filename)',
  304
+      \ 'os.rename': 'os.rename(oldname, newname)',
  305
+      \ 'os.setlocale': 'os.setlocale(locale [, category])',
  306
+      \ 'os.time': 'os.time([table])',
  307
+      \ 'os.tmpname': 'os.tmpname()',
  308
+      \ 'debug.debug': 'debug.debug()',
  309
+      \ 'debug.getfenv': 'debug.getfenv(o)',
  310
+      \ 'debug.gethook': 'debug.gethook([thread])',
  311
+      \ 'debug.getinfo': 'debug.getinfo([thread,] function [, what])',
  312
+      \ 'debug.getlocal': 'debug.getlocal([thread,] level, local)',
  313
+      \ 'debug.getmetatable': 'debug.getmetatable(object)',
  314
+      \ 'debug.getregistry': 'debug.getregistry()',
  315
+      \ 'debug.getupvalue': 'debug.getupvalue(func, up)',
  316
+      \ 'debug.setfenv': 'debug.setfenv(object, table)',
  317
+      \ 'debug.sethook': 'debug.sethook([thread,] hook, mask [, count])',
  318
+      \ 'debug.setlocal': 'debug.setlocal([thread,] level, local, value)',
  319
+      \ 'debug.setmetatable': 'debug.setmetatable(object, table)',
  320
+      \ 'debug.setupvalue': 'debug.setupvalue(func, up, value)',
  321
+      \ 'debug.traceback': 'debug.traceback([thread,] [message] [, level])' }
  322
+
  323
+" }}}
  324
+
  325
+" Restore compatibility options.
  326
+let &cpo = s:cpo_save
  327
+unlet s:cpo_save
  328
+
  329
+" vim: ts=2 sw=2 et
8  ftplugin/lua.vim
@@ -3,7 +3,7 @@
3 3
 " Author: Peter Odding <peter@peterodding.com>
4 4
 " Last Change: June 14, 2011
5 5
 " URL: http://peterodding.com/code/vim/lua-ftplugin
6  
-" Version: 0.6.3
  6
+" Version: 0.6.4
7 7
 
8 8
 " Support for automatic update using the GLVS plug-in.
9 9
 " GetLatestVimScripts: 3625 1 :AutoInstall: lua.zip
@@ -82,6 +82,12 @@ call add(s:undo_ftplugin, "iunmap <buffer> '")
82 82
 inoremap <buffer> <silent> <expr> " xolox#lua#completedynamic('"')
83 83
 call add(s:undo_ftplugin, 'iunmap <buffer> "')
84 84
 
  85
+" Enable tool tips with function signatures? {{{1
  86
+if has('balloon_eval')
  87
+  setlocal ballooneval balloonexpr=xolox#lua#getsignature(v:beval_text)
  88
+  call add(s:undo_ftplugin, 'setlocal ballooneval< balloonexpr<')
  89
+endif
  90
+
85 91
 " }}}1
86 92
 
87 93
 " Let Vim know how to disable the plug-in.
14  misc/lua-ftplugin/getsignatures.lua
... ...
@@ -0,0 +1,14 @@
  1
+#!/usr/bin/env lua
  2
+
  3
+local http = require 'socket.http'
  4
+local webpage = http.request 'http://www.lua.org/manual/5.1/manual.html'
  5
+local matches = {}
  6
+for anchor, signature in webpage:gmatch '<h3>%s*<a%s+name="pdf%-(.-)">%s*<code>%s*(.-)%s*</code>%s*</a>%s*</h3>' do
  7
+  if anchor ~= signature then
  8
+    signature = signature:gsub('&middot;', '.')
  9
+    signature = signature:gsub('%s+%(', '(')
  10
+    table.insert(matches, string.format("'%s': '%s'", anchor, signature))
  11
+  end
  12
+end
  13
+local newline = '\n    \\ '
  14
+print(string.format('let g:xolox#lua_data#signatures = {%s%s }', newline, table.concat(matches, ',' .. newline)))
21  misc/lua-ftplugin/omnicomplete.lua
@@ -25,7 +25,11 @@ local function isident(s)
25 25
   return type(s) == 'string' and s:find('^[A-Za-z_][A-Za-z_0-9]*$') and not keywords[s]
26 26
 end
27 27
 
28  
-local function dump(table, path, cache)
  28
+local function addmatch(output, word, kind, desc)
  29
+  print(string.format("{'word':'%s','kind':'%s','menu':'%s'}", word, kind, desc))
  30
+end
  31
+
  32
+local function dump(table, path, cache, output)
29 33
   local printed = false
30 34
   for key, value in pairs(table) do
31 35
     if isident(key) then
@@ -33,17 +37,17 @@ local function dump(table, path, cache)
33 37
       local vtype = type(value)
34 38
       if vtype == 'function' then
35 39
         printed = true
36  
-        print(path .. "()")
  40
+        addmatch(output, path, 'f', path .. '()')
37 41
       elseif vtype ~= 'table' then
38 42
         printed = true
39  
-        print(path)
  43
+        addmatch(output, path, 'v', path)
40 44
       else
41 45
         if vtype == 'table' and not cache[value] then
42 46
           cache[value] = true
43  
-          if dump(value, path, cache) then
  47
+          if dump(value, path, cache, output) then
44 48
             printed = true
45 49
           else
46  
-            print(path .. "[]")
  50
+            addmatch(output, path, 'm', path .. '[]')
47 51
           end
48 52
         end
49 53
       end
@@ -59,7 +63,6 @@ for _, modulename in ipairs(arg) do
59 63
 end
60 64
 
61 65
 -- Generate completion candidates from global state.
62  
-local cache = {}
63  
-cache[_G] = true
64  
-cache[package.loaded] = true
65  
-dump(_G, nil, cache)
  66
+local cache = { [_G] = true, [package.loaded] = true }
  67
+local output = {}
  68
+dump(_G, nil, cache, output)

0 notes on commit 79a5476

Please sign in to comment.
Something went wrong with that request. Please try again.